@@ -158,6 +158,24 @@ public function testGenerateCsrfTokenUsesFormNameAsIntentionByDefault()
158
158
$ this ->assertEquals ('token ' , $ view ['csrf ' ]->vars ['value ' ]);
159
159
}
160
160
161
+ public function testGenerateCsrfTokenUsesTypeClassAsIntentionIfEmptyFormName ()
162
+ {
163
+ $ this ->csrfProvider ->expects ($ this ->once ())
164
+ ->method ('generateCsrfToken ' )
165
+ ->with ('Symfony\Component\Form\Extension\Core\Type\FormType ' )
166
+ ->will ($ this ->returnValue ('token ' ));
167
+
168
+ $ view = $ this ->factory
169
+ ->createNamed ('' , 'form ' , null , array (
170
+ 'csrf_field_name ' => 'csrf ' ,
171
+ 'csrf_provider ' => $ this ->csrfProvider ,
172
+ 'compound ' => true ,
173
+ ))
174
+ ->createView ();
175
+
176
+ $ this ->assertEquals ('token ' , $ view ['csrf ' ]->vars ['value ' ]);
177
+ }
178
+
161
179
public function provideBoolean ()
162
180
{
163
181
return array (
@@ -201,7 +219,7 @@ public function testValidateTokenOnSubmitIfRootAndCompound($valid)
201
219
/**
202
220
* @dataProvider provideBoolean
203
221
*/
204
- public function testValidateTokenOnBindIfRootAndCompoundUsesFormNameAsIntentionByDefault ($ valid )
222
+ public function testValidateTokenOnSubmitIfRootAndCompoundUsesFormNameAsIntentionByDefault ($ valid )
205
223
{
206
224
$ this ->csrfProvider ->expects ($ this ->once ())
207
225
->method ('isCsrfTokenValid ' )
@@ -229,6 +247,37 @@ public function testValidateTokenOnBindIfRootAndCompoundUsesFormNameAsIntentionB
229
247
$ this ->assertSame ($ valid , $ form ->isValid ());
230
248
}
231
249
250
+ /**
251
+ * @dataProvider provideBoolean
252
+ */
253
+ public function testValidateTokenOnSubmitIfRootAndCompoundUsesTypeClassAsIntentionIfEmptyFormName ($ valid )
254
+ {
255
+ $ this ->csrfProvider ->expects ($ this ->once ())
256
+ ->method ('isCsrfTokenValid ' )
257
+ ->with ('Symfony\Component\Form\Extension\Core\Type\FormType ' , 'token ' )
258
+ ->will ($ this ->returnValue ($ valid ));
259
+
260
+ $ form = $ this ->factory
261
+ ->createNamedBuilder ('' , 'form ' , null , array (
262
+ 'csrf_field_name ' => 'csrf ' ,
263
+ 'csrf_provider ' => $ this ->csrfProvider ,
264
+ 'compound ' => true ,
265
+ ))
266
+ ->add ('child ' , 'text ' )
267
+ ->getForm ();
268
+
269
+ $ form ->submit (array (
270
+ 'child ' => 'foobar ' ,
271
+ 'csrf ' => 'token ' ,
272
+ ));
273
+
274
+ // Remove token from data
275
+ $ this ->assertSame (array ('child ' => 'foobar ' ), $ form ->getData ());
276
+
277
+ // Validate accordingly
278
+ $ this ->assertSame ($ valid , $ form ->isValid ());
279
+ }
280
+
232
281
public function testFailIfRootAndCompoundAndTokenMissing ()
233
282
{
234
283
$ this ->csrfProvider ->expects ($ this ->never ())
0 commit comments