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
|
|
|
|
2011-02-24 15:54:34 +00:00
|
|
|
require_once __DIR__.'/TestCase.php';
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Form\RepeatedField;
|
2011-02-22 00:06:06 +00:00
|
|
|
use Symfony\Component\Form\Field;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2011-02-24 15:54:34 +00:00
|
|
|
class RepeatedFieldTest extends TestCase
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
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
|
|
|
{
|
2011-02-24 15:54:34 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
2011-03-02 11:20:30 +00:00
|
|
|
$this->field = $this->factory->getInstance('repeated', 'name', array(
|
|
|
|
'prototype' => $this->factory->getInstance('field', 'foo'),
|
2011-02-24 15:54:34 +00:00
|
|
|
));
|
|
|
|
$this->field->setData(null);
|
2010-06-24 10:24:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2011-02-24 15:54:34 +00:00
|
|
|
$this->assertFalse($this->field->isTransformationSuccessful());
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals($input, $this->field->getDisplayedData());
|
2011-02-24 15:54:34 +00:00
|
|
|
$this->assertEquals(null, $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());
|
2011-02-24 15:54:34 +00:00
|
|
|
$this->assertTrue($this->field->isTransformationSuccessful());
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals($input, $this->field->getDisplayedData());
|
|
|
|
$this->assertEquals('foo', $this->field->getData());
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|