8000 merged branch bschussek/issue3990 (PR #3996) · symfony/symfony@aebaece · GitHub
[go: up one dir, main page]

Skip to content

Commit aebaece

Browse files
committed
merged branch bschussek/issue3990 (PR #3996)
Commits ------- ccd6bbc [Form] Removed extra CSRF field on collection prototype Discussion ---------- [Form] Removed extra CSRF field on collection prototype Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: #3987, #3990 Todo: - ![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue3990) --------------------------------------------------------------------------- by bschussek at 2012-04-19T08:43:32Z Wait a minute please, I oversaw some tests that have to be adapted. --------------------------------------------------------------------------- by bschussek at 2012-04-19T09:22:45Z Fixed. ping @fabpot
2 parents fd52f93 + ccd6bbc commit aebaece

File tree

5 files changed

+114
-79
lines changed

5 files changed

+114
-79
lines changed

src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public function buildForm(FormBuilder $builder, array $options)
6363
* @param FormView $view The form view
6464
* @param FormInterface $form The form
6565
*/
66-
public function buildView(FormView $view, FormInterface $form)
66+
public function buildViewBottomUp(FormView $view, FormInterface $form)
6767
{
68-
if ($form->isRoot() && $form->hasChildren() && $form->hasAttribute('csrf_field_name')) {
68+
if (!$view->hasParent() && $view->hasChildren() && $form->hasAttribute('csrf_field_name')) {
6969
$name = $form->getAttribute('csrf_field_name');
7070
$csrfProvider = $form->getAttribute('csrf_provider');
7171
$intention = $form->getAttribute('csrf_intention');

src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ public function testRest()
9696
$html = $this->renderRest($view);
9797

9898
$this->assertMatchesXpath($html,
99-
'/input
100-
[@type="hidden"]
101-
[@id="name__token"]
102-
/following-sibling::div
99+
'/div
103100
[
104101
./label[@for="name_field1"]
105102
/following-sibling::input[@type="text"][@id="name_field1"]
@@ -112,6 +109,9 @@ public function testRest()
112109
[count(../div)=2]
113110
[count(..//label)=2]
114111
[count(..//input)=3]
112+
/following-sibling::input
113+
[@type="hidden"]
114+
[@id="name__token"]
115115
'
116116
);
117117
}
@@ -144,8 +144,7 @@ public function testRestWithChildrenForms()
144144
$html = $this->renderRest($view);
145145

146146
$this->assertMatchesXpath($html,
147-
'/input[@type="hidden"][@id="parent__token"]
148-
/following-sibling::div
147+
'/div
149148
[
150149
./label[not(@for)]
151150
/following-sibling::div[@id="parent_child1"]
@@ -172,6 +171,7 @@ public function testRestWithChildrenForms()
172171
]
173172
[count(//label)=4]
174173
[count(//input[@type="text"])=2]
174+
/following-sibling::input[@type="hidden"][@id="parent__token"]
175175
'
176176
);
177177
}
@@ -189,15 +189,15 @@ public function testRestAndRepeatedWithRow()
189189
$html = $this->renderRest($view);
190190

191191
$this->assertMatchesXpath($html,
192-
'/input
193-
[@type="hidden"]
194-
[@id="name__token"]
195-
/following-sibling::div
192+
'/div
196193
[
197194
./label[@for="name_first"]
198195
/following-sibling::input[@type="text"][@id="name_first"]
199196
]
200197
[count(.//input)=1]
198+
/following-sibling::input
199+
[@type="hidden"]
200+
[@id="name__token"]
201201
'
202202
);
203203
}
@@ -216,16 +216,16 @@ public function testRestAndRepeatedWithRowPerChild()
216216
$html = $this->renderRest($view);
217217

218218
$this->assertMatchesXpath($html,
219-
'/input
220-
[@type="hidden"]
221-
[@id="name__token"]
222-
/following-sibling::div
219+
'/div
223220
[
224221
./label[@for="name_first"]
225222
/following-sibling::input[@type="text"][@id="name_first"]
226223
]
227224
[count(.//input)=1]
228225
[count(.//label)=1]
226+
/following-sibling::input
227+
[@type="hidden"]
228+
[@id="name__token"]
229229
'
230230
);
231231
}
@@ -246,16 +246,16 @@ public function testRestAndRepeatedWithWidgetPerChild()
246246
$html = $this->renderRest($view);
247247

248248
$this->assertMatchesXpath($html,
249-
'/input
250-
[@type="hidden"]
251-
[@id="name__token"]
252-
/following-sibling::div
249+
'/div
253250
[
254251
./label[@for="name_first"]
255252
/following-sibling::input[@type="text"][@id="name_first"]
256253
]
257254
[count(//input)=2]
258255
[count(//label)=1]
256+
/following-sibling::input
257+
[@type="hidden"]
258+
[@id="name__token"]
259259
'
260260
);
261261
}
@@ -293,8 +293,7 @@ public function testCollectionRow()
293293
$this->assertWidgetMatchesXpath($form->createView(), array(),
294294
'/div
295295
[
296-
./input[@type="hidden"][@id="form__token"]
297-
/following-sibling::div
296+
./div
298297
[
299298
./label[not(@for)]
300299
/following-sibling::div
@@ -311,6 +310,7 @@ public function testCollectionRow()
311310
]
312311
]
313312
]
313+
/following-sibling::input[@type="hidden"][@id="form__token"]
314314
]
315315
[count(.//input)=3]
316316
'
@@ -327,8 +327,7 @@ public function testForm()
327327
$this->assertWidgetMatchesXpath($form->createView(), array(),
328328
'/div
329329
[
330-
./input[@type="hidden"][@id="name__token"]
331-
/following-sibling::div
330+
./div
332331
[
333332
./label[@for="name_firstName"]
334333
/following-sibling::input[@type="text"][@id="name_firstName"]
@@ -338,6 +337,7 @@ public function testForm()
338337
./label[@for="name_lastName"]
339338
/following-sibling::input[@type="text"][@id="name_lastName"]
340339
]
340+
/following-sibling::input[@type="hidden"][@id="name__token"]
341341
]
342342
[count(.//input)=3]
343343
'
@@ -383,8 +383,8 @@ public function testCsrf()
383383
$this->assertWidgetMatchesXpath($form->createView(), array(),
384384
'/div
385385
[
386-
./input[@type="hidden"][@id="name__token"][@value="foo&bar"]
387-
/following-sibling::div
386+
./div
387+
/following-sibling::input[@type="hidden"][@id="name__token"][@value="foo&bar"]
388388
]
389389
[count(.//input[@type="hidden"])=1]
390390
'
@@ -400,8 +400,7 @@ public function testRepeated()
400400
$this->assertWidgetMatchesXpath($form->createView(), array(),
401401
'/div
402402
[
403-
./input[@type="hidden"][@id="name__token"]
404-
/following-sibling::div
403+
./div
405404
[
406405
./label[@for="name_first"]
407406
/following-sibling::input[@type="text"][@id="name_first"]
@@ -411,6 +410,7 @@ public function testRepeated()
411410
./label[@for="name_second"]
412411
/following-sibling::input[@type="text"][@id="name_second"]
413412
]
413+
/following-sibling::input[@type="hidden"][@id="name__token"]
414414
]
415415
[count(.//input)=3]
416416
'
@@ -428,8 +428,7 @@ public function testRepeatedWithCustomOptions()
428428
$this->assertWidgetMatchesXpath($form->createView(), array(),
429429
'/div
430430
[
431-
./input[@type="hidden"][@id="name__token"]
432-
/following-sibling::div
431+
./div
433432
[
434433
./label[@for="name_first"][.="[trans]Test[/trans]"]
435434
/following-sibling::input[@type="text"][@id="name_first"][@required="required"]
@@ -439,6 +438,7 @@ public function testRepeatedWithCustomOptions()
439438
./label[@for="name_second"][.="[trans]Test2[/trans]"]
440439
/following-sibling::input[@type="text"][@id="name_second"][@required="required"]
441440
]
441+
/following-sibling::input[@type="hidden"][@id="name__token"]
442442
]
443443
[count(.//input)=3]
444444
'
@@ -454,12 +454,12 @@ public function testSearchInputName()
454454
$this->assertWidgetMatchesXpath($form->createView(), array(),
455455
'/div
456456
[
457-
./input[@type="hidden"][@id="full__token"]
458-
/following-sibling::div
457+
./div
459458
[
460459
./label[@for="full_name"]
461460
/following-sibling::input[@type="search"][@id="full_name"][@name="full[name]"]
462461
]
462+
/following-sibling::input[@type="hidden"][@id="full__token"]
463463
]
464464
[count(//input)=2]
465465
'
@@ -521,8 +521,7 @@ public function testThemeInheritance($parentTheme, $childTheme)
521521
$this->assertWidgetMatchesXpath($view, array(),
522522
'/div
523523
[
524-
./input[@type="hidden"]
525-
/following-sibling::div
524+
./div
526525
[
527526
./label[.="parent"]
528527
/following-sibling::input[@type="text"]
@@ -539,6 +538,7 @@ public function testThemeInheritance($parentTheme, $childTheme)
539538
]
540539
]
541540
]
541+
/following-sibling::input[@type="hidden"]
542542
]
543543
'
544544
);

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -646,11 +646,11 @@ public function testSingleChoiceExpanded()
646646
$this->assertWidgetMatchesXpath($form->createView(), array(),
647647
'/div
648648
[
649-
./input[@type="hidden"][@id="name__token"]
650-
/following-sibling::input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
649+
./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
651650
/following-sibling::label[@for="name_0"][.="[trans]Choice&A[/trans]"]
652651
/following-sibling::input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
653652
/following-sibling::label[@for="name_1"][.="[trans]Choice&B[/trans]"]
653+
/following-sibling::input[@type="hidden"][@id="name__token"]
654654
]
655655
[count(./input)=3]
656656
'
@@ -669,11 +669,11 @@ public function testSingleChoiceExpandedSkipEmptyValue()
669669
$this->assertWidgetMatchesXpath($form->createView(), array(),
670670
'/div
671671
[
672-
./input[@type="hidden"][@id="name__token"]
673-
/following-sibling::input[@type="radio"][@name="name"][@id="name_0"][@checked]
672+
./input[@type="radio"][@name="name"][@id="name_0"][@checked]
674673
/following-sibling::label[@for="name_0"][.="[trans]Choice&A[/trans]"]
675674
/following-sibling::input[@type="radio"][@name="name"][@id="name_1"][not(@checked)]
676675
/following-sibling::label[@for="name_1"][.="[trans]Choice&B[/trans]"]
676+
/following-sibling::input[@type="hidden"][@id="name__token"]
677677
]
678678
[count(./input)=3]
679679
'
@@ -691,11 +691,11 @@ public function testSingleChoiceExpandedWithBooleanValue()
691691
$this->assertWidgetMatchesXpath($form->createView(), array(),
692692
'/div
693693
[
694-
./input[@type="hidden"][@id="name__token"]
695-
/following-sibling::input[@type="radio"][@name="name"][@id="name_0"][@checked]
694+
./input[@type="radio"][@name="name"][@id="name_0"][@checked]
696695
/following-sibling::label[@for="name_0"][.="[trans]Choice&A[/trans]"]
697696
/following-sibling::input[@type="radio"][@name="name"][@id="name_1"][not(@checked)]
698697
/following-sibling::label[@for="name_1"][.="[trans]Choice&B[/trans]"]
698+
/following-sibling::input[@type="hidden"][@id="name__token"]
699699
]
700700
[count(./input)=3]
701701
'
@@ -714,13 +714,13 @@ public function testMultipleChoiceExpanded()
714714
$this->assertWidgetMatchesXpath($form->createView(), array(),
715715
'/div
716716
[
717-
./input[@type="hidden"][@id="name__token"]
718-
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
717+
./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
719718
/following-sibling::label[@for="name_0"][.="[trans]Choice&A[/trans]"]
720719
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)]
721720
/following-sibling::label[@for="name_1"][.="[trans]Choice&B[/trans]"]
722721
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)]
723722
/following-sibling::label[@for="name_2"][.="[trans]Choice&C[/trans]"]
723+
/following-sibling::input[@type="hidden"][@id="name__token"]
724724
]
725725
[count(./input)=4]
726726
'

0 commit comments

Comments
 (0)
0