RepeatedFieldTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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__.'/TestCase.php';
  12. use Symfony\Component\Form\RepeatedField;
  13. use Symfony\Component\Form\Field;
  14. class RepeatedFieldTest extends TestCase
  15. {
  16. protected $field;
  17. protected function setUp()
  18. {
  19. parent::setUp();
  20. $this->field = $this->factory->create('repeated', 'name', array(
  21. 'prototype' => $this->factory->create('field', 'foo'),
  22. ));
  23. $this->field->setData(null);
  24. }
  25. public function testSetData()
  26. {
  27. $this->field->setData('foobar');
  28. $this->assertEquals('foobar', $this->field['first']->getData());
  29. $this->assertEquals('foobar', $this->field['second']->getData());
  30. }
  31. public function testSubmitUnequal()
  32. {
  33. $input = array('first' => 'foo', 'second' => 'bar');
  34. $this->field->bind($input);
  35. $this->assertEquals('foo', $this->field['first']->getTransformedData());
  36. $this->assertEquals('bar', $this->field['second']->getTransformedData());
  37. $this->assertFalse($this->field->isTransformationSuccessful());
  38. $this->assertEquals($input, $this->field->getTransformedData());
  39. $this->assertEquals(null, $this->field->getData());
  40. }
  41. public function testSubmitEqual()
  42. {
  43. $input = array('first' => 'foo', 'second' => 'foo');
  44. $this->field->bind($input);
  45. $this->assertEquals('foo', $this->field['first']->getTransformedData());
  46. $this->assertEquals('foo', $this->field['second']->getTransformedData());
  47. $this->assertTrue($this->field->isTransformationSuccessful());
  48. $this->assertEquals($input, $this->field->getTransformedData());
  49. $this->assertEquals('foo', $this->field->getData());
  50. }
  51. }