8000 [Form] getParent() does not receive correct options array by Burgov · Pull Request #3793 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] getParent() does not receive correct options array #3793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Symfony\Component\Form\Tests\Fixtures;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class AuthorType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder->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'
);
}
}
26 changes: 26 additions & 0 deletions src/Symfony/Component/Form/Tests/Fixtures/FooChildType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Symfony\Component\Form\Tests\Fixtures;

use Symfony\Component\Form\AbstractType;

class FooChildType extends AbstractType
{

public function getName()
{
return 'foo_child';
}

public function getParent(array $options)
{
return new FooType();
}

public function getDefaultOptions()
{
return array(
'parent' => new FooParentType()
);
}
}
19 changes: 19 additions & 0 deletions src/Symfony/Component/Form/Tests/Fixtures/FooParentType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Symfony\Component\Form\Tests\Fixtures;

use Symfony\Component\Form\AbstractType;

class FooParentType extends AbstractType
{

public function getName()
{
return 'foo_parent';
}

public function getParent(array $options)
{
return null;
}
}
3 changes: 2 additions & 1 deletion src/Symfony/Component/Form/Tests/Fixtures/FooType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function getDefaultOptions(array $options)
'required' => false,
'max_length' => null,
'a_or_b' => 'a',
'parent' => null,
);
}

Expand All @@ -53,6 +54,6 @@ public function getAllowedOptionValues(array $options)

public function getParent(array $options)
{
return null;
return $options['parent'];
}
}
30 changes: 30 additions & 0 deletions src/Symfony/Component/Form/Tests/FormFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
0