Browse Source

Correct humanize

There isn't any real logic here - it's just a str replace call
AD7six 11 years ago
parent
commit
5273dae2c2
2 changed files with 12 additions and 1 deletions
  1. 10 1
      src/Utility/Inflector.php
  2. 2 0
      tests/TestCase/Utility/InflectorTest.php

+ 10 - 1
src/Utility/Inflector.php

@@ -631,7 +631,16 @@ class Inflector
      */
     public static function humanize($string, $replacement = '_')
     {
-        return ucwords(str_replace($replacement, ' ', static::normalize($string, $replacement)));
+        $cacheKey = __FUNCTION__ . $replacement;
+
+        $result = static::_cache($cacheKey, $string);
+
+        if ($result === false) {
+            $result = ucwords(str_replace($replacement, ' ', $string));
+            static::_cache($cacheKey, $string, $result);
+        }
+
+        return $result;
     }
 
     /**

+ 2 - 0
tests/TestCase/Utility/InflectorTest.php

@@ -428,6 +428,8 @@ class InflectorTest extends TestCase
         $this->assertSame('Test_thing', Inflector::camelize('test_thing', ' '));
         $this->assertSame('Test-thing', Inflector::camelize('test-thing', ' '));
         $this->assertSame('TestThing', Inflector::camelize('test thing', ' '));
+
+        $this->assertSame('TestPlugin.TestPluginComments', Inflector::camelize('TestPlugin.TestPluginComments'));
     }
 
     /**