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\Validator\Type
;
14 use Symfony\Component\Form\FormInterface
;
16 class FormTypeValidatorExtensionTest
extends TypeTestCase
18 public function testValidationGroupNullByDefault()
20 $form = $this->factory
->create('form');
22 $this->assertNull($form->getConfig()->getOption('validation_groups'));
25 public function testValidationGroupsTransformedToArray()
27 $form = $this->factory
->create('form', null, array(
28 'validation_groups' => 'group',
31 $this->assertEquals(array('group'), $form->getConfig()->getOption('validation_groups'));
34 public function testValidationGroupsCanBeSetToArray()
36 $form = $this->factory
->create('form', null, array(
37 'validation_groups' => array('group1', 'group2'),
40 $this->assertEquals(array('group1', 'group2'), $form->getConfig()->getOption('validation_groups'));
43 public function testValidationGroupsCanBeSetToFalse()
45 $form = $this->factory
->create('form', null, array(
46 'validation_groups' => false,
49 $this->assertEquals(array(), $form->getConfig()->getOption('validation_groups'));
52 public function testValidationGroupsCanBeSetToCallback()
54 $form = $this->factory
->create('form', null, array(
55 'validation_groups' => array($this, 'testValidationGroupsCanBeSetToCallback'),
58 $this->assertTrue(is_callable($form->getConfig()->getOption('validation_groups')));
61 public function testValidationGroupsCanBeSetToClosure()
63 $form = $this->factory
->create('form', null, array(
64 'validation_groups' => function(FormInterface
$form){ return null; },
67 $this->assertTrue(is_callable($form->getConfig()->getOption('validation_groups')));
70 public function testSubmitValidatesData()
72 $builder = $this->factory
->createBuilder('form', null, array(
73 'validation_groups' => 'group',
75 $builder->add('firstName', 'form');
76 $form = $builder->getForm();
78 $this->validator
->expects($this->once())
80 ->with($this->equalTo($form));
82 // specific data is irrelevant
83 $form->submit(array());