Skip to content

Commit

Permalink
Removed unused code from DateType
Browse files Browse the repository at this point in the history
Additional tests for ChoiceType and DateType based code
  • Loading branch information
stloyd committed Jun 20, 2011
1 parent cdd39ac commit 7783a05
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/DateType.php
Expand Up @@ -97,7 +97,6 @@ public function buildForm(FormBuilder $builder, array $options)
$builder
->setAttribute('formatter', $formatter)
->setAttribute('widget', $options['widget'])
->setAttribute('empty_value', $options['empty_value'])
;
}

Expand All @@ -107,7 +106,6 @@ public function buildForm(FormBuilder $builder, array $options)
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();
Expand Down
99 changes: 99 additions & 0 deletions tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php
Expand Up @@ -330,6 +330,7 @@ public function testSingleChoice()
$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"]
Expand Down Expand Up @@ -689,6 +690,24 @@ public function testCountry()
);
}

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())
Expand Down Expand Up @@ -999,6 +1018,61 @@ public function testDateSingleText()
);
}

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(
Expand Down Expand Up @@ -1353,14 +1427,17 @@ public function testTimeWithSeconds()
[@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]
'
Expand All @@ -1382,9 +1459,11 @@ public function testTimeWithEmptyValueGlobal()
./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]
'
Expand All @@ -1406,9 +1485,11 @@ public function testTimeWithEmptyValueOnYear()
./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]
'
Expand All @@ -1424,6 +1505,7 @@ public function testTimezone()
$this->assertWidgetMatchesXpath($form->createView(), array(),
'/select
[@name="na&me"]
[@required="required"]
[./optgroup
[@label="Europe"]
[./option[@value="Europe/Vienna"][@selected="selected"][.="Vienna"]]
Expand All @@ -1434,6 +1516,23 @@ public function testTimezone()
);
}

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';
Expand Down

0 comments on commit 7783a05

Please sign in to comment.