From 5d7ce86000160de6f7f8fff6403b845889719b23 Mon Sep 17 00:00:00 2001 From: phpnut Date: Sun, 13 May 2007 00:28:03 +0000 Subject: [PATCH] Adding fix for irregular inflections returning word in lowercase git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5065 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/inflector.php | 4 ++-- cake/tests/cases/libs/inflector.test.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index 65045f3c9..2f6d4140f 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -177,7 +177,7 @@ class Inflector extends Object { } if (preg_match('/(.*)\\b(' . $regexIrregular . ')$/i', $word, $regs)) { - $_this->pluralized[$word] = $regs[1] . $irregular[strtolower($regs[2])]; + $_this->pluralized[$word] = $regs[1] . substr($word, 0, 1) . substr($irregular[strtolower($regs[2])], 1); return $_this->pluralized[$word]; } @@ -316,7 +316,7 @@ class Inflector extends Object { } if (preg_match('/(.*)\\b(' . $regexIrregular . ')$/i', $word, $regs)) { - $_this->singularized[$word] = $regs[1] . $irregular[strtolower($regs[2])]; + $_this->singularized[$word] = $regs[1] . substr($word, 0, 1) . substr($irregular[strtolower($regs[2])], 1); return $_this->singularized[$word]; } diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index 940b7a744..60978b3a0 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -45,6 +45,10 @@ class InflectorTest extends UnitTestCase { $expected = 'menu'; $this->assertEqual($result, $expected); + $result = $this->inflector->singularize('Menus'); + $expected = 'Menu'; + $this->assertEqual($result, $expected); + $result = $this->inflector->singularize('houses'); $expected = 'house'; $this->assertEqual($result, $expected); @@ -111,6 +115,10 @@ class InflectorTest extends UnitTestCase { $expected = 'menus'; $this->assertEqual($result, $expected); + $result = $this->inflector->pluralize('Menu'); + $expected = 'Menus'; + $this->assertEqual($result, $expected); + $result = $this->inflector->pluralize('quiz'); $expected = 'quizzes'; $this->assertEqual($result, $expected);