Fixed Inflector bug #2061

Added tests to InflectorTest

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5382 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-07-06 07:06:06 +00:00
parent fd787a9b74
commit aca00e47c8
2 changed files with 21 additions and 6 deletions

View file

@ -120,7 +120,6 @@ class Inflector extends Object {
'hoof' => 'hoofs', 'hoof' => 'hoofs',
'loaf' => 'loaves', 'loaf' => 'loaves',
'man' => 'men', 'man' => 'men',
'menu' => 'menus',
'money' => 'monies', 'money' => 'monies',
'mongoose' => 'mongooses', 'mongoose' => 'mongooses',
'move' => 'moves', 'move' => 'moves',
@ -206,6 +205,7 @@ class Inflector extends Object {
$_this =& Inflector::getInstance(); $_this =& Inflector::getInstance();
$coreSingularRules = array('/(s)tatuses$/i' => '\1\2tatus', $coreSingularRules = array('/(s)tatuses$/i' => '\1\2tatus',
'/^(.*)(menu)s$/i' => '\1\2',
'/(quiz)zes$/i' => '\\1', '/(quiz)zes$/i' => '\\1',
'/(matr)ices$/i' => '\1ix', '/(matr)ices$/i' => '\1ix',
'/(vert|ind)ices$/i' => '\1ex', '/(vert|ind)ices$/i' => '\1ex',
@ -234,9 +234,10 @@ class Inflector extends Object {
'/(m)en$/i' => '\1an', '/(m)en$/i' => '\1an',
'/(c)hildren$/i' => '\1\2hild', '/(c)hildren$/i' => '\1\2hild',
'/(n)ews$/i' => '\1\2ews', '/(n)ews$/i' => '\1\2ews',
'/^(.*us)$/' => '\\1',
'/s$/i' => ''); '/s$/i' => '');
$coreUninflectedSingular = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', '.*us', '.*ss', 'Amoyese', $coreUninflectedSingular = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', '.*ss', 'Amoyese',
'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus', 'carp', 'chassis', 'clippers', 'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus', 'carp', 'chassis', 'clippers',
'cod', 'coitus', 'Congoese', 'contretemps', 'corps', 'debris', 'diabetes', 'djinn', 'eland', 'elk', 'cod', 'coitus', 'Congoese', 'contretemps', 'corps', 'debris', 'diabetes', 'djinn', 'eland', 'elk',
'equipment', 'Faroese', 'flounder', 'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti', 'equipment', 'Faroese', 'flounder', 'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti',
@ -260,7 +261,6 @@ class Inflector extends Object {
'hoofs' => 'hoof', 'hoofs' => 'hoof',
'loaves' => 'loaf', 'loaves' => 'loaf',
'men' => 'man', 'men' => 'man',
'menus' => 'menu',
'monies' => 'money', 'monies' => 'money',
'mongooses' => 'mongoose', 'mongooses' => 'mongoose',
'moves' => 'move', 'moves' => 'move',
@ -300,7 +300,6 @@ class Inflector extends Object {
* @static * @static
*/ */
function singularize($word) { function singularize($word) {
$_this =& Inflector::getInstance(); $_this =& Inflector::getInstance();
if (!isset($_this->singularRules) || empty($_this->singularRules)) { if (!isset($_this->singularRules) || empty($_this->singularRules)) {
$_this->__initSingularRules(); $_this->__initSingularRules();

View file

@ -45,10 +45,18 @@ class InflectorTest extends UnitTestCase {
$expected = 'menu'; $expected = 'menu';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->inflector->singularize('food_menus');
$expected = 'food_menu';
$this->assertEqual($result, $expected);
$result = $this->inflector->singularize('Menus'); $result = $this->inflector->singularize('Menus');
$expected = 'Menu'; $expected = 'Menu';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->inflector->singularize('FoodMenus');
$expected = 'FoodMenu';
$this->assertEqual($result, $expected);
$result = $this->inflector->singularize('houses'); $result = $this->inflector->singularize('houses');
$expected = 'house'; $expected = 'house';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
@ -92,7 +100,7 @@ class InflectorTest extends UnitTestCase {
$result = $this->inflector->singularize('Alias'); $result = $this->inflector->singularize('Alias');
$expected = 'Alias'; $expected = 'Alias';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->inflector->singularize('Media'); $result = $this->inflector->singularize('Media');
$expected = 'Media'; $expected = 'Media';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
@ -119,10 +127,18 @@ class InflectorTest extends UnitTestCase {
$expected = 'menus'; $expected = 'menus';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->inflector->pluralize('food_menu');
$expected = 'food_menus';
$this->assertEqual($result, $expected);
$result = $this->inflector->pluralize('Menu'); $result = $this->inflector->pluralize('Menu');
$expected = 'Menus'; $expected = 'Menus';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->inflector->pluralize('FoodMenu');
$expected = 'FoodMenus';
$this->assertEqual($result, $expected);
$result = $this->inflector->pluralize('quiz'); $result = $this->inflector->pluralize('quiz');
$expected = 'quizzes'; $expected = 'quizzes';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
@ -150,7 +166,7 @@ class InflectorTest extends UnitTestCase {
$result = $this->inflector->pluralize('Aliases'); $result = $this->inflector->pluralize('Aliases');
$expected = 'Aliases'; $expected = 'Aliases';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->inflector->pluralize('Media'); $result = $this->inflector->pluralize('Media');
$expected = 'Media'; $expected = 'Media';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);