RepeatedFieldTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Symfony\Tests\Component\Form;
  3. require_once __DIR__ . '/Fixtures/TestField.php';
  4. use Symfony\Component\Form\RepeatedField;
  5. use Symfony\Tests\Component\Form\Fixtures\TestField;
  6. class RepeatedFieldTest extends \PHPUnit_Framework_TestCase
  7. {
  8. protected $field;
  9. protected function setUp()
  10. {
  11. $this->field = new RepeatedField(new TestField('name'));
  12. }
  13. public function testSetData()
  14. {
  15. $this->field->setData('foobar');
  16. $this->assertEquals('foobar', $this->field['first']->getData());
  17. $this->assertEquals('foobar', $this->field['second']->getData());
  18. }
  19. public function testBindUnequal()
  20. {
  21. $input = array('first' => 'foo', 'second' => 'bar');
  22. $this->field->bind($input);
  23. $this->assertEquals('foo', $this->field['first']->getDisplayedData());
  24. $this->assertEquals('bar', $this->field['second']->getDisplayedData());
  25. $this->assertFalse($this->field->isFirstEqualToSecond());
  26. $this->assertEquals($input, $this->field->getDisplayedData());
  27. $this->assertEquals(null, $this->field->getData());
  28. }
  29. public function testBindEqual()
  30. {
  31. $input = array('first' => 'foo', 'second' => 'foo');
  32. $this->field->bind($input);
  33. $this->assertEquals('foo', $this->field['first']->getDisplayedData());
  34. $this->assertEquals('foo', $this->field['second']->getDisplayedData());
  35. $this->assertTrue($this->field->isFirstEqualToSecond());
  36. $this->assertEquals($input, $this->field->getDisplayedData());
  37. $this->assertEquals('foo', $this->field->getData());
  38. }
  39. }