Merge branch '1.3' of git@github.com:cakephp/cakephp1x into 1.3

* '1.3' of git@github.com:cakephp/cakephp1x:
  Adding tests for and fixing the behavior of `cake acl initdb` it now correctly delegates to SchemaShell.  Fixes #608
  Making TestTask not depend on Inflection rules for creating directory names,  refs #610
  Adding tests for Inflector::rules() clearing cached values.  Fixes #609
  Clear cache of pluralized, singularized and tableize when set rules.
This commit is contained in:
José Lorenzo Rodríguez 2010-04-22 16:50:25 -04:30
commit fca070fe9e
5 changed files with 41 additions and 3 deletions

View file

@ -379,7 +379,7 @@ class AclShell extends Shell {
* @access public * @access public
*/ */
function initdb() { function initdb() {
$this->Dispatch->args = array('schema', 'run', 'create', 'DbAcl'); $this->Dispatch->args = array('schema', 'create', 'DbAcl');
$this->Dispatch->dispatch(); $this->Dispatch->dispatch();
} }

View file

@ -423,7 +423,7 @@ class TestTask extends BakeTask {
*/ */
function testCaseFileName($type, $className) { function testCaseFileName($type, $className) {
$path = $this->getPath();; $path = $this->getPath();;
$path .= 'cases' . DS . Inflector::tableize($type) . DS; $path .= 'cases' . DS . strtolower($type) . 's' . DS;
if (strtolower($type) == 'controller') { if (strtolower($type) == 'controller') {
$className = $this->getRealClassName($type, $className); $className = $this->getRealClassName($type, $className);
} }

View file

@ -370,6 +370,11 @@ class Inflector {
$_this->{$var}[$rule] = array_merge($pattern, $_this->{$var}[$rule]); $_this->{$var}[$rule] = array_merge($pattern, $_this->{$var}[$rule]);
} }
unset($rules[$rule], $_this->{$var}['cache' . ucfirst($rule)], $_this->{$var}['merged'][$rule]); unset($rules[$rule], $_this->{$var}['cache' . ucfirst($rule)], $_this->{$var}['merged'][$rule]);
if ($type === 'plural') {
$_this->_pluralized = $_this->_tableize = array();
} elseif ($type === 'singular') {
$_this->_singularized = array();
}
} }
} }
$_this->{$var}['rules'] = array_merge($rules, $_this->{$var}['rules']); $_this->{$var}['rules'] = array_merge($rules, $_this->{$var}['rules']);

View file

@ -36,7 +36,7 @@ if (!class_exists('AclShell')) {
Mock::generatePartial( Mock::generatePartial(
'ShellDispatcher', 'TestAclShellMockShellDispatcher', 'ShellDispatcher', 'TestAclShellMockShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment') array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'dispatch')
); );
Mock::generatePartial( Mock::generatePartial(
'AclShell', 'MockAclShell', 'AclShell', 'MockAclShell',
@ -331,5 +331,17 @@ class AclShellTest extends CakeTestCase {
$this->Task->expectAt(3, 'out', array(' [4] Elrond')); $this->Task->expectAt(3, 'out', array(' [4] Elrond'));
$this->Task->getPath(); $this->Task->getPath();
} }
/**
* test that initdb makes the correct call.
*
* @return void
*/
function testInitDb() {
$this->Task->Dispatch->expectOnce('dispatch');
$this->Task->initdb();
$this->assertEqual($this->Task->Dispatch->args, array('schema', 'create', 'DbAcl'));
}
} }
?> ?>

View file

@ -400,6 +400,27 @@ class InflectorTest extends CakeTestCase {
$this->assertEqual(Inflector::slug('Testing æ ø å', '-', array('/ø/' => 'oe')), 'Testing-ae-oe-aa'); $this->assertEqual(Inflector::slug('Testing æ ø å', '-', array('/ø/' => 'oe')), 'Testing-ae-oe-aa');
} }
/**
* test that setting new rules clears the inflector caches.
*
* @return void
*/
function testRulesClearsCaches() {
$this->assertEqual(Inflector::singularize('Bananas'), 'Banana');
$this->assertEqual(Inflector::tableize('Banana'), 'bananas');
$this->assertEqual(Inflector::pluralize('Banana'), 'Bananas');
Inflector::rules('singular', array(
'rules' => array('/(.*)nas$/i' => '\1zzz')
));
$this->assertEqual(Inflector::singularize('Bananas'), 'Banazzz', 'Was inflected with old rules. %s');
Inflector::rules('plural', array(
'rules' => array('/(.*)na$/i' => '\1zzz')
));
$this->assertEqual(Inflector::pluralize('Banana'), 'Banazzz', 'Was inflected with old rules. %s');
}
/** /**
* Test resetting inflection rules. * Test resetting inflection rules.
* *