RepeatedFieldTest.php 1.6 KB

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