Browse Source

Restore second=>true behavior.

This option should have always worked but was missing test coverage
before.

Refs #6518
Mark Story 10 years ago
parent
commit
f02c898d0c

+ 4 - 1
src/View/Helper/FormHelper.php

@@ -2207,7 +2207,10 @@ class FormHelper extends Helper
     protected function _datetimeOptions($options)
     {
         foreach ($this->_datetimeParts as $type) {
-            if (!isset($options[$type])) {
+            if (!array_key_exists($type, $options)) {
+                $options[$type] = [];
+            }
+            if ($options[$type] === true) {
                 $options[$type] = [];
             }
 

+ 20 - 0
tests/TestCase/View/Helper/FormHelperTest.php

@@ -5402,6 +5402,26 @@ class FormHelperTest extends TestCase
     }
 
     /**
+     * test datetime second=true
+     *
+     * @return void
+     */
+    public function testDateTimeSecondOptions()
+    {
+        $result = $this->Form->dateTime('updated', ['second' => true]);
+        $this->assertContains('updated[second]', $result, 'Should have seconds');
+
+        $result = $this->Form->dateTime('updated', ['second' => []]);
+        $this->assertContains('updated[second]', $result, 'Should have seconds');
+
+        $result = $this->Form->dateTime('updated', ['second' => null]);
+        $this->assertNotContains('updated[second]', $result, 'Should not have seconds');
+
+        $result = $this->Form->dateTime('updated', ['second' => false]);
+        $this->assertNotContains('updated[second]', $result, 'Should not have seconds');
+    }
+
+    /**
      * testMonth method
      *
      * @return void

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

@@ -471,7 +471,7 @@ class DateTimeWidgetTest extends TestCase
             'no 13 in value'
         );
     }
-    
+
     /**
      * Test rendering month widget with names.
      *
@@ -899,7 +899,6 @@ class DateTimeWidgetTest extends TestCase
             'hour' => false,
             'minute' => [
                 'data-foo' => 'test',
-                
             ],
             'empty' => '-',
             'default' => '',