4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Tests\Extension\Core\Type
;
14 class RepeatedTypeTest
extends \Symfony\Component\Form\Test\TypeTestCase
18 protected function setUp()
22 $this->form
= $this->factory
->create('repeated', null, array(
25 $this->form
->setData(null);
28 public function testSetData()
30 $this->form
->setData('foobar');
32 $this->assertEquals('foobar', $this->form
['first']->getData());
33 $this->assertEquals('foobar', $this->form
['second']->getData());
36 public function testSetOptions()
38 $form = $this->factory
->create('repeated', null, array(
40 'options' => array('label' => 'Global'),
43 $this->assertEquals('Global', $form['first']->getConfig()->getOption('label'));
44 $this->assertEquals('Global', $form['second']->getConfig()->getOption('label'));
45 $this->assertTrue($form['first']->isRequired());
46 $this->assertTrue($form['second']->isRequired());
49 public function testSetOptionsPerChild()
51 $form = $this->factory
->create('repeated', null, array(
52 // the global required value cannot be overridden
54 'first_options' => array('label' => 'Test', 'required' => false),
55 'second_options' => array('label' => 'Test2')
58 $this->assertEquals('Test', $form['first']->getConfig()->getOption('label'));
59 $this->assertEquals('Test2', $form['second']->getConfig()->getOption('label'));
60 $this->assertTrue($form['first']->isRequired());
61 $this->assertTrue($form['second']->isRequired());
64 public function testSetRequired()
66 $form = $this->factory
->create('repeated', null, array(
71 $this->assertFalse($form['first']->isRequired());
72 $this->assertFalse($form['second']->isRequired());
75 public function testSetErrorBubblingToTrue()
77 $form = $this->factory
->create('repeated', null, array(
78 'error_bubbling' => true,
81 $this->assertTrue($form->getConfig()->getOption('error_bubbling'));
82 $this->assertTrue($form['first']->getConfig()->getOption('error_bubbling'));
83 $this->assertTrue($form['second']->getConfig()->getOption('error_bubbling'));
86 public function testSetErrorBubblingToFalse()
88 $form = $this->factory
->create('repeated', null, array(
89 'error_bubbling' => false,
92 $this->assertFalse($form->getConfig()->getOption('error_bubbling'));
93 $this->assertFalse($form['first']->getConfig()->getOption('error_bubbling'));
94 $this->assertFalse($form['second']->getConfig()->getOption('error_bubbling'));
97 public function testSetErrorBubblingIndividually()
99 $form = $this->factory
->create('repeated', null, array(
100 'error_bubbling' => true,
101 'options' => array('error_bubbling' => false),
102 'second_options' => array('error_bubbling' => true),
105 $this->assertTrue($form->getConfig()->getOption('error_bubbling'));
106 $this->assertFalse($form['first']->getConfig()->getOption('error_bubbling'));
107 $this->assertTrue($form['second']->getConfig()->getOption('error_bubbling'));
110 public function testSetOptionsPerChildAndOverwrite()
112 $form = $this->factory
->create('repeated', null, array(
114 'options' => array('label' => 'Label'),
115 'second_options' => array('label' => 'Second label')
118 $this->assertEquals('Label', $form['first']->getConfig()->getOption('label'));
119 $this->assertEquals('Second label', $form['second']->getConfig()->getOption('label'));
120 $this->assertTrue($form['first']->isRequired());
121 $this->assertTrue($form['second']->isRequired());
124 public function testSubmitUnequal()
126 $input = array('first' => 'foo', 'second' => 'bar');
128 $this->form
->submit($input);
130 $this->assertEquals('foo', $this->form
['first']->getViewData());
131 $this->assertEquals('bar', $this->form
['second']->getViewData());
132 $this->assertFalse($this->form
->isSynchronized());
133 $this->assertEquals($input, $this->form
->getViewData());
134 $this->assertNull($this->form
->getData());
137 public function testSubmitEqual()
139 $input = array('first' => 'foo', 'second' => 'foo');
141 $this->form
->submit($input);
143 $this->assertEquals('foo', $this->form
['first']->getViewData());
144 $this->assertEquals('foo', $this->form
['second']->getViewData());
145 $this->assertTrue($this->form
->isSynchronized());
146 $this->assertEquals($input, $this->form
->getViewData());
147 $this->assertEquals('foo', $this->form
->getData());