2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Tests\Component\Form;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
|
|
|
require_once __DIR__ . '/Fixtures/TestField.php';
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Form\RepeatedField;
|
|
|
|
use Symfony\Tests\Component\Form\Fixtures\TestField;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
|
|
|
class RepeatedFieldTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
protected $field;
|
|
|
|
|
2010-12-06 14:45:37 +00:00
|
|
|
protected function setUp()
|
2010-06-24 10:24:08 +01:00
|
|
|
{
|
|
|
|
$this->field = new RepeatedField(new TestField('name'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetData()
|
|
|
|
{
|
|
|
|
$this->field->setData('foobar');
|
|
|
|
|
2011-01-19 16:40:29 +00:00
|
|
|
$this->assertEquals('foobar', $this->field['first']->getData());
|
|
|
|
$this->assertEquals('foobar', $this->field['second']->getData());
|
2010-06-24 10:24:08 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 09:59:18 +00:00
|
|
|
public function testSubmitUnequal()
|
2010-06-24 10:24:08 +01:00
|
|
|
{
|
2011-01-19 16:40:29 +00:00
|
|
|
$input = array('first' => 'foo', 'second' => 'bar');
|
2010-06-24 10:24:08 +01:00
|
|
|
|
2011-02-01 09:59:18 +00:00
|
|
|
$this->field->submit($input);
|
2010-06-24 10:24:08 +01:00
|
|
|
|
2011-01-19 16:40:29 +00:00
|
|
|
$this->assertEquals('foo', $this->field['first']->getDisplayedData());
|
|
|
|
$this->assertEquals('bar', $this->field['second']->getDisplayedData());
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertFalse($this->field->isFirstEqualToSecond());
|
|
|
|
$this->assertEquals($input, $this->field->getDisplayedData());
|
2011-02-03 12:28:29 +00:00
|
|
|
$this->assertEquals('foo', $this->field->getData());
|
2010-06-24 10:24:08 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 09:59:18 +00:00
|
|
|
public function testSubmitEqual()
|
2010-06-24 10:24:08 +01:00
|
|
|
{
|
2011-01-19 16:40:29 +00:00
|
|
|
$input = array('first' => 'foo', 'second' => 'foo');
|
2010-06-24 10:24:08 +01:00
|
|
|
|
2011-02-01 09:59:18 +00:00
|
|
|
$this->field->submit($input);
|
2010-06-24 10:24:08 +01:00
|
|
|
|
2011-01-19 16:40:29 +00:00
|
|
|
$this->assertEquals('foo', $this->field['first']->getDisplayedData());
|
|
|
|
$this->assertEquals('foo', $this->field['second']->getDisplayedData());
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertTrue($this->field->isFirstEqualToSecond());
|
|
|
|
$this->assertEquals($input, $this->field->getDisplayedData());
|
|
|
|
$this->assertEquals('foo', $this->field->getData());
|
|
|
|
}
|
2011-02-03 12:28:29 +00:00
|
|
|
|
|
|
|
public function testGetDataReturnsSecondValueIfFirstIsEmpty()
|
|
|
|
{
|
|
|
|
$input = array('first' => '', 'second' => 'bar');
|
|
|
|
|
|
|
|
$this->field->submit($input);
|
|
|
|
|
|
|
|
$this->assertEquals('bar', $this->field->getData());
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|