Code Duplication    Length = 71-72 lines in 2 locations

tests/WidgetAreaEditorTest.php 2 locations

@@ 127-197 (lines=71) @@
124
        $this->assertEquals($bottWidgets[0]->getTitle(), 'MyTestWidgetBottom');
125
    }
126
127
    public function testDeletingOneWidgetFromOneArea()
128
    {
129
        // First get some widgets in there
130
        $data = array(
131
            Widget::class => array(
132
                'SideBar' => array(
133
                    'new-1' => array(
134
                        'Title' => 'MyTestWidgetSide',
135
                        'Type' => $this->widgetToTest,
136
                        'Sort' => 0
137
                    )
138
                ),
139
                'BottomBar' => array(
140
                    'new-1' => array(
141
                        'Title' => 'MyTestWidgetBottom',
142
                        'Type' => $this->widgetToTest,
143
                        'Sort' => 0
144
                    )
145
                )
146
            )
147
        );
148
        $request = new HTTPRequest('get', 'post', array(), $data);
149
150
        $editorSide = new WidgetAreaEditor('SideBar');
151
        $editorBott = new WidgetAreaEditor('BottomBar');
152
        $form = new Form(
153
            new ContentController(),
154
            Form::class,
155
            new FieldList($editorSide, $editorBott),
156
            new FieldList()
157
        );
158
        $form->setRequest($request);
159
        $page = new FakePage();
160
161
        $form->saveInto($page);
162
        $page->write();
163
        $page->flushCache();
164
        $page->BottomBar()->flushCache();
165
        $page->SideBar()->flushCache();
166
        $sideWidgets = $page->SideBar()->Widgets()->toArray();
167
        $bottWidgets = $page->BottomBar()->Widgets()->toArray();
168
169
        // Save again (after removing the SideBar's widget)
170
        $data = array(
171
            Widget::class => array(
172
                'SideBar' => array(
173
                ),
174
                'BottomBar' => array(
175
                    $bottWidgets[0]->ID => array(
176
                        'Title' => 'MyTestWidgetBottom',
177
                        'Type' => $this->widgetToTest,
178
                        'Sort' => 0
179
                    )
180
                )
181
            )
182
        );
183
        $request = new HTTPRequest('get', 'post', array(), $data);
184
        $form->setRequest($request);
185
        $form->saveInto($page);
186
187
        $page->write();
188
        $page->flushCache();
189
        $page->BottomBar()->flushCache();
190
        $page->SideBar()->flushCache();
191
        $sideWidgets = $page->SideBar()->Widgets()->toArray();
192
        $bottWidgets = $page->BottomBar()->Widgets()->toArray();
193
194
        $this->assertEquals($page->BottomBar()->Widgets()->Count(), 1);
195
        $this->assertEquals($bottWidgets[0]->getTitle(), 'MyTestWidgetBottom');
196
        $this->assertEquals($page->SideBar()->Widgets()->Count(), 0);
197
    }
198
199
    public function testDeletingAWidgetFromEachArea()
200
    {
@@ 421-492 (lines=72) @@
418
        $this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide-edited');
419
    }
420
421
    public function testEditAWidgetFromOneAreaAndDeleteAWidgetFromAnotherArea()
422
    {
423
        // First get some widgets in there
424
        $data = array(
425
            Widget::class => array(
426
                'SideBar' => array(
427
                    'new-1' => array(
428
                        'Title' => 'MyTestWidgetSide',
429
                        'Type' => $this->widgetToTest,
430
                        'Sort' => 0
431
                    )
432
                ),
433
                'BottomBar' => array(
434
                    'new-1' => array(
435
                        'Title' => 'MyTestWidgetBottom',
436
                        'Type' => $this->widgetToTest,
437
                        'Sort' => 0
438
                    )
439
                )
440
            )
441
        );
442
        $request = new HTTPRequest('get', 'post', array(), $data);
443
444
        $editorSide = new WidgetAreaEditor('SideBar');
445
        $editorBott = new WidgetAreaEditor('BottomBar');
446
        $form = new Form(
447
            new ContentController(),
448
            Form::class,
449
            new FieldList($editorSide, $editorBott),
450
            new FieldList()
451
        );
452
        $form->setRequest($request);
453
        $page = new FakePage();
454
455
        $editorSide->saveInto($page);
456
        $editorBott->saveInto($page);
457
        $page->write();
458
        $page->flushCache();
459
        $page->BottomBar()->flushCache();
460
        $page->SideBar()->flushCache();
461
        $sideWidgets = $page->SideBar()->Widgets()->toArray();
462
        $bottWidgets = $page->BottomBar()->Widgets()->toArray();
463
464
        // Save again (after removing the SideBar's widget)
465
        $data = array(
466
            Widget::class => array(
467
                'SideBar' => array(
468
                    $sideWidgets[0]->ID => array(
469
                        'Title' => 'MyTestWidgetSide-edited',
470
                        'Type' => $this->widgetToTest,
471
                        'Sort' => 0
472
                    )
473
                ),
474
                'BottomBar' => array(
475
                )
476
            )
477
        );
478
        $request = new HTTPRequest('get', 'post', array(), $data);
479
        $form->setRequest($request);
480
        $form->saveInto($page);
481
482
        $page->write();
483
        $page->flushCache();
484
        $page->BottomBar()->flushCache();
485
        $page->SideBar()->flushCache();
486
        $sideWidgets = $page->SideBar()->Widgets()->toArray();
487
        $bottWidgets = $page->BottomBar()->Widgets()->toArray();
488
489
        $this->assertEquals($page->BottomBar()->Widgets()->Count(), 0);
490
        $this->assertEquals($page->SideBar()->Widgets()->Count(), 1);
491
        $this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide-edited');
492
    }
493
}
494