Browse Source

Merge pull request #1 from cakephp/3.0

Refreshing branch
André Teixeira 11 years ago
parent
commit
1db621694c

+ 3 - 0
src/Database/Type/DateTimeType.php

@@ -135,6 +135,9 @@ class DateTimeType extends \Cake\Database\Type
             return $value;
         }
 
+        if (is_array($value) && implode('', $value) === '') {
+            return null;
+        }
         $value += ['hour' => 0, 'minute' => 0, 'second' => 0];
 
         $format = '';

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

@@ -2143,9 +2143,8 @@ class FormHelper extends Helper
                 $options[$type] = [];
             }
 
-            // Pass empty boolean to each type.
+            // Pass empty options to each type.
             if (!empty($options['empty']) &&
-                is_bool($options['empty']) &&
                 is_array($options[$type])
             ) {
                 $options[$type]['empty'] = $options['empty'];

+ 32 - 0
tests/TestCase/Controller/Component/FlashComponentTest.php

@@ -147,4 +147,36 @@ class FlashComponentTest extends TestCase
         $result = $this->Session->read('Flash.flash');
         $this->assertEquals($expected, $result);
     }
+
+    /**
+     * Test magic call method.
+     *
+     * @covers \Cake\Controller\Component\FlashComponent::__call
+     * @return void
+     */
+    public function testCall()
+    {
+        $this->assertNull($this->Session->read('Flash.flash'));
+
+        $this->Flash->success('It worked');
+        $expected = [
+            'message' => 'It worked',
+            'key' => 'flash',
+            'element' => 'Flash/success',
+            'params' => []
+        ];
+        $result = $this->Session->read('Flash.flash');
+        $this->assertEquals($expected, $result);
+
+        $this->Flash->error('It did not work', ['element' => 'error_thing']);
+
+        $expected = [
+            'message' => 'It did not work',
+            'key' => 'flash',
+            'element' => 'Flash/error',
+            'params' => []
+        ];
+        $result = $this->Session->read('Flash.flash');
+        $this->assertEquals($expected, $result, 'Element is ignored in magic call.');
+    }
 }

+ 4 - 0
tests/TestCase/Database/Type/DateTimeTypeTest.php

@@ -116,6 +116,10 @@ class DateTimeTypeTest extends TestCase
 
             // valid array types
             [
+                ['year' => '', 'month' => '', 'day' => '', 'hour' => '', 'minute' => '', 'second' => ''],
+                null
+            ],
+            [
                 ['year' => 2014, 'month' => 2, 'day' => 14, 'hour' => 13, 'minute' => 14, 'second' => 15],
                 new Time('2014-02-14 13:14:15')
             ],

+ 4 - 0
tests/TestCase/Database/Type/DateTypeTest.php

@@ -112,6 +112,10 @@ class DateTypeTest extends TestCase
 
             // valid array types
             [
+                ['year' => '', 'month' => '', 'day' => ''],
+                null,
+            ],
+            [
                 ['year' => 2014, 'month' => 2, 'day' => 14, 'hour' => 13, 'minute' => 14, 'second' => 15],
                 new Time('2014-02-14 00:00:00')
             ],

+ 8 - 0
tests/TestCase/Database/Type/TimeTypeTest.php

@@ -111,6 +111,14 @@ class TimeTypeTest extends TestCase
 
             // valid array types
             [
+                ['hour' => '', 'minute' => '', 'second' => ''],
+                null,
+            ],
+            [
+                ['hour' => '', 'minute' => '', 'meridian' => ''],
+                null,
+            ],
+            [
                 ['year' => 2014, 'month' => 2, 'day' => 14, 'hour' => 13, 'minute' => 14, 'second' => 15],
                 new Time('2014-02-14 13:14:15')
             ],

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

@@ -5178,6 +5178,11 @@ class FormHelperTest extends TestCase
             '*/select',
         ];
         $this->assertHtml($expected, $result);
+
+        $result = $this->Form->month('Contact.published', [
+            'empty' => 'Published on',
+        ]);
+        $this->assertContains('Published on', $result);
     }
 
     /**
@@ -5268,6 +5273,11 @@ class FormHelperTest extends TestCase
             '/select',
         ];
         $this->assertHtml($expected, $result);
+
+        $result = $this->Form->day('Contact.published', [
+            'empty' => 'Published on',
+        ]);
+        $this->assertContains('Published on', $result);
     }
 
     /**
@@ -5545,6 +5555,11 @@ class FormHelperTest extends TestCase
             '/select',
         ];
         $this->assertHtml($expected, $result);
+
+        $result = $this->Form->year('Contact.published', [
+            'empty' => 'Published on',
+        ]);
+        $this->assertContains('Published on', $result);
     }
 
     /**