Browse Source

New test caught bug in _getMonthNames.

In implementing the test, a bug was caught. First unset the old value
then assign the new value, not the other way. Since when it gets to
October onwards, the old and new values are equal.

Also updated the test to look for values out of bounds, and fixed code formatting issues.
Kelvin Mok 11 years ago
parent
commit
30d2d8f785

+ 1 - 1
src/View/Widget/DateTimeWidget.php

@@ -525,8 +525,8 @@ class DateTimeWidget implements WidgetInterface
         if ($leadingZero === false) {
             $i = 1;
             foreach ($months as $key => $name) {
-                $months[$i++] = $name;
                 unset($months[$key]);
+                $months[$i++] = $name;
             }
         }
 

+ 17 - 2
tests/TestCase/View/Widget/DateTimeWidgetTest.php

@@ -430,6 +430,7 @@ class DateTimeWidgetTest extends TestCase
             'minute' => false,
             'second' => false,
             'month' => ['data-foo' => 'test', 'names' => true, 'leadingZeroKey' => false],
+            'meridian' => false,
             'val' => $now,
         ], $this->context);
         $expected = [
@@ -454,8 +455,22 @@ class DateTimeWidgetTest extends TestCase
             $result,
             'no 01 in value'
         );
-        
-    }   
+        $this->assertNotContains(
+            'value="0"',
+            $result,
+            'no 0 in value'
+        );
+        $this->assertNotContains(
+            'value="00"',
+            $result,
+            'no 00 in value'
+        );
+        $this->assertNotContains(
+            'value="13"',
+            $result,
+            'no 13 in value'
+        );
+    }
     
     /**
      * Test rendering month widget with names.