Skip to content

Commit 77653d1

Browse files
committed
Merge branch '2.8' into 3.2
* 2.8: [Serializer] Xml encoder throws exception for valid data [Form] Hardened form type tests fixed CS
2 parents 125cf85 + 663661b commit 77653d1

30 files changed

+1523
-1145
lines changed

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

+275-102
Large diffs are not rendered by default.

src/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php

+29-14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
abstract class BaseTypeTest extends TypeTestCase
2020
{
21+
const TESTED_TYPE = '';
22+
2123
public function testPassDisabledAsOption()
2224
{
2325
$form = $this->factory->create($this->getTestedType(), null, array('disabled' => true));
@@ -47,7 +49,7 @@ public function testStripLeadingUnderscoresAndDigitsFromId()
4749

4850
public function testPassIdAndNameToViewWithParent()
4951
{
50-
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
52+
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
5153
->add('child', $this->getTestedType())
5254
->getForm()
5355
->createView();
@@ -59,8 +61,8 @@ public function testPassIdAndNameToViewWithParent()
5961

6062
public function testPassIdAndNameToViewWithGrandParent()
6163
{
62-
$builder = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
63-
->add('child', 'Symfony\Component\Form\Extension\Core\Type\FormType');
64+
$builder = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
65+
->add('child', FormTypeTest::TESTED_TYPE);
6466
$builder->get('child')->add('grand_child', $this->getTestedType());
6567
$view = $builder->getForm()->createView();
6668

@@ -71,18 +73,18 @@ public function testPassIdAndNameToViewWithGrandParent()
7173

7274
public function testPassTranslationDomainToView()
7375
{
74-
$form = $this->factory->create($this->getTestedType(), null, array(
76+
$view = $this->factory->create($this->getTestedType(), null, array(
7577
'translation_domain' => 'domain',
76-
));
77-
$view = $form->createView();
78+
))
79+
->createView();
7880

7981
$this->assertSame('domain', $view->vars['translation_domain']);
8082
}
8183

8284
public function testInheritTranslationDomainFromParent()
8385
{
8486
$view = $this->factory
85-
->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
87+
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
8688
'translation_domain' => 'domain',
8789
))
8890
->add('child', $this->getTestedType())
@@ -95,7 +97,7 @@ public function testInheritTranslationDomainFromParent()
9597
public function testPreferOwnTranslationDomain()
9698
{
9799
$view = $this->factory
98-
->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
100+
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
99101
'translation_domain' => 'parent_domain',
100102
))
101103
->add('child', $this->getTestedType(), array(
@@ -109,7 +111,7 @@ public function testPreferOwnTranslationDomain()
109111

110112
public function testDefaultTranslationDomain()
111113
{
112-
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
114+
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
113115
->add('child', $this->getTestedType())
114116
->getForm()
115117
->createView();
@@ -119,19 +121,32 @@ public function testDefaultTranslationDomain()
119121

120122
public function testPassLabelToView()
121123
{
122-
$form = $this->factory->createNamed('__test___field', $this->getTestedType(), null, array('label' => 'My label'));
123-
$view = $form->createView();
124+
$view = $this->factory->createNamed('__test___field', $this->getTestedType(), null, array('label' => 'My label'))
125+
->createView();
124126

125127
$this->assertSame('My label', $view->vars['label']);
126128
}
127129

128130
public function testPassMultipartFalseToView()
129131
{
130-
$form = $this->factory->create($this->getTestedType());
131-
$view = $form->createView();
132+
$view = $this->factory->create($this->getTestedType())
133+
->createView();
132134

133135
$this->assertFalse($view->vars['multipart']);
134136
}
135137

136-
abstract protected function getTestedType();
138+
public function testSubmitNull($expected = null, $norm = null, $view = null)
139+
{
140+
$form = $this->factory->create($this->getTestedType());
141+
$form->submit(null);
142+
143+
$this->assertSame($expected, $form->getData());
144+
$this->assertSame($norm, $form->getNormData());
145+
$this->assertSame($view, $form->getViewData());
146+
}
147+
148+
protected function getTestedType()
149+
{
150+
return static::TESTED_TYPE;
151+
}
137152
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/BirthdayTypeTest.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,17 @@
1414
/**
1515
* @author Stepan Anchugov <kixxx1@gmail.com>
1616
*/
17-
class BirthdayTypeTest extends BaseTypeTest
17+
class BirthdayTypeTest extends DateTypeTest
1818
{
19+
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\BirthdayType';
20+
1921
/**
2022
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
2123
*/
2224
public function testSetInvalidYearsOption()
2325
{
24-
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\BirthdayType', null, array(
26+
$this->factory->create(static::TESTED_TYPE, null, array(
2527
'years' => 'bad value',
2628
));
2729
}
28-
29-
protected function getTestedType()
30-
{
31-
return 'Symfony\Component\Form\Extension\Core\Type\BirthdayType';
32-
}
3330
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616
*/
1717
class ButtonTypeTest extends BaseTypeTest
1818
{
19-
public function testCreateButtonInstances()
20-
{
21-
$this->assertInstanceOf('Symfony\Component\Form\Button', $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ButtonType'));
22-
}
19+
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\ButtonType';
2320

24-
protected function getTestedType()
21+
public function testCreateButtonInstances()
2522
{
26-
return 'Symfony\Component\Form\Extension\Core\Type\ButtonType';
23+
$this->assertInstanceOf('Symfony\Component\Form\Button', $this->factory->create(static::TESTED_TYPE));
2724
}
2825
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php

+28-22
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\CallbackTransformer;
15-
use Symfony\Component\Form\Test\TypeTestCase;
1615

17-
class CheckboxTypeTest extends TypeTestCase
16+
class CheckboxTypeTest extends BaseTypeTest
1817
{
18+
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\CheckboxType';
19+
1920
public function testDataIsFalseByDefault()
2021
{
21-
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType');
22+
$form = $this->factory->create(static::TESTED_TYPE);
2223

2324
$this->assertFalse($form->getData());
2425
$this->assertFalse($form->getNormData());
@@ -27,42 +28,42 @@ public function testDataIsFalseByDefault()
2728

2829
public function testPassValueToView()
2930
{
30-
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array('value' => 'foobar'));
31-
$view = $form->createView();
31+
$view = $this->factory->create(static::TESTED_TYPE, null, array('value' => 'foobar'))
32+
->createView();
3233

3334
$this->assertEquals('foobar', $view->vars['value']);
3435
}
3536

3637
public function testCheckedIfDataTrue()
3738
{
38-
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType');
39-
$form->setData(true);
40-
$view = $form->createView();
39+
$view = $this->factory->create(static::TESTED_TYPE)
40+
->setData(true)
41+
->createView();
4142

4243
$this->assertTrue($view->vars['checked']);
4344
}
4445

4546
public function testCheckedIfDataTrueWithEmptyValue()
4647
{
47-
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array('value' => ''));
48-
$form->setData(true);
49-
$view = $form->createView();
48+
$view = $this->factory->create(static::TESTED_TYPE, null, array('value' => ''))
49+
->setData(true)
50+
->createView();
5051

5152
$this->assertTrue($view->vars['checked']);
5253
}
5354

5455
public function testNotCheckedIfDataFalse()
5556
{
56-
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType');
57-
$form->setData(false);
58-
$view = $form->createView();
57+
$view = $this->factory->create(static::TESTED_TYPE)
58+
->setData(false)
59+
->createView();
5960

6061
$this->assertFalse($view->vars['checked']);
6162
}
6263

6364
public function testSubmitWithValueChecked()
6465
{
65-
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
66+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
6667
'value' => 'foobar',
6768
));
6869
$form->submit('foobar');
@@ -73,7 +74,7 @@ public function testSubmitWithValueChecked()
7374

7475
public function testSubmitWithRandomValueChecked()
7576
{
76-
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
77+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
7778
'value' => 'foobar',
7879
));
7980
$form->submit('krixikraxi');
@@ -84,7 +85,7 @@ public function testSubmitWithRandomValueChecked()
8485

8586
public function testSubmitWithValueUnchecked()
8687
{
87-
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
88+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
8889
'value' => 'foobar',
8990
));
9091
$form->submit(null);
@@ -95,7 +96,7 @@ public function testSubmitWithValueUnchecked()
9596

9697
public function testSubmitWithEmptyValueChecked()
9798
{
98-
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
99+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
99100
'value' => '',
100101
));
101102
$form->submit('');
@@ -106,7 +107,7 @@ public function testSubmitWithEmptyValueChecked()
106107

107108
public function testSubmitWithEmptyValueUnchecked()
108109
{
109-
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
110+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
110111
'value' => '',
111112
));
112113
$form->submit(null);
@@ -117,7 +118,7 @@ public function testSubmitWithEmptyValueUnchecked()
117118

118119
public function testSubmitWithEmptyValueAndFalseUnchecked()
119120
{
120-
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
121+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
121122
'value' => '',
122123
));
123124
$form->submit(false);
@@ -128,7 +129,7 @@ public function testSubmitWithEmptyValueAndFalseUnchecked()
128129

129130
public function testSubmitWithEmptyValueAndTrueChecked()
130131
{
131-
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
132+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
132133
'value' => '',
133134
));
134135
$form->submit(true);
@@ -152,7 +153,7 @@ function ($value) {
152153
}
153154
);
154155

155-
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\CheckboxType')
156+
$form = $this->factory->createBuilder(static::TESTED_TYPE)
156157
->addModelTransformer($transformer)
157158
->getForm();
158159

@@ -171,4 +172,9 @@ public function provideCustomModelTransformerData()
171172
array('unchecked', false),
172173
);
173174
}
175+
176+
public function testSubmitNull($expected = null, $norm = null, $view = null)
177+
{
178+
parent::testSubmitNull(false, false, null);
179+
}
174180
}

0 commit comments

Comments
 (0)