Merge branch '2.7' into 2.8
* 2.7: [Serializer] Xml encoder throws exception for valid data [Form] Hardened form type tests fixed CS
This commit is contained in:
commit
663661b30f
@ -29,13 +29,16 @@ use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity;
|
||||
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
|
||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||
use Symfony\Component\Form\Forms;
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
use Symfony\Component\Form\Tests\Extension\Core\Type\BaseTypeTest;
|
||||
use Symfony\Component\Form\Tests\Extension\Core\Type\FormTypeTest;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleAssociationToIntIdEntity;
|
||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
|
||||
|
||||
class EntityTypeTest extends TypeTestCase
|
||||
class EntityTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Bridge\Doctrine\Form\Type\EntityType';
|
||||
|
||||
const ITEM_GROUP_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\GroupableEntity';
|
||||
const SINGLE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity';
|
||||
const SINGLE_IDENT_NO_TO_STRING_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity';
|
||||
@ -116,7 +119,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
*/
|
||||
public function testLegacyName()
|
||||
{
|
||||
$field = $this->factory->createNamed('name', 'entity', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
));
|
||||
@ -129,7 +132,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
*/
|
||||
public function testClassOptionIsRequired()
|
||||
{
|
||||
$this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType');
|
||||
$this->factory->createNamed('name', static::TESTED_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,7 +140,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
*/
|
||||
public function testInvalidClassOption()
|
||||
{
|
||||
$this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'class' => 'foo',
|
||||
));
|
||||
}
|
||||
@ -149,7 +152,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
@ -166,13 +169,14 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$view = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $field->createView()->vars['choices']);
|
||||
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $view->vars['choices']);
|
||||
}
|
||||
|
||||
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
|
||||
@ -183,15 +187,16 @@ class EntityTypeTest extends TypeTestCase
|
||||
$this->persist(array($entity1, $entity2));
|
||||
$qb = $this->em->createQueryBuilder()->select('e')->from(self::SINGLE_IDENT_CLASS, 'e');
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$view = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
'choice_label' => 'name',
|
||||
'query_builder' => $qb,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $field->createView()->vars['choices']);
|
||||
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $view->vars['choices']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -199,7 +204,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
*/
|
||||
public function testConfigureQueryBuilderWithNonQueryBuilderAndNonClosure()
|
||||
{
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'query_builder' => new \stdClass(),
|
||||
@ -211,7 +216,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
*/
|
||||
public function testConfigureQueryBuilderWithClosureReturningNonQueryBuilder()
|
||||
{
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'query_builder' => function () {
|
||||
@ -229,7 +234,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'query_builder' => function () {
|
||||
@ -242,7 +247,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
public function testSetDataSingleNull()
|
||||
{
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => false,
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
@ -255,7 +260,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
public function testSetDataMultipleExpandedNull()
|
||||
{
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'em' => 'default',
|
||||
@ -269,7 +274,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
public function testSetDataMultipleNonExpandedNull()
|
||||
{
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -281,47 +286,6 @@ class EntityTypeTest extends TypeTestCase
|
||||
$this->assertSame(array(), $field->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitSingleExpandedNull()
|
||||
{
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
));
|
||||
$field->submit(null);
|
||||
|
||||
$this->assertNull($field->getData());
|
||||
$this->assertSame('', $field->getViewData(), 'View data is always a string');
|
||||
}
|
||||
|
||||
public function testSubmitSingleNonExpandedNull()
|
||||
{
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
));
|
||||
$field->submit(null);
|
||||
|
||||
$this->assertNull($field->getData());
|
||||
$this->assertSame('', $field->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitMultipleNull()
|
||||
{
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
'multiple' => true,
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
));
|
||||
$field->submit(null);
|
||||
|
||||
$this->assertEquals(new ArrayCollection(), $field->getData());
|
||||
$this->assertSame(array(), $field->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitSingleNonExpandedSingleIdentifier()
|
||||
{
|
||||
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||
@ -329,7 +293,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -354,7 +318,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($innerEntity1, $innerEntity2, $entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -376,7 +340,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -400,7 +364,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -429,7 +393,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($innerEntity1, $innerEntity2, $innerEntity3, $entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -454,7 +418,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -485,7 +449,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -511,7 +475,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -541,7 +505,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'em' => 'default',
|
||||
@ -567,7 +531,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'em' => 'default',
|
||||
@ -596,7 +560,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'em' => 'default',
|
||||
@ -621,7 +585,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -643,7 +607,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'em' => 'default',
|
||||
@ -669,7 +633,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -700,7 +664,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -725,7 +689,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'em' => 'default',
|
||||
@ -755,7 +719,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
// not all persisted entities should be displayed
|
||||
@ -778,7 +742,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'choice_label' => 'name',
|
||||
@ -800,7 +764,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::ITEM_GROUP_CLASS,
|
||||
'choice_label' => 'name',
|
||||
@ -831,7 +795,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'choice_label' => 'name',
|
||||
@ -857,7 +821,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($item1, $item2, $item3, $item4));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::ITEM_GROUP_CLASS,
|
||||
'choices' => array($item1, $item2, $item3, $item4),
|
||||
@ -888,7 +852,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'preferred_choices' => array($entity3, $entity2),
|
||||
@ -907,7 +871,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'choices' => array($entity2, $entity3),
|
||||
@ -927,7 +891,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'choices' => array($entity1, $entity2),
|
||||
@ -950,7 +914,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($innerEntity1, $innerEntity2, $entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_ASSOC_IDENT_CLASS,
|
||||
'choices' => array($entity1, $entity2),
|
||||
@ -971,7 +935,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::COMPOSITE_IDENT_CLASS,
|
||||
'choices' => array($entity1, $entity2),
|
||||
@ -994,7 +958,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$repository = $this->em->getRepository(self::SINGLE_IDENT_CLASS);
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'query_builder' => $repository->createQueryBuilder('e')
|
||||
@ -1022,7 +986,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$repository = $this->em->getRepository(self::SINGLE_ASSOC_IDENT_CLASS);
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_ASSOC_IDENT_CLASS,
|
||||
'query_builder' => $repository->createQueryBuilder('e')
|
||||
@ -1044,10 +1008,10 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'query_builder' => function ($repository) {
|
||||
'query_builder' => function (EntityRepository $repository) {
|
||||
return $repository->createQueryBuilder('e')
|
||||
->where('e.id IN (1, 2)');
|
||||
},
|
||||
@ -1068,10 +1032,10 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2, $entity3));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::COMPOSITE_IDENT_CLASS,
|
||||
'query_builder' => function ($repository) {
|
||||
'query_builder' => function (EntityRepository $repository) {
|
||||
return $repository->createQueryBuilder('e')
|
||||
->where('e.id1 IN (10, 50)');
|
||||
},
|
||||
@ -1090,7 +1054,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -1111,7 +1075,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
@ -1137,7 +1101,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
->with(self::SINGLE_IDENT_CLASS)
|
||||
->will($this->returnValue($this->em));
|
||||
|
||||
$this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
'choice_label' => 'name',
|
||||
@ -1152,7 +1116,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
$this->emRegistry->expects($this->never())
|
||||
->method('getManagerForClass');
|
||||
|
||||
$this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => $this->em,
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'choice_label' => 'name',
|
||||
@ -1181,15 +1145,15 @@ class EntityTypeTest extends TypeTestCase
|
||||
->addTypeGuesser($entityTypeGuesser)
|
||||
->getFormFactory();
|
||||
|
||||
$formBuilder = $factory->createNamedBuilder('form', 'Symfony\Component\Form\Extension\Core\Type\FormType');
|
||||
$formBuilder = $factory->createNamedBuilder('form', FormTypeTest::TESTED_TYPE);
|
||||
|
||||
$formBuilder->add('property1', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
|
||||
$formBuilder->add('property1', static::TESTED_TYPE, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'query_builder' => $repo->createQueryBuilder('e')->where('e.id IN (1, 2)'),
|
||||
));
|
||||
|
||||
$formBuilder->add('property2', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
|
||||
$formBuilder->add('property2', static::TESTED_TYPE, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'query_builder' => function (EntityRepository $repo) {
|
||||
@ -1197,7 +1161,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
},
|
||||
));
|
||||
|
||||
$formBuilder->add('property3', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
|
||||
$formBuilder->add('property3', static::TESTED_TYPE, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'query_builder' => function (EntityRepository $repo) {
|
||||
@ -1244,15 +1208,15 @@ class EntityTypeTest extends TypeTestCase
|
||||
->addTypeGuesser($entityTypeGuesser)
|
||||
->getFormFactory();
|
||||
|
||||
$formBuilder = $factory->createNamedBuilder('form', 'Symfony\Component\Form\Extension\Core\Type\FormType');
|
||||
$formBuilder = $factory->createNamedBuilder('form', FormTypeTest::TESTED_TYPE);
|
||||
|
||||
$formBuilder->add('property1', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
|
||||
$formBuilder->add('property1', static::TESTED_TYPE, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'query_builder' => $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1),
|
||||
));
|
||||
|
||||
$formBuilder->add('property2', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
|
||||
$formBuilder->add('property2', static::TESTED_TYPE, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'query_builder' => function (EntityRepository $repo) {
|
||||
@ -1260,7 +1224,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
},
|
||||
));
|
||||
|
||||
$formBuilder->add('property3', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
|
||||
$formBuilder->add('property3', static::TESTED_TYPE, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'query_builder' => function (EntityRepository $repo) {
|
||||
@ -1294,14 +1258,14 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1));
|
||||
|
||||
$field1 = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field1 = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field2 = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$field2 = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
@ -1322,14 +1286,15 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||
$view = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
'property' => 'name',
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $field->createView()->vars['choices']);
|
||||
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $view->vars['choices']);
|
||||
}
|
||||
|
||||
protected function createRegistryMock($name, $em)
|
||||
@ -1342,4 +1307,213 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
return $registry;
|
||||
}
|
||||
|
||||
public function testPassDisabledAsOption()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'disabled' => true,
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
));
|
||||
|
||||
$this->assertTrue($form->isDisabled());
|
||||
}
|
||||
|
||||
public function testPassIdAndNameToView()
|
||||
{
|
||||
$view = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals('name', $view->vars['id']);
|
||||
$this->assertEquals('name', $view->vars['name']);
|
||||
$this->assertEquals('name', $view->vars['full_name']);
|
||||
}
|
||||
|
||||
public function testStripLeadingUnderscoresAndDigitsFromId()
|
||||
{
|
||||
$view = $this->factory->createNamed('_09name', static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals('name', $view->vars['id']);
|
||||
$this->assertEquals('_09name', $view->vars['name']);
|
||||
$this->assertEquals('_09name', $view->vars['full_name']);
|
||||
}
|
||||
|
||||
public function testPassIdAndNameToViewWithParent()
|
||||
{
|
||||
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||
->add('child', static::TESTED_TYPE, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
))
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
$this->assertEquals('parent_child', $view['child']->vars['id']);
|
||||
$this->assertEquals('child', $view['child']->vars['name']);
|
||||
$this->assertEquals('parent[child]', $view['child']->vars['full_name']);
|
||||
}
|
||||
|
||||
public function testPassIdAndNameToViewWithGrandParent()
|
||||
{
|
||||
$builder = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||
->add('child', FormTypeTest::TESTED_TYPE);
|
||||
$builder->get('child')->add('grand_child', static::TESTED_TYPE, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
));
|
||||
$view = $builder->getForm()->createView();
|
||||
|
||||
$this->assertEquals('parent_child_grand_child', $view['child']['grand_child']->vars['id']);
|
||||
$this->assertEquals('grand_child', $view['child']['grand_child']->vars['name']);
|
||||
$this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->vars['full_name']);
|
||||
}
|
||||
|
||||
public function testPassTranslationDomainToView()
|
||||
{
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'translation_domain' => 'domain',
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertSame('domain', $view->vars['translation_domain']);
|
||||
}
|
||||
|
||||
public function testInheritTranslationDomainFromParent()
|
||||
{
|
||||
$view = $this->factory
|
||||
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||
'translation_domain' => 'domain',
|
||||
))
|
||||
->add('child', static::TESTED_TYPE, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
))
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
$this->assertEquals('domain', $view['child']->vars['translation_domain']);
|
||||
}
|
||||
|
||||
public function testPreferOwnTranslationDomain()
|
||||
{
|
||||
$view = $this->factory
|
||||
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||
'translation_domain' => 'parent_domain',
|
||||
))
|
||||
->add('child', static::TESTED_TYPE, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'translation_domain' => 'domain',
|
||||
))
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
$this->assertEquals('domain', $view['child']->vars['translation_domain']);
|
||||
}
|
||||
|
||||
public function testDefaultTranslationDomain()
|
||||
{
|
||||
$view = $this->factory
|
||||
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||
->add('child', static::TESTED_TYPE, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
))
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
$this->assertNull($view['child']->vars['translation_domain']);
|
||||
}
|
||||
|
||||
public function testPassLabelToView()
|
||||
{
|
||||
$view = $this->factory->createNamed('__test___field', static::TESTED_TYPE, null, array(
|
||||
'label' => 'My label',
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertSame('My label', $view->vars['label']);
|
||||
}
|
||||
|
||||
public function testPassMultipartFalseToView()
|
||||
{
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertFalse($view->vars['multipart']);
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
));
|
||||
$form->submit(null);
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
$this->assertNull($form->getNormData());
|
||||
$this->assertSame('', $form->getViewData(), 'View data is always a string');
|
||||
}
|
||||
|
||||
public function testSubmitNullExpanded()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'expanded' => true,
|
||||
));
|
||||
$form->submit(null);
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
$this->assertNull($form->getNormData());
|
||||
$this->assertSame('', $form->getViewData(), 'View data is always a string');
|
||||
}
|
||||
|
||||
public function testSubmitNullMultiple()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'multiple' => true,
|
||||
));
|
||||
$form->submit(null);
|
||||
|
||||
$collection = new ArrayCollection();
|
||||
|
||||
$this->assertEquals($collection, $form->getData());
|
||||
$this->assertEquals($collection, $form->getNormData());
|
||||
$this->assertSame(array(), $form->getViewData(), 'View data is always an array');
|
||||
}
|
||||
|
||||
public function testSubmitNullExpandedMultiple()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'expanded' => true,
|
||||
'multiple' => true,
|
||||
));
|
||||
$form->submit(null);
|
||||
|
||||
$collection = new ArrayCollection();
|
||||
|
||||
$this->assertEquals($collection, $form->getData());
|
||||
$this->assertEquals($collection, $form->getNormData());
|
||||
$this->assertSame(array(), $form->getViewData(), 'View data is always an array');
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ use Symfony\Component\Form\Test\TypeTestCase;
|
||||
*/
|
||||
abstract class BaseTypeTest extends TypeTestCase
|
||||
{
|
||||
const TESTED_TYPE = '';
|
||||
|
||||
public function testPassDisabledAsOption()
|
||||
{
|
||||
$form = $this->factory->create($this->getTestedType(), null, array('disabled' => true));
|
||||
@ -47,7 +49,7 @@ abstract class BaseTypeTest extends TypeTestCase
|
||||
|
||||
public function testPassIdAndNameToViewWithParent()
|
||||
{
|
||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||
->add('child', $this->getTestedType())
|
||||
->getForm()
|
||||
->createView();
|
||||
@ -59,8 +61,8 @@ abstract class BaseTypeTest extends TypeTestCase
|
||||
|
||||
public function testPassIdAndNameToViewWithGrandParent()
|
||||
{
|
||||
$builder = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\FormType');
|
||||
$builder = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||
->add('child', FormTypeTest::TESTED_TYPE);
|
||||
$builder->get('child')->add('grand_child', $this->getTestedType());
|
||||
$view = $builder->getForm()->createView();
|
||||
|
||||
@ -71,10 +73,10 @@ abstract class BaseTypeTest extends TypeTestCase
|
||||
|
||||
public function testPassTranslationDomainToView()
|
||||
{
|
||||
$form = $this->factory->create($this->getTestedType(), null, array(
|
||||
$view = $this->factory->create($this->getTestedType(), null, array(
|
||||
'translation_domain' => 'domain',
|
||||
));
|
||||
$view = $form->createView();
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertSame('domain', $view->vars['translation_domain']);
|
||||
}
|
||||
@ -82,7 +84,7 @@ abstract class BaseTypeTest extends TypeTestCase
|
||||
public function testInheritTranslationDomainFromParent()
|
||||
{
|
||||
$view = $this->factory
|
||||
->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||
'translation_domain' => 'domain',
|
||||
))
|
||||
->add('child', $this->getTestedType())
|
||||
@ -95,7 +97,7 @@ abstract class BaseTypeTest extends TypeTestCase
|
||||
public function testPreferOwnTranslationDomain()
|
||||
{
|
||||
$view = $this->factory
|
||||
->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||
'translation_domain' => 'parent_domain',
|
||||
))
|
||||
->add('child', $this->getTestedType(), array(
|
||||
@ -109,7 +111,7 @@ abstract class BaseTypeTest extends TypeTestCase
|
||||
|
||||
public function testDefaultTranslationDomain()
|
||||
{
|
||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||
->add('child', $this->getTestedType())
|
||||
->getForm()
|
||||
->createView();
|
||||
@ -119,19 +121,32 @@ abstract class BaseTypeTest extends TypeTestCase
|
||||
|
||||
public function testPassLabelToView()
|
||||
{
|
||||
$form = $this->factory->createNamed('__test___field', $this->getTestedType(), null, array('label' => 'My label'));
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->createNamed('__test___field', $this->getTestedType(), null, array('label' => 'My label'))
|
||||
->createView();
|
||||
|
||||
$this->assertSame('My label', $view->vars['label']);
|
||||
}
|
||||
|
||||
public function testPassMultipartFalseToView()
|
||||
{
|
||||
$form = $this->factory->create($this->getTestedType());
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->create($this->getTestedType())
|
||||
->createView();
|
||||
|
||||
$this->assertFalse($view->vars['multipart']);
|
||||
}
|
||||
|
||||
abstract protected function getTestedType();
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
$form = $this->factory->create($this->getTestedType());
|
||||
$form->submit(null);
|
||||
|
||||
$this->assertSame($expected, $form->getData());
|
||||
$this->assertSame($norm, $form->getNormData());
|
||||
$this->assertSame($view, $form->getViewData());
|
||||
}
|
||||
|
||||
protected function getTestedType()
|
||||
{
|
||||
return static::TESTED_TYPE;
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,10 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
/**
|
||||
* @author Stepan Anchugov <kixxx1@gmail.com>
|
||||
*/
|
||||
class BirthdayTypeTest extends BaseTypeTest
|
||||
class BirthdayTypeTest extends DateTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\BirthdayType';
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
@ -31,13 +33,8 @@ class BirthdayTypeTest extends BaseTypeTest
|
||||
*/
|
||||
public function testSetInvalidYearsOption()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\BirthdayType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'years' => 'bad value',
|
||||
));
|
||||
}
|
||||
|
||||
protected function getTestedType()
|
||||
{
|
||||
return 'Symfony\Component\Form\Extension\Core\Type\BirthdayType';
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
*/
|
||||
class ButtonTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\ButtonType';
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
@ -28,11 +30,6 @@ class ButtonTypeTest extends BaseTypeTest
|
||||
|
||||
public function testCreateButtonInstances()
|
||||
{
|
||||
$this->assertInstanceOf('Symfony\Component\Form\Button', $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ButtonType'));
|
||||
}
|
||||
|
||||
protected function getTestedType()
|
||||
{
|
||||
return 'Symfony\Component\Form\Extension\Core\Type\ButtonType';
|
||||
$this->assertInstanceOf('Symfony\Component\Form\Button', $this->factory->create(static::TESTED_TYPE));
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,11 @@
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
|
||||
class CheckboxTypeTest extends TypeTestCase
|
||||
class CheckboxTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\CheckboxType';
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
@ -28,7 +29,7 @@ class CheckboxTypeTest extends TypeTestCase
|
||||
|
||||
public function testDataIsFalseByDefault()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType');
|
||||
$form = $this->factory->create(static::TESTED_TYPE);
|
||||
|
||||
$this->assertFalse($form->getData());
|
||||
$this->assertFalse($form->getNormData());
|
||||
@ -37,42 +38,42 @@ class CheckboxTypeTest extends TypeTestCase
|
||||
|
||||
public function testPassValueToView()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array('value' => 'foobar'));
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array('value' => 'foobar'))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals('foobar', $view->vars['value']);
|
||||
}
|
||||
|
||||
public function testCheckedIfDataTrue()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType');
|
||||
$form->setData(true);
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->create(static::TESTED_TYPE)
|
||||
->setData(true)
|
||||
->createView();
|
||||
|
||||
$this->assertTrue($view->vars['checked']);
|
||||
}
|
||||
|
||||
public function testCheckedIfDataTrueWithEmptyValue()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array('value' => ''));
|
||||
$form->setData(true);
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array('value' => ''))
|
||||
->setData(true)
|
||||
->createView();
|
||||
|
||||
$this->assertTrue($view->vars['checked']);
|
||||
}
|
||||
|
||||
public function testNotCheckedIfDataFalse()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType');
|
||||
$form->setData(false);
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->create(static::TESTED_TYPE)
|
||||
->setData(false)
|
||||
->createView();
|
||||
|
||||
$this->assertFalse($view->vars['checked']);
|
||||
}
|
||||
|
||||
public function testSubmitWithValueChecked()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'value' => 'foobar',
|
||||
));
|
||||
$form->submit('foobar');
|
||||
@ -83,7 +84,7 @@ class CheckboxTypeTest extends TypeTestCase
|
||||
|
||||
public function testSubmitWithRandomValueChecked()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'value' => 'foobar',
|
||||
));
|
||||
$form->submit('krixikraxi');
|
||||
@ -94,7 +95,7 @@ class CheckboxTypeTest extends TypeTestCase
|
||||
|
||||
public function testSubmitWithValueUnchecked()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'value' => 'foobar',
|
||||
));
|
||||
$form->submit(null);
|
||||
@ -105,7 +106,7 @@ class CheckboxTypeTest extends TypeTestCase
|
||||
|
||||
public function testSubmitWithEmptyValueChecked()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'value' => '',
|
||||
));
|
||||
$form->submit('');
|
||||
@ -116,7 +117,7 @@ class CheckboxTypeTest extends TypeTestCase
|
||||
|
||||
public function testSubmitWithEmptyValueUnchecked()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'value' => '',
|
||||
));
|
||||
$form->submit(null);
|
||||
@ -127,7 +128,7 @@ class CheckboxTypeTest extends TypeTestCase
|
||||
|
||||
public function testSubmitWithEmptyValueAndFalseUnchecked()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'value' => '',
|
||||
));
|
||||
$form->submit(false);
|
||||
@ -138,7 +139,7 @@ class CheckboxTypeTest extends TypeTestCase
|
||||
|
||||
public function testSubmitWithEmptyValueAndTrueChecked()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'value' => '',
|
||||
));
|
||||
$form->submit(true);
|
||||
@ -162,7 +163,7 @@ class CheckboxTypeTest extends TypeTestCase
|
||||
}
|
||||
);
|
||||
|
||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\CheckboxType')
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||
->addModelTransformer($transformer)
|
||||
->getForm();
|
||||
|
||||
@ -181,4 +182,9 @@ class CheckboxTypeTest extends TypeTestCase
|
||||
array('unchecked', false),
|
||||
);
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull(false, false, null);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -11,18 +11,19 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
use Symfony\Component\Form\Tests\Fixtures\Author;
|
||||
|
||||
class CollectionTypeTest extends TypeTestCase
|
||||
class CollectionTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\CollectionType';
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyName()
|
||||
{
|
||||
$form = $this->factory->create('collection', array(
|
||||
'entry_type' => 'text',
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
));
|
||||
|
||||
$this->assertSame('collection', $form->getConfig()->getType()->getName());
|
||||
@ -30,8 +31,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testContainsNoChildByDefault()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
));
|
||||
|
||||
$this->assertCount(0, $form);
|
||||
@ -39,8 +40,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testSetDataAdjustsSize()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
'entry_options' => array(
|
||||
'attr' => array('maxlength' => 20),
|
||||
),
|
||||
@ -68,8 +69,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testThrowsExceptionIfObjectIsNotTraversable()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
));
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||
$form->setData(new \stdClass());
|
||||
@ -77,8 +78,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testNotResizedIfSubmittedWithMissingData()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
));
|
||||
$form->setData(array('foo@foo.com', 'bar@bar.com'));
|
||||
$form->submit(array('foo@bar.com'));
|
||||
@ -91,8 +92,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testResizedDownIfSubmittedWithMissingDataAndAllowDelete()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
'allow_delete' => true,
|
||||
));
|
||||
$form->setData(array('foo@foo.com', 'bar@bar.com'));
|
||||
@ -106,8 +107,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testResizedDownIfSubmittedWithEmptyDataAndDeleteEmpty()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
'allow_delete' => true,
|
||||
'delete_empty' => true,
|
||||
));
|
||||
@ -123,8 +124,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testDontAddEmptyDataIfDeleteEmpty()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
'allow_add' => true,
|
||||
'delete_empty' => true,
|
||||
));
|
||||
@ -140,8 +141,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testNoDeleteEmptyIfDeleteNotAllowed()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
'allow_delete' => false,
|
||||
'delete_empty' => true,
|
||||
));
|
||||
@ -155,7 +156,7 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testResizedDownIfSubmittedWithCompoundEmptyDataAndDeleteEmpty()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Tests\Fixtures\AuthorType',
|
||||
// If the field is not required, no new Author will be created if the
|
||||
// form is completely empty
|
||||
@ -178,8 +179,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testNotResizedIfSubmittedWithExtraData()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
));
|
||||
$form->setData(array('foo@bar.com'));
|
||||
$form->submit(array('foo@foo.com', 'bar@bar.com'));
|
||||
@ -191,8 +192,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testResizedUpIfSubmittedWithExtraDataAndAllowAdd()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
'allow_add' => true,
|
||||
));
|
||||
$form->setData(array('foo@bar.com'));
|
||||
@ -207,8 +208,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testAllowAddButNoPrototype()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FormType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => FormTypeTest::TESTED_TYPE,
|
||||
'allow_add' => true,
|
||||
'prototype' => false,
|
||||
));
|
||||
@ -219,8 +220,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
public function testPrototypeMultipartPropagation()
|
||||
{
|
||||
$form = $this->factory
|
||||
->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
||||
->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||
'allow_add' => true,
|
||||
'prototype' => true,
|
||||
))
|
||||
@ -231,8 +232,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testGetDataDoesNotContainsPrototypeNameBeforeDataAreSet()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||
'prototype' => true,
|
||||
'allow_add' => true,
|
||||
));
|
||||
@ -243,8 +244,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testGetDataDoesNotContainsPrototypeNameAfterDataAreSet()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||
'allow_add' => true,
|
||||
'prototype' => true,
|
||||
));
|
||||
@ -256,16 +257,16 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testPrototypeNameOption()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FormType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => FormTypeTest::TESTED_TYPE,
|
||||
'prototype' => true,
|
||||
'allow_add' => true,
|
||||
));
|
||||
|
||||
$this->assertSame('__name__', $form->getConfig()->getAttribute('prototype')->getName(), '__name__ is the default');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FormType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'entry_type' => FormTypeTest::TESTED_TYPE,
|
||||
'prototype' => true,
|
||||
'allow_add' => true,
|
||||
'prototype_name' => '__test__',
|
||||
@ -279,8 +280,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
*/
|
||||
public function testLegacyEntryOptions()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\NumberType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||
'type' => NumberTypeTest::TESTED_TYPE,
|
||||
'options' => array('attr' => array('maxlength' => '10')),
|
||||
));
|
||||
|
||||
@ -292,8 +293,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testPrototypeDefaultLabel()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||
'allow_add' => true,
|
||||
'prototype' => true,
|
||||
'prototype_name' => '__test__',
|
||||
@ -304,11 +305,11 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testPrototypeData()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||
'allow_add' => true,
|
||||
'prototype' => true,
|
||||
'prototype_data' => 'foo',
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||
'entry_options' => array(
|
||||
'data' => 'bar',
|
||||
'label' => false,
|
||||
@ -324,10 +325,10 @@ class CollectionTypeTest extends TypeTestCase
|
||||
*/
|
||||
public function testLegacyPrototypeData()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||
'allow_add' => true,
|
||||
'prototype' => true,
|
||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
'type' => TextTypeTest::TESTED_TYPE,
|
||||
'options' => array(
|
||||
'data' => 'bar',
|
||||
'label' => false,
|
||||
@ -339,8 +340,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testPrototypeDefaultRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||
'allow_add' => true,
|
||||
'prototype' => true,
|
||||
'prototype_name' => '__test__',
|
||||
@ -351,8 +352,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testPrototypeSetNotRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||
'allow_add' => true,
|
||||
'prototype' => true,
|
||||
'prototype_name' => '__test__',
|
||||
@ -365,14 +366,14 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testPrototypeSetNotRequiredIfParentNotRequired()
|
||||
{
|
||||
$child = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
||||
$child = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||
'allow_add' => true,
|
||||
'prototype' => true,
|
||||
'prototype_name' => '__test__',
|
||||
));
|
||||
|
||||
$parent = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', array(), array(
|
||||
$parent = $this->factory->create(FormTypeTest::TESTED_TYPE, array(), array(
|
||||
'required' => false,
|
||||
));
|
||||
|
||||
@ -384,8 +385,8 @@ class CollectionTypeTest extends TypeTestCase
|
||||
|
||||
public function testPrototypeNotOverrideRequiredByEntryOptionsInFavorOfParent()
|
||||
{
|
||||
$child = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
||||
$child = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||
'allow_add' => true,
|
||||
'prototype' => true,
|
||||
'prototype_name' => '__test__',
|
||||
@ -394,7 +395,7 @@ class CollectionTypeTest extends TypeTestCase
|
||||
),
|
||||
));
|
||||
|
||||
$parent = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', array(), array(
|
||||
$parent = $this->factory->create(FormTypeTest::TESTED_TYPE, array(), array(
|
||||
'required' => false,
|
||||
));
|
||||
|
||||
@ -404,4 +405,9 @@ class CollectionTypeTest extends TypeTestCase
|
||||
$this->assertFalse($child->createView()->vars['required'], 'Child is not required');
|
||||
$this->assertFalse($child->createView()->vars['prototype']->vars['required'], '"Prototype" should not be required');
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull(array(), array(), array());
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
class CountryTypeTest extends TestCase
|
||||
class CountryTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\CountryType';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
IntlTestHelper::requireIntl($this, false);
|
||||
@ -36,9 +37,8 @@ class CountryTypeTest extends TestCase
|
||||
|
||||
public function testCountriesAreSelectable()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CountryType');
|
||||
$view = $form->createView();
|
||||
$choices = $view->vars['choices'];
|
||||
$choices = $this->factory->create(static::TESTED_TYPE)
|
||||
->createView()->vars['choices'];
|
||||
|
||||
// Don't check objects for identity
|
||||
$this->assertContains(new ChoiceView('DE', 'DE', 'Germany'), $choices, '', false, false);
|
||||
@ -50,9 +50,8 @@ class CountryTypeTest extends TestCase
|
||||
|
||||
public function testUnknownCountryIsNotIncluded()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CountryType', 'Symfony\Component\Form\Extension\Core\Type\CountryType');
|
||||
$view = $form->createView();
|
||||
$choices = $view->vars['choices'];
|
||||
$choices = $this->factory->create(static::TESTED_TYPE, 'country')
|
||||
->createView()->vars['choices'];
|
||||
|
||||
foreach ($choices as $choice) {
|
||||
if ('ZZ' === $choice->value) {
|
||||
@ -60,4 +59,9 @@ class CountryTypeTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, '');
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
class CurrencyTypeTest extends TestCase
|
||||
class CurrencyTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\CurrencyType';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
IntlTestHelper::requireIntl($this, false);
|
||||
@ -36,12 +37,16 @@ class CurrencyTypeTest extends TestCase
|
||||
|
||||
public function testCurrenciesAreSelectable()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CurrencyType');
|
||||
$view = $form->createView();
|
||||
$choices = $view->vars['choices'];
|
||||
$choices = $this->factory->create(static::TESTED_TYPE)
|
||||
->createView()->vars['choices'];
|
||||
|
||||
$this->assertContains(new ChoiceView('EUR', 'EUR', 'Euro'), $choices, '', false, false);
|
||||
$this->assertContains(new ChoiceView('USD', 'USD', 'US Dollar'), $choices, '', false, false);
|
||||
$this->assertContains(new ChoiceView('SIT', 'SIT', 'Slovenian Tolar'), $choices, '', false, false);
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, '');
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,11 @@
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
||||
|
||||
class DateTimeTypeTest extends TestCase
|
||||
class DateTimeTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\DateTimeType';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
\Locale::setDefault('en');
|
||||
@ -35,7 +36,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitDateTime()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'date_widget' => 'choice',
|
||||
@ -63,7 +64,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitString()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'string',
|
||||
@ -89,7 +90,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitTimestamp()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'timestamp',
|
||||
@ -117,7 +118,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitWithoutMinutes()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'date_widget' => 'choice',
|
||||
@ -147,7 +148,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitWithSeconds()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'date_widget' => 'choice',
|
||||
@ -179,7 +180,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitDifferentTimezones()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'America/New_York',
|
||||
'view_timezone' => 'Pacific/Tahiti',
|
||||
'date_widget' => 'choice',
|
||||
@ -211,7 +212,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitDifferentTimezonesDateTime()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'America/New_York',
|
||||
'view_timezone' => 'Pacific/Tahiti',
|
||||
'widget' => 'single_text',
|
||||
@ -230,7 +231,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitStringSingleText()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'string',
|
||||
@ -245,7 +246,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitStringSingleTextWithSeconds()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'string',
|
||||
@ -261,7 +262,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitDifferentPattern()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'date_format' => 'MM*yyyy*dd',
|
||||
'date_widget' => 'single_text',
|
||||
'time_widget' => 'single_text',
|
||||
@ -282,27 +283,27 @@ class DateTimeTypeTest extends TestCase
|
||||
{
|
||||
// Throws an exception if "data_class" option is not explicitly set
|
||||
// to null in the type
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', new \DateTime());
|
||||
$this->factory->create(static::TESTED_TYPE, new \DateTime());
|
||||
}
|
||||
|
||||
public function testSingleTextWidgetShouldUseTheRightInputType()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertEquals('datetime', $view->vars['type']);
|
||||
}
|
||||
|
||||
public function testPassDefaultPlaceholderToViewIfNotRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => false,
|
||||
'with_seconds' => true,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('', $view['date']['year']->vars['placeholder']);
|
||||
$this->assertSame('', $view['date']['month']->vars['placeholder']);
|
||||
$this->assertSame('', $view['date']['day']->vars['placeholder']);
|
||||
@ -313,12 +314,12 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testPassNoPlaceholderToViewIfRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => true,
|
||||
'with_seconds' => true,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertNull($view['date']['year']->vars['placeholder']);
|
||||
$this->assertNull($view['date']['month']->vars['placeholder']);
|
||||
$this->assertNull($view['date']['day']->vars['placeholder']);
|
||||
@ -329,12 +330,12 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testPassPlaceholderAsString()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'placeholder' => 'Empty',
|
||||
'with_seconds' => true,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('Empty', $view['date']['year']->vars['placeholder']);
|
||||
$this->assertSame('Empty', $view['date']['month']->vars['placeholder']);
|
||||
$this->assertSame('Empty', $view['date']['day']->vars['placeholder']);
|
||||
@ -348,12 +349,12 @@ class DateTimeTypeTest extends TestCase
|
||||
*/
|
||||
public function testPassEmptyValueBC()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'empty_value' => 'Empty',
|
||||
'with_seconds' => true,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('Empty', $view['date']['year']->vars['placeholder']);
|
||||
$this->assertSame('Empty', $view['date']['month']->vars['placeholder']);
|
||||
$this->assertSame('Empty', $view['date']['day']->vars['placeholder']);
|
||||
@ -370,7 +371,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testPassPlaceholderAsArray()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'placeholder' => array(
|
||||
'year' => 'Empty year',
|
||||
'month' => 'Empty month',
|
||||
@ -380,9 +381,9 @@ class DateTimeTypeTest extends TestCase
|
||||
'second' => 'Empty second',
|
||||
),
|
||||
'with_seconds' => true,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('Empty year', $view['date']['year']->vars['placeholder']);
|
||||
$this->assertSame('Empty month', $view['date']['month']->vars['placeholder']);
|
||||
$this->assertSame('Empty day', $view['date']['day']->vars['placeholder']);
|
||||
@ -393,7 +394,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => false,
|
||||
'placeholder' => array(
|
||||
'year' => 'Empty year',
|
||||
@ -402,9 +403,9 @@ class DateTimeTypeTest extends TestCase
|
||||
'second' => 'Empty second',
|
||||
),
|
||||
'with_seconds' => true,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('Empty year', $view['date']['year']->vars['placeholder']);
|
||||
$this->assertSame('', $view['date']['month']->vars['placeholder']);
|
||||
$this->assertSame('Empty day', $view['date']['day']->vars['placeholder']);
|
||||
@ -415,7 +416,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testPassPlaceholderAsPartialArrayAddNullIfRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => true,
|
||||
'placeholder' => array(
|
||||
'year' => 'Empty year',
|
||||
@ -424,9 +425,9 @@ class DateTimeTypeTest extends TestCase
|
||||
'second' => 'Empty second',
|
||||
),
|
||||
'with_seconds' => true,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('Empty year', $view['date']['year']->vars['placeholder']);
|
||||
$this->assertNull($view['date']['month']->vars['placeholder']);
|
||||
$this->assertSame('Empty day', $view['date']['day']->vars['placeholder']);
|
||||
@ -437,50 +438,50 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testPassHtml5TypeIfSingleTextAndHtml5Format()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('datetime', $view->vars['type']);
|
||||
}
|
||||
|
||||
public function testDontPassHtml5TypeIfHtml5NotAllowed()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
'html5' => false,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertFalse(isset($view->vars['type']));
|
||||
}
|
||||
|
||||
public function testDontPassHtml5TypeIfNotHtml5Format()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
'format' => 'yyyy-MM-dd HH:mm',
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertFalse(isset($view->vars['type']));
|
||||
}
|
||||
|
||||
public function testDontPassHtml5TypeIfNotSingleText()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'text',
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertFalse(isset($view->vars['type']));
|
||||
}
|
||||
|
||||
public function testDateTypeChoiceErrorsBubbleUp()
|
||||
{
|
||||
$error = new FormError('Invalid!');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null);
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null);
|
||||
|
||||
$form['date']->addError($error);
|
||||
|
||||
@ -491,7 +492,7 @@ class DateTimeTypeTest extends TestCase
|
||||
public function testDateTypeSingleTextErrorsBubbleUp()
|
||||
{
|
||||
$error = new FormError('Invalid!');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'date_widget' => 'single_text',
|
||||
));
|
||||
|
||||
@ -504,7 +505,7 @@ class DateTimeTypeTest extends TestCase
|
||||
public function testTimeTypeChoiceErrorsBubbleUp()
|
||||
{
|
||||
$error = new FormError('Invalid!');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null);
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null);
|
||||
|
||||
$form['time']->addError($error);
|
||||
|
||||
@ -515,7 +516,7 @@ class DateTimeTypeTest extends TestCase
|
||||
public function testTimeTypeSingleTextErrorsBubbleUp()
|
||||
{
|
||||
$error = new FormError('Invalid!');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'time_widget' => 'single_text',
|
||||
));
|
||||
|
||||
@ -527,7 +528,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testPassDefaultChoiceTranslationDomain()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'with_seconds' => true,
|
||||
));
|
||||
|
||||
@ -543,7 +544,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testPassChoiceTranslationDomainAsString()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'choice_translation_domain' => 'messages',
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -559,7 +560,7 @@ class DateTimeTypeTest extends TestCase
|
||||
|
||||
public function testPassChoiceTranslationDomainAsArray()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'choice_translation_domain' => array(
|
||||
'year' => 'foo',
|
||||
'month' => 'test',
|
||||
@ -577,4 +578,41 @@ class DateTimeTypeTest extends TestCase
|
||||
$this->assertFalse($view['time']['minute']->vars['choice_translation_domain']);
|
||||
$this->assertSame('test', $view['time']['second']->vars['choice_translation_domain']);
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, array(
|
||||
// View data is an array of choice values array
|
||||
'date' => array('year' => '', 'month' => '', 'day' => ''),
|
||||
'time' => array('hour' => '', 'minute' => ''),
|
||||
));
|
||||
}
|
||||
|
||||
public function testSubmitNullWithText()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'text',
|
||||
));
|
||||
$form->submit(null);
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
$this->assertNull($form->getNormData());
|
||||
$this->assertSame(array(
|
||||
// View data is an array of choice values array
|
||||
'date' => array('year' => '', 'month' => '', 'day' => ''),
|
||||
'time' => array('hour' => '', 'minute' => ''),
|
||||
), $form->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitNullWithSingleText()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
$form->submit(null);
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
$this->assertNull($form->getNormData());
|
||||
$this->assertSame('', $form->getViewData());
|
||||
}
|
||||
}
|
||||
|
@ -13,11 +13,12 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
class DateTypeTest extends TestCase
|
||||
class DateTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\DateType';
|
||||
|
||||
private $defaultTimezone;
|
||||
|
||||
protected function setUp()
|
||||
@ -47,7 +48,7 @@ class DateTypeTest extends TestCase
|
||||
*/
|
||||
public function testInvalidWidgetOption()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'fake_widget',
|
||||
));
|
||||
}
|
||||
@ -57,14 +58,14 @@ class DateTypeTest extends TestCase
|
||||
*/
|
||||
public function testInvalidInputOption()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'input' => 'fake_input',
|
||||
));
|
||||
}
|
||||
|
||||
public function testSubmitFromSingleTextDateTimeWithDefaultFormat()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'widget' => 'single_text',
|
||||
@ -79,7 +80,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testSubmitFromSingleTextDateTimeWithCustomFormat()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'widget' => 'single_text',
|
||||
@ -100,7 +101,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
\Locale::setDefault('de_DE');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
@ -121,7 +122,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
\Locale::setDefault('de_DE');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
@ -142,7 +143,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
\Locale::setDefault('de_DE');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
@ -165,7 +166,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
\Locale::setDefault('de_DE');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
@ -187,7 +188,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testSubmitFromText()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'widget' => 'text',
|
||||
@ -209,7 +210,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testSubmitFromChoice()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'widget' => 'choice',
|
||||
@ -232,7 +233,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testSubmitFromChoiceEmpty()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'widget' => 'choice',
|
||||
@ -253,7 +254,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testSubmitFromInputDateTimeDifferentPattern()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'format' => 'MM*yyyy*dd',
|
||||
@ -269,7 +270,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testSubmitFromInputStringDifferentPattern()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'format' => 'MM*yyyy*dd',
|
||||
@ -285,7 +286,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testSubmitFromInputTimestampDifferentPattern()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'format' => 'MM*yyyy*dd',
|
||||
@ -303,7 +304,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testSubmitFromInputRawDifferentPattern()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'format' => 'MM*yyyy*dd',
|
||||
@ -328,11 +329,10 @@ class DateTypeTest extends TestCase
|
||||
*/
|
||||
public function testDatePatternWithFormatOption($format, $pattern)
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => $format,
|
||||
));
|
||||
|
||||
$view = $form->createView();
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals($pattern, $view->vars['date_pattern']);
|
||||
}
|
||||
@ -354,7 +354,7 @@ class DateTypeTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfFormatIsNoPattern()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => '0',
|
||||
'widget' => 'single_text',
|
||||
'input' => 'string',
|
||||
@ -367,7 +367,7 @@ class DateTypeTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'months' => array(6, 7),
|
||||
'format' => 'yy',
|
||||
));
|
||||
@ -379,7 +379,7 @@ class DateTypeTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfFormatMissesYearMonthAndDayWithSingleTextWidget()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
'format' => 'wrong',
|
||||
));
|
||||
@ -390,7 +390,7 @@ class DateTypeTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfFormatIsNoConstant()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => 105,
|
||||
));
|
||||
}
|
||||
@ -400,7 +400,7 @@ class DateTypeTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfFormatIsInvalid()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => array(),
|
||||
));
|
||||
}
|
||||
@ -410,7 +410,7 @@ class DateTypeTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfYearsIsInvalid()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'years' => 'bad value',
|
||||
));
|
||||
}
|
||||
@ -420,7 +420,7 @@ class DateTypeTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfMonthsIsInvalid()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'months' => 'bad value',
|
||||
));
|
||||
}
|
||||
@ -430,7 +430,7 @@ class DateTypeTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfDaysIsInvalid()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'days' => 'bad value',
|
||||
));
|
||||
}
|
||||
@ -442,7 +442,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
\Locale::setDefault('de_DE');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'America/New_York',
|
||||
@ -464,7 +464,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
\Locale::setDefault('de_DE');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'America/New_York',
|
||||
@ -484,7 +484,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testYearsOption()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'years' => array(2010, 2011),
|
||||
));
|
||||
|
||||
@ -498,7 +498,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testMonthsOption()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'months' => array(6, 7),
|
||||
'format' => \IntlDateFormatter::SHORT,
|
||||
));
|
||||
@ -518,7 +518,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
\Locale::setDefault('de_AT');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'months' => array(1, 4),
|
||||
'format' => 'dd.MMM.yy',
|
||||
));
|
||||
@ -538,12 +538,11 @@ class DateTypeTest extends TestCase
|
||||
|
||||
\Locale::setDefault('de_AT');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'months' => array(1, 4),
|
||||
'format' => 'dd.MMMM.yy',
|
||||
));
|
||||
|
||||
$view = $form->createView();
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals(array(
|
||||
new ChoiceView(1, '1', 'Jänner'),
|
||||
@ -558,12 +557,11 @@ class DateTypeTest extends TestCase
|
||||
|
||||
\Locale::setDefault('de_AT');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'months' => array(1, 4),
|
||||
'format' => 'dd.MMMM.yy',
|
||||
));
|
||||
|
||||
$view = $form->createView();
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals(array(
|
||||
new ChoiceView(1, '1', 'Jänner'),
|
||||
@ -573,11 +571,10 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testIsDayWithinRangeReturnsTrueIfWithin()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'days' => array(6, 7),
|
||||
));
|
||||
|
||||
$view = $form->createView();
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals(array(
|
||||
new ChoiceView(6, '6', '06'),
|
||||
@ -585,26 +582,9 @@ class DateTypeTest extends TestCase
|
||||
), $view['day']->vars['choices']);
|
||||
}
|
||||
|
||||
public function testIsPartiallyFilledReturnsFalseIfSingleText()
|
||||
public function testIsSynchronizedReturnsTrueIfChoiceAndCompletelyEmpty()
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
|
||||
$form->submit('7.6.2010');
|
||||
|
||||
$this->assertFalse($form->isPartiallyFilled());
|
||||
}
|
||||
|
||||
public function testIsPartiallyFilledReturnsFalseIfChoiceAndCompletelyEmpty()
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'widget' => 'choice',
|
||||
@ -616,33 +596,29 @@ class DateTypeTest extends TestCase
|
||||
'year' => '',
|
||||
));
|
||||
|
||||
$this->assertFalse($form->isPartiallyFilled());
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
}
|
||||
|
||||
public function testIsPartiallyFilledReturnsFalseIfChoiceAndCompletelyFilled()
|
||||
public function testIsSynchronizedReturnsTrueIfChoiceAndCompletelyFilled()
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, new \DateTime(), array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'widget' => 'choice',
|
||||
));
|
||||
|
||||
$form->submit(array(
|
||||
'day' => '2',
|
||||
'day' => '0',
|
||||
'month' => '6',
|
||||
'year' => '2010',
|
||||
));
|
||||
|
||||
$this->assertFalse($form->isPartiallyFilled());
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
}
|
||||
|
||||
public function testIsPartiallyFilledReturnsTrueIfChoiceAndDayEmpty()
|
||||
public function testIsSynchronizedReturnsFalseIfChoiceAndDayEmpty()
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'widget' => 'choice',
|
||||
@ -654,7 +630,7 @@ class DateTypeTest extends TestCase
|
||||
'year' => '2010',
|
||||
));
|
||||
|
||||
$this->assertTrue($form->isPartiallyFilled());
|
||||
$this->assertFalse($form->isSynchronized());
|
||||
}
|
||||
|
||||
public function testPassDatePatternToView()
|
||||
@ -664,8 +640,8 @@ class DateTypeTest extends TestCase
|
||||
|
||||
\Locale::setDefault('de_AT');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType');
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->create(static::TESTED_TYPE)
|
||||
->createView();
|
||||
|
||||
$this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
|
||||
}
|
||||
@ -677,43 +653,40 @@ class DateTypeTest extends TestCase
|
||||
|
||||
\Locale::setDefault('de_AT');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => \IntlDateFormatter::LONG,
|
||||
));
|
||||
|
||||
$view = $form->createView();
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
|
||||
}
|
||||
|
||||
public function testPassDatePatternToViewDifferentPattern()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => 'MMyyyydd',
|
||||
));
|
||||
|
||||
$view = $form->createView();
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertSame('{{ month }}{{ year }}{{ day }}', $view->vars['date_pattern']);
|
||||
}
|
||||
|
||||
public function testPassDatePatternToViewDifferentPatternWithSeparators()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'format' => 'MM*yyyy*dd',
|
||||
));
|
||||
|
||||
$view = $form->createView();
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertSame('{{ month }}*{{ year }}*{{ day }}', $view->vars['date_pattern']);
|
||||
}
|
||||
|
||||
public function testDontPassDatePatternIfText()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
$view = $form->createView();
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertFalse(isset($view->vars['date_pattern']));
|
||||
}
|
||||
@ -725,22 +698,21 @@ class DateTypeTest extends TestCase
|
||||
|
||||
\Locale::setDefault('es_ES');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
// EEEE, d 'de' MMMM 'de' y
|
||||
'format' => \IntlDateFormatter::FULL,
|
||||
));
|
||||
|
||||
$view = $form->createView();
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
|
||||
}
|
||||
|
||||
public function testPassWidgetToView()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
$view = $form->createView();
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertSame('single_text', $view->vars['widget']);
|
||||
}
|
||||
@ -749,26 +721,26 @@ class DateTypeTest extends TestCase
|
||||
{
|
||||
// Throws an exception if "data_class" option is not explicitly set
|
||||
// to null in the type
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', new \DateTime());
|
||||
$this->factory->create(static::TESTED_TYPE, new \DateTime());
|
||||
}
|
||||
|
||||
public function testSingleTextWidgetShouldUseTheRightInputType()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertEquals('date', $view->vars['type']);
|
||||
}
|
||||
|
||||
public function testPassDefaultPlaceholderToViewIfNotRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => false,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('', $view['year']->vars['placeholder']);
|
||||
$this->assertSame('', $view['month']->vars['placeholder']);
|
||||
$this->assertSame('', $view['day']->vars['placeholder']);
|
||||
@ -776,11 +748,11 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testPassNoPlaceholderToViewIfRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => true,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertNull($view['year']->vars['placeholder']);
|
||||
$this->assertNull($view['month']->vars['placeholder']);
|
||||
$this->assertNull($view['day']->vars['placeholder']);
|
||||
@ -788,11 +760,11 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testPassPlaceholderAsString()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'placeholder' => 'Empty',
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('Empty', $view['year']->vars['placeholder']);
|
||||
$this->assertSame('Empty', $view['month']->vars['placeholder']);
|
||||
$this->assertSame('Empty', $view['day']->vars['placeholder']);
|
||||
@ -803,11 +775,11 @@ class DateTypeTest extends TestCase
|
||||
*/
|
||||
public function testPassEmptyValueBC()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'empty_value' => 'Empty',
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('Empty', $view['year']->vars['placeholder']);
|
||||
$this->assertSame('Empty', $view['month']->vars['placeholder']);
|
||||
$this->assertSame('Empty', $view['day']->vars['placeholder']);
|
||||
@ -818,15 +790,15 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testPassPlaceholderAsArray()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'placeholder' => array(
|
||||
'year' => 'Empty year',
|
||||
'month' => 'Empty month',
|
||||
'day' => 'Empty day',
|
||||
),
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('Empty year', $view['year']->vars['placeholder']);
|
||||
$this->assertSame('Empty month', $view['month']->vars['placeholder']);
|
||||
$this->assertSame('Empty day', $view['day']->vars['placeholder']);
|
||||
@ -834,15 +806,15 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => false,
|
||||
'placeholder' => array(
|
||||
'year' => 'Empty year',
|
||||
'day' => 'Empty day',
|
||||
),
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('Empty year', $view['year']->vars['placeholder']);
|
||||
$this->assertSame('', $view['month']->vars['placeholder']);
|
||||
$this->assertSame('Empty day', $view['day']->vars['placeholder']);
|
||||
@ -850,15 +822,15 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testPassPlaceholderAsPartialArrayAddNullIfRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => true,
|
||||
'placeholder' => array(
|
||||
'year' => 'Empty year',
|
||||
'day' => 'Empty day',
|
||||
),
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('Empty year', $view['year']->vars['placeholder']);
|
||||
$this->assertNull($view['month']->vars['placeholder']);
|
||||
$this->assertSame('Empty day', $view['day']->vars['placeholder']);
|
||||
@ -866,43 +838,43 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testPassHtml5TypeIfSingleTextAndHtml5Format()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertSame('date', $view->vars['type']);
|
||||
}
|
||||
|
||||
public function testDontPassHtml5TypeIfHtml5NotAllowed()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
'html5' => false,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertFalse(isset($view->vars['type']));
|
||||
}
|
||||
|
||||
public function testDontPassHtml5TypeIfNotHtml5Format()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertFalse(isset($view->vars['type']));
|
||||
}
|
||||
|
||||
public function testDontPassHtml5TypeIfNotSingleText()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'text',
|
||||
));
|
||||
))
|
||||
->createView();
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertFalse(isset($view->vars['type']));
|
||||
}
|
||||
|
||||
@ -920,7 +892,7 @@ class DateTypeTest extends TestCase
|
||||
public function testYearErrorsBubbleUp($widget)
|
||||
{
|
||||
$error = new FormError('Invalid!');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => $widget,
|
||||
));
|
||||
$form['year']->addError($error);
|
||||
@ -935,7 +907,7 @@ class DateTypeTest extends TestCase
|
||||
public function testMonthErrorsBubbleUp($widget)
|
||||
{
|
||||
$error = new FormError('Invalid!');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => $widget,
|
||||
));
|
||||
$form['month']->addError($error);
|
||||
@ -950,7 +922,7 @@ class DateTypeTest extends TestCase
|
||||
public function testDayErrorsBubbleUp($widget)
|
||||
{
|
||||
$error = new FormError('Invalid!');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => $widget,
|
||||
));
|
||||
$form['day']->addError($error);
|
||||
@ -965,11 +937,10 @@ class DateTypeTest extends TestCase
|
||||
$this->markTestSkipped('PHP 32 bit is required.');
|
||||
}
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'years' => range(1900, 2040),
|
||||
));
|
||||
|
||||
$view = $form->createView();
|
||||
))
|
||||
->createView();
|
||||
|
||||
$listChoices = array();
|
||||
foreach (range(1902, 2037) as $y) {
|
||||
@ -981,7 +952,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testPassDefaultChoiceTranslationDomain()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType');
|
||||
$form = $this->factory->create(static::TESTED_TYPE);
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertFalse($view['year']->vars['choice_translation_domain']);
|
||||
@ -991,7 +962,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testPassChoiceTranslationDomainAsString()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'choice_translation_domain' => 'messages',
|
||||
));
|
||||
|
||||
@ -1003,7 +974,7 @@ class DateTypeTest extends TestCase
|
||||
|
||||
public function testPassChoiceTranslationDomainAsArray()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'choice_translation_domain' => array(
|
||||
'year' => 'foo',
|
||||
'day' => 'test',
|
||||
@ -1015,4 +986,21 @@ class DateTypeTest extends TestCase
|
||||
$this->assertFalse($view['month']->vars['choice_translation_domain']);
|
||||
$this->assertSame('test', $view['day']->vars['choice_translation_domain']);
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, array('year' => '', 'month' => '', 'day' => ''));
|
||||
}
|
||||
|
||||
public function testSubmitNullWithSingleText()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
$form->submit(null);
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
$this->assertNull($form->getNormData());
|
||||
$this->assertSame('', $form->getViewData());
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
|
||||
class FileTypeTest extends TypeTestCase
|
||||
class FileTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\FileType';
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
@ -28,17 +28,20 @@ class FileTypeTest extends TypeTestCase
|
||||
// https://github.com/symfony/symfony/pull/5028
|
||||
public function testSetData()
|
||||
{
|
||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FileType')->getForm();
|
||||
$data = $this->createUploadedFileMock('abcdef', 'original.jpg', true);
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE)->getForm();
|
||||
$data = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File')
|
||||
->setConstructorArgs(array(__DIR__.'/../../../Fixtures/foo', 'foo'))
|
||||
->getMock();
|
||||
|
||||
$form->setData($data);
|
||||
|
||||
// Ensures the data class is defined to accept File instance
|
||||
$this->assertSame($data, $form->getData());
|
||||
}
|
||||
|
||||
public function testSubmit()
|
||||
{
|
||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FileType')->getForm();
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE)->getForm();
|
||||
$data = $this->createUploadedFileMock('abcdef', 'original.jpg', true);
|
||||
|
||||
$form->submit($data);
|
||||
@ -46,31 +49,9 @@ class FileTypeTest extends TypeTestCase
|
||||
$this->assertSame($data, $form->getData());
|
||||
}
|
||||
|
||||
// https://github.com/symfony/symfony/issues/6134
|
||||
public function testSubmitEmpty()
|
||||
{
|
||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FileType')->getForm();
|
||||
|
||||
$form->submit(null);
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
}
|
||||
|
||||
public function testSubmitEmptyMultiple()
|
||||
{
|
||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FileType', null, array(
|
||||
'multiple' => true,
|
||||
))->getForm();
|
||||
|
||||
// submitted data when an input file is uploaded without choosing any file
|
||||
$form->submit(array(null));
|
||||
|
||||
$this->assertSame(array(), $form->getData());
|
||||
}
|
||||
|
||||
public function testSetDataMultiple()
|
||||
{
|
||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FileType', null, array(
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
))->getForm();
|
||||
|
||||
@ -85,7 +66,7 @@ class FileTypeTest extends TypeTestCase
|
||||
|
||||
public function testSubmitMultiple()
|
||||
{
|
||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FileType', null, array(
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
))->getForm();
|
||||
|
||||
@ -104,13 +85,38 @@ class FileTypeTest extends TypeTestCase
|
||||
|
||||
public function testDontPassValueToView()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FileType');
|
||||
$form = $this->factory->create(static::TESTED_TYPE);
|
||||
$form->submit(array(
|
||||
'Symfony\Component\Form\Extension\Core\Type\FileType' => $this->createUploadedFileMock('abcdef', 'original.jpg', true),
|
||||
'file' => $this->createUploadedFileMock('abcdef', 'original.jpg', true),
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertEquals('', $view->vars['value']);
|
||||
$this->assertEquals('', $form->createView()->vars['value']);
|
||||
}
|
||||
|
||||
public function testPassMultipartFalseToView()
|
||||
{
|
||||
$view = $this->factory->create(static::TESTED_TYPE)
|
||||
->createView();
|
||||
|
||||
$this->assertTrue($view->vars['multipart']);
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, '');
|
||||
}
|
||||
|
||||
public function testSubmitNullWhenMultiple()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'multiple' => true,
|
||||
));
|
||||
// submitted data when an input file is uploaded without choosing any file
|
||||
$form->submit(array(null));
|
||||
|
||||
$this->assertSame(array(), $form->getData());
|
||||
$this->assertSame(array(), $form->getNormData());
|
||||
$this->assertSame(array(), $form->getViewData());
|
||||
}
|
||||
|
||||
private function createUploadedFileMock($name, $originalName, $valid)
|
||||
|
@ -51,6 +51,8 @@ class FormTest_AuthorWithoutRefSetter
|
||||
|
||||
class FormTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\FormType';
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
@ -63,25 +65,25 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testCreateFormInstances()
|
||||
{
|
||||
$this->assertInstanceOf('Symfony\Component\Form\Form', $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType'));
|
||||
$this->assertInstanceOf('Symfony\Component\Form\Form', $this->factory->create(static::TESTED_TYPE));
|
||||
}
|
||||
|
||||
public function testPassRequiredAsOption()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array('required' => false));
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array('required' => false));
|
||||
|
||||
$this->assertFalse($form->isRequired());
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array('required' => true));
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array('required' => true));
|
||||
|
||||
$this->assertTrue($form->isRequired());
|
||||
}
|
||||
|
||||
public function testSubmittedDataIsTrimmedBeforeTransforming()
|
||||
{
|
||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
null => '',
|
||||
'' => '',
|
||||
'reverse[a]' => 'a',
|
||||
)))
|
||||
->setCompound(false)
|
||||
@ -95,9 +97,9 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testSubmittedDataIsNotTrimmedBeforeTransformingIfNoTrimming()
|
||||
{
|
||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array('trim' => false))
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array('trim' => false))
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
null => '',
|
||||
'' => '',
|
||||
'reverse[ a ]' => ' a ',
|
||||
)))
|
||||
->setCompound(false)
|
||||
@ -114,8 +116,8 @@ class FormTypeTest extends BaseTypeTest
|
||||
*/
|
||||
public function testLegacyNonReadOnlyFormWithReadOnlyParentIsReadOnly()
|
||||
{
|
||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array('read_only' => true))
|
||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE, null, array('read_only' => true))
|
||||
->add('child', static::TESTED_TYPE)
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
@ -124,8 +126,8 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testNonReadOnlyFormWithReadOnlyParentIsReadOnly()
|
||||
{
|
||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array('attr' => array('readonly' => true)))
|
||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE, null, array('attr' => array('readonly' => true)))
|
||||
->add('child', static::TESTED_TYPE)
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
@ -137,8 +139,8 @@ class FormTypeTest extends BaseTypeTest
|
||||
*/
|
||||
public function testLegacyReadOnlyFormWithNonReadOnlyParentIsReadOnly()
|
||||
{
|
||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\FormType', array('read_only' => true))
|
||||
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE)
|
||||
->add('child', static::TESTED_TYPE, array('read_only' => true))
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
@ -147,8 +149,8 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testReadOnlyFormWithNonReadOnlyParentIsReadOnly()
|
||||
{
|
||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\FormType', array('attr' => array('readonly' => true)))
|
||||
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE)
|
||||
->add('child', static::TESTED_TYPE, array('attr' => array('readonly' => true)))
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
@ -160,8 +162,8 @@ class FormTypeTest extends BaseTypeTest
|
||||
*/
|
||||
public function testLegacyNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly()
|
||||
{
|
||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE)
|
||||
->add('child', static::TESTED_TYPE)
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
@ -170,8 +172,8 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly()
|
||||
{
|
||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE)
|
||||
->add('child', static::TESTED_TYPE)
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
@ -180,37 +182,37 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testPassMaxLengthToView()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array('attr' => array('maxlength' => 10)));
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array('attr' => array('maxlength' => 10)))
|
||||
->createView();
|
||||
|
||||
$this->assertSame(10, $view->vars['attr']['maxlength']);
|
||||
}
|
||||
|
||||
public function testPassMaxLengthBCToView()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array('max_length' => 10));
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array('max_length' => 10))
|
||||
->createView();
|
||||
|
||||
$this->assertSame(10, $view->vars['attr']['maxlength']);
|
||||
}
|
||||
|
||||
public function testDataClassMayBeNull()
|
||||
{
|
||||
$this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
'data_class' => null,
|
||||
));
|
||||
}
|
||||
|
||||
public function testDataClassMayBeAbstractClass()
|
||||
{
|
||||
$this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AbstractAuthor',
|
||||
));
|
||||
}
|
||||
|
||||
public function testDataClassMayBeInterface()
|
||||
{
|
||||
$this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AuthorInterface',
|
||||
));
|
||||
}
|
||||
@ -220,22 +222,23 @@ class FormTypeTest extends BaseTypeTest
|
||||
*/
|
||||
public function testDataClassMustBeValidClassOrInterface()
|
||||
{
|
||||
$this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
'data_class' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
public function testSubmitWithEmptyDataCreatesObjectIfClassAvailable()
|
||||
{
|
||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||
'required' => false,
|
||||
));
|
||||
$builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$builder->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$form = $builder->getForm();
|
||||
))
|
||||
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||
->add('lastName', TextTypeTest::TESTED_TYPE)
|
||||
->getForm();
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
|
||||
$form->setData(null);
|
||||
// partially empty, still an object is created
|
||||
$form->submit(array('firstName' => 'Bernhard', 'lastName' => ''));
|
||||
|
||||
@ -246,19 +249,19 @@ class FormTypeTest extends BaseTypeTest
|
||||
$this->assertEquals($author, $form->getData());
|
||||
}
|
||||
|
||||
public function testSubmitWithEmptyDataCreatesObjectIfInitiallySubmittedWithObject()
|
||||
public function testSubmitWithDefaultDataDontCreateObject()
|
||||
{
|
||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$defaultAuthor = new Author();
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
// data class is inferred from the passed object
|
||||
'data' => new Author(),
|
||||
'data' => $defaultAuthor,
|
||||
'required' => false,
|
||||
));
|
||||
$builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$builder->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$form = $builder->getForm();
|
||||
))
|
||||
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||
->add('lastName', TextTypeTest::TESTED_TYPE)
|
||||
->getForm();
|
||||
|
||||
$form->setData(null);
|
||||
// partially empty, still an object is created
|
||||
// partially empty
|
||||
$form->submit(array('firstName' => 'Bernhard', 'lastName' => ''));
|
||||
|
||||
$author = new Author();
|
||||
@ -266,34 +269,37 @@ class FormTypeTest extends BaseTypeTest
|
||||
$author->setLastName('');
|
||||
|
||||
$this->assertEquals($author, $form->getData());
|
||||
$this->assertSame($defaultAuthor, $form->getData());
|
||||
}
|
||||
|
||||
public function testSubmitWithEmptyDataCreatesArrayIfDataClassIsNull()
|
||||
{
|
||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
'data_class' => null,
|
||||
'required' => false,
|
||||
));
|
||||
$builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$form = $builder->getForm();
|
||||
))
|
||||
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||
->getForm();
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
|
||||
$form->setData(null);
|
||||
$form->submit(array('firstName' => 'Bernhard'));
|
||||
|
||||
$this->assertSame(array('firstName' => 'Bernhard'), $form->getData());
|
||||
}
|
||||
|
||||
public function testSubmitEmptyWithEmptyDataCreatesNoObjectIfNotRequired()
|
||||
public function testSubmitEmptyWithEmptyDataDontCreateObjectIfNotRequired()
|
||||
{
|
||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||
'required' => false,
|
||||
));
|
||||
$builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$builder->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$form = $builder->getForm();
|
||||
))
|
||||
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||
->add('lastName', TextTypeTest::TESTED_TYPE)
|
||||
->getForm();
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
|
||||
$form->setData(null);
|
||||
$form->submit(array('firstName' => '', 'lastName' => ''));
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
@ -301,15 +307,16 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testSubmitEmptyWithEmptyDataCreatesObjectIfRequired()
|
||||
{
|
||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||
'required' => true,
|
||||
));
|
||||
$builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$builder->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$form = $builder->getForm();
|
||||
))
|
||||
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||
->add('lastName', TextTypeTest::TESTED_TYPE)
|
||||
->getForm();
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
|
||||
$form->setData(null);
|
||||
$form->submit(array('firstName' => '', 'lastName' => ''));
|
||||
|
||||
$this->assertEquals(new Author(), $form->getData());
|
||||
@ -320,11 +327,12 @@ class FormTypeTest extends BaseTypeTest
|
||||
*/
|
||||
public function testSubmitWithEmptyDataStoresArrayIfNoClassAvailable()
|
||||
{
|
||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||
->getForm();
|
||||
|
||||
$form->setData(null);
|
||||
$this->assertNull($form->getData());
|
||||
|
||||
$form->submit(array('firstName' => 'Bernhard'));
|
||||
|
||||
$this->assertSame(array('firstName' => 'Bernhard'), $form->getData());
|
||||
@ -332,31 +340,40 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testSubmitWithEmptyDataPassesEmptyStringToTransformerIfNotCompound()
|
||||
{
|
||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
// required for the initial, internal setData(null)
|
||||
null => 'null',
|
||||
'' => 'null',
|
||||
// required to test that submit(null) is converted to ''
|
||||
'empty' => '',
|
||||
)))
|
||||
->setCompound(false)
|
||||
->getForm();
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
$this->assertNull($form->getNormData());
|
||||
$this->assertSame('null', $form->getViewData());
|
||||
|
||||
$form->submit(null);
|
||||
|
||||
$this->assertSame('empty', $form->getData());
|
||||
$this->assertSame('empty', $form->getNormData());
|
||||
$this->assertSame('', $form->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitWithEmptyDataUsesEmptyDataOption()
|
||||
{
|
||||
$author = new Author();
|
||||
|
||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||
'empty_data' => $author,
|
||||
));
|
||||
$builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$form = $builder->getForm();
|
||||
))
|
||||
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||
->getForm();
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
$this->assertNull($form->getViewData());
|
||||
|
||||
$form->submit(array('firstName' => 'Bernhard'));
|
||||
|
||||
@ -364,62 +381,34 @@ class FormTypeTest extends BaseTypeTest
|
||||
$this->assertEquals('Bernhard', $author->firstName);
|
||||
}
|
||||
|
||||
public function provideZeros()
|
||||
{
|
||||
return array(
|
||||
array(0, '0'),
|
||||
array('0', '0'),
|
||||
array('00000', '00000'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideZeros
|
||||
*
|
||||
* @see https://github.com/symfony/symfony/issues/1986
|
||||
*/
|
||||
public function testSetDataThroughParamsWithZero($data, $dataAsString)
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
'data' => $data,
|
||||
'compound' => false,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertFalse($form->isEmpty());
|
||||
|
||||
$this->assertSame($dataAsString, $view->vars['value']);
|
||||
$this->assertSame($dataAsString, $form->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
*/
|
||||
public function testAttributesException()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array('attr' => ''));
|
||||
$this->factory->create(static::TESTED_TYPE, null, array('attr' => ''));
|
||||
}
|
||||
|
||||
public function testNameCanBeEmptyString()
|
||||
{
|
||||
$form = $this->factory->createNamed('', 'Symfony\Component\Form\Extension\Core\Type\FormType');
|
||||
$form = $this->factory->createNamed('', static::TESTED_TYPE);
|
||||
|
||||
$this->assertEquals('', $form->getName());
|
||||
}
|
||||
|
||||
public function testSubformDoesntCallSetters()
|
||||
public function testSubformDoesntCallSettersForReferences()
|
||||
{
|
||||
$author = new FormTest_AuthorWithoutRefSetter(new Author());
|
||||
|
||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', $author);
|
||||
$builder->add('reference', 'Symfony\Component\Form\Extension\Core\Type\FormType', array(
|
||||
$builder = $this->factory->createBuilder(static::TESTED_TYPE, $author);
|
||||
$builder->add('reference', static::TESTED_TYPE, array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||
));
|
||||
$builder->get('reference')->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$builder->get('reference')->add('firstName', TextTypeTest::TESTED_TYPE);
|
||||
$form = $builder->getForm();
|
||||
|
||||
$form->submit(array(
|
||||
// reference has a getter, but not setter
|
||||
// reference has a getter, but no setter
|
||||
'reference' => array(
|
||||
'firstName' => 'Foo',
|
||||
),
|
||||
@ -434,17 +423,17 @@ class FormTypeTest extends BaseTypeTest
|
||||
$author = new FormTest_AuthorWithoutRefSetter(null);
|
||||
$newReference = new Author();
|
||||
|
||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', $author);
|
||||
$builder->add('referenceCopy', 'Symfony\Component\Form\Extension\Core\Type\FormType', array(
|
||||
$builder = $this->factory->createBuilder(static::TESTED_TYPE, $author);
|
||||
$builder->add('referenceCopy', static::TESTED_TYPE, array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||
));
|
||||
$builder->get('referenceCopy')->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$builder->get('referenceCopy')->add('firstName', TextTypeTest::TESTED_TYPE);
|
||||
$form = $builder->getForm();
|
||||
|
||||
$form['referenceCopy']->setData($newReference); // new author object
|
||||
|
||||
$form->submit(array(
|
||||
// referenceCopy has a getter that returns a copy
|
||||
// referenceCopy has a getter that returns a copy
|
||||
'referenceCopy' => array(
|
||||
'firstName' => 'Foo',
|
||||
),
|
||||
@ -457,12 +446,12 @@ class FormTypeTest extends BaseTypeTest
|
||||
{
|
||||
$author = new FormTest_AuthorWithoutRefSetter(new Author());
|
||||
|
||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', $author);
|
||||
$builder->add('referenceCopy', 'Symfony\Component\Form\Extension\Core\Type\FormType', array(
|
||||
$builder = $this->factory->createBuilder(static::TESTED_TYPE, $author);
|
||||
$builder->add('referenceCopy', static::TESTED_TYPE, array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||
'by_reference' => false,
|
||||
));
|
||||
$builder->get('referenceCopy')->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$builder->get('referenceCopy')->add('firstName', TextTypeTest::TESTED_TYPE);
|
||||
$form = $builder->getForm();
|
||||
|
||||
$form->submit(array(
|
||||
@ -480,8 +469,8 @@ class FormTypeTest extends BaseTypeTest
|
||||
{
|
||||
$author = new FormTest_AuthorWithoutRefSetter('scalar');
|
||||
|
||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', $author);
|
||||
$builder->add('referenceCopy', 'Symfony\Component\Form\Extension\Core\Type\FormType');
|
||||
$builder = $this->factory->createBuilder(static::TESTED_TYPE, $author);
|
||||
$builder->add('referenceCopy', static::TESTED_TYPE);
|
||||
$builder->get('referenceCopy')->addViewTransformer(new CallbackTransformer(
|
||||
function () {},
|
||||
function ($value) { // reverseTransform
|
||||
@ -504,9 +493,9 @@ class FormTypeTest extends BaseTypeTest
|
||||
$ref2 = new Author();
|
||||
$author = array('referenceCopy' => $ref1);
|
||||
|
||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType');
|
||||
$builder = $this->factory->createBuilder(static::TESTED_TYPE);
|
||||
$builder->setData($author);
|
||||
$builder->add('referenceCopy', 'Symfony\Component\Form\Extension\Core\Type\FormType');
|
||||
$builder->add('referenceCopy', static::TESTED_TYPE);
|
||||
$builder->get('referenceCopy')->addViewTransformer(new CallbackTransformer(
|
||||
function () {},
|
||||
function ($value) use ($ref2) { // reverseTransform
|
||||
@ -516,7 +505,7 @@ class FormTypeTest extends BaseTypeTest
|
||||
$form = $builder->getForm();
|
||||
|
||||
$form->submit(array(
|
||||
'referenceCopy' => array('a' => 'b'), // doesn't matter actually
|
||||
'referenceCopy' => array(), // doesn't matter actually
|
||||
));
|
||||
|
||||
// the new reference was inserted into the array
|
||||
@ -526,9 +515,9 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testPassMultipartTrueIfAnyChildIsMultipartToView()
|
||||
{
|
||||
$view = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
->add('foo', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
||||
->add('bar', 'Symfony\Component\Form\Extension\Core\Type\FileType')
|
||||
$view = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||
->add('foo', TextTypeTest::TESTED_TYPE)
|
||||
->add('bar', FileTypeTest::TESTED_TYPE)
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
@ -537,8 +526,8 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testViewIsNotRenderedByDefault()
|
||||
{
|
||||
$view = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
->add('foo', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
$view = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||
->add('foo', static::TESTED_TYPE)
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
@ -547,16 +536,14 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testErrorBubblingIfCompound()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
'compound' => true,
|
||||
));
|
||||
$form = $this->factory->create(static::TESTED_TYPE);
|
||||
|
||||
$this->assertTrue($form->getConfig()->getErrorBubbling());
|
||||
}
|
||||
|
||||
public function testNoErrorBubblingIfNotCompound()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'compound' => false,
|
||||
));
|
||||
|
||||
@ -565,7 +552,7 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testOverrideErrorBubbling()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'compound' => false,
|
||||
'error_bubbling' => true,
|
||||
));
|
||||
@ -575,7 +562,7 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testPropertyPath()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'property_path' => 'foo',
|
||||
));
|
||||
|
||||
@ -585,7 +572,7 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testPropertyPathNullImpliesDefault()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$form = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'property_path' => null,
|
||||
));
|
||||
|
||||
@ -595,7 +582,7 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testNotMapped()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'property_path' => 'foo',
|
||||
'mapped' => false,
|
||||
));
|
||||
@ -606,38 +593,40 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testViewValidNotSubmitted()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType');
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->create(static::TESTED_TYPE)
|
||||
->createView();
|
||||
|
||||
$this->assertTrue($view->vars['valid']);
|
||||
}
|
||||
|
||||
public function testViewNotValidSubmitted()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType');
|
||||
$form = $this->factory->create(static::TESTED_TYPE);
|
||||
$form->submit(array());
|
||||
$form->addError(new FormError('An error'));
|
||||
$view = $form->createView();
|
||||
$this->assertFalse($view->vars['valid']);
|
||||
|
||||
$this->assertFalse($form->createView()->vars['valid']);
|
||||
}
|
||||
|
||||
public function testViewSubmittedNotSubmitted()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType');
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->create(static::TESTED_TYPE)
|
||||
->createView();
|
||||
|
||||
$this->assertFalse($view->vars['submitted']);
|
||||
}
|
||||
|
||||
public function testViewSubmittedSubmitted()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType');
|
||||
$form = $this->factory->create(static::TESTED_TYPE);
|
||||
$form->submit(array());
|
||||
$view = $form->createView();
|
||||
$this->assertTrue($view->vars['submitted']);
|
||||
|
||||
$this->assertTrue($form->createView()->vars['submitted']);
|
||||
}
|
||||
|
||||
public function testDataOptionSupersedesSetDataCalls()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'data' => 'default',
|
||||
'compound' => false,
|
||||
));
|
||||
@ -647,9 +636,20 @@ class FormTypeTest extends BaseTypeTest
|
||||
$this->assertSame('default', $form->getData());
|
||||
}
|
||||
|
||||
public function testPassedDataSupersedesSetDataCalls()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, 'default', array(
|
||||
'compound' => false,
|
||||
));
|
||||
|
||||
$form->setData('foobar');
|
||||
|
||||
$this->assertSame('default', $form->getData());
|
||||
}
|
||||
|
||||
public function testDataOptionSupersedesSetDataCallsIfNull()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'data' => null,
|
||||
'compound' => false,
|
||||
));
|
||||
@ -661,22 +661,25 @@ class FormTypeTest extends BaseTypeTest
|
||||
|
||||
public function testNormDataIsPassedToView()
|
||||
{
|
||||
$view = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
$view = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||
->addModelTransformer(new FixedDataTransformer(array(
|
||||
'foo' => 'bar',
|
||||
)))
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
'bar' => 'baz',
|
||||
)))
|
||||
->setData('foo')
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
$this->assertSame('foo', $view->vars['data']);
|
||||
$this->assertSame('bar', $view->vars['value']);
|
||||
$this->assertSame('bar', $view->vars['data']);
|
||||
$this->assertSame('baz', $view->vars['value']);
|
||||
}
|
||||
|
||||
// https://github.com/symfony/symfony/issues/6862
|
||||
public function testPassZeroLabelToView()
|
||||
{
|
||||
$view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'label' => '0',
|
||||
))
|
||||
->createView();
|
||||
@ -689,20 +692,20 @@ class FormTypeTest extends BaseTypeTest
|
||||
*/
|
||||
public function testCanGetErrorsWhenButtonInForm()
|
||||
{
|
||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
||||
$builder = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||
'required' => false,
|
||||
));
|
||||
$builder->add('foo', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
||||
$builder->add('submit', 'Symfony\Component\Form\Extension\Core\Type\SubmitType');
|
||||
$builder->add('foo', 'text');
|
||||
$builder->add('submit', 'submit');
|
||||
$form = $builder->getForm();
|
||||
|
||||
//This method should not throw a Fatal Error Exception.
|
||||
$form->getErrorsAsString();
|
||||
}
|
||||
|
||||
protected function getTestedType()
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
return 'Symfony\Component\Form\Extension\Core\Type\FormType';
|
||||
parent::testSubmitNull(array(), array(), array());
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,12 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
class IntegerTypeTest extends TestCase
|
||||
class IntegerTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\IntegerType';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
IntlTestHelper::requireIntl($this, false);
|
||||
@ -35,11 +36,16 @@ class IntegerTypeTest extends TestCase
|
||||
|
||||
public function testSubmitCastsToInteger()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\IntegerType');
|
||||
$form = $this->factory->create(static::TESTED_TYPE);
|
||||
|
||||
$form->submit('1.678');
|
||||
|
||||
$this->assertSame(1, $form->getData());
|
||||
$this->assertSame('1', $form->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, '');
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
class LanguageTypeTest extends TestCase
|
||||
class LanguageTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\LanguageType';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
IntlTestHelper::requireIntl($this, false);
|
||||
@ -36,9 +37,8 @@ class LanguageTypeTest extends TestCase
|
||||
|
||||
public function testCountriesAreSelectable()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\LanguageType');
|
||||
$view = $form->createView();
|
||||
$choices = $view->vars['choices'];
|
||||
$choices = $this->factory->create(static::TESTED_TYPE)
|
||||
->createView()->vars['choices'];
|
||||
|
||||
$this->assertContains(new ChoiceView('en', 'en', 'English'), $choices, '', false, false);
|
||||
$this->assertContains(new ChoiceView('en_GB', 'en_GB', 'British English'), $choices, '', false, false);
|
||||
@ -49,10 +49,14 @@ class LanguageTypeTest extends TestCase
|
||||
|
||||
public function testMultipleLanguagesIsNotIncluded()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\LanguageType', 'Symfony\Component\Form\Extension\Core\Type\LanguageType');
|
||||
$view = $form->createView();
|
||||
$choices = $view->vars['choices'];
|
||||
$choices = $this->factory->create(static::TESTED_TYPE, 'language')
|
||||
->createView()->vars['choices'];
|
||||
|
||||
$this->assertNotContains(new ChoiceView('mul', 'mul', 'Mehrsprachig'), $choices, '', false, false);
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, '');
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
class LocaleTypeTest extends TestCase
|
||||
class LocaleTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\LocaleType';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
IntlTestHelper::requireIntl($this, false);
|
||||
@ -36,12 +37,16 @@ class LocaleTypeTest extends TestCase
|
||||
|
||||
public function testLocalesAreSelectable()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\LocaleType');
|
||||
$view = $form->createView();
|
||||
$choices = $view->vars['choices'];
|
||||
$choices = $this->factory->create(static::TESTED_TYPE)
|
||||
->createView()->vars['choices'];
|
||||
|
||||
$this->assertContains(new ChoiceView('en', 'en', 'English'), $choices, '', false, false);
|
||||
$this->assertContains(new ChoiceView('en_GB', 'en_GB', 'English (United Kingdom)'), $choices, '', false, false);
|
||||
$this->assertContains(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'Chinese (Traditional, Macau SAR China)'), $choices, '', false, false);
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, '');
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,12 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
class MoneyTypeTest extends TestCase
|
||||
class MoneyTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\MoneyType';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
// we test against different locales, so we need the full
|
||||
@ -39,8 +40,8 @@ class MoneyTypeTest extends TestCase
|
||||
{
|
||||
\Locale::setDefault('de_DE');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\MoneyType');
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->create(static::TESTED_TYPE)
|
||||
->createView();
|
||||
|
||||
$this->assertSame('{{ widget }} €', $view->vars['money_pattern']);
|
||||
}
|
||||
@ -49,8 +50,9 @@ class MoneyTypeTest extends TestCase
|
||||
{
|
||||
\Locale::setDefault('en_US');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\MoneyType', null, array('currency' => 'JPY'));
|
||||
$view = $form->createView();
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array('currency' => 'JPY'))
|
||||
->createView();
|
||||
|
||||
$this->assertTrue((bool) strstr($view->vars['money_pattern'], '¥'));
|
||||
}
|
||||
|
||||
@ -59,12 +61,15 @@ class MoneyTypeTest extends TestCase
|
||||
{
|
||||
\Locale::setDefault('de_DE');
|
||||
|
||||
$form1 = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\MoneyType', null, array('currency' => 'GBP'));
|
||||
$form2 = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\MoneyType', null, array('currency' => 'EUR'));
|
||||
$view1 = $form1->createView();
|
||||
$view2 = $form2->createView();
|
||||
$view1 = $this->factory->create(static::TESTED_TYPE, null, array('currency' => 'GBP'))->createView();
|
||||
$view2 = $this->factory->create(static::TESTED_TYPE, null, array('currency' => 'EUR'))->createView();
|
||||
|
||||
$this->assertSame('{{ widget }} £', $view1->vars['money_pattern']);
|
||||
$this->assertSame('{{ widget }} €', $view2->vars['money_pattern']);
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, '');
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,12 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
|
||||
class NumberTypeTest extends TestCase
|
||||
class NumberTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\NumberType';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
@ -38,37 +39,38 @@ class NumberTypeTest extends TestCase
|
||||
|
||||
public function testDefaultFormatting()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\NumberType');
|
||||
$form = $this->factory->create(static::TESTED_TYPE);
|
||||
$form->setData('12345.67890');
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertSame('12345,679', $view->vars['value']);
|
||||
$this->assertSame('12345,679', $form->createView()->vars['value']);
|
||||
}
|
||||
|
||||
public function testDefaultFormattingWithGrouping()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\NumberType', null, array('grouping' => true));
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array('grouping' => true));
|
||||
$form->setData('12345.67890');
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertSame('12.345,679', $view->vars['value']);
|
||||
$this->assertSame('12.345,679', $form->createView()->vars['value']);
|
||||
}
|
||||
|
||||
public function testDefaultFormattingWithScale()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\NumberType', null, array('scale' => 2));
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array('scale' => 2));
|
||||
$form->setData('12345.67890');
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertSame('12345,68', $view->vars['value']);
|
||||
$this->assertSame('12345,68', $form->createView()->vars['value']);
|
||||
}
|
||||
|
||||
public function testDefaultFormattingWithRounding()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\NumberType', null, array('scale' => 0, 'rounding_mode' => \NumberFormatter::ROUND_UP));
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array('scale' => 0, 'rounding_mode' => \NumberFormatter::ROUND_UP));
|
||||
$form->setData('12345.54321');
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertSame('12346', $view->vars['value']);
|
||||
$this->assertSame('12346', $form->createView()->vars['value']);
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, '');
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
|
||||
class PasswordTypeTest extends TypeTestCase
|
||||
class PasswordTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\PasswordType';
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
@ -27,37 +27,38 @@ class PasswordTypeTest extends TypeTestCase
|
||||
|
||||
public function testEmptyIfNotSubmitted()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\PasswordType');
|
||||
$form = $this->factory->create(static::TESTED_TYPE);
|
||||
$form->setData('pAs5w0rd');
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertSame('', $view->vars['value']);
|
||||
$this->assertSame('', $form->createView()->vars['value']);
|
||||
}
|
||||
|
||||
public function testEmptyIfSubmitted()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\PasswordType');
|
||||
$form = $this->factory->create(static::TESTED_TYPE);
|
||||
$form->submit('pAs5w0rd');
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertSame('', $view->vars['value']);
|
||||
$this->assertSame('', $form->createView()->vars['value']);
|
||||
}
|
||||
|
||||
public function testNotEmptyIfSubmittedAndNotAlwaysEmpty()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\PasswordType', null, array('always_empty' => false));
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array('always_empty' => false));
|
||||
$form->submit('pAs5w0rd');
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertSame('pAs5w0rd', $view->vars['value']);
|
||||
$this->assertSame('pAs5w0rd', $form->createView()->vars['value']);
|
||||
}
|
||||
|
||||
public function testNotTrimmed()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\PasswordType', null);
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null);
|
||||
$form->submit(' pAs5w0rd ');
|
||||
$data = $form->getData();
|
||||
|
||||
$this->assertSame(' pAs5w0rd ', $data);
|
||||
$this->assertSame(' pAs5w0rd ', $form->getData());
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, '');
|
||||
}
|
||||
}
|
||||
|
@ -11,20 +11,24 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
use Symfony\Component\Form\Form;
|
||||
|
||||
class RepeatedTypeTest extends TypeTestCase
|
||||
class RepeatedTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\RepeatedType';
|
||||
|
||||
/**
|
||||
* @var Form
|
||||
*/
|
||||
protected $form;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$this->form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'type' => TextTypeTest::TESTED_TYPE,
|
||||
));
|
||||
$this->form->setData(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,43 +47,43 @@ class RepeatedTypeTest extends TypeTestCase
|
||||
{
|
||||
$this->form->setData('foobar');
|
||||
|
||||
$this->assertEquals('foobar', $this->form['first']->getData());
|
||||
$this->assertEquals('foobar', $this->form['second']->getData());
|
||||
$this->assertSame('foobar', $this->form['first']->getData());
|
||||
$this->assertSame('foobar', $this->form['second']->getData());
|
||||
}
|
||||
|
||||
public function testSetOptions()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'type' => TextTypeTest::TESTED_TYPE,
|
||||
'options' => array('label' => 'Global'),
|
||||
));
|
||||
|
||||
$this->assertEquals('Global', $form['first']->getConfig()->getOption('label'));
|
||||
$this->assertEquals('Global', $form['second']->getConfig()->getOption('label'));
|
||||
$this->assertSame('Global', $form['first']->getConfig()->getOption('label'));
|
||||
$this->assertSame('Global', $form['second']->getConfig()->getOption('label'));
|
||||
$this->assertTrue($form['first']->isRequired());
|
||||
$this->assertTrue($form['second']->isRequired());
|
||||
}
|
||||
|
||||
public function testSetOptionsPerChild()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
// the global required value cannot be overridden
|
||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
'type' => TextTypeTest::TESTED_TYPE,
|
||||
'first_options' => array('label' => 'Test', 'required' => false),
|
||||
'second_options' => array('label' => 'Test2'),
|
||||
));
|
||||
|
||||
$this->assertEquals('Test', $form['first']->getConfig()->getOption('label'));
|
||||
$this->assertEquals('Test2', $form['second']->getConfig()->getOption('label'));
|
||||
$this->assertSame('Test', $form['first']->getConfig()->getOption('label'));
|
||||
$this->assertSame('Test2', $form['second']->getConfig()->getOption('label'));
|
||||
$this->assertTrue($form['first']->isRequired());
|
||||
$this->assertTrue($form['second']->isRequired());
|
||||
}
|
||||
|
||||
public function testSetRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => false,
|
||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
'type' => TextTypeTest::TESTED_TYPE,
|
||||
));
|
||||
|
||||
$this->assertFalse($form['first']->isRequired());
|
||||
@ -91,8 +95,8 @@ class RepeatedTypeTest extends TypeTestCase
|
||||
*/
|
||||
public function testSetInvalidOptions()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'type' => TextTypeTest::TESTED_TYPE,
|
||||
'options' => 'bad value',
|
||||
));
|
||||
}
|
||||
@ -102,8 +106,8 @@ class RepeatedTypeTest extends TypeTestCase
|
||||
*/
|
||||
public function testSetInvalidFirstOptions()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'type' => TextTypeTest::TESTED_TYPE,
|
||||
'first_options' => 'bad value',
|
||||
));
|
||||
}
|
||||
@ -113,15 +117,15 @@ class RepeatedTypeTest extends TypeTestCase
|
||||
*/
|
||||
public function testSetInvalidSecondOptions()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'type' => TextTypeTest::TESTED_TYPE,
|
||||
'second_options' => 'bad value',
|
||||
));
|
||||
}
|
||||
|
||||
public function testSetErrorBubblingToTrue()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'error_bubbling' => true,
|
||||
));
|
||||
|
||||
@ -132,7 +136,7 @@ class RepeatedTypeTest extends TypeTestCase
|
||||
|
||||
public function testSetErrorBubblingToFalse()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'error_bubbling' => false,
|
||||
));
|
||||
|
||||
@ -143,7 +147,7 @@ class RepeatedTypeTest extends TypeTestCase
|
||||
|
||||
public function testSetErrorBubblingIndividually()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'error_bubbling' => true,
|
||||
'options' => array('error_bubbling' => false),
|
||||
'second_options' => array('error_bubbling' => true),
|
||||
@ -156,14 +160,14 @@ class RepeatedTypeTest extends TypeTestCase
|
||||
|
||||
public function testSetOptionsPerChildAndOverwrite()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'type' => TextTypeTest::TESTED_TYPE,
|
||||
'options' => array('label' => 'Label'),
|
||||
'second_options' => array('label' => 'Second label'),
|
||||
));
|
||||
|
||||
$this->assertEquals('Label', $form['first']->getConfig()->getOption('label'));
|
||||
$this->assertEquals('Second label', $form['second']->getConfig()->getOption('label'));
|
||||
$this->assertSame('Label', $form['first']->getConfig()->getOption('label'));
|
||||
$this->assertSame('Second label', $form['second']->getConfig()->getOption('label'));
|
||||
$this->assertTrue($form['first']->isRequired());
|
||||
$this->assertTrue($form['second']->isRequired());
|
||||
}
|
||||
@ -174,10 +178,10 @@ class RepeatedTypeTest extends TypeTestCase
|
||||
|
||||
$this->form->submit($input);
|
||||
|
||||
$this->assertEquals('foo', $this->form['first']->getViewData());
|
||||
$this->assertEquals('bar', $this->form['second']->getViewData());
|
||||
$this->assertSame('foo', $this->form['first']->getViewData());
|
||||
$this->assertSame('bar', $this->form['second']->getViewData());
|
||||
$this->assertFalse($this->form->isSynchronized());
|
||||
$this->assertEquals($input, $this->form->getViewData());
|
||||
$this->assertSame($input, $this->form->getViewData());
|
||||
$this->assertNull($this->form->getData());
|
||||
}
|
||||
|
||||
@ -187,10 +191,15 @@ class RepeatedTypeTest extends TypeTestCase
|
||||
|
||||
$this->form->submit($input);
|
||||
|
||||
$this->assertEquals('foo', $this->form['first']->getViewData());
|
||||
$this->assertEquals('foo', $this->form['second']->getViewData());
|
||||
$this->assertSame('foo', $this->form['first']->getViewData());
|
||||
$this->assertSame('foo', $this->form['second']->getViewData());
|
||||
$this->assertTrue($this->form->isSynchronized());
|
||||
$this->assertEquals($input, $this->form->getViewData());
|
||||
$this->assertEquals('foo', $this->form->getData());
|
||||
$this->assertSame($input, $this->form->getViewData());
|
||||
$this->assertSame('foo', $this->form->getData());
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, array('first' => null, 'second' => null));
|
||||
}
|
||||
}
|
||||
|
@ -11,13 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class SubmitTypeTest extends TestCase
|
||||
class SubmitTypeTest extends ButtonTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\SubmitType';
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
@ -30,19 +30,19 @@ class SubmitTypeTest extends TestCase
|
||||
|
||||
public function testCreateSubmitButtonInstances()
|
||||
{
|
||||
$this->assertInstanceOf('Symfony\Component\Form\SubmitButton', $this->factory->create('Symfony\Component\Form\Extension\Core\Type\SubmitType'));
|
||||
$this->assertInstanceOf('Symfony\Component\Form\SubmitButton', $this->factory->create(static::TESTED_TYPE));
|
||||
}
|
||||
|
||||
public function testNotClickedByDefault()
|
||||
{
|
||||
$button = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\SubmitType');
|
||||
$button = $this->factory->create(static::TESTED_TYPE);
|
||||
|
||||
$this->assertFalse($button->isClicked());
|
||||
}
|
||||
|
||||
public function testNotClickedIfSubmittedWithNull()
|
||||
{
|
||||
$button = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\SubmitType');
|
||||
$button = $this->factory->create(static::TESTED_TYPE);
|
||||
$button->submit(null);
|
||||
|
||||
$this->assertFalse($button->isClicked());
|
||||
@ -50,7 +50,7 @@ class SubmitTypeTest extends TestCase
|
||||
|
||||
public function testClickedIfSubmittedWithEmptyString()
|
||||
{
|
||||
$button = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\SubmitType');
|
||||
$button = $this->factory->create(static::TESTED_TYPE);
|
||||
$button->submit('');
|
||||
|
||||
$this->assertTrue($button->isClicked());
|
||||
@ -58,7 +58,7 @@ class SubmitTypeTest extends TestCase
|
||||
|
||||
public function testClickedIfSubmittedWithUnemptyString()
|
||||
{
|
||||
$button = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\SubmitType');
|
||||
$button = $this->factory->create(static::TESTED_TYPE);
|
||||
$button->submit('foo');
|
||||
|
||||
$this->assertTrue($button->isClicked());
|
||||
@ -67,9 +67,9 @@ class SubmitTypeTest extends TestCase
|
||||
public function testSubmitCanBeAddedToForm()
|
||||
{
|
||||
$form = $this->factory
|
||||
->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
||||
->createBuilder(FormTypeTest::TESTED_TYPE)
|
||||
->getForm();
|
||||
|
||||
$this->assertSame($form, $form->add('send', 'Symfony\Component\Form\Extension\Core\Type\SubmitType'));
|
||||
$this->assertSame($form, $form->add('send', static::TESTED_TYPE));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
class TextTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\TextType';
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyName()
|
||||
{
|
||||
$form = $this->factory->create('text');
|
||||
|
||||
$this->assertSame('text', $form->getConfig()->getType()->getName());
|
||||
}
|
||||
|
||||
public function testSubmitNullReturnsNullWithEmptyDataAsString()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, 'name', array(
|
||||
'empty_data' => '',
|
||||
));
|
||||
|
||||
$form->submit(null);
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
}
|
||||
|
||||
public function provideZeros()
|
||||
{
|
||||
return array(
|
||||
array(0, '0'),
|
||||
array('0', '0'),
|
||||
array('00000', '00000'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideZeros
|
||||
*
|
||||
* @see https://github.com/symfony/symfony/issues/1986
|
||||
*/
|
||||
public function testSetDataThroughParamsWithZero($data, $dataAsString)
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'data' => $data,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertFalse($form->isEmpty());
|
||||
|
||||
$this->assertSame($dataAsString, $view->vars['value']);
|
||||
$this->assertSame($dataAsString, $form->getData());
|
||||
}
|
||||
}
|
@ -13,10 +13,11 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
||||
|
||||
class TimeTypeTest extends TestCase
|
||||
class TimeTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\TimeType';
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
@ -29,7 +30,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitDateTime()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'datetime',
|
||||
@ -50,7 +51,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitString()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'string',
|
||||
@ -69,7 +70,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitTimestamp()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'timestamp',
|
||||
@ -90,7 +91,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitArray()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'array',
|
||||
@ -109,7 +110,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitDatetimeSingleText()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'datetime',
|
||||
@ -124,7 +125,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitDatetimeSingleTextWithoutMinutes()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'datetime',
|
||||
@ -140,7 +141,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitArraySingleText()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'array',
|
||||
@ -160,7 +161,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitArraySingleTextWithoutMinutes()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'array',
|
||||
@ -180,7 +181,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitArraySingleTextWithSeconds()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'array',
|
||||
@ -202,7 +203,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitStringSingleText()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'string',
|
||||
@ -217,7 +218,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitStringSingleTextWithoutMinutes()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'string',
|
||||
@ -233,7 +234,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSubmitWithSecondsAndBrowserOmissionSeconds()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'string',
|
||||
@ -249,7 +250,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSetDataWithoutMinutes()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'datetime',
|
||||
@ -263,7 +264,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSetDataWithSeconds()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
'input' => 'datetime',
|
||||
@ -277,7 +278,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSetDataDifferentTimezones()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'America/New_York',
|
||||
'view_timezone' => 'Asia/Hong_Kong',
|
||||
'input' => 'string',
|
||||
@ -303,7 +304,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSetDataDifferentTimezonesDateTime()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'model_timezone' => 'America/New_York',
|
||||
'view_timezone' => 'Asia/Hong_Kong',
|
||||
'input' => 'datetime',
|
||||
@ -330,7 +331,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testHoursOption()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'hours' => array(6, 7),
|
||||
));
|
||||
|
||||
@ -344,7 +345,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testIsMinuteWithinRangeReturnsTrueIfWithin()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'minutes' => array(6, 7),
|
||||
));
|
||||
|
||||
@ -358,7 +359,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testIsSecondWithinRangeReturnsTrueIfWithin()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'seconds' => array(6, 7),
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -375,7 +376,7 @@ class TimeTypeTest extends TestCase
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'choice',
|
||||
));
|
||||
|
||||
@ -391,7 +392,7 @@ class TimeTypeTest extends TestCase
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'choice',
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -409,7 +410,7 @@ class TimeTypeTest extends TestCase
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'choice',
|
||||
));
|
||||
|
||||
@ -425,7 +426,7 @@ class TimeTypeTest extends TestCase
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'choice',
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -443,7 +444,7 @@ class TimeTypeTest extends TestCase
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'choice',
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -461,7 +462,7 @@ class TimeTypeTest extends TestCase
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'choice',
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -479,7 +480,7 @@ class TimeTypeTest extends TestCase
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'choice',
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -497,12 +498,12 @@ class TimeTypeTest extends TestCase
|
||||
{
|
||||
// Throws an exception if "data_class" option is not explicitly set
|
||||
// to null in the type
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', new \DateTime());
|
||||
$this->factory->create(static::TESTED_TYPE, new \DateTime());
|
||||
}
|
||||
|
||||
public function testSingleTextWidgetShouldUseTheRightInputType()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
|
||||
@ -512,7 +513,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSingleTextWidgetWithSecondsShouldHaveRightStepAttribute()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -524,7 +525,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testSingleTextWidgetWithSecondsShouldNotOverrideStepAttribute()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
'with_seconds' => true,
|
||||
'attr' => array(
|
||||
@ -539,7 +540,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testDontPassHtml5TypeIfHtml5NotAllowed()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => 'single_text',
|
||||
'html5' => false,
|
||||
));
|
||||
@ -550,7 +551,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testPassDefaultPlaceholderToViewIfNotRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => false,
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -563,7 +564,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testPassNoPlaceholderToViewIfRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => true,
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -576,7 +577,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testPassPlaceholderAsString()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'placeholder' => 'Empty',
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -592,7 +593,7 @@ class TimeTypeTest extends TestCase
|
||||
*/
|
||||
public function testPassEmptyValueBC()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'empty_value' => 'Empty',
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -608,7 +609,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testPassPlaceholderAsArray()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'placeholder' => array(
|
||||
'hour' => 'Empty hour',
|
||||
'minute' => 'Empty minute',
|
||||
@ -625,7 +626,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => false,
|
||||
'placeholder' => array(
|
||||
'hour' => 'Empty hour',
|
||||
@ -642,7 +643,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testPassPlaceholderAsPartialArrayAddNullIfRequired()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'required' => true,
|
||||
'placeholder' => array(
|
||||
'hour' => 'Empty hour',
|
||||
@ -671,7 +672,7 @@ class TimeTypeTest extends TestCase
|
||||
public function testHourErrorsBubbleUp($widget)
|
||||
{
|
||||
$error = new FormError('Invalid!');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => $widget,
|
||||
));
|
||||
$form['hour']->addError($error);
|
||||
@ -686,7 +687,7 @@ class TimeTypeTest extends TestCase
|
||||
public function testMinuteErrorsBubbleUp($widget)
|
||||
{
|
||||
$error = new FormError('Invalid!');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => $widget,
|
||||
));
|
||||
$form['minute']->addError($error);
|
||||
@ -701,7 +702,7 @@ class TimeTypeTest extends TestCase
|
||||
public function testSecondErrorsBubbleUp($widget)
|
||||
{
|
||||
$error = new FormError('Invalid!');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'widget' => $widget,
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -716,7 +717,7 @@ class TimeTypeTest extends TestCase
|
||||
*/
|
||||
public function testInitializeWithSecondsAndWithoutMinutes()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'with_minutes' => false,
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -727,7 +728,7 @@ class TimeTypeTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfHoursIsInvalid()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'hours' => 'bad value',
|
||||
));
|
||||
}
|
||||
@ -737,7 +738,7 @@ class TimeTypeTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfMinutesIsInvalid()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'minutes' => 'bad value',
|
||||
));
|
||||
}
|
||||
@ -747,14 +748,14 @@ class TimeTypeTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfSecondsIsInvalid()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'seconds' => 'bad value',
|
||||
));
|
||||
}
|
||||
|
||||
public function testPassDefaultChoiceTranslationDomain()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType');
|
||||
$form = $this->factory->create(static::TESTED_TYPE);
|
||||
|
||||
$view = $form->createView();
|
||||
$this->assertFalse($view['hour']->vars['choice_translation_domain']);
|
||||
@ -763,7 +764,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testPassChoiceTranslationDomainAsString()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'choice_translation_domain' => 'messages',
|
||||
'with_seconds' => true,
|
||||
));
|
||||
@ -776,7 +777,7 @@ class TimeTypeTest extends TestCase
|
||||
|
||||
public function testPassChoiceTranslationDomainAsArray()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'choice_translation_domain' => array(
|
||||
'hour' => 'foo',
|
||||
'second' => 'test',
|
||||
@ -789,4 +790,11 @@ class TimeTypeTest extends TestCase
|
||||
$this->assertFalse($view['minute']->vars['choice_translation_domain']);
|
||||
$this->assertSame('test', $view['second']->vars['choice_translation_domain']);
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
$view = array('hour' => '', 'minute' => '');
|
||||
|
||||
parent::testSubmitNull($expected, $norm, $view);
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,11 @@
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
|
||||
class TimezoneTypeTest extends TypeTestCase
|
||||
class TimezoneTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\TimezoneType';
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
@ -28,9 +29,8 @@ class TimezoneTypeTest extends TypeTestCase
|
||||
|
||||
public function testTimezonesAreSelectable()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimezoneType');
|
||||
$view = $form->createView();
|
||||
$choices = $view->vars['choices'];
|
||||
$choices = $this->factory->create(static::TESTED_TYPE)
|
||||
->createView()->vars['choices'];
|
||||
|
||||
$this->assertArrayHasKey('Africa', $choices);
|
||||
$this->assertContains(new ChoiceView('Africa/Kinshasa', 'Africa/Kinshasa', 'Kinshasa'), $choices['Africa'], '', false, false);
|
||||
@ -38,4 +38,9 @@ class TimezoneTypeTest extends TypeTestCase
|
||||
$this->assertArrayHasKey('America', $choices);
|
||||
$this->assertContains(new ChoiceView('America/New_York', 'America/New_York', 'New York'), $choices['America'], '', false, false);
|
||||
}
|
||||
|
||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||
{
|
||||
parent::testSubmitNull($expected, $norm, '');
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
||||
|
||||
class UrlTypeTest extends TestCase
|
||||
class UrlTypeTest extends TextTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\UrlType';
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
@ -27,7 +27,7 @@ class UrlTypeTest extends TestCase
|
||||
|
||||
public function testSubmitAddsDefaultProtocolIfNoneIsIncluded()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\UrlType', 'name');
|
||||
$form = $this->factory->create(static::TESTED_TYPE, 'name');
|
||||
|
||||
$form->submit('www.domain.com');
|
||||
|
||||
@ -37,7 +37,7 @@ class UrlTypeTest extends TestCase
|
||||
|
||||
public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\UrlType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'default_protocol' => 'http',
|
||||
));
|
||||
|
||||
@ -49,7 +49,7 @@ class UrlTypeTest extends TestCase
|
||||
|
||||
public function testSubmitAddsNoDefaultProtocolIfEmpty()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\UrlType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'default_protocol' => 'http',
|
||||
));
|
||||
|
||||
@ -61,7 +61,7 @@ class UrlTypeTest extends TestCase
|
||||
|
||||
public function testSubmitAddsNoDefaultProtocolIfNull()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\UrlType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'default_protocol' => 'http',
|
||||
));
|
||||
|
||||
@ -73,7 +73,7 @@ class UrlTypeTest extends TestCase
|
||||
|
||||
public function testSubmitAddsNoDefaultProtocolIfSetToNull()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\UrlType', null, array(
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'default_protocol' => null,
|
||||
));
|
||||
|
||||
@ -88,7 +88,7 @@ class UrlTypeTest extends TestCase
|
||||
*/
|
||||
public function testThrowExceptionIfDefaultProtocolIsInvalid()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\UrlType', null, array(
|
||||
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'default_protocol' => array(),
|
||||
));
|
||||
}
|
||||
|
@ -513,6 +513,24 @@ class SimpleFormTest extends AbstractFormTest
|
||||
$this->assertSame('default', $form->getData());
|
||||
}
|
||||
|
||||
public function testPresSetDataChangesDataIfDataIsLocked()
|
||||
{
|
||||
$config = new FormConfigBuilder('name', null, $this->dispatcher);
|
||||
$config
|
||||
->setData('default')
|
||||
->setDataLocked(true)
|
||||
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
|
||||
$event->setData('foobar');
|
||||
});
|
||||
$form = new Form($config);
|
||||
|
||||
$form->submit(false);
|
||||
|
||||
$this->assertTrue($form->isValid());
|
||||
|
||||
$this->assertSame('foobar', $form->getData());
|
||||
}
|
||||
|
||||
public function testSubmitConvertsEmptyToNullIfNoTransformer()
|
||||
{
|
||||
$form = $this->getBuilder()->getForm();
|
||||
|
@ -96,6 +96,6 @@ class TimeZoneTransformer extends Transformer
|
||||
return 'Etc/GMT'.($hours !== 0 ? $signal.$hours : '');
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf("The GMT time zone '%s' does not match with the supported formats GMT[+-]HH:MM or GMT[+-]HHMM.", $formattedTimeZone));
|
||||
throw new \InvalidArgumentException(sprintf('The GMT time zone "%s" does not match with the supported formats GMT[+-]HH:MM or GMT[+-]HHMM.', $formattedTimeZone));
|
||||
}
|
||||
}
|
||||
|
@ -369,7 +369,10 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
||||
if (is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
|
||||
foreach ($data as $key => $data) {
|
||||
//Ah this is the magic @ attribute types.
|
||||
if (0 === strpos($key, '@') && is_scalar($data) && $this->isElementNameValid($attributeName = substr($key, 1))) {
|
||||
if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
|
||||
if (!is_scalar($data)) {
|
||||
$data = $this->serializer->normalize($data, $this->format, $this->context);
|
||||
}
|
||||
$parentNode->setAttribute($attributeName, $data);
|
||||
} elseif ($key === '#') {
|
||||
$append = $this->selectNodeType($parentNode, $data);
|
||||
@ -474,7 +477,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
||||
} elseif ($val instanceof \Traversable) {
|
||||
$this->buildXml($node, $val);
|
||||
} elseif (is_object($val)) {
|
||||
return $this->buildXml($node, $this->serializer->normalize($val, $this->format, $this->context));
|
||||
return $this->selectNodeType($node, $this->serializer->normalize($val, $this->format, $this->context));
|
||||
} elseif (is_numeric($val)) {
|
||||
return $this->appendText($node, (string) $val);
|
||||
} elseif (is_string($val) && $this->needsCdataWrapping($val)) {
|
||||
|
@ -19,11 +19,17 @@ use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
class XmlEncoderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var XmlEncoder
|
||||
*/
|
||||
private $encoder;
|
||||
|
||||
private $exampleDateTimeString = '2017-02-19T15:16:08+0300';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->encoder = new XmlEncoder();
|
||||
@ -529,4 +535,89 @@ XML;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function testEncodeXmlWithBoolValue()
|
||||
{
|
||||
$expectedXml = <<<'XML'
|
||||
<?xml version="1.0"?>
|
||||
<response><foo>1</foo><bar>0</bar></response>
|
||||
|
||||
XML;
|
||||
|
||||
$actualXml = $this->encoder->encode(array('foo' => true, 'bar' => false), 'xml');
|
||||
|
||||
$this->assertEquals($expectedXml, $actualXml);
|
||||
}
|
||||
|
||||
public function testEncodeXmlWithDateTimeObjectValue()
|
||||
{
|
||||
$xmlEncoder = $this->createXmlEncoderWithDateTimeNormalizer();
|
||||
|
||||
$actualXml = $xmlEncoder->encode(array('dateTime' => new \DateTime($this->exampleDateTimeString)), 'xml');
|
||||
|
||||
$this->assertEquals($this->createXmlWithDateTime(), $actualXml);
|
||||
}
|
||||
|
||||
public function testEncodeXmlWithDateTimeObjectField()
|
||||
{
|
||||
$xmlEncoder = $this->createXmlEncoderWithDateTimeNormalizer();
|
||||
|
||||
$actualXml = $xmlEncoder->encode(array('foo' => array('@dateTime' => new \DateTime($this->exampleDateTimeString))), 'xml');
|
||||
|
||||
$this->assertEquals($this->createXmlWithDateTimeField(), $actualXml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return XmlEncoder
|
||||
*/
|
||||
private function createXmlEncoderWithDateTimeNormalizer()
|
||||
{
|
||||
$encoder = new XmlEncoder();
|
||||
$serializer = new Serializer(array($this->createMockDateTimeNormalizer()), array('xml' => new XmlEncoder()));
|
||||
$encoder->setSerializer($serializer);
|
||||
|
||||
return $encoder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject|NormalizerInterface
|
||||
*/
|
||||
private function createMockDateTimeNormalizer()
|
||||
{
|
||||
$mock = $this->getMockBuilder('\Symfony\Component\Serializer\Normalizer\CustomNormalizer')->getMock();
|
||||
|
||||
$mock
|
||||
->expects($this->once())
|
||||
->method('normalize')
|
||||
->with(new \DateTime($this->exampleDateTimeString), 'xml', array())
|
||||
->willReturn($this->exampleDateTimeString);
|
||||
|
||||
$mock
|
||||
->expects($this->once())
|
||||
->method('supportsNormalization')
|
||||
->with(new \DateTime($this->exampleDateTimeString), 'xml')
|
||||
->willReturn(true);
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function createXmlWithDateTime()
|
||||
{
|
||||
return sprintf('<?xml version="1.0"?>
|
||||
<response><dateTime>%s</dateTime></response>
|
||||
', $this->exampleDateTimeString);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function createXmlWithDateTimeField()
|
||||
{
|
||||
return sprintf('<?xml version="1.0"?>
|
||||
<response><foo dateTime="%s"/></response>
|
||||
', $this->exampleDateTimeString);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user