4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Tests\Extension\Core\Type
;
15 * @author Bernhard Schussek <bschussek@gmail.com>
17 abstract class BaseTypeTest
extends \Symfony\Component\Form\Test\TypeTestCase
19 public function testPassDisabledAsOption()
21 $form = $this->factory
->create($this->getTestedType(), null, array('disabled' => true));
23 $this->assertTrue($form->isDisabled());
26 public function testPassIdAndNameToView()
28 $view = $this->factory
->createNamed('name', $this->getTestedType())
31 $this->assertEquals('name', $view->vars
['id']);
32 $this->assertEquals('name', $view->vars
['name']);
33 $this->assertEquals('name', $view->vars
['full_name']);
36 public function testStripLeadingUnderscoresAndDigitsFromId()
38 $view = $this->factory
->createNamed('_09name', $this->getTestedType())
41 $this->assertEquals('name', $view->vars
['id']);
42 $this->assertEquals('_09name', $view->vars
['name']);
43 $this->assertEquals('_09name', $view->vars
['full_name']);
46 public function testPassIdAndNameToViewWithParent()
48 $view = $this->factory
->createNamedBuilder('parent', 'form')
49 ->add('child', $this->getTestedType())
53 $this->assertEquals('parent_child', $view['child']->vars
['id']);
54 $this->assertEquals('child', $view['child']->vars
['name']);
55 $this->assertEquals('parent[child]', $view['child']->vars
['full_name']);
58 public function testPassIdAndNameToViewWithGrandParent()
60 $builder = $this->factory
->createNamedBuilder('parent', 'form')
61 ->add('child', 'form');
62 $builder->get('child')->add('grand_child', $this->getTestedType());
63 $view = $builder->getForm()->createView();
65 $this->assertEquals('parent_child_grand_child', $view['child']['grand_child']->vars
['id']);
66 $this->assertEquals('grand_child', $view['child']['grand_child']->vars
['name']);
67 $this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->vars
['full_name']);
70 public function testPassTranslationDomainToView()
72 $form = $this->factory
->create($this->getTestedType(), null, array(
73 'translation_domain' => 'domain',
75 $view = $form->createView();
77 $this->assertSame('domain', $view->vars
['translation_domain']);
80 public function testInheritTranslationDomainFromParent()
82 $view = $this->factory
83 ->createNamedBuilder('parent', 'form', null, array(
84 'translation_domain' => 'domain',
86 ->add('child', $this->getTestedType())
90 $this->assertEquals('domain', $view['child']->vars
['translation_domain']);
93 public function testPreferOwnTranslationDomain()
95 $view = $this->factory
96 ->createNamedBuilder('parent', 'form', null, array(
97 'translation_domain' => 'parent_domain',
99 ->add('child', $this->getTestedType(), array(
100 'translation_domain' => 'domain',
105 $this->assertEquals('domain', $view['child']->vars
['translation_domain']);
108 public function testDefaultTranslationDomain()
110 $view = $this->factory
->createNamedBuilder('parent', 'form')
111 ->add('child', $this->getTestedType())
115 $this->assertEquals('messages', $view['child']->vars
['translation_domain']);
118 public function testPassLabelToView()
120 $form = $this->factory
->createNamed('__test___field', $this->getTestedType(), null, array('label' => 'My label'));
121 $view = $form->createView();
123 $this->assertSame('My label', $view->vars
['label']);
126 public function testPassMultipartFalseToView()
128 $form = $this->factory
->create($this->getTestedType());
129 $view = $form->createView();
131 $this->assertFalse($view->vars
['multipart']);
134 abstract protected function getTestedType();