function testEditAWidgetFromOneAreaAndDeleteAWidgetFromAnotherArea() { $oldRequest = $_REQUEST; // First get some widgets in there $_REQUEST = array('Widget' => array('SideBar' => array('new-1' => array('Title' => 'MyTestWidgetSide', 'Type' => $this->widgetToTest, 'Sort' => 0)), 'BottomBar' => array('new-1' => array('Title' => 'MyTestWidgetBottom', 'Type' => $this->widgetToTest, 'Sort' => 0)))); $editorSide = new WidgetAreaEditor('SideBar'); $editorBott = new WidgetAreaEditor('BottomBar'); $page = new WidgetAreaEditorTest_FakePage(); $editorSide->saveInto($page); $editorBott->saveInto($page); $page->write(); $page->flushCache(); $page->BottomBar()->flushCache(); $page->SideBar()->flushCache(); $sideWidgets = $page->SideBar()->Widgets()->toArray(); $bottWidgets = $page->BottomBar()->Widgets()->toArray(); // Save again (after removing the SideBar's widget) $_REQUEST = array('Widget' => array('SideBar' => array($sideWidgets[0]->ID => array('Title' => 'MyTestWidgetSide-edited', 'Type' => $this->widgetToTest, 'Sort' => 0)), 'BottomBar' => array())); $editorSide->saveInto($page); $editorBott->saveInto($page); $page->write(); $page->flushCache(); $page->BottomBar()->flushCache(); $page->SideBar()->flushCache(); $sideWidgets = $page->SideBar()->Widgets()->toArray(); $bottWidgets = $page->BottomBar()->Widgets()->toArray(); $this->assertEquals($page->BottomBar()->Widgets()->Count(), 0); $this->assertEquals($page->SideBar()->Widgets()->Count(), 1); $this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide-edited'); $_REQUEST = $oldRequest; }
function testEditAWidgetFromOneAreaAndDeleteAWidgetFromAnotherArea() { // First get some widgets in there $data = array('Widget' => array('SideBar' => array('new-1' => array('Title' => 'MyTestWidgetSide', 'Type' => $this->widgetToTest, 'Sort' => 0)), 'BottomBar' => array('new-1' => array('Title' => 'MyTestWidgetBottom', 'Type' => $this->widgetToTest, 'Sort' => 0)))); $request = new SS_HTTPRequest('get', 'post', array(), $data); $editorSide = new WidgetAreaEditor('SideBar'); $editorBott = new WidgetAreaEditor('BottomBar'); $form = new Form(new ContentController(), 'Form', new FieldList($editorSide, $editorBott), new FieldList()); $form->setRequest($request); $page = new WidgetAreaEditorTest_FakePage(); $editorSide->saveInto($page); $editorBott->saveInto($page); $page->write(); $page->flushCache(); $page->BottomBar()->flushCache(); $page->SideBar()->flushCache(); $sideWidgets = $page->SideBar()->Widgets()->toArray(); $bottWidgets = $page->BottomBar()->Widgets()->toArray(); // Save again (after removing the SideBar's widget) $data = array('Widget' => array('SideBar' => array($sideWidgets[0]->ID => array('Title' => 'MyTestWidgetSide-edited', 'Type' => $this->widgetToTest, 'Sort' => 0)), 'BottomBar' => array())); $request = new SS_HTTPRequest('get', 'post', array(), $data); $form->setRequest($request); $form->saveInto($page); $page->write(); $page->flushCache(); $page->BottomBar()->flushCache(); $page->SideBar()->flushCache(); $sideWidgets = $page->SideBar()->Widgets()->toArray(); $bottWidgets = $page->BottomBar()->Widgets()->toArray(); $this->assertEquals($page->BottomBar()->Widgets()->Count(), 0); $this->assertEquals($page->SideBar()->Widgets()->Count(), 1); $this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide-edited'); }