Skip to content
Permalink
Browse files

Forward port changes from #6544 to 3.0

  • Loading branch information...
markstory committed May 12, 2015
1 parent f10d283 commit c7c32b6a13eb6151e81b2cc544cb043c790318b8
Showing with 30 additions and 4 deletions.
  1. +4 −4 src/Utility/Inflector.php
  2. +26 −0 tests/TestCase/Utility/InflectorTest.php
@@ -511,8 +511,8 @@ public static function pluralize($word)
static::$_cache['irregular']['pluralize'] = '(?:' . implode('|', array_keys(static::$_irregular)) . ')';
}
if (preg_match('/(.*)\\b(' . static::$_cache['irregular']['pluralize'] . ')$/i', $word, $regs)) {
static::$_cache['pluralize'][$word] = $regs[1] . substr($word, 0, 1) .
if (preg_match('/(.*(?:\\b|_))(' . static::$_cache['irregular']['pluralize'] . ')$/i', $word, $regs)) {
static::$_cache['pluralize'][$word] = $regs[1] . substr($regs[2], 0, 1) .
substr(static::$_irregular[strtolower($regs[2])], 1);
return static::$_cache['pluralize'][$word];
}
@@ -551,8 +551,8 @@ public static function singularize($word)
static::$_cache['irregular']['singular'] = '(?:' . implode('|', static::$_irregular) . ')';
}
if (preg_match('/(.*)\\b(' . static::$_cache['irregular']['singular'] . ')$/i', $word, $regs)) {
static::$_cache['singularize'][$word] = $regs[1] . substr($word, 0, 1) .
if (preg_match('/(.*(?:\\b|_))(' . static::$_cache['irregular']['singular'] . ')$/i', $word, $regs)) {
static::$_cache['singularize'][$word] = $regs[1] . substr($regs[2], 0, 1) .
substr(array_search(strtolower($regs[2]), static::$_irregular), 1);
return static::$_cache['singularize'][$word];
}
@@ -258,6 +258,32 @@ public function testInflectingPlurals()
$this->assertEquals('', Inflector::pluralize(''));
}
/**
* testInflectingMultiWordIrregulars
*
* @return void
*/
public function testInflectingMultiWordIrregulars()
{
// unset the default rules in order to avoid them possibly matching
// the words in case the irregular regex won't match, the tests
// should fail in that case
Inflector::rules('plural', [
'rules' => [],
]);
Inflector::rules('singular', [
'rules' => [],
]);
$this->assertEquals(Inflector::singularize('wisdom teeth'), 'wisdom tooth');
$this->assertEquals(Inflector::singularize('wisdom-teeth'), 'wisdom-tooth');
$this->assertEquals(Inflector::singularize('wisdom_teeth'), 'wisdom_tooth');
$this->assertEquals(Inflector::pluralize('sweet potato'), 'sweet potatoes');
$this->assertEquals(Inflector::pluralize('sweet-potato'), 'sweet-potatoes');
$this->assertEquals(Inflector::pluralize('sweet_potato'), 'sweet_potatoes');
}
/**
* testSlug method
*

0 comments on commit c7c32b6

Please sign in to comment.
You can’t perform that action at this time.