소스 검색

Removed unused code from DateType
Additional tests for ChoiceType and DateType based code

stloyd 14 년 전
부모
커밋
7783a050c2
2개의 변경된 파일99개의 추가작업 그리고 2개의 파일을 삭제
  1. 0 2
      src/Symfony/Component/Form/Extension/Core/Type/DateType.php
  2. 99 0
      tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php

+ 0 - 2
src/Symfony/Component/Form/Extension/Core/Type/DateType.php

@@ -97,7 +97,6 @@ class DateType extends AbstractType
         $builder
             ->setAttribute('formatter', $formatter)
             ->setAttribute('widget', $options['widget'])
-            ->setAttribute('empty_value', $options['empty_value'])
         ;
     }
 
@@ -107,7 +106,6 @@ class DateType extends AbstractType
     public function buildViewBottomUp(FormView $view, FormInterface $form)
     {
         $view->set('widget', $form->getAttribute('widget'));
-        $view->set('empty_value', $form->getAttribute('empty_value'));
 
         if ($view->hasChildren()) {
             $pattern = $form->getAttribute('formatter')->getPattern();

+ 99 - 0
tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php

@@ -330,6 +330,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         $this->assertWidgetMatchesXpath($form->createView(), array(),
 '/select
     [@name="na&me"]
+    [@required="required"]
     [
         ./option[@value="&a"][@selected="selected"][.="Choice&A"]
         /following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"]
@@ -689,6 +690,24 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         );
     }
 
+    public function testCountryWithEmptyValue()
+    {
+        $form = $this->factory->createNamed('country', 'na&me', 'AT', array(
+            'property_path' => 'name',
+            'empty_value' => 'Select&Country',
+            'required' => false,
+        ));
+
+        $this->assertWidgetMatchesXpath($form->createView(), array(),
+'/select
+    [@name="na&me"]
+    [./option[@value=""][not(@selected)][.="[trans]Select&Country[/trans]"]]
+    [./option[@value="AT"][@selected="selected"][.="Austria"]]
+    [count(./option)>201]
+'
+        );
+    }
+
     public function testCsrf()
     {
         $this->csrfProvider->expects($this->any())
@@ -999,6 +1018,61 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         );
     }
 
+    public function testBirthDay()
+    {
+        $form = $this->factory->createNamed('birthday', 'na&me', '2000-02-03', array(
+            'property_path' => 'name',
+            'input' => 'string',
+        ));
+
+        $this->assertWidgetMatchesXpath($form->createView(), array(),
+'/div
+    [
+        ./select
+            [@id="na&me_month"]
+            [./option[@value="2"][@selected="selected"]]
+        /following-sibling::select
+            [@id="na&me_day"]
+            [./option[@value="3"][@selected="selected"]]
+        /following-sibling::select
+            [@id="na&me_year"]
+            [./option[@value="2000"][@selected="selected"]]
+    ]
+    [count(./select)=3]
+'
+        );
+    }
+
+    public function testBirthDayWithEmptyValue()
+    {
+        $form = $this->factory->createNamed('birthday', 'na&me', '1950-01-01', array(
+            'property_path' => 'name',
+            'input' => 'string',
+            'empty_value' => '',
+            'required' => false,
+        ));
+
+        $this->assertWidgetMatchesXpath($form->createView(), array(),
+'/div
+    [
+        ./select
+            [@id="na&me_month"]
+            [./option[@value=""][.="[trans][/trans]"]]
+            [./option[@value="1"][@selected="selected"]]
+        /following-sibling::select
+            [@id="na&me_day"]
+            [./option[@value=""][.="[trans][/trans]"]]
+            [./option[@value="1"][@selected="selected"]]
+        /following-sibling::select
+            [@id="na&me_year"]
+            [./option[@value=""][.="[trans][/trans]"]]
+            [./option[@value="1950"][@selected="selected"]]
+    ]
+    [count(./select)=3]
+'
+        );
+    }
+
     public function testEmail()
     {
         $form = $this->factory->createNamed('email', 'na&me', 'foo&bar', array(
@@ -1353,14 +1427,17 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             [@id="na&me_hour"]
             [@size="1"]
             [./option[@value="4"][@selected="selected"]]
+            [count(./option)>23]
         /following-sibling::select
             [@id="na&me_minute"]
             [@size="1"]
             [./option[@value="5"][@selected="selected"]]
+            [count(./option)>59]
         /following-sibling::select
             [@id="na&me_second"]
             [@size="1"]
             [./option[@value="6"][@selected="selected"]]
+            [count(./option)>59]
     ]
     [count(./select)=3]
 '
@@ -1382,9 +1459,11 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         ./select
             [@id="na&me_hour"]
             [./option[@value=""][.="[trans]Change&Me[/trans]"]]
+            [count(./option)>24]
         /following-sibling::select
             [@id="na&me_minute"]
             [./option[@value=""][.="[trans]Change&Me[/trans]"]]
+            [count(./option)>60]
     ]
     [count(./select)=2]
 '
@@ -1406,9 +1485,11 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         ./select
             [@id="na&me_hour"]
             [./option[@value=""][.="[trans]Change&Me[/trans]"]]
+            [count(./option)>24]
         /following-sibling::select
             [@id="na&me_minute"]
             [./option[@value="1"]]
+            [count(./option)>59]
     ]
     [count(./select)=2]
 '
@@ -1424,6 +1505,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         $this->assertWidgetMatchesXpath($form->createView(), array(),
 '/select
     [@name="na&me"]
+    [@required="required"]
     [./optgroup
         [@label="Europe"]
         [./option[@value="Europe/Vienna"][@selected="selected"][.="Vienna"]]
@@ -1434,6 +1516,23 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         );
     }
 
+    public function testTimezoneWithEmptyValue()
+    {
+        $form = $this->factory->createNamed('timezone', 'na&me', null, array(
+            'property_path' => 'name',
+            'empty_value' => 'Select&Timezone',
+            'required' => false,
+        ));
+
+        $this->assertWidgetMatchesXpath($form->createView(), array(),
+'/select
+    [./option[@value=""][.="[trans]Select&Timezone[/trans]"]]
+    [count(./optgroup)>10]
+    [count(.//option)>201]
+'
+        );
+    }
+
     public function testUrl()
     {
         $url = 'http://www.google.com?foo1=bar1&foo2=bar2';