Browse Source

Fix failing tests related to year rollover.

I flubbed a few tests and they started to fail once GMT got ahead of my
timezone. This also fixes some invalid values cases that aren't actually
invalid, namely `null` and `-1`.
Mark Story 11 years ago
parent
commit
656c24a532

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

@@ -186,7 +186,7 @@ class DateTimeWidget implements WidgetInterface
      */
     protected function _deconstructDate($value, $options)
     {
-        if (empty($value)) {
+        if ($value === '' || $value === null) {
             return [
                 'year' => '', 'month' => '', 'day' => '',
                 'hour' => '', 'minute' => '', 'second' => '',
@@ -196,7 +196,7 @@ class DateTimeWidget implements WidgetInterface
         try {
             if (is_string($value)) {
                 $date = new \DateTime($value);
-            } elseif (is_bool($value) || $value === null) {
+            } elseif (is_bool($value)) {
                 $date = new \DateTime();
             } elseif (is_int($value)) {
                 $date = new \DateTime('@' . $value);

+ 3 - 5
tests/TestCase/View/Widget/DateTimeWidgetTest.php

@@ -53,11 +53,9 @@ class DateTimeWidgetTest extends TestCase
     public static function invalidSelectedValuesProvider()
     {
         return [
-            'null' => null,
-            'false' => false,
-            'true' => true,
+            'false' => [false],
+            'true' => [true],
             'string' => ['Bag of poop'],
-            'int' => [-1],
             'array' => [[
                 'derp' => 'hurt'
             ]]
@@ -67,7 +65,7 @@ class DateTimeWidgetTest extends TestCase
     /**
      * test rendering selected values.
      *
-     * @dataProvider selectedValuesProvider
+     * @dataProvider invalidSelectedValuesProvider
      * @return void
      */
     public function testRenderSelectedInvalid($selected)