]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / form / Symfony / Component / Form / Tests / Extension / Validator / Type / FormTypeValidatorExtensionTest.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
13
14 use Symfony\Component\Form\FormInterface;
15
16 class FormTypeValidatorExtensionTest extends TypeTestCase
17 {
18 public function testValidationGroupNullByDefault()
19 {
20 $form = $this->factory->create('form');
21
22 $this->assertNull($form->getConfig()->getOption('validation_groups'));
23 }
24
25 public function testValidationGroupsTransformedToArray()
26 {
27 $form = $this->factory->create('form', null, array(
28 'validation_groups' => 'group',
29 ));
30
31 $this->assertEquals(array('group'), $form->getConfig()->getOption('validation_groups'));
32 }
33
34 public function testValidationGroupsCanBeSetToArray()
35 {
36 $form = $this->factory->create('form', null, array(
37 'validation_groups' => array('group1', 'group2'),
38 ));
39
40 $this->assertEquals(array('group1', 'group2'), $form->getConfig()->getOption('validation_groups'));
41 }
42
43 public function testValidationGroupsCanBeSetToFalse()
44 {
45 $form = $this->factory->create('form', null, array(
46 'validation_groups' => false,
47 ));
48
49 $this->assertEquals(array(), $form->getConfig()->getOption('validation_groups'));
50 }
51
52 public function testValidationGroupsCanBeSetToCallback()
53 {
54 $form = $this->factory->create('form', null, array(
55 'validation_groups' => array($this, 'testValidationGroupsCanBeSetToCallback'),
56 ));
57
58 $this->assertTrue(is_callable($form->getConfig()->getOption('validation_groups')));
59 }
60
61 public function testValidationGroupsCanBeSetToClosure()
62 {
63 $form = $this->factory->create('form', null, array(
64 'validation_groups' => function(FormInterface $form){ return null; },
65 ));
66
67 $this->assertTrue(is_callable($form->getConfig()->getOption('validation_groups')));
68 }
69
70 public function testSubmitValidatesData()
71 {
72 $builder = $this->factory->createBuilder('form', null, array(
73 'validation_groups' => 'group',
74 ));
75 $builder->add('firstName', 'form');
76 $form = $builder->getForm();
77
78 $this->validator->expects($this->once())
79 ->method('validate')
80 ->with($this->equalTo($form));
81
82 // specific data is irrelevant
83 $form->submit(array());
84 }
85 }