Skip to content

Commit

Permalink
Additional test coverage for changes in RepeatedType
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd authored and root committed Sep 24, 2011
1 parent b23d47d commit 0679220
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 5 deletions.
26 changes: 26 additions & 0 deletions tests/Symfony/Tests/Component/Form/AbstractDivLayoutTest.php
Expand Up @@ -369,6 +369,32 @@ public function testRepeated()
);
}

public function testRepeatedWithCustomOptions()
{
$form = $this->factory->createNamed('repeated', 'name', null, array(
'first_options' => array('label' => 'Test', 'required' => false),
'second_options' => array('label' => 'Test2')
));

$this->assertWidgetMatchesXpath($form->createView(), array(),
'/div
[
./div
[
./label[@for="name_first"][.="[trans]Test[/trans]"]
/following-sibling::input[@type="text"][@id="name_first"][not(@required)]
]
/following-sibling::div
[
./label[@for="name_second"][.="[trans]Test2[/trans]"]
/following-sibling::input[@type="text"][@id="name_second"][@required="required"]
]
]
[count(.//input)=2]
'
);
}

public function testSearchInputName()
{
$form = $this->factory->createNamedBuilder('form', 'full')
Expand Down
34 changes: 32 additions & 2 deletions tests/Symfony/Tests/Component/Form/AbstractTableLayoutTest.php
Expand Up @@ -210,14 +210,44 @@ public function testRepeated()
./td
[./label[@for="name_first"]]
/following-sibling::td
[./input[@id="name_first"]]
[./input[@type="text"][@id="name_first"]]
]
/following-sibling::tr
[
./td
[./label[@for="name_second"]]
/following-sibling::td
[./input[@id="name_second"]]
[./input[@type="text"][@id="name_second"]]
]
]
[count(.//input)=2]
'
);
}

public function testRepeatedWithCustomOptions()
{
$form = $this->factory->createNamed('repeated', 'name', 'foobar', array(
'first_options' => array('label' => 'Test', 'required' => false),
'second_options' => array('label' => 'Test2')
));

$this->assertWidgetMatchesXpath($form->createView(), array(),
'/table
[
./tr
[
./td
[./label[@for="name_first"][.="[trans]Test[/trans]"]]
/following-sibling::td
[./input[@type="text"][@id="name_first"][not(@required)]]
]
/following-sibling::tr
[
./td
[./label[@for="name_second"][.="[trans]Test2[/trans]"]]
/following-sibling::td
[./input[@type="text"][@id="name_second"][@required="required"]]
]
]
[count(.//input)=2]
Expand Down
Expand Up @@ -37,12 +37,24 @@ public function testSetData()
}

public function testSetOptions()
{
$form = $this->factory->create('repeated', null, array(
'type' => 'field',
'options' => array('label' => 'Global'),
));

$this->assertEquals('Global', $form['first']->getAttribute('label'));
$this->assertEquals('Global', $form['second']->getAttribute('label'));
$this->assertTrue($form['first']->isRequired());
$this->assertTrue($form['second']->isRequired());
}

public function testSetOptionsPerField()
{
$form = $this->factory->create('repeated', null, array(
'type' => 'field',
'options' => array('label' => 'Test'),
'first_options' => array('required' => false),
'second_options' => array('label' => 'Test2'),
'first_options' => array('label' => 'Test', 'required' => false),
'second_options' => array('label' => 'Test2')
));

$this->assertEquals('Test', $form['first']->getAttribute('label'));
Expand All @@ -51,6 +63,21 @@ public function testSetOptions()
$this->assertTrue($form['second']->isRequired());
}

public function testSetOptionsPerFieldAndOverwrite()
{
$form = $this->factory->create('repeated', null, array(
'type' => 'field',
'options' => array('label' => 'Label'),
'first_options' => array('required' => false),
'second_options' => array('label' => 'Second label')
));

$this->assertEquals('Label', $form['first']->getAttribute('label'));
$this->assertEquals('Second label', $form['second']->getAttribute('label'));
$this->assertFalse($form['first']->isRequired());
$this->assertTrue($form['second']->isRequired());
}

public function testSubmitUnequal()
{
$input = array('first' => 'foo', 'second' => 'bar');
Expand Down

0 comments on commit 0679220

Please sign in to comment.