Browse Source

fixed pluralize + singularize rules for tests

tags/2.0.0-beta
Antonio Ramirez 12 years ago
parent
commit
05523640f2
  1. 9
      framework/yii/helpers/base/Inflector.php
  2. 26
      tests/unit/framework/helpers/InflectorTest.php

9
framework/yii/helpers/base/Inflector.php

@ -23,7 +23,12 @@ class Inflector
*/ */
protected static $plural = array( protected static $plural = array(
'rules' => array( 'rules' => array(
'/(m)ove$/i' => '\1oves',
'/(f)oot$/i' => '\1eet',
'/(h)uman$/i' => '\1umans',
'/(s)tatus$/i' => '\1\2tatuses', '/(s)tatus$/i' => '\1\2tatuses',
'/(s)taff$/i' => '\1taff',
'/(t)ooth$/i' => '\1eeth',
'/(quiz)$/i' => '\1zes', '/(quiz)$/i' => '\1zes',
'/^(ox)$/i' => '\1\2en', '/^(ox)$/i' => '\1\2en',
'/([m|l])ouse$/i' => '\1ice', '/([m|l])ouse$/i' => '\1ice',
@ -37,7 +42,7 @@ class Inflector
'/(p)erson$/i' => '\1eople', '/(p)erson$/i' => '\1eople',
'/(m)an$/i' => '\1en', '/(m)an$/i' => '\1en',
'/(c)hild$/i' => '\1hildren', '/(c)hild$/i' => '\1hildren',
'/(buffal|tomat)o$/i' => '\1\2oes', '/(buffal|tomat|potat|ech|her|vet)o$/i' => '\1oes',
'/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i' => '\1i', '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i' => '\1i',
'/us$/i' => 'uses', '/us$/i' => 'uses',
'/(alias)$/i' => '\1es', '/(alias)$/i' => '\1es',
@ -97,6 +102,8 @@ class Inflector
protected static $singular = array( protected static $singular = array(
'rules' => array( 'rules' => array(
'/(s)tatuses$/i' => '\1\2tatus', '/(s)tatuses$/i' => '\1\2tatus',
'/(f)eet$/i' => '\1oot',
'/(t)eeth$/i' => '\1ooth',
'/^(.*)(menu)s$/i' => '\1\2', '/^(.*)(menu)s$/i' => '\1\2',
'/(quiz)zes$/i' => '\\1', '/(quiz)zes$/i' => '\\1',
'/(matr)ices$/i' => '\1ix', '/(matr)ices$/i' => '\1ix',

26
tests/unit/framework/helpers/InflectorTest.php

@ -39,10 +39,28 @@ class InflectorTest extends TestCase
public function testSingularize() public function testSingularize()
{ {
$this->assertEquals("person", Inflector::singularize('people')); $testData = array(
$this->assertEquals("fish", Inflector::singularize('fish')); 'moves' => 'move',
$this->assertEquals("man", Inflector::singularize('men')); 'feet' => 'foot',
$this->assertEquals("table", Inflector::singularize('tables')); 'children' => 'child',
'humans' => 'human',
'men' => 'man',
'staff' => 'staff',
'teeth' => 'tooth',
'people' => 'person',
'mice' => 'mouse',
'touches' => 'touch',
'hashes' => 'hash',
'shelves' => 'shelf',
'potatoes' => 'potato',
'buses' => 'bus',
'tests' => 'test',
'cars' => 'car',
);
foreach ($testData as $testIn => $testOut) {
$this->assertEquals($testOut, Inflector::pluralize($testIn));
$this->assertEquals(ucfirst($testOut), ucfirst(Inflector::pluralize($testIn)));
}
} }
public function testTitleize() public function testTitleize()

Loading…
Cancel
Save