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',
'loaf' => 'loaves',
'man' => 'men',
'menu' => 'menus',
'money' => 'monies',
'mongoose' => 'mongooses',
'move' => 'moves',
@ -206,6 +205,7 @@ class Inflector extends Object {
$_this =& Inflector::getInstance();
$coreSingularRules = array('/(s)tatuses$/i' => '\1\2tatus',
'/^(.*)(menu)s$/i' => '\1\2',
'/(quiz)zes$/i' => '\\1',
'/(matr)ices$/i' => '\1ix',
'/(vert|ind)ices$/i' => '\1ex',
@ -234,9 +234,10 @@ class Inflector extends Object {
'/(m)en$/i' => '\1an',
'/(c)hildren$/i' => '\1\2hild',
'/(n)ews$/i' => '\1\2ews',
'/^(.*us)$/' => '\\1',
'/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',
'cod', 'coitus', 'Congoese', 'contretemps', 'corps', 'debris', 'diabetes', 'djinn', 'eland', 'elk',
'equipment', 'Faroese', 'flounder', 'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti',
@ -260,7 +261,6 @@ class Inflector extends Object {
'hoofs' => 'hoof',
'loaves' => 'loaf',
'men' => 'man',
'menus' => 'menu',
'monies' => 'money',
'mongooses' => 'mongoose',
'moves' => 'move',
@ -300,7 +300,6 @@ class Inflector extends Object {
* @static
*/
function singularize($word) {
$_this =& Inflector::getInstance();
if (!isset($_this->singularRules) || empty($_this->singularRules)) {
$_this->__initSingularRules();

View file

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