Преглед изворни кода

[Form] removed some incomplete unit tests, added some new ones

Fabien Potencier пре 13 година
родитељ
комит
af6f0d5548

+ 8 - 181
tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTypeTest.php

@@ -317,210 +317,37 @@ class DateTypeTest extends LocalizedTestCase
         $this->assertEquals('01.06.2010', $form->getClientData());
     }
 
-    public function testIsYearWithinRangeReturnsTrueIfWithin()
+    public function testYearsOption()
     {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
         $form = $this->factory->create('date', null, array(
-            'data_timezone' => 'UTC',
-            'user_timezone' => 'UTC',
-            'widget' => 'single_text',
-            'years' => array(2010, 2011),
-        ));
-
-        $form->bind('2.6.2010');
-
-        $this->assertTrue($form->isYearWithinRange());
-    }
-
-    public function testIsYearWithinRangeReturnsTrueIfEmpty()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('date', null, array(
-            'data_timezone' => 'UTC',
-            'user_timezone' => 'UTC',
-            'widget' => 'single_text',
             'years' => array(2010, 2011),
         ));
 
-        $form->bind('');
-
-        $this->assertTrue($form->isYearWithinRange());
-    }
-
-    public function testIsYearWithinRangeReturnsTrueIfEmptyChoice()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('date', null, array(
-            'data_timezone' => 'UTC',
-            'user_timezone' => 'UTC',
-            'widget' => 'choice',
-            'years' => array(2010, 2011),
-        ));
-
-        $form->bind(array(
-            'day' => '1',
-            'month' => '2',
-            'year' => '',
-        ));
-
-        $this->assertTrue($form->isYearWithinRange());
-    }
-
-    public function testIsYearWithinRangeReturnsFalseIfNotContained()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('date', null, array(
-            'data_timezone' => 'UTC',
-            'user_timezone' => 'UTC',
-            'widget' => 'single_text',
-            'years' => array(2010, 2012),
-        ));
-
-        $form->bind('2.6.2011');
-
-        $this->assertFalse($form->isYearWithinRange());
-    }
-
-    public function testIsMonthWithinRangeReturnsTrueIfWithin()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('date', null, array(
-            'data_timezone' => 'UTC',
-            'user_timezone' => 'UTC',
-            'widget' => 'single_text',
-            'months' => array(6, 7),
-        ));
-
-        $form->bind('2.6.2010');
-
-        $this->assertTrue($form->isMonthWithinRange());
-    }
-
-    public function testIsMonthWithinRangeReturnsTrueIfEmpty()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('date', null, array(
-            'data_timezone' => 'UTC',
-            'user_timezone' => 'UTC',
-            'widget' => 'single_text',
-            'months' => array(6, 7),
-        ));
-
-        $form->bind('');
+        $view = $form->createView();
 
-        $this->assertTrue($form->isMonthWithinRange());
+        $this->assertSame(array(2010 => '2010', 2011 => '2011'), $view->getChild('year')->get('choices'));
     }
 
-    public function testIsMonthWithinRangeReturnsTrueIfEmptyChoice()
+    public function testMonthsOption()
     {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
         $form = $this->factory->create('date', null, array(
-            'data_timezone' => 'UTC',
-            'user_timezone' => 'UTC',
-            'widget' => 'choice',
             'months' => array(6, 7),
         ));
 
-        $form->bind(array(
-            'day' => '1',
-            'month' => '',
-            'year' => '2011',
-        ));
-
-        $this->assertTrue($form->isMonthWithinRange());
-    }
-
-    public function testIsMonthWithinRangeReturnsFalseIfNotContained()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('date', null, array(
-            'data_timezone' => 'UTC',
-            'user_timezone' => 'UTC',
-            'widget' => 'single_text',
-            'months' => array(6, 8),
-        ));
-
-        $form->bind('2.7.2010');
+        $view = $form->createView();
 
-        $this->assertFalse($form->isMonthWithinRange());
+        $this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('month')->get('choices'));
     }
 
     public function testIsDayWithinRangeReturnsTrueIfWithin()
     {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
         $form = $this->factory->create('date', null, array(
-            'data_timezone' => 'UTC',
-            'user_timezone' => 'UTC',
-            'widget' => 'single_text',
             'days' => array(6, 7),
         ));
 
-        $form->bind('6.6.2010');
-
-        $this->assertTrue($form->isDayWithinRange());
-    }
-
-    public function testIsDayWithinRangeReturnsTrueIfEmpty()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('date', null, array(
-            'data_timezone' => 'UTC',
-            'user_timezone' => 'UTC',
-            'widget' => 'single_text',
-            'days' => array(6, 7),
-        ));
-
-        $form->bind('');
-
-        $this->assertTrue($form->isDayWithinRange());
-    }
-
-    public function testIsDayWithinRangeReturnsTrueIfEmptyChoice()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('date', null, array(
-            'data_timezone' => 'UTC',
-            'user_timezone' => 'UTC',
-            'widget' => 'choice',
-            'days' => array(6, 7),
-        ));
-
-        $form->bind(array(
-            'day' => '',
-            'month' => '1',
-            'year' => '2011',
-        ));
-
-        $this->assertTrue($form->isDayWithinRange());
-    }
-
-    public function testIsDayWithinRangeReturnsFalseIfNotContained()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('date', null, array(
-            'data_timezone' => 'UTC',
-            'user_timezone' => 'UTC',
-            'widget' => 'single_text',
-            'days' => array(6, 8),
-        ));
-
-        $form->bind('7.6.2010');
+        $view = $form->createView();
 
-        $this->assertFalse($form->isDayWithinRange());
+        $this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('day')->get('choices'));
     }
 
     public function testIsPartiallyFilledReturnsFalseIfSingleText()

+ 7 - 106
tests/Symfony/Tests/Component/Form/Extension/Core/Type/TimeTypeTest.php

@@ -235,137 +235,38 @@ class TimeTypeTest extends LocalizedTestCase
         $this->assertEquals($displayedData, $form->getClientData());
     }
 
-    public function testIsHourWithinRange_returnsTrueIfWithin()
+    public function testHoursOption()
     {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('time', null, array(
-            'hours' => array(6, 7),
-        ));
-
-        $form->bind(array('hour' => '06', 'minute' => '12'));
-
-        $this->assertTrue($form->isHourWithinRange());
-    }
-
-    public function testIsHourWithinRange_returnsTrueIfEmpty()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
         $form = $this->factory->create('time', null, array(
             'hours' => array(6, 7),
         ));
 
-        $form->bind(array('hour' => '', 'minute' => '06'));
+        $view = $form->createView();
 
-        $this->assertTrue($form->isHourWithinRange());
-    }
-
-    public function testIsHourWithinRange_returnsFalseIfNotContained()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('time', null, array(
-            'hours' => array(6, 7),
-        ));
-
-        $form->bind(array('hour' => '08', 'minute' => '12'));
-
-        $this->assertFalse($form->isHourWithinRange());
+        $this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('hour')->get('choices'));
     }
 
     public function testIsMinuteWithinRange_returnsTrueIfWithin()
     {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('time', null, array(
-            'minutes' => array(6, 7),
-        ));
-
-        $form->bind(array('hour' => '06', 'minute' => '06'));
-
-        $this->assertTrue($form->isMinuteWithinRange());
-    }
-
-    public function testIsMinuteWithinRange_returnsTrueIfEmpty()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('time', null, array(
-            'minutes' => array(6, 7),
-        ));
-
-        $form->bind(array('hour' => '06', 'minute' => ''));
-
-        $this->assertTrue($form->isMinuteWithinRange());
-    }
-
-    public function testIsMinuteWithinRange_returnsFalseIfNotContained()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
         $form = $this->factory->create('time', null, array(
             'minutes' => array(6, 7),
         ));
 
-        $form->bind(array('hour' => '06', 'minute' => '08'));
+        $view = $form->createView();
 
-        $this->assertFalse($form->isMinuteWithinRange());
+        $this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('minute')->get('choices'));
     }
 
     public function testIsSecondWithinRange_returnsTrueIfWithin()
     {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('time', null, array(
-            'seconds' => array(6, 7),
-            'with_seconds' => true,
-        ));
-
-        $form->bind(array('hour' => '04', 'minute' => '05', 'second' => '06'));
-
-        $this->assertTrue($form->isSecondWithinRange());
-    }
-
-    public function testIsSecondWithinRange_returnsTrueIfEmpty()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('time', null, array(
-            'seconds' => array(6, 7),
-            'with_seconds' => true,
-        ));
-
-        $form->bind(array('hour' => '06', 'minute' => '06', 'second' => ''));
-
-        $this->assertTrue($form->isSecondWithinRange());
-    }
-
-    public function testIsSecondWithinRange_returnsTrueIfNotWithSeconds()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
-        $form = $this->factory->create('time', null, array(
-            'seconds' => array(6, 7),
-        ));
-
-        $form->bind(array('hour' => '06', 'minute' => '06'));
-
-        $this->assertTrue($form->isSecondWithinRange());
-    }
-
-    public function testIsSecondWithinRange_returnsFalseIfNotContained()
-    {
-        $this->markTestIncomplete('Needs to be reimplemented using validators');
-
         $form = $this->factory->create('time', null, array(
             'seconds' => array(6, 7),
             'with_seconds' => true,
         ));
 
-        $form->bind(array('hour' => '04', 'minute' => '05', 'second' => '08'));
+        $view = $form->createView();
 
-        $this->assertFalse($form->isSecondWithinRange());
+        $this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('second')->get('choices'));
     }
 
     public function testIsPartiallyFilled_returnsFalseIfCompletelyEmpty()