@@ -129,6 +129,24 @@ public function testGenerateCsrfToken()
129
129
$ this ->assertEquals ('token ' , $ view ['csrf ' ]->vars ['value ' ]);
130
130
}
131
131
132
+ public function testGenerateCsrfTokenUsesFormNameAsIntentionByDefault ()
133
+ {
134
+ $ this ->csrfProvider ->expects ($ this ->once ())
135
+ ->method ('generateCsrfToken ' )
136
+ ->with ('FORM_NAME ' )
137
+ ->will ($ this ->returnValue ('token ' ));
138
+
139
+ $ view = $ this ->factory
140
+ ->createNamed ('FORM_NAME ' , 'form ' , null , array (
141
+ 'csrf_field_name ' => 'csrf ' ,
142
+ 'csrf_provider ' => $ this ->csrfProvider ,
143
+ 'compound ' => true ,
144
+ ))
145
+ ->createView ();
146
+
147
+ $ this ->assertEquals ('token ' , $ view ['csrf ' ]->vars ['value ' ]);
148
+ }
149
+
132
150
public function provideBoolean ()
133
151
{
134
152
return array (
@@ -169,6 +187,37 @@ public function testValidateTokenOnBindIfRootAndCompound($valid)
169
187
$ this ->assertSame ($ valid , $ form ->isValid ());
170
188
}
171
189
190
+ /**
191
+ * @dataProvider provideBoolean
192
+ */
193
+ public function testValidateTokenOnBindIfRootAndCompoundUsesFormNameAsIntentionByDefault ($ valid )
194
+ {
195
+ $ this ->csrfProvider ->expects ($ this ->once ())
196
+ ->method ('isCsrfTokenValid ' )
197
+ ->with ('FORM_NAME ' , 'token ' )
198
+ ->will ($ this ->returnValue ($ valid ));
199
+
200
+ $ form = $ this ->factory
201
+ ->createNamedBuilder ('FORM_NAME ' , 'form ' , null , array (
202
+ 'csrf_field_name ' => 'csrf ' ,
203
+ 'csrf_provider ' => $ this ->csrfProvider ,
204
+ 'compound ' => true ,
205
+ ))
206
+ ->add ('child ' , 'text ' )
207
+ ->getForm ();
208
+
209
+ $ form ->bind (array (
210
+ 'child ' => 'foobar ' ,
211
+ 'csrf ' => 'token ' ,
212
+ ));
213
+
214
+ // Remove token from data
215
+ $ this ->assertSame (array ('child ' => 'foobar ' ), $ form ->getData ());
216
+
217
+ // Validate accordingly
218
+ $ this ->assertSame ($ valid , $ form ->isValid ());
219
+ }
220
+
172
221
public function testFailIfRootAndCompoundAndTokenMissing ()
173
222
{
174
223
$ this ->csrfProvider ->expects ($ this ->never ())
0 commit comments