8000 test for ensuring creating form returns data of type specified in data_c... by cordoval · Pull Request #3383 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

test for ensuring creating form returns data of type specified in data_c... #3383

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
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
52 changes: 52 additions & 0 deletions tests/Symfony/Tests/Component/Form/Fixtures/BarType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Symfony\Tests\Component\Form\Fixtures;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Tests\Component\Form\Fixtures\Author;

class BarType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder->setAttribute('bar', 'x');
$builder->setAttribute('data_option', $options['data']);
}

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

public function createBuilder($name, FormFactoryInterface $factory, array $options)
{
return new FormBuilder($name, $factory, new EventDispatcher());
}

public function getDefaultOptions(array $options)
{
return array(
'data' => null,
'data_class' => 'Symfony\Tests\Component\Form\Fixtures\Author',
'empty_data' => true,
'required' => false,
'max_length' => null,
'a_or_b' => 'a',
);
}

public function getAllowedOptionValues(array $options)
{
return array(
'a_or_b' => array('a', 'b'),
);
}

public function getParent(array $options)
{
return null;
}
}
15 changes: 15 additions & 0 deletions tests/Symfony/Tests/Component/Form/FormFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Symfony\Component\Form\Guess\TypeGuess;
use Symfony\Tests\Component\Form\Fixtures\TestExtension;
use Symfony\Tests\Component\Form\Fixtures\FooType;
use Symfony\Tests\Component\Form\Fixtures\BarType;
use Symfony\Tests\Component\Form\Fixtures\Author;
use Symfony\Tests\Component\Form\Fixtures\FooTypeBarExtension;
use Symfony\Tests\Component\Form\Fixtures\FooTypeBazExtension;

Expand Down Expand Up @@ -516,6 +518,19 @@ public function testUnknownOptions()
$factory->createNamedBuilder($type, "text", "value", array("invalid" => "opt", "unknown" => "opt"));
}

public function testNullObjectWithCustomTypeReturnsCorrectObjectType 63C2 ()
{
$type = new BarType();
$form = $this->factory->create($type);
$form->setData(new Author());
$fdata = $form->getData();
$this->assertTrue($fdata instanceof Author);

$form = $this->factory->create($type);
$fdata = $form->getData();
$this->assertTrue($fdata instanceof Author, 'Failing in returning object of type specified in data_class when creating with empty data');
}

public function testUnknownOption()
{
$type = new \Symfony\Component\Form\Extension\Core\Type\TextType();
Expand Down
0