@@ -159,6 +159,24 @@ public function testGenerateCsrfTokenUsesFormNameAsIntentionByDefault()
159159 $ this ->assertEquals ('token ' , $ view ['csrf ' ]->vars ['value ' ]);
160160 }
161161
162+ public function testGenerateCsrfTokenUsesTypeClassAsIntentionIfEmptyFormName ()
163+ {
164+ $ this ->tokenManager ->expects ($ this ->once ())
165+ ->method ('getToken ' )
166+ ->with ('Symfony\Component\Form\Extension\Core\Type\FormType ' )
167+ ->will ($ this ->returnValue ('token ' ));
168+
169+ $ view = $ this ->factory
170+ ->createNamed ('' , 'form ' , null , array (
171+ 'csrf_field_name ' => 'csrf ' ,
172+ 'csrf_token_manager ' => $ this ->tokenManager ,
173+ 'compound ' => true ,
174+ ))
175+ ->createView ();
176+
177+ $ this ->assertEquals ('token ' , $ view ['csrf ' ]->vars ['value ' ]);
178+ }
179+
162180 public function provideBoolean ()
163181 {
164182 return array (
@@ -202,7 +220,7 @@ public function testValidateTokenOnSubmitIfRootAndCompound($valid)
202220 /**
203221 * @dataProvider provideBoolean
204222 */
205- public function testValidateTokenOnBindIfRootAndCompoundUsesFormNameAsIntentionByDefault ($ valid )
223+ public function testValidateTokenOnSubmitIfRootAndCompoundUsesFormNameAsIntentionByDefault ($ valid )
206224 {
207225 $ this ->tokenManager ->expects ($ this ->once ())
208226 ->method ('isTokenValid ' )
@@ -230,6 +248,37 @@ public function testValidateTokenOnBindIfRootAndCompoundUsesFormNameAsIntentionB
230248 $ this ->assertSame ($ valid , $ form ->isValid ());
231249 }
232250
251+ /**
252+ * @dataProvider provideBoolean
253+ */
254+ public function testValidateTokenOnSubmitIfRootAndCompoundUsesTypeClassAsIntentionIfEmptyFormName ($ valid )
255+ {
256+ $ this ->tokenManager ->expects ($ this ->once ())
257+ ->method ('isTokenValid ' )
258+ ->with (new CsrfToken ('Symfony\Component\Form\Extension\Core\Type\FormType ' , 'token ' ))
259+ ->will ($ this ->returnValue ($ valid ));
260+
261+ $ form = $ this ->factory
262+ ->createNamedBuilder ('' , 'form ' , null , array (
263+ 'csrf_field_name ' => 'csrf ' ,
264+ 'csrf_token_manager ' => $ this ->tokenManager ,
265+ 'compound ' => true ,
266+ ))
267+ ->add ('child ' , 'text ' )
268+ ->getForm ();
269+
270+ $ form ->submit (array (
271+ 'child ' => 'foobar ' ,
272+ 'csrf ' => 'token ' ,
273+ ));
274+
275+ // Remove token from data
276+ $ this ->assertSame (array ('child ' => 'foobar ' ), $ form ->getData ());
277+
278+ // Validate accordingly
279+ $ this ->assertSame ($ valid , $ form ->isValid ());
280+ }
281+
233282 public function testFailIfRootAndCompoundAndTokenMissing ()
234283 {
235284 $ this ->tokenManager ->expects ($ this ->never ())
0 commit comments