File tree Expand file tree Collapse file tree 2 files changed +69
-0
lines changed
src/Symfony/Component/Form/Tests/Extension/Core/Type Expand file tree Collapse file tree 2 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -170,4 +170,38 @@ public function provideCustomModelTransformerData()
170
170
array ('unchecked ' , false ),
171
171
);
172
172
}
173
+
174
+ public function testSubmitNullWithEmptyDataTrueWhenNested ()
175
+ {
176
+ $ form = $ this ->factory ->create ('form ' )
177
+ ->add ('agree ' , 'checkbox ' , array (
178
+ 'empty_data ' => true ,
179
+ ));
180
+
181
+ $ form ->submit (null );
182
+
183
+ $ this ->assertTrue ($ form ->get ('agree ' )->getData ());
184
+ $ this ->assertSame ('1 ' , $ form ->get ('agree ' )->getViewData ());
185
+
186
+ $ view = $ form ->get ('agree ' )->createView ();
187
+
188
+ $ this ->assertTrue ($ view ->vars ['checked ' ]);
189
+ }
190
+
191
+ public function testSubmitNullWithEmptyDataFalseWhenNested ()
192
+ {
193
+ $ form = $ this ->factory ->create ('form ' )
194
+ ->add ('agree ' , 'checkbox ' , array (
195
+ 'empty_data ' => false ,
196
+ ));
197
+
198
+ $ form ->submit (null );
199
+
200
+ $ this ->assertFalse ($ form ->get ('agree ' )->getData ());
201
+ $ this ->assertEmpty ($ form ->get ('agree ' )->getViewData ());
202
+
203
+ $ view = $ form ->get ('agree ' )->createView ();
204
+
205
+ $ this ->assertFalse ($ view ->vars ['checked ' ]);
206
+ }
173
207
}
Original file line number Diff line number Diff line change @@ -32,4 +32,39 @@ public function testSubmitCastsToInteger()
32
32
$ this ->assertSame (1 , $ form ->getData ());
33
33
$ this ->assertSame ('1 ' , $ form ->getViewData ());
34
34
}
35
+
36
+ public function testSubmitNull ()
37
+ {
38
+ $ form = $ this ->factory ->create ('integer ' );
39
+
40
+ $ form ->submit (null );
41
+
42
+ $ this ->assertNull ($ form ->getData ());
43
+ $ this ->assertSame ('' , $ form ->getViewData ());
44
+ }
45
+
46
+ public function testSubmitNullWithEmptyData ()
47
+ {
48
+ $ form = $ this ->factory ->create ('integer ' , null , array (
49
+ 'empty_data ' => 1 ,
50
+ ));
51
+
52
+ $ form ->submit (null );
53
+
54
+ $ this ->assertSame (1 , $ form ->getData ());
55
+ $ this ->assertSame ('1 ' , $ form ->getViewData ());
56
+ }
57
+
58
+ public function testSubmitNullWithEmptyDataWhenNested ()
59
+ {
60
+ $ form = $ this ->factory ->create ('form ' )
61
+ ->add ('age ' , 'integer ' , array (
62
+ 'empty_data ' => 1 ,
63
+ ));
64
+
65
+ $ form ->submit (null );
66
+
67
+ $ this ->assertSame (1 , $ form ->get ('age ' )->getData ());
68
+ $ this ->assertSame ('1 ' , $ form ->get ('age ' )->getViewData ());
69
+ }
35
70
}
You can’t perform that action at this time.
0 commit comments