diff --git a/tests/Symfony/Tests/Component/Form/AbstractDivLayoutTest.php b/tests/Symfony/Tests/Component/Form/AbstractDivLayoutTest.php index a0536b754e5e..22ddc204c162 100644 --- a/tests/Symfony/Tests/Component/Form/AbstractDivLayoutTest.php +++ b/tests/Symfony/Tests/Component/Form/AbstractDivLayoutTest.php @@ -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') diff --git a/tests/Symfony/Tests/Component/Form/AbstractTableLayoutTest.php b/tests/Symfony/Tests/Component/Form/AbstractTableLayoutTest.php index 304bc6fb340f..c5f2e3c826e9 100644 --- a/tests/Symfony/Tests/Component/Form/AbstractTableLayoutTest.php +++ b/tests/Symfony/Tests/Component/Form/AbstractTableLayoutTest.php @@ -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] diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/RepeatedTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/RepeatedTypeTest.php index 96957d2f1000..fc8afe856cb9 100644 --- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/RepeatedTypeTest.php +++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/RepeatedTypeTest.php @@ -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')); @@ -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');