Browse Source

Make underscore and dasherize consistent

Also Rename normalize to delimit, it isn't normalizing (take
inconsistent and make consistent).
AD7six 11 years ago
parent
commit
11c03e0aa0
2 changed files with 8 additions and 7 deletions
  1. 6 6
      src/Utility/Inflector.php
  2. 2 1
      tests/TestCase/Utility/InflectorTest.php

+ 6 - 6
src/Utility/Inflector.php

@@ -606,7 +606,7 @@ class Inflector
      */
     public static function underscore($string)
     {
-        return static::normalize($string, '_');
+        return static::delimit(str_replace('-', '_', $string), '_');
     }
 
     /**
@@ -617,7 +617,7 @@ class Inflector
      */
     public static function dasherize($string)
     {
-        return static::normalize($string, '-');
+        return static::delimit(str_replace('_', '-', $string), '-');
     }
 
     /**
@@ -644,13 +644,13 @@ class Inflector
     }
 
     /**
-     * Takes the input string, and based on the replacement character converts to a normalized string
+     * Takes the input string, and based on the replacement character converts to a delimited string
      *
-     * @param string $string String to normalize
+     * @param string $string String to delimit
      * @param string $replacement the character to use as a delimiter
-     * @return string normalized string
+     * @return string delimited string
      */
-    public static function normalize($string, $replacement = '_')
+    public static function delimit($string, $replacement = '_')
     {
         $cacheKey = __FUNCTION__ . $replacement;
 

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

@@ -377,6 +377,7 @@ class InflectorTest extends TestCase
         $this->assertSame('test_thing', Inflector::underscore('testThing'));
         $this->assertSame('test_thing_extra', Inflector::underscore('TestThingExtra'));
         $this->assertSame('test_thing_extra', Inflector::underscore('testThingExtra'));
+        $this->assertSame('test_this_thing', Inflector::underscore('test-this-thing'));
 
         // Identical checks test the cache code path.
         $this->assertSame('test_thing', Inflector::underscore('TestThing'));
@@ -401,7 +402,7 @@ class InflectorTest extends TestCase
         $this->assertSame('test-thing', Inflector::dasherize('testThing'));
         $this->assertSame('test-thing-extra', Inflector::dasherize('TestThingExtra'));
         $this->assertSame('test-thing-extra', Inflector::dasherize('testThingExtra'));
-        $this->assertSame('test_this_thing', Inflector::dasherize('test_this_thing'), 'Should be unchanged');
+        $this->assertSame('test-this-thing', Inflector::dasherize('test_this_thing'));
 
         // Test stupid values
         $this->assertSame('', Inflector::dasherize(null));