| @@ 265-341 (lines=77) @@ | ||
| 262 | $this->assertEquals($page->SideBar()->Widgets()->Count(), 0); | |
| 263 | } | |
| 264 | ||
| 265 | public function testEditingOneWidget() | |
| 266 |     { | |
| 267 | // First get some widgets in there | |
| 268 | $data = array( | |
| 269 | 'Widget' => array( | |
| 270 | 'SideBar' => array( | |
| 271 | 'new-1' => array( | |
| 272 | 'Title' => 'MyTestWidgetSide', | |
| 273 | 'Type' => $this->widgetToTest, | |
| 274 | 'Sort' => 0 | |
| 275 | ) | |
| 276 | ), | |
| 277 | 'BottomBar' => array( | |
| 278 | 'new-1' => array( | |
| 279 | 'Title' => 'MyTestWidgetBottom', | |
| 280 | 'Type' => $this->widgetToTest, | |
| 281 | 'Sort' => 0 | |
| 282 | ) | |
| 283 | ) | |
| 284 | ) | |
| 285 | ); | |
| 286 |         $request = new HTTPRequest('get', 'post', array(), $data); | |
| 287 | ||
| 288 |         $editorSide = new WidgetAreaEditor('SideBar'); | |
| 289 |         $editorBott = new WidgetAreaEditor('BottomBar'); | |
| 290 | $form = new Form( | |
| 291 | new ContentController(), | |
| 292 | Form::class, | |
| 293 | new FieldList($editorSide, $editorBott), | |
| 294 | new FieldList() | |
| 295 | ); | |
| 296 | $form->setRequest($request); | |
| 297 | $page = new FakePage(); | |
| 298 | ||
| 299 | $form->saveInto($page); | |
| 300 | $page->write(); | |
| 301 | $page->flushCache(); | |
| 302 | $page->BottomBar()->flushCache(); | |
| 303 | $page->SideBar()->flushCache(); | |
| 304 | $sideWidgets = $page->SideBar()->Widgets()->toArray(); | |
| 305 | $bottWidgets = $page->BottomBar()->Widgets()->toArray(); | |
| 306 | ||
| 307 | // Save again (after removing the SideBar's widget) | |
| 308 | $data = array( | |
| 309 | 'Widget' => array( | |
| 310 | 'SideBar' => array( | |
| 311 | $sideWidgets[0]->ID => array( | |
| 312 | 'Title' => 'MyTestWidgetSide-edited', | |
| 313 | 'Type' => $this->widgetToTest, | |
| 314 | 'Sort' => 0 | |
| 315 | ) | |
| 316 | ), | |
| 317 | 'BottomBar' => array( | |
| 318 | $bottWidgets[0]->ID => array( | |
| 319 | 'Title' => 'MyTestWidgetBottom', | |
| 320 | 'Type' => $this->widgetToTest, | |
| 321 | 'Sort' => 0 | |
| 322 | ) | |
| 323 | ) | |
| 324 | ) | |
| 325 | ); | |
| 326 |         $request = new HTTPRequest('get', 'post', array(), $data); | |
| 327 | $form->setRequest($request); | |
| 328 | $form->saveInto($page); | |
| 329 | ||
| 330 | $page->write(); | |
| 331 | $page->flushCache(); | |
| 332 | $page->BottomBar()->flushCache(); | |
| 333 | $page->SideBar()->flushCache(); | |
| 334 | $sideWidgets = $page->SideBar()->Widgets()->toArray(); | |
| 335 | $bottWidgets = $page->BottomBar()->Widgets()->toArray(); | |
| 336 | ||
| 337 | $this->assertEquals($page->BottomBar()->Widgets()->Count(), 1); | |
| 338 | $this->assertEquals($page->SideBar()->Widgets()->Count(), 1); | |
| 339 | $this->assertEquals($bottWidgets[0]->getTitle(), 'MyTestWidgetBottom'); | |
| 340 | $this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide-edited'); | |
| 341 | } | |
| 342 | ||
| 343 | public function testEditingAWidgetFromEachArea() | |
| 344 |     { | |
| @@ 343-419 (lines=77) @@ | ||
| 340 | $this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide-edited'); | |
| 341 | } | |
| 342 | ||
| 343 | public function testEditingAWidgetFromEachArea() | |
| 344 |     { | |
| 345 | // First get some widgets in there | |
| 346 | $data = array( | |
| 347 | 'Widget' => array( | |
| 348 | 'SideBar' => array( | |
| 349 | 'new-1' => array( | |
| 350 | 'Title' => 'MyTestWidgetSide', | |
| 351 | 'Type' => $this->widgetToTest, | |
| 352 | 'Sort' => 0 | |
| 353 | ) | |
| 354 | ), | |
| 355 | 'BottomBar' => array( | |
| 356 | 'new-1' => array( | |
| 357 | 'Title' => 'MyTestWidgetBottom', | |
| 358 | 'Type' => $this->widgetToTest, | |
| 359 | 'Sort' => 0 | |
| 360 | ) | |
| 361 | ) | |
| 362 | ) | |
| 363 | ); | |
| 364 |         $request = new HTTPRequest('get', 'post', array(), $data); | |
| 365 | ||
| 366 |         $editorSide = new WidgetAreaEditor('SideBar'); | |
| 367 |         $editorBott = new WidgetAreaEditor('BottomBar'); | |
| 368 | $form = new Form( | |
| 369 | new ContentController(), | |
| 370 | Form::class, | |
| 371 | new FieldList($editorSide, $editorBott), | |
| 372 | new FieldList() | |
| 373 | ); | |
| 374 | $form->setRequest($request); | |
| 375 | $page = new FakePage(); | |
| 376 | ||
| 377 | $form->saveInto($page); | |
| 378 | $page->write(); | |
| 379 | $page->flushCache(); | |
| 380 | $page->BottomBar()->flushCache(); | |
| 381 | $page->SideBar()->flushCache(); | |
| 382 | $sideWidgets = $page->SideBar()->Widgets()->toArray(); | |
| 383 | $bottWidgets = $page->BottomBar()->Widgets()->toArray(); | |
| 384 | ||
| 385 | // Save again (after removing the SideBar's widget) | |
| 386 | $data = array( | |
| 387 | 'Widget' => array( | |
| 388 | 'SideBar' => array( | |
| 389 | $sideWidgets[0]->ID => array( | |
| 390 | 'Title' => 'MyTestWidgetSide-edited', | |
| 391 | 'Type' => $this->widgetToTest, | |
| 392 | 'Sort' => 0 | |
| 393 | ) | |
| 394 | ), | |
| 395 | 'BottomBar' => array( | |
| 396 | $bottWidgets[0]->ID => array( | |
| 397 | 'Title' => 'MyTestWidgetBottom-edited', | |
| 398 | 'Type' => $this->widgetToTest, | |
| 399 | 'Sort' => 0 | |
| 400 | ) | |
| 401 | ) | |
| 402 | ) | |
| 403 | ); | |
| 404 |         $request = new HTTPRequest('get', 'post', array(), $data); | |
| 405 | $form->setRequest($request); | |
| 406 | $form->saveInto($page); | |
| 407 | ||
| 408 | $page->write(); | |
| 409 | $page->flushCache(); | |
| 410 | $page->BottomBar()->flushCache(); | |
| 411 | $page->SideBar()->flushCache(); | |
| 412 | $sideWidgets = $page->SideBar()->Widgets()->toArray(); | |
| 413 | $bottWidgets = $page->BottomBar()->Widgets()->toArray(); | |
| 414 | ||
| 415 | $this->assertEquals($page->BottomBar()->Widgets()->Count(), 1); | |
| 416 | $this->assertEquals($page->SideBar()->Widgets()->Count(), 1); | |
| 417 | $this->assertEquals($bottWidgets[0]->getTitle(), 'MyTestWidgetBottom-edited'); | |
| 418 | $this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide-edited'); | |
| 419 | } | |
| 420 | ||
| 421 | public function testEditAWidgetFromOneAreaAndDeleteAWidgetFromAnotherArea() | |
| 422 |     { | |