2012-04-18 23:15:45 +02:00
|
|
|
<?php
|
2017-01-17 23:43:11 +01:00
|
|
|
|
|
|
|
namespace SilverStripe\Widgets\Tests;
|
|
|
|
|
|
|
|
use SilverStripe\CMS\Controllers\ContentController;
|
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
|
|
|
use SilverStripe\Control\HTTPRequest;
|
2017-12-18 04:30:49 +01:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-01-17 23:43:11 +01:00
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Forms\Form;
|
|
|
|
use SilverStripe\Widgets\Extensions\WidgetPageExtension;
|
|
|
|
use SilverStripe\Widgets\Forms\WidgetAreaEditor;
|
|
|
|
use SilverStripe\Widgets\Tests\WidgetAreaEditorTest\FakePage;
|
|
|
|
use SilverStripe\Widgets\Tests\WidgetAreaEditorTest\TestWidget;
|
|
|
|
|
2012-04-18 23:15:45 +02:00
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2015-11-18 05:08:21 +01:00
|
|
|
class WidgetAreaEditorTest extends SapphireTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* This is the widget you want to use for your unit tests.
|
|
|
|
*/
|
2017-01-17 23:43:11 +01:00
|
|
|
protected $widgetToTest = TestWidget::class;
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2017-08-25 06:46:09 +02:00
|
|
|
protected static $extra_dataobjects = [
|
2017-01-17 23:43:11 +01:00
|
|
|
FakePage::class,
|
|
|
|
TestWidget::class,
|
2017-08-25 06:46:09 +02:00
|
|
|
];
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
protected $usesDatabase = true;
|
2015-11-04 05:01:46 +01:00
|
|
|
|
2017-08-25 06:46:09 +02:00
|
|
|
protected static $required_extensions = [
|
|
|
|
SiteTree::class => [WidgetPageExtension::class]
|
|
|
|
];
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
public function testFillingOneArea()
|
|
|
|
{
|
|
|
|
$data = array(
|
2017-01-18 02:49:15 +01:00
|
|
|
'Widget' => array(
|
2015-11-18 05:08:21 +01:00
|
|
|
'BottomBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidget',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
$request = new HTTPRequest('get', 'post', array(), $data);
|
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$editorSide = new WidgetAreaEditor('SideBar');
|
|
|
|
$editorBott = new WidgetAreaEditor('BottomBar');
|
2017-01-17 23:43:11 +01:00
|
|
|
$form = new Form(
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller = new ContentController(),
|
2017-01-17 23:43:11 +01:00
|
|
|
Form::class,
|
|
|
|
new FieldList($editorSide, $editorBott),
|
|
|
|
new FieldList()
|
|
|
|
);
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller->setRequest($request);
|
|
|
|
$controller->setRequest($request);
|
|
|
|
$form->setController($controller);
|
2017-01-17 23:43:11 +01:00
|
|
|
|
|
|
|
$page = new FakePage();
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$form->saveInto($page);
|
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
$page->BottomBar()->flushCache();
|
|
|
|
$page->SideBar()->flushCache();
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 1);
|
|
|
|
$this->assertEquals($page->SideBar()->Widgets()->Count(), 0);
|
|
|
|
}
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
public function testFillingTwoAreas()
|
|
|
|
{
|
|
|
|
$data = array(
|
2017-01-18 02:49:15 +01:00
|
|
|
'Widget' => array(
|
2015-11-18 05:08:21 +01:00
|
|
|
'SideBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidgetSide',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'BottomBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidgetBottom',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
$request = new HTTPRequest('get', 'post', array(), $data);
|
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$editorSide = new WidgetAreaEditor('SideBar');
|
|
|
|
$editorBott = new WidgetAreaEditor('BottomBar');
|
2017-01-17 23:43:11 +01:00
|
|
|
$form = new Form(
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller = new ContentController(),
|
2017-01-17 23:43:11 +01:00
|
|
|
Form::class,
|
|
|
|
new FieldList($editorSide, $editorBott),
|
|
|
|
new FieldList()
|
|
|
|
);
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller->setRequest($request);
|
|
|
|
$form->setController($controller);
|
2017-01-17 23:43:11 +01:00
|
|
|
$page = new FakePage();
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$form->saveInto($page);
|
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
$page->BottomBar()->flushCache();
|
|
|
|
$page->SideBar()->flushCache();
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
// Make sure they both got saved
|
|
|
|
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 1);
|
|
|
|
$this->assertEquals($page->SideBar()->Widgets()->Count(), 1);
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
|
|
|
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
2017-01-17 23:43:11 +01:00
|
|
|
$this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide');
|
|
|
|
$this->assertEquals($bottWidgets[0]->getTitle(), 'MyTestWidgetBottom');
|
2015-11-18 05:08:21 +01:00
|
|
|
}
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
public function testDeletingOneWidgetFromOneArea()
|
|
|
|
{
|
|
|
|
// First get some widgets in there
|
|
|
|
$data = array(
|
2017-01-18 02:49:15 +01:00
|
|
|
'Widget' => array(
|
2015-11-18 05:08:21 +01:00
|
|
|
'SideBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidgetSide',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'BottomBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidgetBottom',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
$request = new HTTPRequest('get', 'post', array(), $data);
|
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$editorSide = new WidgetAreaEditor('SideBar');
|
|
|
|
$editorBott = new WidgetAreaEditor('BottomBar');
|
2017-01-17 23:43:11 +01:00
|
|
|
$form = new Form(
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller = new ContentController(),
|
2017-01-17 23:43:11 +01:00
|
|
|
Form::class,
|
|
|
|
new FieldList($editorSide, $editorBott),
|
|
|
|
new FieldList()
|
|
|
|
);
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller->setRequest($request);
|
|
|
|
$form->setController($controller);
|
2017-01-17 23:43:11 +01:00
|
|
|
$page = new FakePage();
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$form->saveInto($page);
|
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
$page->BottomBar()->flushCache();
|
|
|
|
$page->SideBar()->flushCache();
|
|
|
|
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
|
|
|
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
// Save again (after removing the SideBar's widget)
|
|
|
|
$data = array(
|
2017-01-18 02:49:15 +01:00
|
|
|
'Widget' => array(
|
2015-11-18 05:08:21 +01:00
|
|
|
'SideBar' => array(
|
|
|
|
),
|
|
|
|
'BottomBar' => array(
|
|
|
|
$bottWidgets[0]->ID => array(
|
|
|
|
'Title' => 'MyTestWidgetBottom',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
$request = new HTTPRequest('get', 'post', array(), $data);
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller->setRequest($request);
|
|
|
|
$form->setController($controller);
|
2015-11-18 05:08:21 +01:00
|
|
|
$form->saveInto($page);
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
$page->BottomBar()->flushCache();
|
|
|
|
$page->SideBar()->flushCache();
|
|
|
|
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
|
|
|
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 1);
|
2017-01-17 23:43:11 +01:00
|
|
|
$this->assertEquals($bottWidgets[0]->getTitle(), 'MyTestWidgetBottom');
|
2015-11-18 05:08:21 +01:00
|
|
|
$this->assertEquals($page->SideBar()->Widgets()->Count(), 0);
|
|
|
|
}
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
public function testDeletingAWidgetFromEachArea()
|
|
|
|
{
|
|
|
|
// First get some widgets in there
|
|
|
|
$data = array(
|
2017-01-18 02:49:15 +01:00
|
|
|
'Widget' => array(
|
2015-11-18 05:08:21 +01:00
|
|
|
'SideBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidgetSide',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'BottomBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidgetBottom',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
$request = new HTTPRequest('get', 'post', array(), $data);
|
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$editorSide = new WidgetAreaEditor('SideBar');
|
|
|
|
$editorBott = new WidgetAreaEditor('BottomBar');
|
2017-01-17 23:43:11 +01:00
|
|
|
$form = new Form(
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller = new ContentController(),
|
2017-01-17 23:43:11 +01:00
|
|
|
Form::class,
|
|
|
|
new FieldList($editorSide, $editorBott),
|
|
|
|
new FieldList()
|
|
|
|
);
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller->setRequest($request);
|
|
|
|
$form->setController($controller);
|
2017-01-17 23:43:11 +01:00
|
|
|
$page = new FakePage();
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$form->saveInto($page);
|
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
$page->BottomBar()->flushCache();
|
|
|
|
$page->SideBar()->flushCache();
|
|
|
|
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
|
|
|
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
// Save again (after removing the SideBar's widget)
|
|
|
|
$data = array(
|
2017-01-18 02:49:15 +01:00
|
|
|
'Widget' => array(
|
2015-11-18 05:08:21 +01:00
|
|
|
'SideBar' => array(
|
|
|
|
),
|
|
|
|
'BottomBar' => array(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
$request = new HTTPRequest('get', 'post', array(), $data);
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller->setRequest($request);
|
|
|
|
$form->setController($controller);
|
2015-11-18 05:08:21 +01:00
|
|
|
$form->saveInto($page);
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
$page->BottomBar()->flushCache();
|
|
|
|
$page->SideBar()->flushCache();
|
|
|
|
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
|
|
|
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 0);
|
|
|
|
$this->assertEquals($page->SideBar()->Widgets()->Count(), 0);
|
|
|
|
}
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
public function testEditingOneWidget()
|
|
|
|
{
|
|
|
|
// First get some widgets in there
|
|
|
|
$data = array(
|
2017-01-18 02:49:15 +01:00
|
|
|
'Widget' => array(
|
2015-11-18 05:08:21 +01:00
|
|
|
'SideBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidgetSide',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'BottomBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidgetBottom',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
$request = new HTTPRequest('get', 'post', array(), $data);
|
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$editorSide = new WidgetAreaEditor('SideBar');
|
|
|
|
$editorBott = new WidgetAreaEditor('BottomBar');
|
2017-01-17 23:43:11 +01:00
|
|
|
$form = new Form(
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller = new ContentController(),
|
2017-01-17 23:43:11 +01:00
|
|
|
Form::class,
|
|
|
|
new FieldList($editorSide, $editorBott),
|
|
|
|
new FieldList()
|
|
|
|
);
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller->setRequest($request);
|
|
|
|
$form->setController($controller);
|
2017-01-17 23:43:11 +01:00
|
|
|
$page = new FakePage();
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$form->saveInto($page);
|
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
$page->BottomBar()->flushCache();
|
|
|
|
$page->SideBar()->flushCache();
|
|
|
|
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
|
|
|
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
// Save again (after removing the SideBar's widget)
|
|
|
|
$data = array(
|
2017-01-18 02:49:15 +01:00
|
|
|
'Widget' => array(
|
2015-11-18 05:08:21 +01:00
|
|
|
'SideBar' => array(
|
|
|
|
$sideWidgets[0]->ID => array(
|
|
|
|
'Title' => 'MyTestWidgetSide-edited',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'BottomBar' => array(
|
|
|
|
$bottWidgets[0]->ID => array(
|
|
|
|
'Title' => 'MyTestWidgetBottom',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
$request = new HTTPRequest('get', 'post', array(), $data);
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller->setRequest($request);
|
|
|
|
$form->setController($controller);
|
2015-11-18 05:08:21 +01:00
|
|
|
$form->saveInto($page);
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
$page->BottomBar()->flushCache();
|
|
|
|
$page->SideBar()->flushCache();
|
|
|
|
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
|
|
|
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 1);
|
|
|
|
$this->assertEquals($page->SideBar()->Widgets()->Count(), 1);
|
2017-01-17 23:43:11 +01:00
|
|
|
$this->assertEquals($bottWidgets[0]->getTitle(), 'MyTestWidgetBottom');
|
|
|
|
$this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide-edited');
|
2015-11-18 05:08:21 +01:00
|
|
|
}
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
public function testEditingAWidgetFromEachArea()
|
|
|
|
{
|
|
|
|
// First get some widgets in there
|
|
|
|
$data = array(
|
2017-01-18 02:49:15 +01:00
|
|
|
'Widget' => array(
|
2015-11-18 05:08:21 +01:00
|
|
|
'SideBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidgetSide',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'BottomBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidgetBottom',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
$request = new HTTPRequest('get', 'post', array(), $data);
|
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$editorSide = new WidgetAreaEditor('SideBar');
|
|
|
|
$editorBott = new WidgetAreaEditor('BottomBar');
|
2017-01-17 23:43:11 +01:00
|
|
|
$form = new Form(
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller = new ContentController(),
|
2017-01-17 23:43:11 +01:00
|
|
|
Form::class,
|
|
|
|
new FieldList($editorSide, $editorBott),
|
|
|
|
new FieldList()
|
|
|
|
);
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller->setRequest($request);
|
|
|
|
$form->setController($controller);
|
2017-01-17 23:43:11 +01:00
|
|
|
$page = new FakePage();
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$form->saveInto($page);
|
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
$page->BottomBar()->flushCache();
|
|
|
|
$page->SideBar()->flushCache();
|
|
|
|
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
|
|
|
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
// Save again (after removing the SideBar's widget)
|
|
|
|
$data = array(
|
2017-01-18 02:49:15 +01:00
|
|
|
'Widget' => array(
|
2015-11-18 05:08:21 +01:00
|
|
|
'SideBar' => array(
|
|
|
|
$sideWidgets[0]->ID => array(
|
|
|
|
'Title' => 'MyTestWidgetSide-edited',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'BottomBar' => array(
|
|
|
|
$bottWidgets[0]->ID => array(
|
|
|
|
'Title' => 'MyTestWidgetBottom-edited',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
$request = new HTTPRequest('get', 'post', array(), $data);
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller->setRequest($request);
|
|
|
|
$form->setController($controller);
|
2015-11-18 05:08:21 +01:00
|
|
|
$form->saveInto($page);
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
$page->BottomBar()->flushCache();
|
|
|
|
$page->SideBar()->flushCache();
|
|
|
|
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
|
|
|
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 1);
|
|
|
|
$this->assertEquals($page->SideBar()->Widgets()->Count(), 1);
|
2017-01-17 23:43:11 +01:00
|
|
|
$this->assertEquals($bottWidgets[0]->getTitle(), 'MyTestWidgetBottom-edited');
|
|
|
|
$this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide-edited');
|
2015-11-18 05:08:21 +01:00
|
|
|
}
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
public function testEditAWidgetFromOneAreaAndDeleteAWidgetFromAnotherArea()
|
|
|
|
{
|
|
|
|
// First get some widgets in there
|
|
|
|
$data = array(
|
2017-01-18 02:49:15 +01:00
|
|
|
'Widget' => array(
|
2015-11-18 05:08:21 +01:00
|
|
|
'SideBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidgetSide',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'BottomBar' => array(
|
|
|
|
'new-1' => array(
|
|
|
|
'Title' => 'MyTestWidgetBottom',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
$request = new HTTPRequest('get', 'post', array(), $data);
|
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$editorSide = new WidgetAreaEditor('SideBar');
|
|
|
|
$editorBott = new WidgetAreaEditor('BottomBar');
|
2017-01-17 23:43:11 +01:00
|
|
|
$form = new Form(
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller = new ContentController(),
|
2017-01-17 23:43:11 +01:00
|
|
|
Form::class,
|
|
|
|
new FieldList($editorSide, $editorBott),
|
|
|
|
new FieldList()
|
|
|
|
);
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller->setRequest($request);
|
|
|
|
$form->setController($controller);
|
2017-01-17 23:43:11 +01:00
|
|
|
$page = new FakePage();
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$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();
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
// Save again (after removing the SideBar's widget)
|
|
|
|
$data = array(
|
2017-01-18 02:49:15 +01:00
|
|
|
'Widget' => array(
|
2015-11-18 05:08:21 +01:00
|
|
|
'SideBar' => array(
|
|
|
|
$sideWidgets[0]->ID => array(
|
|
|
|
'Title' => 'MyTestWidgetSide-edited',
|
|
|
|
'Type' => $this->widgetToTest,
|
|
|
|
'Sort' => 0
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'BottomBar' => array(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
$request = new HTTPRequest('get', 'post', array(), $data);
|
2017-08-25 06:46:09 +02:00
|
|
|
$controller->setRequest($request);
|
|
|
|
$form->setController($controller);
|
2015-11-18 05:08:21 +01:00
|
|
|
$form->saveInto($page);
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
$page->BottomBar()->flushCache();
|
|
|
|
$page->SideBar()->flushCache();
|
|
|
|
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
|
|
|
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 0);
|
|
|
|
$this->assertEquals($page->SideBar()->Widgets()->Count(), 1);
|
2017-01-17 23:43:11 +01:00
|
|
|
$this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide-edited');
|
2015-11-18 05:08:21 +01:00
|
|
|
}
|
2012-04-18 23:15:45 +02:00
|
|
|
}
|