RepeatedFieldTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Form;
  11. use Symfony\Component\Form\RepeatedField;
  12. use Symfony\Component\Form\Field;
  13. class RepeatedFieldTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected $field;
  16. protected function setUp()
  17. {
  18. $this->field = new RepeatedField(new Field('name'));
  19. }
  20. public function testSetData()
  21. {
  22. $this->field->setData('foobar');
  23. $this->assertEquals('foobar', $this->field['first']->getData());
  24. $this->assertEquals('foobar', $this->field['second']->getData());
  25. }
  26. public function testSubmitUnequal()
  27. {
  28. $input = array('first' => 'foo', 'second' => 'bar');
  29. $this->field->submit($input);
  30. $this->assertEquals('foo', $this->field['first']->getDisplayedData());
  31. $this->assertEquals('bar', $this->field['second']->getDisplayedData());
  32. $this->assertFalse($this->field->isFirstEqualToSecond());
  33. $this->assertEquals($input, $this->field->getDisplayedData());
  34. $this->assertEquals('foo', $this->field->getData());
  35. }
  36. public function testSubmitEqual()
  37. {
  38. $input = array('first' => 'foo', 'second' => 'foo');
  39. $this->field->submit($input);
  40. $this->assertEquals('foo', $this->field['first']->getDisplayedData());
  41. $this->assertEquals('foo', $this->field['second']->getDisplayedData());
  42. $this->assertTrue($this->field->isFirstEqualToSecond());
  43. $this->assertEquals($input, $this->field->getDisplayedData());
  44. $this->assertEquals('foo', $this->field->getData());
  45. }
  46. public function testGetDataReturnsSecondValueIfFirstIsEmpty()
  47. {
  48. $input = array('first' => '', 'second' => 'bar');
  49. $this->field->submit($input);
  50. $this->assertEquals('bar', $this->field->getData());
  51. }
  52. }