From 05523640f2a65ae09b75480a445b085b5dca5077 Mon Sep 17 00:00:00 2001 From: Antonio Ramirez Date: Wed, 22 May 2013 10:59:09 +0200 Subject: [PATCH] fixed pluralize + singularize rules for tests --- framework/yii/helpers/base/Inflector.php | 9 ++++++++- tests/unit/framework/helpers/InflectorTest.php | 26 ++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/framework/yii/helpers/base/Inflector.php b/framework/yii/helpers/base/Inflector.php index f233547..3c1927c 100644 --- a/framework/yii/helpers/base/Inflector.php +++ b/framework/yii/helpers/base/Inflector.php @@ -23,7 +23,12 @@ class Inflector */ protected static $plural = array( 'rules' => array( + '/(m)ove$/i' => '\1oves', + '/(f)oot$/i' => '\1eet', + '/(h)uman$/i' => '\1umans', '/(s)tatus$/i' => '\1\2tatuses', + '/(s)taff$/i' => '\1taff', + '/(t)ooth$/i' => '\1eeth', '/(quiz)$/i' => '\1zes', '/^(ox)$/i' => '\1\2en', '/([m|l])ouse$/i' => '\1ice', @@ -37,7 +42,7 @@ class Inflector '/(p)erson$/i' => '\1eople', '/(m)an$/i' => '\1en', '/(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', '/us$/i' => 'uses', '/(alias)$/i' => '\1es', @@ -97,6 +102,8 @@ class Inflector protected static $singular = array( 'rules' => array( '/(s)tatuses$/i' => '\1\2tatus', + '/(f)eet$/i' => '\1oot', + '/(t)eeth$/i' => '\1ooth', '/^(.*)(menu)s$/i' => '\1\2', '/(quiz)zes$/i' => '\\1', '/(matr)ices$/i' => '\1ix', diff --git a/tests/unit/framework/helpers/InflectorTest.php b/tests/unit/framework/helpers/InflectorTest.php index 49c958e..ee6050c 100644 --- a/tests/unit/framework/helpers/InflectorTest.php +++ b/tests/unit/framework/helpers/InflectorTest.php @@ -39,10 +39,28 @@ class InflectorTest extends TestCase public function testSingularize() { - $this->assertEquals("person", Inflector::singularize('people')); - $this->assertEquals("fish", Inflector::singularize('fish')); - $this->assertEquals("man", Inflector::singularize('men')); - $this->assertEquals("table", Inflector::singularize('tables')); + $testData = array( + 'moves' => 'move', + 'feet' => 'foot', + '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()