@@ -140,6 +140,24 @@ public function testGenerateCsrfToken()
140
140
$ this ->assertEquals ('token ' , $ view ['csrf ' ]->vars ['value ' ]);
141
141
}
142
142
143
+ public function testGenerateCsrfTokenUsesFormNameAsIntentionByDefault ()
144
+ {
145
+ $ this ->csrfProvider ->expects ($ this ->once ())
146
+ ->method ('generateCsrfToken ' )
147
+ ->with ('FORM_NAME ' )
148
+ ->will ($ this ->returnValue ('token ' ));
149
+
150
+ $ view = $ this ->factory
151
+ ->createNamed ('FORM_NAME ' , 'form ' , null , array (
152
+ 'csrf_field_name ' => 'csrf ' ,
153
+ 'csrf_provider ' => $ this ->csrfProvider ,
154
+ 'compound ' => true ,
155
+ ))
156
+ ->createView ();
157
+
158
+ $ this ->assertEquals ('token ' , $ view ['csrf ' ]->vars ['value ' ]);
159
+ }
160
+
143
161
public function provideBoolean ()
144
162
{
145
163
return array (
@@ -180,6 +198,37 @@ public function testValidateTokenOnSubmitIfRootAndCompound($valid)
180
198
$ this ->assertSame ($ valid , $ form ->isValid ());
181
199
}
182
200
201
+ /**
202
+ * @dataProvider provideBoolean
203
+ */
204
+ public function testValidateTokenOnBindIfRootAndCompoundUsesFormNameAsIntentionByDefault ($ valid )
205
+ {
206
+ $ this ->csrfProvider ->expects ($ this ->once ())
207
+ ->method ('isCsrfTokenValid ' )
208
+ ->with ('FORM_NAME ' , 'token ' )
209
+ ->will ($ this ->returnValue ($ valid ));
210
+
211
+ $ form = $ this ->factory
212
+ ->createNamedBuilder ('FORM_NAME ' , 'form ' , null , array (
213
+ 'csrf_field_name ' => 'csrf ' ,
214
+ 'csrf_provider ' => $ this ->csrfProvider ,
215
+ 'compound ' => true ,
216
+ ))
217
+ ->add ('child ' , 'text ' )
218
+ ->getForm ();
219
+
220
+ $ form ->submit (array (
221
+ 'child ' => 'foobar ' ,
222
+ 'csrf ' => 'token ' ,
223
+ ));
224
+
225
+ // Remove token from data
226
+ $ this ->assertSame (array ('child ' => 'foobar ' ), $ form ->getData ());
227
+
228
+ // Validate accordingly
229
+ $ this ->assertSame ($ valid , $ form ->isValid ());
230
+ }
231
+
183
232
public function testFailIfRootAndCompoundAndTokenMissing ()
184
233
{
185
234
$ this ->csrfProvider ->expects ($ this ->never ())
0 commit comments