diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index e87713f561af4..065050199951a 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -29,13 +29,16 @@ 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 @@ protected function persist(array $entities) */ public function testClassOptionIsRequired() { - $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType'); + $this->factory->createNamed('name', static::TESTED_TYPE); } /** @@ -124,7 +127,7 @@ public function testClassOptionIsRequired() */ 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', )); } @@ -136,7 +139,7 @@ public function testSetDataToUninitializedEntityWithNonRequired() $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, @@ -153,13 +156,14 @@ public function testSetDataToUninitializedEntityWithNonRequiredToString() $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() @@ -170,15 +174,16 @@ public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder() $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']); } /** @@ -186,7 +191,7 @@ public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder() */ 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(), @@ -198,7 +203,7 @@ public function testConfigureQueryBuilderWithNonQueryBuilderAndNonClosure() */ 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 () { @@ -216,7 +221,7 @@ public function testConfigureQueryBuilderWithClosureReturningNullUseDefault() $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 () { @@ -229,7 +234,7 @@ public function testConfigureQueryBuilderWithClosureReturningNullUseDefault() 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, @@ -242,7 +247,7 @@ public function testSetDataSingleNull() 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', @@ -256,7 +261,7 @@ public function testSetDataMultipleExpandedNull() 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', @@ -268,47 +273,6 @@ public function testSetDataMultipleNonExpandedNull() $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'); @@ -316,7 +280,7 @@ public function testSubmitSingleNonExpandedSingleIdentifier() $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', @@ -341,7 +305,7 @@ public function testSubmitSingleNonExpandedSingleAssocIdentifier() $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', @@ -363,7 +327,7 @@ public function testSubmitSingleNonExpandedCompositeIdentifier() $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', @@ -387,7 +351,7 @@ public function testSubmitMultipleNonExpandedSingleIdentifier() $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', @@ -416,7 +380,7 @@ public function testSubmitMultipleNonExpandedSingleAssocIdentifier() $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', @@ -441,7 +405,7 @@ public function testSubmitMultipleNonExpandedSingleIdentifierForExistingData() $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', @@ -472,7 +436,7 @@ public function testSubmitMultipleNonExpandedCompositeIdentifier() $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', @@ -498,7 +462,7 @@ public function testSubmitMultipleNonExpandedCompositeIdentifierExistingData() $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', @@ -528,7 +492,7 @@ public function testSubmitSingleExpanded() $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', @@ -554,7 +518,7 @@ public function testSubmitMultipleExpanded() $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', @@ -583,7 +547,7 @@ public function testSubmitMultipleExpandedWithNegativeIntegerId() $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', @@ -608,7 +572,7 @@ public function testSubmitSingleNonExpandedStringCastableIdentifier() $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', @@ -630,7 +594,7 @@ public function testSubmitSingleStringCastableIdentifierExpanded() $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', @@ -656,7 +620,7 @@ public function testSubmitMultipleNonExpandedStringCastableIdentifierForExisting $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', @@ -687,7 +651,7 @@ public function testSubmitMultipleNonExpandedStringCastableIdentifier() $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', @@ -712,7 +676,7 @@ public function testSubmitMultipleStringCastableIdentifierExpanded() $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', @@ -742,7 +706,7 @@ public function testOverrideChoices() $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 @@ -765,7 +729,7 @@ public function testOverrideChoicesValues() $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', @@ -787,7 +751,7 @@ public function testOverrideChoicesValuesWithCallable() $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', @@ -818,7 +782,7 @@ public function testChoicesForValuesOptimization() $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', @@ -844,7 +808,7 @@ public function testGroupByChoices() $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), @@ -875,7 +839,7 @@ public function testPreferredChoices() $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), @@ -894,7 +858,7 @@ public function testOverrideChoicesWithPreferredChoices() $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), @@ -914,7 +878,7 @@ public function testDisallowChoicesThatAreNotIncludedChoicesSingleIdentifier() $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), @@ -937,7 +901,7 @@ public function testDisallowChoicesThatAreNotIncludedChoicesSingleAssocIdentifie $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), @@ -958,7 +922,7 @@ public function testDisallowChoicesThatAreNotIncludedChoicesCompositeIdentifier( $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), @@ -981,7 +945,7 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifie $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') @@ -1009,7 +973,7 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleAssocIden $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') @@ -1031,10 +995,10 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureSingle $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)'); }, @@ -1055,10 +1019,10 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureCompos $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)'); }, @@ -1077,7 +1041,7 @@ public function testSubmitSingleStringIdentifier() $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', @@ -1098,7 +1062,7 @@ public function testSubmitCompositeStringIdentifier() $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', @@ -1124,7 +1088,7 @@ public function testGetManagerForClassIfNoEm() ->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', @@ -1139,7 +1103,7 @@ public function testExplicitEm() $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', @@ -1168,15 +1132,15 @@ public function testLoaderCaching() ->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) { @@ -1184,7 +1148,7 @@ public function testLoaderCaching() }, )); - $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) { @@ -1231,15 +1195,15 @@ public function testLoaderCachingWithParameters() ->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) { @@ -1247,7 +1211,7 @@ public function testLoaderCachingWithParameters() }, )); - $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) { @@ -1282,4 +1246,213 @@ protected function createRegistryMock($name, $em) 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'); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php index 997622faa3127..facab9730908b 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php @@ -18,6 +18,8 @@ */ 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 @@ public function testStripLeadingUnderscoresAndDigitsFromId() 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 @@ public function testPassIdAndNameToViewWithParent() 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 @@ public function testPassIdAndNameToViewWithGrandParent() 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 @@ public function testPassTranslationDomainToView() 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 @@ public function testInheritTranslationDomainFromParent() 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 @@ public function testPreferOwnTranslationDomain() 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 @@ public function testDefaultTranslationDomain() 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; + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/BirthdayTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/BirthdayTypeTest.php index 867816bb76bad..7f9130b90ee41 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/BirthdayTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/BirthdayTypeTest.php @@ -14,20 +14,17 @@ /** * @author Stepan Anchugov */ -class BirthdayTypeTest extends BaseTypeTest +class BirthdayTypeTest extends DateTypeTest { + const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\BirthdayType'; + /** * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException */ 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'; - } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php index 4d480d5de65aa..4e2b4f49b8dea 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php @@ -16,13 +16,10 @@ */ class ButtonTypeTest extends BaseTypeTest { - public function testCreateButtonInstances() - { - $this->assertInstanceOf('Symfony\Component\Form\Button', $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ButtonType')); - } + const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\ButtonType'; - protected function getTestedType() + public function testCreateButtonInstances() { - return 'Symfony\Component\Form\Extension\Core\Type\ButtonType'; + $this->assertInstanceOf('Symfony\Component\Form\Button', $this->factory->create(static::TESTED_TYPE)); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php index e235fcb8fef0f..a9aeb9c270ec7 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php @@ -12,13 +12,14 @@ 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'; + 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()); @@ -27,42 +28,42 @@ public function testDataIsFalseByDefault() 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'); @@ -73,7 +74,7 @@ public function testSubmitWithValueChecked() 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'); @@ -84,7 +85,7 @@ public function testSubmitWithRandomValueChecked() 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); @@ -95,7 +96,7 @@ public function testSubmitWithValueUnchecked() 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(''); @@ -106,7 +107,7 @@ public function testSubmitWithEmptyValueChecked() 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); @@ -117,7 +118,7 @@ public function testSubmitWithEmptyValueUnchecked() 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); @@ -128,7 +129,7 @@ public function testSubmitWithEmptyValueAndFalseUnchecked() 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); @@ -152,7 +153,7 @@ function ($value) { } ); - $form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\CheckboxType') + $form = $this->factory->createBuilder(static::TESTED_TYPE) ->addModelTransformer($transformer) ->getForm(); @@ -171,4 +172,9 @@ public function provideCustomModelTransformerData() array('unchecked', false), ); } + + public function testSubmitNull($expected = null, $norm = null, $view = null) + { + parent::testSubmitNull(false, false, null); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 864e670a6e66e..93f370341d319 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -13,11 +13,11 @@ use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView; use Symfony\Component\Form\ChoiceList\View\ChoiceView; -use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList; -use Symfony\Component\Form\Test\TypeTestCase; -class ChoiceTypeTest extends TypeTestCase +class ChoiceTypeTest extends BaseTypeTest { + const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\ChoiceType'; + private $choices = array( 'Bernhard' => 'a', 'Fabien' => 'b', @@ -85,7 +85,7 @@ protected function tearDown() */ public function testChoicesOptionExpectsArrayOrTraversable() { - $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => new \stdClass(), )); } @@ -95,20 +95,19 @@ public function testChoicesOptionExpectsArrayOrTraversable() */ public function testChoiceLoaderOptionExpectsChoiceLoaderInterface() { - $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $this->factory->create(static::TESTED_TYPE, null, array( 'choice_loader' => new \stdClass(), )); } public function testChoiceListAndChoicesCanBeEmpty() { - $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( - )); + $this->factory->create(static::TESTED_TYPE); } public function testExpandedChoicesOptionsTurnIntoChildren() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'expanded' => true, 'choices' => $this->choices, )); @@ -118,7 +117,7 @@ public function testExpandedChoicesOptionsTurnIntoChildren() public function testChoiceListWithScalarValues() { - $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => $this->scalarChoices, ))->createView(); @@ -132,7 +131,7 @@ public function testChoiceListWithScalarValues() public function testChoiceListWithScalarValuesAndFalseAsPreSetData() { - $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( + $view = $this->factory->create(static::TESTED_TYPE, false, array( 'choices' => $this->scalarChoices, ))->createView(); @@ -141,7 +140,7 @@ public function testChoiceListWithScalarValuesAndFalseAsPreSetData() public function testExpandedChoiceListWithScalarValues() { - $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => $this->scalarChoices, 'expanded' => true, ))->createView(); @@ -153,7 +152,7 @@ public function testExpandedChoiceListWithScalarValues() public function testExpandedChoiceListWithBooleanAndNullValues() { - $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => $this->booleanChoicesWithNull, 'expanded' => true, ))->createView(); @@ -165,7 +164,7 @@ public function testExpandedChoiceListWithBooleanAndNullValues() public function testExpandedChoiceListWithScalarValuesAndFalseAsPreSetData() { - $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( + $view = $this->factory->create(static::TESTED_TYPE, false, array( 'choices' => $this->scalarChoices, 'expanded' => true, ))->createView(); @@ -178,7 +177,7 @@ public function testExpandedChoiceListWithScalarValuesAndFalseAsPreSetData() public function testExpandedChoiceListWithBooleanAndNullValuesAndFalseAsPreSetData() { - $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( + $view = $this->factory->create(static::TESTED_TYPE, false, array( 'choices' => $this->booleanChoicesWithNull, 'expanded' => true, ))->createView(); @@ -190,7 +189,7 @@ public function testExpandedChoiceListWithBooleanAndNullValuesAndFalseAsPreSetDa public function testPlaceholderPresentOnNonRequiredExpandedSingleChoice() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -203,7 +202,7 @@ public function testPlaceholderPresentOnNonRequiredExpandedSingleChoice() public function testPlaceholderNotPresentIfRequired() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => true, @@ -216,7 +215,7 @@ public function testPlaceholderNotPresentIfRequired() public function testPlaceholderNotPresentIfMultiple() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => true, 'required' => false, @@ -229,7 +228,7 @@ public function testPlaceholderNotPresentIfMultiple() public function testPlaceholderNotPresentIfEmptyChoice() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -245,7 +244,7 @@ public function testPlaceholderNotPresentIfEmptyChoice() public function testPlaceholderWithBooleanChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, 'required' => false, @@ -254,9 +253,8 @@ public function testPlaceholderWithBooleanChoices() 'No' => false, ), 'placeholder' => 'Select an option', - )); - - $view = $form->createView(); + )) + ->createView(); $this->assertSame('', $view->vars['value'], 'Value should be empty'); $this->assertSame('1', $view->vars['choices'][0]->value); @@ -266,7 +264,7 @@ public function testPlaceholderWithBooleanChoices() public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( + $view = $this->factory->create(static::TESTED_TYPE, false, array( 'multiple' => false, 'expanded' => false, 'required' => false, @@ -275,9 +273,8 @@ public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData() 'No' => false, ), 'placeholder' => 'Select an option', - )); - - $view = $form->createView(); + )) + ->createView(); $this->assertSame('0', $view->vars['value'], 'Value should be "0"'); $this->assertSame('1', $view->vars['choices'][0]->value); @@ -287,7 +284,7 @@ public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData() public function testPlaceholderWithExpandedBooleanChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -311,7 +308,7 @@ public function testPlaceholderWithExpandedBooleanChoices() public function testPlaceholderWithExpandedBooleanChoicesAndWithFalseAsPreSetData() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( + $form = $this->factory->create(static::TESTED_TYPE, false, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -335,7 +332,7 @@ public function testPlaceholderWithExpandedBooleanChoicesAndWithFalseAsPreSetDat public function testExpandedChoicesOptionsAreFlattened() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'expanded' => true, 'choices' => $this->groupedChoices, )); @@ -360,7 +357,7 @@ public function testExpandedChoicesOptionsAreFlattenedObjectChoices() $obj4 = (object) array('id' => 4, 'name' => 'Jon'); $obj5 = (object) array('id' => 5, 'name' => 'Roman'); - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'expanded' => true, 'choices' => array( 'Symfony' => array($obj1, $obj2, $obj3), @@ -379,7 +376,7 @@ public function testExpandedChoicesOptionsAreFlattenedObjectChoices() public function testExpandedCheckboxesAreNeverRequired() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => true, 'required' => true, @@ -393,7 +390,7 @@ public function testExpandedCheckboxesAreNeverRequired() public function testExpandedRadiosAreRequiredIfChoiceChildIsRequired() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => true, @@ -407,7 +404,7 @@ public function testExpandedRadiosAreRequiredIfChoiceChildIsRequired() public function testExpandedRadiosAreNotRequiredIfChoiceChildIsNotRequired() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -421,7 +418,7 @@ public function testExpandedRadiosAreNotRequiredIfChoiceChildIsNotRequired() public function testSubmitSingleNonExpanded() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, 'choices' => $this->choices, @@ -436,7 +433,7 @@ public function testSubmitSingleNonExpanded() public function testSubmitSingleNonExpandedInvalidChoice() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, 'choices' => $this->choices, @@ -451,7 +448,7 @@ public function testSubmitSingleNonExpandedInvalidChoice() public function testSubmitSingleNonExpandedNull() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, 'choices' => $this->choices, @@ -467,9 +464,9 @@ public function testSubmitSingleNonExpandedNull() // In edge cases (for example, when choices are loaded dynamically by a // loader), the choices may be empty. Make sure to behave the same as when // choices are available. - public function testSubmitSingleNonExpandedNullNoChoices() + public function testSubmitNull($expected = null, $norm = null, $view = null) { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, 'choices' => array(), @@ -478,13 +475,14 @@ public function testSubmitSingleNonExpandedNullNoChoices() $form->submit(null); $this->assertNull($form->getData()); + $this->assertNull($form->getNormData()); $this->assertSame('', $form->getViewData()); $this->assertTrue($form->isSynchronized()); } public function testSubmitSingleNonExpandedEmpty() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, 'choices' => $this->choices, @@ -499,7 +497,7 @@ public function testSubmitSingleNonExpandedEmpty() public function testSubmitSingleNonExpandedEmptyExplicitEmptyChoice() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, 'choices' => array( @@ -522,7 +520,7 @@ public function testSubmitSingleNonExpandedEmptyExplicitEmptyChoice() // choices are available. public function testSubmitSingleNonExpandedEmptyNoChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, 'choices' => array(), @@ -537,7 +535,7 @@ public function testSubmitSingleNonExpandedEmptyNoChoices() public function testSubmitSingleNonExpandedFalse() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, 'choices' => $this->choices, @@ -555,7 +553,7 @@ public function testSubmitSingleNonExpandedFalse() // choices are available. public function testSubmitSingleNonExpandedFalseNoChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, 'choices' => array(), @@ -570,7 +568,7 @@ public function testSubmitSingleNonExpandedFalseNoChoices() public function testSubmitSingleNonExpandedObjectChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, 'choices' => $this->objectChoices, @@ -588,7 +586,7 @@ public function testSubmitSingleNonExpandedObjectChoices() public function testSubmitSingleChoiceWithEmptyData() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, 'choices' => array('test'), @@ -602,7 +600,7 @@ public function testSubmitSingleChoiceWithEmptyData() public function testSubmitMultipleChoiceWithEmptyData() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => false, 'choices' => array('test'), @@ -616,7 +614,7 @@ public function testSubmitMultipleChoiceWithEmptyData() public function testSubmitSingleChoiceExpandedWithEmptyData() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'choices' => array('test'), @@ -630,7 +628,7 @@ public function testSubmitSingleChoiceExpandedWithEmptyData() public function testSubmitMultipleChoiceExpandedWithEmptyData() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => true, 'choices' => array('test'), @@ -644,7 +642,7 @@ public function testSubmitMultipleChoiceExpandedWithEmptyData() public function testSubmitMultipleNonExpanded() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => false, 'choices' => $this->choices, @@ -659,7 +657,7 @@ public function testSubmitMultipleNonExpanded() public function testSubmitMultipleNonExpandedEmpty() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => false, 'choices' => $this->choices, @@ -677,7 +675,7 @@ public function testSubmitMultipleNonExpandedEmpty() // choices are available. public function testSubmitMultipleNonExpandedEmptyNoChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => false, 'choices' => array(), @@ -692,7 +690,7 @@ public function testSubmitMultipleNonExpandedEmptyNoChoices() public function testSubmitMultipleNonExpandedInvalidScalarChoice() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => false, 'choices' => $this->choices, @@ -707,7 +705,7 @@ public function testSubmitMultipleNonExpandedInvalidScalarChoice() public function testSubmitMultipleNonExpandedInvalidArrayChoice() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => false, 'choices' => $this->choices, @@ -722,7 +720,7 @@ public function testSubmitMultipleNonExpandedInvalidArrayChoice() public function testSubmitMultipleNonExpandedObjectChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => false, 'choices' => $this->objectChoices, @@ -739,7 +737,7 @@ public function testSubmitMultipleNonExpandedObjectChoices() public function testSubmitSingleExpandedRequired() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => true, @@ -767,7 +765,7 @@ public function testSubmitSingleExpandedRequired() public function testSubmitSingleExpandedRequiredInvalidChoice() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => true, @@ -795,7 +793,7 @@ public function testSubmitSingleExpandedRequiredInvalidChoice() public function testSubmitSingleExpandedNonRequired() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -825,7 +823,7 @@ public function testSubmitSingleExpandedNonRequired() public function testSubmitSingleExpandedNonRequiredInvalidChoice() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -853,7 +851,7 @@ public function testSubmitSingleExpandedNonRequiredInvalidChoice() public function testSubmitSingleExpandedRequiredNull() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => true, @@ -884,7 +882,7 @@ public function testSubmitSingleExpandedRequiredNull() // choices are available. public function testSubmitSingleExpandedRequiredNullNoChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => true, @@ -901,7 +899,7 @@ public function testSubmitSingleExpandedRequiredNullNoChoices() public function testSubmitSingleExpandedRequiredEmpty() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => true, @@ -932,7 +930,7 @@ public function testSubmitSingleExpandedRequiredEmpty() // choices are available. public function testSubmitSingleExpandedRequiredEmptyNoChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => true, @@ -949,7 +947,7 @@ public function testSubmitSingleExpandedRequiredEmptyNoChoices() public function testSubmitSingleExpandedRequiredFalse() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => true, @@ -980,7 +978,7 @@ public function testSubmitSingleExpandedRequiredFalse() // choices are available. public function testSubmitSingleExpandedRequiredFalseNoChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => true, @@ -997,7 +995,7 @@ public function testSubmitSingleExpandedRequiredFalseNoChoices() public function testSubmitSingleExpandedNonRequiredNull() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -1030,7 +1028,7 @@ public function testSubmitSingleExpandedNonRequiredNull() // choices are available. public function testSubmitSingleExpandedNonRequiredNullNoChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -1047,7 +1045,7 @@ public function testSubmitSingleExpandedNonRequiredNullNoChoices() public function testSubmitSingleExpandedNonRequiredEmpty() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -1080,7 +1078,7 @@ public function testSubmitSingleExpandedNonRequiredEmpty() // choices are available. public function testSubmitSingleExpandedNonRequiredEmptyNoChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -1097,7 +1095,7 @@ public function testSubmitSingleExpandedNonRequiredEmptyNoChoices() public function testSubmitSingleExpandedNonRequiredFalse() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -1130,7 +1128,7 @@ public function testSubmitSingleExpandedNonRequiredFalse() // choices are available. public function testSubmitSingleExpandedNonRequiredFalseNoChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -1147,7 +1145,7 @@ public function testSubmitSingleExpandedNonRequiredFalseNoChoices() public function testSubmitSingleExpandedWithEmptyChild() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'choices' => array( @@ -1169,7 +1167,7 @@ public function testSubmitSingleExpandedWithEmptyChild() public function testSubmitSingleExpandedObjectChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => true, 'choices' => $this->objectChoices, @@ -1196,7 +1194,7 @@ public function testSubmitSingleExpandedObjectChoices() public function testSubmitMultipleExpanded() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => true, 'choices' => $this->choices, @@ -1223,7 +1221,7 @@ public function testSubmitMultipleExpanded() public function testSubmitMultipleExpandedInvalidScalarChoice() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => true, 'choices' => $this->choices, @@ -1250,7 +1248,7 @@ public function testSubmitMultipleExpandedInvalidScalarChoice() public function testSubmitMultipleExpandedInvalidArrayChoice() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => true, 'choices' => $this->choices, @@ -1277,7 +1275,7 @@ public function testSubmitMultipleExpandedInvalidArrayChoice() public function testSubmitMultipleExpandedEmpty() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => true, 'choices' => $this->choices, @@ -1305,7 +1303,7 @@ public function testSubmitMultipleExpandedEmpty() // choices are available. public function testSubmitMultipleExpandedEmptyNoChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => true, 'choices' => array(), @@ -1319,7 +1317,7 @@ public function testSubmitMultipleExpandedEmptyNoChoices() public function testSubmitMultipleExpandedWithEmptyChild() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => true, 'choices' => array( @@ -1344,7 +1342,7 @@ public function testSubmitMultipleExpandedWithEmptyChild() public function testSubmitMultipleExpandedObjectChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => true, 'choices' => $this->objectChoices, @@ -1371,15 +1369,16 @@ public function testSubmitMultipleExpandedObjectChoices() public function testSingleSelectedObjectChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', $this->objectChoices[3], array( + $view = $this->factory->create(static::TESTED_TYPE, $this->objectChoices[3], array( 'multiple' => false, 'expanded' => false, 'choices' => $this->objectChoices, 'choice_label' => 'name', 'choice_value' => 'id', - )); + )) + ->createView(); - $view = $form->createView(); + /** @var callable $selectedChecker */ $selectedChecker = $view->vars['is_selected']; $this->assertTrue($selectedChecker($view->vars['choices'][3]->value, $view->vars['value'])); @@ -1388,15 +1387,16 @@ public function testSingleSelectedObjectChoices() public function testMultipleSelectedObjectChoices() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', array($this->objectChoices[3]), array( + $view = $this->factory->create(static::TESTED_TYPE, array($this->objectChoices[3]), array( 'multiple' => true, 'expanded' => false, 'choices' => $this->objectChoices, 'choice_label' => 'name', 'choice_value' => 'id', - )); + )) + ->createView(); - $view = $form->createView(); + /** @var callable $selectedChecker */ $selectedChecker = $view->vars['is_selected']; $this->assertTrue($selectedChecker($view->vars['choices'][3]->value, $view->vars['value'])); @@ -1405,75 +1405,75 @@ public function testMultipleSelectedObjectChoices() public function testPassRequiredToView() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => $this->choices, - )); - $view = $form->createView(); + )) + ->createView(); $this->assertTrue($view->vars['required']); } public function testPassNonRequiredToView() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'required' => false, 'choices' => $this->choices, - )); - $view = $form->createView(); + )) + ->createView(); $this->assertFalse($view->vars['required']); } public function testPassMultipleToView() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => true, 'choices' => $this->choices, - )); - $view = $form->createView(); + )) + ->createView(); $this->assertTrue($view->vars['multiple']); } public function testPassExpandedToView() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'expanded' => true, 'choices' => $this->choices, - )); - $view = $form->createView(); + )) + ->createView(); $this->assertTrue($view->vars['expanded']); } public function testPassChoiceTranslationDomainToView() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => $this->choices, - )); - $view = $form->createView(); + )) + ->createView(); $this->assertNull($view->vars['choice_translation_domain']); } public function testChoiceTranslationDomainWithTrueValueToView() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => $this->choices, 'choice_translation_domain' => true, - )); - $view = $form->createView(); + )) + ->createView(); $this->assertNull($view->vars['choice_translation_domain']); } public function testDefaultChoiceTranslationDomainIsSameAsTranslationDomainToView() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => $this->choices, 'translation_domain' => 'foo', - )); - $view = $form->createView(); + )) + ->createView(); $this->assertEquals('foo', $view->vars['choice_translation_domain']); } @@ -1481,12 +1481,10 @@ public function testDefaultChoiceTranslationDomainIsSameAsTranslationDomainToVie public function testInheritChoiceTranslationDomainFromParent() { $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', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array( - 'choices' => array(), - )) + ->add('child', static::TESTED_TYPE) ->getForm() ->createView(); @@ -1495,24 +1493,24 @@ public function testInheritChoiceTranslationDomainFromParent() public function testPlaceholderIsNullByDefaultIfRequired() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'required' => true, 'choices' => $this->choices, - )); - $view = $form->createView(); + )) + ->createView(); $this->assertNull($view->vars['placeholder']); } public function testPlaceholderIsEmptyStringByDefaultIfNotRequired() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'required' => false, 'choices' => $this->choices, - )); - $view = $form->createView(); + )) + ->createView(); $this->assertSame('', $view->vars['placeholder']); } @@ -1522,14 +1520,14 @@ public function testPlaceholderIsEmptyStringByDefaultIfNotRequired() */ public function testPassPlaceholderToView($multiple, $expanded, $required, $placeholder, $viewValue) { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => $multiple, 'expanded' => $expanded, 'required' => $required, 'placeholder' => $placeholder, 'choices' => $this->choices, - )); - $view = $form->createView(); + )) + ->createView(); $this->assertSame($viewValue, $view->vars['placeholder']); $this->assertFalse($view->vars['placeholder_in_choices']); @@ -1540,14 +1538,14 @@ public function testPassPlaceholderToView($multiple, $expanded, $required, $plac */ public function testDontPassPlaceholderIfContainedInChoices($multiple, $expanded, $required, $placeholder, $viewValue) { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => $multiple, 'expanded' => $expanded, 'required' => $required, 'placeholder' => $placeholder, 'choices' => array('Empty' => '', 'A' => 'a'), - )); - $view = $form->createView(); + )) + ->createView(); $this->assertNull($view->vars['placeholder']); $this->assertTrue($view->vars['placeholder_in_choices']); @@ -1600,10 +1598,10 @@ public function getOptionsWithPlaceholder() public function testPassChoicesToView() { $choices = array('A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd'); - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => $choices, - )); - $view = $form->createView(); + )) + ->createView(); $this->assertEquals(array( new ChoiceView('a', 'a', 'A'), @@ -1616,11 +1614,11 @@ public function testPassChoicesToView() public function testPassPreferredChoicesToView() { $choices = array('A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd'); - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => $choices, 'preferred_choices' => array('b', 'd'), - )); - $view = $form->createView(); + )) + ->createView(); $this->assertEquals(array( 0 => new ChoiceView('a', 'a', 'A'), @@ -1634,11 +1632,11 @@ public function testPassPreferredChoicesToView() public function testPassHierarchicalChoicesToView() { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => $this->groupedChoices, 'preferred_choices' => array('b', 'd'), - )); - $view = $form->createView(); + )) + ->createView(); $this->assertEquals(array( 'Symfony' => new ChoiceGroupView('Symfony', array( @@ -1665,12 +1663,12 @@ public function testPassChoiceDataToView() $obj2 = (object) array('value' => 'b', 'label' => 'B'); $obj3 = (object) array('value' => 'c', 'label' => 'C'); $obj4 = (object) array('value' => 'd', 'label' => 'D'); - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => array($obj1, $obj2, $obj3, $obj4), 'choice_label' => 'label', 'choice_value' => 'value', - )); - $view = $form->createView(); + )) + ->createView(); $this->assertEquals(array( new ChoiceView($obj1, 'a', 'A'), @@ -1682,12 +1680,12 @@ public function testPassChoiceDataToView() public function testAdjustFullNameForMultipleNonExpanded() { - $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $view = $this->factory->createNamed('name', static::TESTED_TYPE, null, array( 'multiple' => true, 'expanded' => false, 'choices' => $this->choices, - )); - $view = $form->createView(); + )) + ->createView(); $this->assertSame('name[]', $view->vars['full_name']); } @@ -1695,7 +1693,7 @@ public function testAdjustFullNameForMultipleNonExpanded() // https://github.com/symfony/symfony/issues/3298 public function testInitializeWithEmptyChoices() { - $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $this->factory->createNamed('name', static::TESTED_TYPE, null, array( 'choices' => array(), )); } @@ -1707,7 +1705,7 @@ public function testInitializeWithDefaultObjectChoice() $obj3 = (object) array('value' => 'c', 'label' => 'C'); $obj4 = (object) array('value' => 'd', 'label' => 'D'); - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => array($obj1, $obj2, $obj3, $obj4), 'choice_label' => 'label', 'choice_value' => 'value', @@ -1717,7 +1715,7 @@ public function testInitializeWithDefaultObjectChoice() )); // Trigger data initialization - $form->getViewData(); + $this->assertSame('c', $form->getViewData()); } /** @@ -1730,7 +1728,7 @@ public function testInitializeWithDefaultObjectChoice() public function testCustomChoiceTypeDoesNotInheritChoiceLabels() { $builder = $this->factory->createBuilder(); - $builder->add('choice', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array( + $builder->add('choice', static::TESTED_TYPE, array( 'choices' => array( '1' => '1', '2' => '2', @@ -1751,7 +1749,7 @@ public function testCustomChoiceTypeDoesNotInheritChoiceLabels() */ public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionData) { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( 'choices' => $this->choices, 'multiple' => $multiple, 'expanded' => $expanded, diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php index ee0546f6cfd67..7ed25ce27e42f 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php @@ -11,15 +11,16 @@ 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'; + 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); @@ -27,8 +28,8 @@ public function testContainsNoChildByDefault() 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), ), @@ -56,8 +57,8 @@ public function testSetDataAdjustsSize() 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()); @@ -65,8 +66,8 @@ public function testThrowsExceptionIfObjectIsNotTraversable() 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')); @@ -79,8 +80,8 @@ public function testNotResizedIfSubmittedWithMissingData() 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')); @@ -94,8 +95,8 @@ public function testResizedDownIfSubmittedWithMissingDataAndAllowDelete() 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, )); @@ -111,8 +112,8 @@ public function testResizedDownIfSubmittedWithEmptyDataAndDeleteEmpty() 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, )); @@ -128,8 +129,8 @@ public function testDontAddEmptyDataIfDeleteEmpty() 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, )); @@ -143,7 +144,7 @@ public function testNoDeleteEmptyIfDeleteNotAllowed() 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 @@ -166,8 +167,8 @@ public function testResizedDownIfSubmittedWithCompoundEmptyDataAndDeleteEmpty() 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')); @@ -179,8 +180,8 @@ public function testNotResizedIfSubmittedWithExtraData() 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')); @@ -195,8 +196,8 @@ public function testResizedUpIfSubmittedWithExtraDataAndAllowAdd() 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, )); @@ -207,8 +208,8 @@ public function testAllowAddButNoPrototype() 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, )) @@ -219,8 +220,8 @@ public function testPrototypeMultipartPropagation() 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, )); @@ -231,8 +232,8 @@ public function testGetDataDoesNotContainsPrototypeNameBeforeDataAreSet() 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, )); @@ -244,16 +245,16 @@ public function testGetDataDoesNotContainsPrototypeNameAfterDataAreSet() 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__', @@ -264,8 +265,8 @@ public function testPrototypeNameOption() 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__', @@ -276,11 +277,11 @@ public function testPrototypeDefaultLabel() 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, @@ -293,8 +294,8 @@ public function testPrototypeData() 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__', @@ -305,8 +306,8 @@ public function testPrototypeDefaultRequired() 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__', @@ -319,14 +320,14 @@ public function testPrototypeSetNotRequired() 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, )); @@ -338,8 +339,8 @@ public function testPrototypeSetNotRequiredIfParentNotRequired() 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__', @@ -348,7 +349,7 @@ public function testPrototypeNotOverrideRequiredByEntryOptionsInFavorOfParent() ), )); - $parent = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', array(), array( + $parent = $this->factory->create(FormTypeTest::TESTED_TYPE, array(), array( 'required' => false, )); @@ -358,4 +359,9 @@ public function testPrototypeNotOverrideRequiredByEntryOptionsInFavorOfParent() $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()); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php index e006e075d4c78..e7f91ce4405af 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php @@ -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); @@ -26,9 +27,8 @@ protected function setUp() 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); @@ -40,9 +40,8 @@ public function testCountriesAreSelectable() 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) { @@ -50,4 +49,9 @@ public function testUnknownCountryIsNotIncluded() } } } + + public function testSubmitNull($expected = null, $norm = null, $view = null) + { + parent::testSubmitNull($expected, $norm, ''); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php index cd894a52c3260..be9264d7b19db 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php @@ -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); @@ -26,12 +27,16 @@ protected function setUp() 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, ''); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php index 8d44e3c934a1f..dd28f04df5dfb 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php @@ -13,228 +13,199 @@ use Symfony\Component\Form\Extension\Core\Type\DateIntervalType; use Symfony\Component\Form\FormError; -use Symfony\Component\Form\Test\TypeTestCase as TestCase; -class DateIntervalTypeTest extends TestCase +class DateIntervalTypeTest extends BaseTypeTest { + const TESTED_TYPE = DateIntervalType::class; + public function testSubmitDateInterval() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'input' => 'dateinterval', - ) - ); - $form->submit( - array( - 'years' => '7', - 'months' => '6', - 'days' => '5', - ) - ); - $dateInterval = new \DateInterval('P7Y6M5D'); - $this->assertDateIntervalEquals($dateInterval, $form->getData()); + $form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'dateinterval')); + + $form->submit(array( + 'years' => '7', + 'months' => '6', + 'days' => '5', + )); + + $this->assertDateIntervalEquals(new \DateInterval('P7Y6M5D'), $form->getData()); } public function testSubmitString() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'input' => 'string', - ) - ); - $form->submit( - array( - 'years' => '7', - 'months' => '6', - 'days' => '5', - ) - ); - $this->assertEquals('P7Y6M5D', $form->getData()); + $form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'string')); + + $form->submit(array( + 'years' => '7', + 'months' => '6', + 'days' => '5', + )); + + $this->assertSame('P7Y6M5D', $form->getData()); } public function testSubmitArray() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'input' => 'array', - ) - ); - $form->submit( - array( - 'years' => '7', - 'months' => '6', - 'days' => '5', - ) + $form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'array')); + + $input = array( + 'years' => '7', + 'months' => '6', + 'days' => '5', ); - $this->assertEquals(array('years' => '7', 'months' => '6', 'days' => '5'), $form->getData()); + + $form->submit($input); + + $this->assertSame($input, $form->getData()); } public function testSubmitWithoutMonths() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'input' => 'dateinterval', - 'with_months' => false, - ) - ); - $form->setData(new \DateInterval('P7Y5D')); - $input = array( + $interval = new \DateInterval('P7Y5D'); + + $form = $this->factory->create(static::TESTED_TYPE, $interval, array( + 'input' => 'dateinterval', + 'with_months' => false, + )); + + $form->submit(array( 'years' => '7', 'months' => '6', 'days' => '5', - ); - $form->submit($input); - $this->assertDateIntervalEquals(new \DateInterval('P7Y5D'), $form->getData()); + )); + + $this->assertDateIntervalEquals($interval, $form->getData()); + $this->assertTrue($form->isSynchronized()); } public function testSubmitWithTime() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'input' => 'dateinterval', - 'with_hours' => true, - 'with_minutes' => true, - 'with_seconds' => true, - ) - ); - $form->setData(new \DateInterval('P7Y6M5DT4H3M2S')); - $input = array( + $interval = new \DateInterval('P7Y6M5DT4H3M2S'); + $form = $this->factory->create(static::TESTED_TYPE, $interval, array( + 'input' => 'dateinterval', + 'with_hours' => true, + 'with_minutes' => true, + 'with_seconds' => true, + )); + + $form->submit(array( 'years' => '7', 'months' => '6', 'days' => '5', 'hours' => '4', 'minutes' => '3', 'seconds' => '2', - ); - $form->submit($input); - $this->assertDateIntervalEquals(new \DateInterval('P7Y6M5DT4H3M2S'), $form->getData()); + )); + + $this->assertDateIntervalEquals($interval, $form->getData()); + $this->assertTrue($form->isSynchronized()); } public function testSubmitWithWeeks() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'input' => 'dateinterval', - 'with_years' => false, - 'with_months' => false, - 'with_weeks' => true, - 'with_days' => false, - ) - ); - $form->setData(new \DateInterval('P0Y')); - $input = array( + $form = $this->factory->create(static::TESTED_TYPE, new \DateInterval('P0Y'), array( + 'input' => 'dateinterval', + 'with_years' => false, + 'with_months' => false, + 'with_weeks' => true, + 'with_days' => false, + )); + + $form->submit(array( 'weeks' => '30', - ); - $form->submit($input); + )); + $this->assertDateIntervalEquals(new \DateInterval('P30W'), $form->getData()); } public function testSubmitWithInvert() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'input' => 'dateinterval', - 'with_invert' => true, - ) - ); - $input = array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'input' => 'dateinterval', + 'with_invert' => true, + )); + + $form->submit(array( 'years' => '7', 'months' => '6', 'days' => '5', 'invert' => true, - ); - $form->submit($input); + )); + $interval = new \DateInterval('P7Y6M5D'); $interval->invert = 1; + $this->assertDateIntervalEquals($interval, $form->getData()); } public function testSubmitStringSingleText() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'input' => 'string', - 'widget' => 'single_text', - ) - ); - $form->submit('P7Y6M5D'); - $this->assertEquals('P7Y6M5D', $form->getData()); - $this->assertEquals('P7Y6M5D', $form->getViewData()); + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'input' => 'string', + 'widget' => 'single_text', + )); + + $interval = 'P7Y6M5D'; + + $form->submit($interval); + + $this->assertSame($interval, $form->getData()); + $this->assertSame($interval, $form->getViewData()); } public function testSubmitStringSingleTextWithSeconds() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'input' => 'string', - 'widget' => 'single_text', - 'with_hours' => true, - 'with_minutes' => true, - 'with_seconds' => true, - ) - ); - $form->submit('P7Y6M5DT4H3M2S'); - $this->assertEquals('P7Y6M5DT4H3M2S', $form->getData()); - $this->assertEquals('P7Y6M5DT4H3M2S', $form->getViewData()); + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'input' => 'string', + 'widget' => 'single_text', + 'with_hours' => true, + 'with_minutes' => true, + 'with_seconds' => true, + )); + + $interval = 'P7Y6M5DT4H3M2S'; + + $form->submit($interval); + + $this->assertSame($interval, $form->getData()); + $this->assertSame($interval, $form->getViewData()); } public function testSubmitArrayInteger() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'widget' => 'integer', - 'with_invert' => true, - ) - ); - $input = array( + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'widget' => 'integer', + 'with_invert' => true, + )); + + $years = '7'; + + $form->submit(array( 'years' => '7', 'months' => '6', 'days' => '5', 'invert' => true, - ); - $form->submit($input); - $this->assertSame('7', $form['years']->getData()); - $this->assertSame('7', $form['years']->getViewData()); + )); + + $this->assertSame($years, $form['years']->getData()); + $this->assertSame($years, $form['years']->getViewData()); } public function testInitializeWithDateInterval() { // 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\DateIntervalType', new \DateInterval('P0Y')); + $this->factory->create(static::TESTED_TYPE, new \DateInterval('P0Y')); } public function testPassDefaultPlaceholderToViewIfNotRequired() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'required' => false, - 'with_seconds' => true, - ) - ); - $view = $form->createView(); + $view = $this->factory->create(static::TESTED_TYPE, null, array( + 'required' => false, + 'with_seconds' => true, + )) + ->createView(); + $this->assertSame('', $view['years']->vars['placeholder']); $this->assertSame('', $view['months']->vars['placeholder']); $this->assertSame('', $view['days']->vars['placeholder']); @@ -243,15 +214,12 @@ public function testPassDefaultPlaceholderToViewIfNotRequired() public function testPassNoPlaceholderToViewIfRequired() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'required' => true, - 'with_seconds' => true, - ) - ); - $view = $form->createView(); + $view = $this->factory->create(static::TESTED_TYPE, null, array( + 'required' => true, + 'with_seconds' => true, + )) + ->createView(); + $this->assertNull($view['years']->vars['placeholder']); $this->assertNull($view['months']->vars['placeholder']); $this->assertNull($view['days']->vars['placeholder']); @@ -260,15 +228,12 @@ public function testPassNoPlaceholderToViewIfRequired() public function testPassPlaceholderAsString() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'placeholder' => 'Empty', - 'with_seconds' => true, - ) - ); - $view = $form->createView(); + $view = $this->factory->create(static::TESTED_TYPE, null, array( + 'placeholder' => 'Empty', + 'with_seconds' => true, + )) + ->createView(); + $this->assertSame('Empty', $view['years']->vars['placeholder']); $this->assertSame('Empty', $view['months']->vars['placeholder']); $this->assertSame('Empty', $view['days']->vars['placeholder']); @@ -277,24 +242,21 @@ public function testPassPlaceholderAsString() public function testPassPlaceholderAsArray() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'placeholder' => array( - 'years' => 'Empty years', - 'months' => 'Empty months', - 'days' => 'Empty days', - 'hours' => 'Empty hours', - 'minutes' => 'Empty minutes', - 'seconds' => 'Empty seconds', - ), - 'with_hours' => true, - 'with_minutes' => true, - 'with_seconds' => true, - ) - ); - $view = $form->createView(); + $view = $this->factory->create(static::TESTED_TYPE, null, array( + 'placeholder' => array( + 'years' => 'Empty years', + 'months' => 'Empty months', + 'days' => 'Empty days', + 'hours' => 'Empty hours', + 'minutes' => 'Empty minutes', + 'seconds' => 'Empty seconds', + ), + 'with_hours' => true, + 'with_minutes' => true, + 'with_seconds' => true, + )) + ->createView(); + $this->assertSame('Empty years', $view['years']->vars['placeholder']); $this->assertSame('Empty months', $view['months']->vars['placeholder']); $this->assertSame('Empty days', $view['days']->vars['placeholder']); @@ -305,23 +267,20 @@ public function testPassPlaceholderAsArray() public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'required' => false, - 'placeholder' => array( - 'years' => 'Empty years', - 'days' => 'Empty days', - 'hours' => 'Empty hours', - 'seconds' => 'Empty seconds', - ), - 'with_hours' => true, - 'with_minutes' => true, - 'with_seconds' => true, - ) - ); - $view = $form->createView(); + $view = $this->factory->create(static::TESTED_TYPE, null, array( + 'required' => false, + 'placeholder' => array( + 'years' => 'Empty years', + 'days' => 'Empty days', + 'hours' => 'Empty hours', + 'seconds' => 'Empty seconds', + ), + 'with_hours' => true, + 'with_minutes' => true, + 'with_seconds' => true, + )) + ->createView(); + $this->assertSame('Empty years', $view['years']->vars['placeholder']); $this->assertSame('', $view['months']->vars['placeholder']); $this->assertSame('Empty days', $view['days']->vars['placeholder']); @@ -332,23 +291,20 @@ public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired() public function testPassPlaceholderAsPartialArrayAddNullIfRequired() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'required' => true, - 'placeholder' => array( - 'years' => 'Empty years', - 'days' => 'Empty days', - 'hours' => 'Empty hours', - 'seconds' => 'Empty seconds', - ), - 'with_hours' => true, - 'with_minutes' => true, - 'with_seconds' => true, - ) - ); - $view = $form->createView(); + $view = $this->factory->create(static::TESTED_TYPE, null, array( + 'required' => true, + 'placeholder' => array( + 'years' => 'Empty years', + 'days' => 'Empty days', + 'hours' => 'Empty hours', + 'seconds' => 'Empty seconds', + ), + 'with_hours' => true, + 'with_minutes' => true, + 'with_seconds' => true, + )) + ->createView(); + $this->assertSame('Empty years', $view['years']->vars['placeholder']); $this->assertNull($view['months']->vars['placeholder']); $this->assertSame('Empty days', $view['days']->vars['placeholder']); @@ -360,24 +316,23 @@ public function testPassPlaceholderAsPartialArrayAddNullIfRequired() public function testDateTypeChoiceErrorsBubbleUp() { $error = new FormError('Invalid!'); - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateIntervalType', null); + $form = $this->factory->create(static::TESTED_TYPE, null); + $form['years']->addError($error); + $this->assertSame(array(), iterator_to_array($form['years']->getErrors())); $this->assertSame(array($error), iterator_to_array($form->getErrors())); } public function testTranslationsAreDisabledForChoiceWidget() { - $form = $this->factory->create( - DateIntervalType::class, - null, - array( - 'widget' => 'choice', - 'with_hours' => true, - 'with_minutes' => true, - 'with_seconds' => true, - ) - ); + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'widget' => 'choice', + 'with_hours' => true, + 'with_minutes' => true, + 'with_seconds' => true, + )); + $this->assertFalse($form->get('years')->getConfig()->getOption('choice_translation_domain')); $this->assertFalse($form->get('months')->getConfig()->getOption('choice_translation_domain')); $this->assertFalse($form->get('days')->getConfig()->getOption('choice_translation_domain')); @@ -388,15 +343,21 @@ public function testTranslationsAreDisabledForChoiceWidget() public function testInvertDoesNotInheritRequiredOption() { - $form = $this->factory->create( - 'Symfony\Component\Form\Extension\Core\Type\DateIntervalType', - null, - array( - 'input' => 'dateinterval', - 'with_invert' => true, - 'required' => true, - ) - ); + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'input' => 'dateinterval', + 'with_invert' => true, + 'required' => true, + )); + $this->assertFalse($form->get('invert')->getConfig()->getOption('required')); } + + public function testSubmitNull($expected = null, $norm = null, $view = null) + { + parent::testSubmitNull($expected, $norm, array( + 'years' => '', + 'months' => '', + 'days' => '', + )); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php index 29df5231f1320..72a14f28f172e 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php @@ -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'); @@ -25,7 +26,7 @@ protected function setUp() 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', @@ -53,7 +54,7 @@ public function testSubmitDateTime() 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', @@ -79,7 +80,7 @@ public function testSubmitString() 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', @@ -107,7 +108,7 @@ public function testSubmitTimestamp() 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', @@ -137,7 +138,7 @@ public function testSubmitWithoutMinutes() 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', @@ -169,7 +170,7 @@ public function testSubmitWithSeconds() 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', @@ -201,7 +202,7 @@ public function testSubmitDifferentTimezones() 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', @@ -220,7 +221,7 @@ public function testSubmitDifferentTimezonesDateTime() 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', @@ -235,7 +236,7 @@ public function testSubmitStringSingleText() 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', @@ -251,7 +252,7 @@ public function testSubmitStringSingleTextWithSeconds() 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', @@ -272,27 +273,27 @@ public function testInitializeWithDateTime() { // 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']); @@ -303,12 +304,12 @@ public function testPassDefaultPlaceholderToViewIfNotRequired() 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']); @@ -319,12 +320,12 @@ public function testPassNoPlaceholderToViewIfRequired() 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']); @@ -335,7 +336,7 @@ public function testPassPlaceholderAsString() 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', @@ -345,9 +346,9 @@ public function testPassPlaceholderAsArray() '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']); @@ -358,7 +359,7 @@ public function testPassPlaceholderAsArray() 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', @@ -367,9 +368,9 @@ public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired() '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']); @@ -380,7 +381,7 @@ public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired() 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', @@ -389,9 +390,9 @@ public function testPassPlaceholderAsPartialArrayAddNullIfRequired() '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']); @@ -402,50 +403,50 @@ public function testPassPlaceholderAsPartialArrayAddNullIfRequired() 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); @@ -456,7 +457,7 @@ public function testDateTypeChoiceErrorsBubbleUp() 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', )); @@ -469,7 +470,7 @@ public function testDateTypeSingleTextErrorsBubbleUp() 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); @@ -480,7 +481,7 @@ public function testTimeTypeChoiceErrorsBubbleUp() 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', )); @@ -492,7 +493,7 @@ public function testTimeTypeSingleTextErrorsBubbleUp() 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, )); @@ -508,7 +509,7 @@ public function testPassDefaultChoiceTranslationDomain() 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, )); @@ -524,7 +525,7 @@ public function testPassChoiceTranslationDomainAsString() 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', @@ -542,4 +543,41 @@ public function testPassChoiceTranslationDomainAsArray() $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()); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index 6e92ecc3ca5ac..c1f95096784fd 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -13,11 +13,12 @@ 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() @@ -37,7 +38,7 @@ protected function tearDown() */ 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', )); } @@ -47,14 +48,14 @@ public function testInvalidWidgetOption() */ 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', @@ -69,7 +70,7 @@ public function testSubmitFromSingleTextDateTimeWithDefaultFormat() 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', @@ -90,7 +91,7 @@ public function testSubmitFromSingleTextDateTime() \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', @@ -111,7 +112,7 @@ public function testSubmitFromSingleTextString() \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', @@ -132,7 +133,7 @@ public function testSubmitFromSingleTextTimestamp() \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', @@ -155,7 +156,7 @@ public function testSubmitFromSingleTextRaw() \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', @@ -177,7 +178,7 @@ public function testSubmitFromSingleTextRaw() 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', @@ -199,7 +200,7 @@ public function testSubmitFromText() 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', @@ -222,7 +223,7 @@ public function testSubmitFromChoice() 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', @@ -243,7 +244,7 @@ public function testSubmitFromChoiceEmpty() 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', @@ -259,7 +260,7 @@ public function testSubmitFromInputDateTimeDifferentPattern() 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', @@ -275,7 +276,7 @@ public function testSubmitFromInputStringDifferentPattern() 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', @@ -293,7 +294,7 @@ public function testSubmitFromInputTimestampDifferentPattern() 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', @@ -318,11 +319,10 @@ public function testSubmitFromInputRawDifferentPattern() */ 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']); } @@ -344,7 +344,7 @@ public function provideDateFormats() */ 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', @@ -357,7 +357,7 @@ public function testThrowExceptionIfFormatIsNoPattern() */ 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', )); @@ -369,7 +369,7 @@ public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay() */ 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', )); @@ -380,7 +380,7 @@ public function testThrowExceptionIfFormatMissesYearMonthAndDayWithSingleTextWid */ 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, )); } @@ -390,7 +390,7 @@ public function testThrowExceptionIfFormatIsNoConstant() */ 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(), )); } @@ -400,7 +400,7 @@ public function testThrowExceptionIfFormatIsInvalid() */ 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', )); } @@ -410,7 +410,7 @@ public function testThrowExceptionIfYearsIsInvalid() */ 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', )); } @@ -420,7 +420,7 @@ public function testThrowExceptionIfMonthsIsInvalid() */ 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', )); } @@ -432,7 +432,7 @@ public function testSetDataWithNegativeTimezoneOffsetStringInput() \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', @@ -454,7 +454,7 @@ public function testSetDataWithNegativeTimezoneOffsetDateTimeInput() \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', @@ -474,7 +474,7 @@ public function testSetDataWithNegativeTimezoneOffsetDateTimeInput() 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), )); @@ -488,7 +488,7 @@ public function testYearsOption() 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, )); @@ -508,7 +508,7 @@ public function testMonthsOptionShortFormat() \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', )); @@ -528,12 +528,11 @@ public function testMonthsOptionLongFormat() \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'), @@ -548,12 +547,11 @@ public function testMonthsOptionLongFormatWithDifferentTimezone() \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'), @@ -563,11 +561,10 @@ public function testMonthsOptionLongFormatWithDifferentTimezone() 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'), @@ -575,26 +572,9 @@ public function testIsDayWithinRangeReturnsTrueIfWithin() ), $view['day']->vars['choices']); } - public function testIsPartiallyFilledReturnsFalseIfSingleText() - { - $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() + public function testIsSynchronizedReturnsTrueIfChoiceAndCompletelyEmpty() { - $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', @@ -606,33 +586,29 @@ public function testIsPartiallyFilledReturnsFalseIfChoiceAndCompletelyEmpty() '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', @@ -644,7 +620,7 @@ public function testIsPartiallyFilledReturnsTrueIfChoiceAndDayEmpty() 'year' => '2010', )); - $this->assertTrue($form->isPartiallyFilled()); + $this->assertFalse($form->isSynchronized()); } public function testPassDatePatternToView() @@ -654,8 +630,8 @@ public function testPassDatePatternToView() \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']); } @@ -667,43 +643,40 @@ public function testPassDatePatternToViewDifferentFormat() \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'])); } @@ -715,22 +688,21 @@ public function testDatePatternFormatWithQuotedStrings() \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']); } @@ -739,26 +711,26 @@ public function testInitializeWithDateTime() { // 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']); @@ -766,11 +738,11 @@ public function testPassDefaultPlaceholderToViewIfNotRequired() 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']); @@ -778,11 +750,11 @@ public function testPassNoPlaceholderToViewIfRequired() 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']); @@ -790,15 +762,15 @@ public function testPassPlaceholderAsString() 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']); @@ -806,15 +778,15 @@ public function testPassPlaceholderAsArray() 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']); @@ -822,15 +794,15 @@ public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired() 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']); @@ -838,43 +810,43 @@ public function testPassPlaceholderAsPartialArrayAddNullIfRequired() 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'])); } @@ -892,7 +864,7 @@ public function provideCompoundWidgets() 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); @@ -907,7 +879,7 @@ public function testYearErrorsBubbleUp($widget) 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); @@ -922,7 +894,7 @@ public function testMonthErrorsBubbleUp($widget) 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); @@ -937,11 +909,10 @@ public function testYearsFor32BitsMachines() $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) { @@ -953,7 +924,7 @@ public function testYearsFor32BitsMachines() 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']); @@ -963,7 +934,7 @@ public function testPassDefaultChoiceTranslationDomain() 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', )); @@ -975,7 +946,7 @@ public function testPassChoiceTranslationDomainAsString() 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', @@ -987,4 +958,21 @@ public function testPassChoiceTranslationDomainAsArray() $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()); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php index e93f8c3d19951..1545e8ae9d4b1 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php @@ -11,24 +11,27 @@ 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'; + // 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); @@ -36,31 +39,9 @@ public function testSubmit() $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(); @@ -75,7 +56,7 @@ public function testSetDataMultiple() 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(); @@ -94,13 +75,38 @@ public function testSubmitMultiple() 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) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index eef01cfc56216..640c8761c260b 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -51,27 +51,29 @@ public function setReferenceCopy($reference) class FormTypeTest extends BaseTypeTest { + const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\FormType'; + 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) @@ -85,9 +87,9 @@ public function testSubmittedDataIsTrimmedBeforeTransforming() 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) @@ -101,8 +103,8 @@ public function testSubmittedDataIsNotTrimmedBeforeTransformingIfNoTrimming() 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(); @@ -111,8 +113,8 @@ public function testNonReadOnlyFormWithReadOnlyParentIsReadOnly() 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(); @@ -121,8 +123,8 @@ public function testReadOnlyFormWithNonReadOnlyParentIsReadOnly() 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(); @@ -131,29 +133,29 @@ public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly() 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 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', )); } @@ -163,22 +165,23 @@ public function testDataClassMayBeInterface() */ 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' => '')); @@ -189,19 +192,19 @@ public function testSubmitWithEmptyDataCreatesObjectIfClassAvailable() $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(); @@ -209,34 +212,37 @@ public function testSubmitWithEmptyDataCreatesObjectIfInitiallySubmittedWithObje $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()); @@ -244,15 +250,16 @@ public function testSubmitEmptyWithEmptyDataCreatesNoObjectIfNotRequired() 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()); @@ -263,11 +270,12 @@ public function testSubmitEmptyWithEmptyDataCreatesObjectIfRequired() */ 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()); @@ -275,31 +283,40 @@ public function testSubmitWithEmptyDataStoresArrayIfNoClassAvailable() 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')); @@ -307,62 +324,34 @@ public function testSubmitWithEmptyDataUsesEmptyDataOption() $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', ), @@ -377,17 +366,17 @@ public function testSubformCallsSettersIfTheObjectChanged() $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', ), @@ -400,12 +389,12 @@ public function testSubformCallsSettersIfByReferenceIsFalse() { $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( @@ -423,8 +412,8 @@ public function testSubformCallsSettersIfReferenceIsScalar() { $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 @@ -447,9 +436,9 @@ public function testSubformAlwaysInsertsIntoArrays() $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 @@ -459,7 +448,7 @@ function ($value) use ($ref2) { // reverseTransform $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 @@ -469,9 +458,9 @@ function ($value) use ($ref2) { // reverseTransform 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(); @@ -480,8 +469,8 @@ public function testPassMultipartTrueIfAnyChildIsMultipartToView() 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(); @@ -490,16 +479,14 @@ public function testViewIsNotRenderedByDefault() 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, )); @@ -508,7 +495,7 @@ public function testNoErrorBubblingIfNotCompound() 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, )); @@ -518,7 +505,7 @@ public function testOverrideErrorBubbling() 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', )); @@ -528,7 +515,7 @@ public function testPropertyPath() 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, )); @@ -538,7 +525,7 @@ public function testPropertyPathNullImpliesDefault() 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, )); @@ -549,38 +536,40 @@ public function testNotMapped() 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, )); @@ -590,9 +579,20 @@ public function testDataOptionSupersedesSetDataCalls() $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, )); @@ -604,22 +604,25 @@ public function testDataOptionSupersedesSetDataCallsIfNull() 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(); @@ -627,8 +630,8 @@ public function testPassZeroLabelToView() $this->assertSame('0', $view->vars['label']); } - 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()); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php index c5a6236d1b13e..27a57eea79a69 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php @@ -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); @@ -25,11 +26,16 @@ protected function setUp() 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, ''); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php index ca03ef3205aa3..5ea3c4a732165 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php @@ -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); @@ -26,9 +27,8 @@ protected function setUp() 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); @@ -39,10 +39,14 @@ public function testCountriesAreSelectable() 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, ''); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php index 2a46755bdc64e..58b94517d4572 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php @@ -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); @@ -26,12 +27,16 @@ protected function setUp() 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, ''); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php index 3938454c3a4a4..26098f3ddc569 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php @@ -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 @@ -29,8 +30,8 @@ public function testPassMoneyPatternToView() { \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']); } @@ -39,8 +40,9 @@ public function testMoneyPatternWorksForYen() { \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'], '¥')); } @@ -49,12 +51,15 @@ public function testPassDifferentPatternsForDifferentCurrencies() { \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, ''); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php index b8675d2684679..1daec3c05913a 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php @@ -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(); @@ -28,37 +29,38 @@ protected function setUp() 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, ''); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php index 7d7c48e421765..c48240c651f21 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php @@ -11,43 +11,44 @@ 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'; + 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, ''); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/RepeatedTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/RepeatedTypeTest.php index 500a39471e4fb..8021abdb84986 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/RepeatedTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/RepeatedTypeTest.php @@ -11,63 +11,67 @@ 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); } public function testSetData() { $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()); @@ -79,8 +83,8 @@ public function testSetRequired() */ 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', )); } @@ -90,8 +94,8 @@ public function testSetInvalidOptions() */ 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', )); } @@ -101,15 +105,15 @@ public function testSetInvalidFirstOptions() */ 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, )); @@ -120,7 +124,7 @@ public function testSetErrorBubblingToTrue() 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, )); @@ -131,7 +135,7 @@ public function testSetErrorBubblingToFalse() 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), @@ -144,14 +148,14 @@ public function testSetErrorBubblingIndividually() 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()); } @@ -162,10 +166,10 @@ public function testSubmitUnequal() $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()); } @@ -175,10 +179,15 @@ public function testSubmitEqual() $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)); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/SubmitTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/SubmitTypeTest.php index 8652d1b7e8ce3..e86704bcfb2ad 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/SubmitTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/SubmitTypeTest.php @@ -11,28 +11,28 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type; -use Symfony\Component\Form\Test\TypeTestCase as TestCase; - /** * @author Bernhard Schussek */ -class SubmitTypeTest extends TestCase +class SubmitTypeTest extends ButtonTypeTest { + const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\SubmitType'; + 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()); @@ -40,7 +40,7 @@ public function testNotClickedIfSubmittedWithNull() 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()); @@ -48,7 +48,7 @@ public function testClickedIfSubmittedWithEmptyString() 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()); @@ -57,9 +57,9 @@ public function testClickedIfSubmittedWithUnemptyString() 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)); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TextTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TextTypeTest.php index ac63c4cf452b7..c4dba3734876a 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TextTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TextTypeTest.php @@ -11,27 +11,51 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type; -use Symfony\Component\Form\Test\TypeTestCase as TestCase; - -class TextTypeTest extends TestCase +class TextTypeTest extends BaseTypeTest { - public function testSubmitNullReturnsNull() + const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\TextType'; + + public function testSubmitNull($expected = null, $norm = null, $view = null) { - $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TextType', 'name'); + parent::testSubmitNull($expected, $norm, ''); + } + + public function testSubmitNullReturnsNullWithEmptyDataAsString() + { + $form = $this->factory->create(static::TESTED_TYPE, 'name', array( + 'empty_data' => '', + )); $form->submit(null); + $this->assertSame('', $form->getData()); + $this->assertSame('', $form->getNormData()); + $this->assertSame('', $form->getViewData()); + } - $this->assertNull($form->getData()); + public function provideZeros() + { + return array( + array(0, '0'), + array('0', '0'), + array('00000', '00000'), + ); } - public function testSubmitNullReturnsEmptyStringWithEmptyDataAsString() + /** + * @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\TextType', 'name', array( - 'empty_data' => '', + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'data' => $data, )); + $view = $form->createView(); - $form->submit(null); + $this->assertFalse($form->isEmpty()); - $this->assertSame('', $form->getData()); + $this->assertSame($dataAsString, $view->vars['value']); + $this->assertSame($dataAsString, $form->getData()); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php index 64878ca4454e9..a0913e8068084 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php @@ -13,13 +13,14 @@ 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'; + 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', @@ -40,7 +41,7 @@ public function testSubmitDateTime() 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', @@ -59,7 +60,7 @@ public function testSubmitString() 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', @@ -80,7 +81,7 @@ public function testSubmitTimestamp() 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', @@ -99,7 +100,7 @@ public function testSubmitArray() 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', @@ -114,7 +115,7 @@ public function testSubmitDatetimeSingleText() 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', @@ -130,7 +131,7 @@ public function testSubmitDatetimeSingleTextWithoutMinutes() 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', @@ -150,7 +151,7 @@ public function testSubmitArraySingleText() 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', @@ -170,7 +171,7 @@ public function testSubmitArraySingleTextWithoutMinutes() 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', @@ -192,7 +193,7 @@ public function testSubmitArraySingleTextWithSeconds() 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', @@ -207,7 +208,7 @@ public function testSubmitStringSingleText() 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', @@ -223,7 +224,7 @@ public function testSubmitStringSingleTextWithoutMinutes() 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', @@ -239,7 +240,7 @@ public function testSubmitWithSecondsAndBrowserOmissionSeconds() 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', @@ -253,7 +254,7 @@ public function testSetDataWithoutMinutes() 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', @@ -267,7 +268,7 @@ public function testSetDataWithSeconds() 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', @@ -293,7 +294,7 @@ public function testSetDataDifferentTimezones() 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', @@ -320,7 +321,7 @@ public function testSetDataDifferentTimezonesDateTime() 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), )); @@ -334,7 +335,7 @@ public function testHoursOption() 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), )); @@ -348,7 +349,7 @@ public function testIsMinuteWithinRangeReturnsTrueIfWithin() 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, )); @@ -365,7 +366,7 @@ public function testIsPartiallyFilledReturnsFalseIfCompletelyEmpty() { $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', )); @@ -381,7 +382,7 @@ public function testIsPartiallyFilledReturnsFalseIfCompletelyEmptyWithSeconds() { $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, )); @@ -399,7 +400,7 @@ public function testIsPartiallyFilledReturnsFalseIfCompletelyFilled() { $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', )); @@ -415,7 +416,7 @@ public function testIsPartiallyFilledReturnsFalseIfCompletelyFilledWithSeconds() { $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, )); @@ -433,7 +434,7 @@ public function testIsPartiallyFilledReturnsTrueIfChoiceAndHourEmpty() { $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, )); @@ -451,7 +452,7 @@ public function testIsPartiallyFilledReturnsTrueIfChoiceAndMinuteEmpty() { $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, )); @@ -469,7 +470,7 @@ public function testIsPartiallyFilledReturnsTrueIfChoiceAndSecondsEmpty() { $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, )); @@ -487,12 +488,12 @@ public function testInitializeWithDateTime() { // 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', )); @@ -502,7 +503,7 @@ public function testSingleTextWidgetShouldUseTheRightInputType() 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, )); @@ -514,7 +515,7 @@ public function testSingleTextWidgetWithSecondsShouldHaveRightStepAttribute() 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( @@ -529,7 +530,7 @@ public function testSingleTextWidgetWithSecondsShouldNotOverrideStepAttribute() 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, )); @@ -540,7 +541,7 @@ public function testDontPassHtml5TypeIfHtml5NotAllowed() 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, )); @@ -553,7 +554,7 @@ public function testPassDefaultPlaceholderToViewIfNotRequired() 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, )); @@ -566,7 +567,7 @@ public function testPassNoPlaceholderToViewIfRequired() 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, )); @@ -579,7 +580,7 @@ public function testPassPlaceholderAsString() 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', @@ -596,7 +597,7 @@ public function testPassPlaceholderAsArray() 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', @@ -613,7 +614,7 @@ public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired() 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', @@ -642,7 +643,7 @@ public function provideCompoundWidgets() 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); @@ -657,7 +658,7 @@ public function testHourErrorsBubbleUp($widget) 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); @@ -672,7 +673,7 @@ public function testMinuteErrorsBubbleUp($widget) 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, )); @@ -687,7 +688,7 @@ public function testSecondErrorsBubbleUp($widget) */ 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, )); @@ -698,7 +699,7 @@ public function testInitializeWithSecondsAndWithoutMinutes() */ 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', )); } @@ -708,7 +709,7 @@ public function testThrowExceptionIfHoursIsInvalid() */ 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', )); } @@ -718,14 +719,14 @@ public function testThrowExceptionIfMinutesIsInvalid() */ 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']); @@ -734,7 +735,7 @@ public function testPassDefaultChoiceTranslationDomain() 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, )); @@ -747,7 +748,7 @@ public function testPassChoiceTranslationDomainAsString() 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', @@ -760,4 +761,11 @@ public function testPassChoiceTranslationDomainAsArray() $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); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php index 9285c4823a0b1..8682efed69356 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php @@ -12,15 +12,15 @@ 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'; + 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); @@ -28,4 +28,9 @@ public function testTimezonesAreSelectable() $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, ''); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php index 641f9a7b6362f..ad2d955b317d2 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php @@ -11,13 +11,13 @@ 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'; + 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'); @@ -27,7 +27,7 @@ public function testSubmitAddsDefaultProtocolIfNoneIsIncluded() 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', )); @@ -39,7 +39,7 @@ public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded() 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', )); @@ -51,7 +51,7 @@ public function testSubmitAddsNoDefaultProtocolIfEmpty() 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', )); @@ -63,7 +63,7 @@ public function testSubmitAddsNoDefaultProtocolIfNull() 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, )); @@ -78,7 +78,7 @@ public function testSubmitAddsNoDefaultProtocolIfSetToNull() */ 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(), )); } diff --git a/src/Symfony/Component/Form/Tests/SimpleFormTest.php b/src/Symfony/Component/Form/Tests/SimpleFormTest.php index 624365b446dcf..11d4c1de17218 100644 --- a/src/Symfony/Component/Form/Tests/SimpleFormTest.php +++ b/src/Symfony/Component/Form/Tests/SimpleFormTest.php @@ -517,6 +517,24 @@ public function testSetDataIsIgnoredIfDataIsLocked() $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();