Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2f7d1e

Browse files
committed
merged branch bschussek/fix-submit (PR #8764)
This PR was merged into the 2.3 branch. Discussion ---------- [Form] Fixed: Added "validation_groups" option to submit button | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8209 | License | MIT | Doc PR | - Commits ------- c342715 [Form] Fixed: Added "validation_groups" option to submit button
2 parents e6d0e69 + c342715 commit e2f7d1e

File tree

4 files changed

+101
-58
lines changed

4 files changed

+101
-58
lines changed

src/Symfony/Component/Form/Extension/Validator/Type/SubmitTypeValidatorExtension.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111

1212
namespace Symfony\Component\Form\Extension\Validator\Type;
1313

14-
use Symfony\Component\Form\AbstractTypeExtension;
15-
1614
/**
1715
* @author Bernhard Schussek <[email protected]>
1816
*/
19-
class SubmitTypeValidatorExtension extends AbstractTypeExtension
17+
class SubmitTypeValidatorExtension extends BaseValidatorExtension
2018
{
2119
/**
2220
* {@inheritdoc}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Test\FormInterface;
15+
16+
/**
17+
* @author Bernhard Schussek <[email protected]>
18+
*/
19+
abstract class BaseValidatorExtensionTest extends TypeTestCase
20+
{
21+
public function testValidationGroupNullByDefault()
22+
{
23+
$form = $this->createForm();
24+
25+
$this->assertNull($form->getConfig()->getOption('validation_groups'));
26+
}
27+
28+
public function testValidationGroupsTransformedToArray()
29+
{
30+
$form = $this->createForm(array(
31+
'validation_groups' => 'group',
32+
));
33+
34+
$this->assertEquals(array('group'), $form->getConfig()->getOption('validation_groups'));
35+
}
36+
37+
public function testValidationGroupsCanBeSetToArray()
38+
{
39+
$form = $this->createForm(array(
40+
'validation_groups' => array('group1', 'group2'),
41+
));
42+
43+
$this->assertEquals(array('group1', 'group2'), $form->getConfig()->getOption('validation_groups'));
44+
}
45+
46+
public function testValidationGroupsCanBeSetToFalse()
47+
{
48+
$form = $this->createForm(array(
49+
'validation_groups' => false,
50+
));
51+
52+
$this->assertEquals(array(), $form->getConfig()->getOption('validation_groups'));
53+
}
54+
55+
public function testValidationGroupsCanBeSetToCallback()
56+
{
57+
$form = $this->createForm(array(
58+
'validation_groups' => array($this, 'testValidationGroupsCanBeSetToCallback'),
59+
));
60+
61+
$this->assertTrue(is_callable($form->getConfig()->getOption('validation_groups')));
62+
}
63+
64+
public function testValidationGroupsCanBeSetToClosure()
65+
{
66+
$form = $this->createForm(array(
67+
'validation_groups' => function(FormInterface $form){ return null; },
68+
));
69+
70+
$this->assertTrue(is_callable($form->getConfig()->getOption('validation_groups')));
71+
}
72+
73+
abstract protected function createForm(array $options = array());
74+
}

src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,62 +11,8 @@
1111

1212
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
1313

14-
use Symfony\Component\Form\FormInterface;
15-
16-
class FormTypeValidatorExtensionTest extends TypeTestCase
14+
class FormTypeValidatorExtensionTest extends BaseValidatorExtensionTest
1715
{
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-
7016
public function testSubmitValidatesData()
7117
{
7218
$builder = $this->factory->createBuilder('form', null, array(
@@ -82,4 +28,9 @@ public function testSubmitValidatesData()
8228
// specific data is irrelevant
8329
$form->submit(array());
8430
}
31+
32+
protected function createForm(array $options = array())
33+
{
34+
return $this->factory->create('form', null, $options);
35+
}
8536
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
class SubmitTypeValidatorExtensionTest extends BaseValidatorExtensionTest
15+
{
16+
protected function createForm(array $options = array())
17+
{
18+
return $this->factory->create('submit', null, $options);
19+
}
20+
}

0 commit comments

Comments
 (0)