From 958478ee5fdc73579ce0eb810bb49e5004489a56 Mon Sep 17 00:00:00 2001 From: Bart van den Burg Date: Thu, 5 Apr 2012 11:30:37 +0200 Subject: [PATCH] Added tests which were broken by the last PR --- .../Form/Tests/Fixtures/AuthorType.php | 27 +++++++++++++++++ .../Form/Tests/Fixtures/FooChildType.php | 26 ++++++++++++++++ .../Form/Tests/Fixtures/FooParentType.php | 19 ++++++++++++ .../Component/Form/Tests/Fixtures/FooType.php | 3 +- .../Component/Form/Tests/FormFactoryTest.php | 30 +++++++++++++++++++ 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php create mode 100644 src/Symfony/Component/Form/Tests/Fixtures/FooChildType.php create mode 100644 src/Symfony/Component/Form/Tests/Fixtures/FooParentType.php diff --git a/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php b/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php new file mode 100644 index 0000000000000..3ba13ec18baba --- /dev/null +++ b/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php @@ -0,0 +1,27 @@ +add('firstName', 'text'); + $builder->add('lastName', 'text'); + } + + public function getName() + { + return 'collection_row'; + } + + public function getDefaultOptions() + { + return array( + 'data_class'=>'Symfony\Component\Form\Tests\Fixtures\Author' + ); + } +} \ No newline at end of file diff --git a/src/Symfony/Component/Form/Tests/Fixtures/FooChildType.php b/src/Symfony/Component/Form/Tests/Fixtures/FooChildType.php new file mode 100644 index 0000000000000..30a0f7587544d --- /dev/null +++ b/src/Symfony/Component/Form/Tests/Fixtures/FooChildType.php @@ -0,0 +1,26 @@ + new FooParentType() + ); + } +} diff --git a/src/Symfony/Component/Form/Tests/Fixtures/FooParentType.php b/src/Symfony/Component/Form/Tests/Fixtures/FooParentType.php new file mode 100644 index 0000000000000..a94859d5fbd29 --- /dev/null +++ b/src/Symfony/Component/Form/Tests/Fixtures/FooParentType.php @@ -0,0 +1,19 @@ + false, 'max_length' => null, 'a_or_b' => 'a', + 'parent' => null, ); } @@ -53,6 +54,6 @@ public function getAllowedOptionValues(array $options) public function getParent(array $options) { - return null; + return $options['parent']; } } diff --git a/src/Symfony/Component/Form/Tests/FormFactoryTest.php b/src/Symfony/Component/Form/Tests/FormFactoryTest.php index 3f206a798ac06..f423981f35ff7 100644 --- a/src/Symfony/Component/Form/Tests/FormFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/FormFactoryTest.php @@ -535,6 +535,36 @@ public function testUnknownOption() $factory->createNamedBuilder($type, "text", "value", array("unknown" => "opt")); } + public function testChildDefaultOptionIsPassedToChildsGetParentMethod() + { + $type = new Fixtures\FooChildType(); + + $builder = $this->factory->createNamedBuilder($type, 'foo_child'); + $this->assertCount(3, $builder->getTypes()); + + $builder = $this->factory->createNamedBuilder($type, 'foo_child', null, array('parent'=>null)); + $this->assertCount(2, $builder->getTypes()); + } + + public function testCollectionTypeGetParentAndGetDefaultOptionsReceiveCorrectOptions() + { + $collectionType = new \Symfony\Component\Form\Extension\Core\Type\CollectionType(); + $type = new Fixtures\AuthorType(); + $this->factory->addType(new \Symfony\Component\Form\Extension\Core\Type\FormType()); + $this->factory->addType(new \Symfony\Component\Form\Extension\Core\Type\FieldType()); + $this->factory->addType(new \Symfony\Component\Form\Extension\Core\Type\TextType()); + + $builder = $this->factory->createNamedBuilder($collectionType, 'collection', null, array('type'=>$type, 'allow_add'=>true)); + + $form = $builder->getForm(); + $form->bind(array(array('firstName'=>'foo', 'lastName'=>'bar'))); + + $author = new Fixtures\Author(); + $author->setLastName('bar'); + $author->firstName = 'foo'; + $this->assertEquals($author, current($form->getData())); + } + private function createMockFactory(array $methods = array()) { return $this->getMockBuilder('Symfony\Component\Form\FormFactory')