RepeatedFieldTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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. require_once __DIR__ . '/Fixtures/TestField.php';
  12. use Symfony\Component\Form\RepeatedField;
  13. use Symfony\Tests\Component\Form\Fixtures\TestField;
  14. class RepeatedFieldTest extends \PHPUnit_Framework_TestCase
  15. {
  16. protected $field;
  17. protected function setUp()
  18. {
  19. $this->field = new RepeatedField(new TestField('name'));
  20. }
  21. public function testSetData()
  22. {
  23. $this->field->setData('foobar');
  24. $this->assertEquals('foobar', $this->field['first']->getData());
  25. $this->assertEquals('foobar', $this->field['second']->getData());
  26. }
  27. public function testSubmitUnequal()
  28. {
  29. $input = array('first' => 'foo', 'second' => 'bar');
  30. $this->field->submit($input);
  31. $this->assertEquals('foo', $this->field['first']->getDisplayedData());
  32. $this->assertEquals('bar', $this->field['second']->getDisplayedData());
  33. $this->assertFalse($this->field->isFirstEqualToSecond());
  34. $this->assertEquals($input, $this->field->getDisplayedData());
  35. $this->assertEquals('foo', $this->field->getData());
  36. }
  37. public function testSubmitEqual()
  38. {
  39. $input = array('first' => 'foo', 'second' => 'foo');
  40. $this->field->submit($input);
  41. $this->assertEquals('foo', $this->field['first']->getDisplayedData());
  42. $this->assertEquals('foo', $this->field['second']->getDisplayedData());
  43. $this->assertTrue($this->field->isFirstEqualToSecond());
  44. $this->assertEquals($input, $this->field->getDisplayedData());
  45. $this->assertEquals('foo', $this->field->getData());
  46. }
  47. public function testGetDataReturnsSecondValueIfFirstIsEmpty()
  48. {
  49. $input = array('first' => '', 'second' => 'bar');
  50. $this->field->submit($input);
  51. $this->assertEquals('bar', $this->field->getData());
  52. }
  53. }