mirror of
https://github.com/silverstripe/silverstripe-widgets
synced 2024-10-22 17:05:54 +02:00
Remove reliance on $_REQUEST global
Update to support 4.0 Alias dev-master as 1.0
This commit is contained in:
parent
f35800541e
commit
9c678ca540
@ -6,10 +6,12 @@ php:
|
||||
|
||||
env:
|
||||
- DB=MYSQL CORE_RELEASE=3.1
|
||||
- DB=PGSQL CORE_RELEASE=master
|
||||
- DB=PGSQL CORE_RELEASE=3.1
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.4
|
||||
env: DB=MYSQL CORE_RELEASE=3
|
||||
- php: 5.4
|
||||
env: DB=MYSQL CORE_RELEASE=master
|
||||
|
||||
@ -19,4 +21,4 @@ before_script:
|
||||
- cd ~/builds/ss
|
||||
|
||||
script:
|
||||
- phpunit widgets/tests/
|
||||
- vendor/bin/phpunit widgets/tests/
|
||||
|
@ -118,51 +118,50 @@ class WidgetAreaEditor extends FormField {
|
||||
$missingWidgets[$existingWidget->ID] = $existingWidget;
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_REQUEST['Widget'])) {
|
||||
foreach(array_keys($_REQUEST['Widget']) as $widgetAreaName) {
|
||||
if ($widgetAreaName !== $this->name) {
|
||||
continue;
|
||||
|
||||
if(!$this->getForm()) throw new Exception("no form");
|
||||
|
||||
$widgetData = $this->getForm()->getRequest()->requestVar('Widget');
|
||||
if($widgetData && isset($widgetData[$this->getName()])) {
|
||||
$widgetAreaData = $widgetData[$this->getName()];
|
||||
|
||||
foreach($widgetAreaData as $newWidgetID => $newWidgetData) {
|
||||
|
||||
// Sometimes the id is "new-1" or similar, ensure this doesn't get into the query
|
||||
if(!is_numeric($newWidgetID)) {
|
||||
$newWidgetID = 0;
|
||||
}
|
||||
|
||||
foreach(array_keys($_REQUEST['Widget'][$widgetAreaName]) as $newWidgetID) {
|
||||
$newWidgetData = $_REQUEST['Widget'][$widgetAreaName][$newWidgetID];
|
||||
|
||||
// Sometimes the id is "new-1" or similar, ensure this doesn't get into the query
|
||||
if(!is_numeric($newWidgetID)) {
|
||||
$newWidgetID = 0;
|
||||
}
|
||||
|
||||
$widget = null;
|
||||
if($newWidgetID) {
|
||||
// \"ParentID\" = '0' is for the new page
|
||||
$widget = DataObject::get_one(
|
||||
'Widget',
|
||||
"(\"ParentID\" = '{$record->$name()->ID}' OR ".
|
||||
"\"ParentID\" = '0') AND \"Widget\".\"ID\" = '$newWidgetID'"
|
||||
);
|
||||
$widget = Widget::get()
|
||||
->filter('ParentID', array(0, $record->$name()->ID))
|
||||
->byID($newWidgetID);
|
||||
|
||||
// check if we are updating an existing widget
|
||||
if($widget && isset($missingWidgets[$widget->ID])) {
|
||||
unset($missingWidgets[$widget->ID]);
|
||||
}
|
||||
|
||||
// create a new object
|
||||
if(!$widget && !empty($newWidgetData['Type']) && class_exists($newWidgetData['Type'])) {
|
||||
$widget = new $newWidgetData['Type']();
|
||||
$widget->ID = 0;
|
||||
}
|
||||
|
||||
// create a new object
|
||||
if(!$widget
|
||||
&& !empty($newWidgetData['Type'])
|
||||
&& class_exists($newWidgetData['Type'])
|
||||
&& is_subclass_of($newWidgetData['Type'], 'Widget')
|
||||
) {
|
||||
$widget = Injector::inst()->create($newWidgetData['Type']);
|
||||
$widget->ID = 0;
|
||||
$widget->ParentID = $record->$name()->ID;
|
||||
}
|
||||
|
||||
if($widget) {
|
||||
if($widget->ParentID == 0) {
|
||||
$widget->ParentID = $record->$name()->ID;
|
||||
|
||||
if(!is_subclass_of($widget, 'Widget')) {
|
||||
$widget = null;
|
||||
}
|
||||
}
|
||||
|
||||
if($widget) {
|
||||
if($widget->ParentID == 0) {
|
||||
$widget->ParentID = $record->$name()->ID;
|
||||
}
|
||||
|
||||
$widget->populateFromPostData($newWidgetData);
|
||||
}
|
||||
$widget->populateFromPostData($newWidgetData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,14 +4,21 @@
|
||||
"type": "silverstripe-module",
|
||||
"keywords": ["silverstripe", "widgets", "blog"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ingo Schommer",
|
||||
"email": "ingo@silverstripe.com"
|
||||
}
|
||||
{
|
||||
"name": "Ingo Schommer",
|
||||
"email": "ingo@silverstripe.com"
|
||||
}
|
||||
],
|
||||
"require":
|
||||
{
|
||||
"silverstripe/framework": "~3.1",
|
||||
"silverstripe/cms": "~3.1"
|
||||
"require": {
|
||||
"silverstripe/framework": ">=3.1",
|
||||
"silverstripe/cms": ">=3.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/PHPUnit": "~3.7@stable"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,7 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
protected $usesDatabase = true;
|
||||
|
||||
function testFillingOneArea() {
|
||||
$oldRequest = $_REQUEST;
|
||||
|
||||
$_REQUEST = array(
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
'BottomBar' => array(
|
||||
'new-1' => array(
|
||||
@ -30,13 +28,16 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
)
|
||||
)
|
||||
);
|
||||
$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);
|
||||
$form->saveInto($page);
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
$page->BottomBar()->flushCache();
|
||||
@ -44,14 +45,10 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
|
||||
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 1);
|
||||
$this->assertEquals($page->SideBar()->Widgets()->Count(), 0);
|
||||
|
||||
$_REQUEST = $oldRequest;
|
||||
}
|
||||
|
||||
function testFillingTwoAreas() {
|
||||
$oldRequest = $_REQUEST;
|
||||
|
||||
$_REQUEST = array(
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
'SideBar' => array(
|
||||
'new-1' => array(
|
||||
@ -69,13 +66,15 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
)
|
||||
)
|
||||
);
|
||||
$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);
|
||||
$form->saveInto($page);
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
$page->BottomBar()->flushCache();
|
||||
@ -89,15 +88,11 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
$this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide');
|
||||
$this->assertEquals($bottWidgets[0]->Title(), 'MyTestWidgetBottom');
|
||||
|
||||
$_REQUEST = $oldRequest;
|
||||
}
|
||||
|
||||
function testDeletingOneWidgetFromOneArea() {
|
||||
$oldRequest = $_REQUEST;
|
||||
|
||||
// First get some widgets in there
|
||||
$_REQUEST = array(
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
'SideBar' => array(
|
||||
'new-1' => array(
|
||||
@ -115,13 +110,15 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
)
|
||||
)
|
||||
);
|
||||
$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);
|
||||
$form->saveInto($page);
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
$page->BottomBar()->flushCache();
|
||||
@ -130,7 +127,7 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
// Save again (after removing the SideBar's widget)
|
||||
$_REQUEST = array(
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
'SideBar' => array(
|
||||
),
|
||||
@ -143,9 +140,9 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$editorSide->saveInto($page);
|
||||
$editorBott->saveInto($page);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
@ -157,15 +154,11 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 1);
|
||||
$this->assertEquals($bottWidgets[0]->Title(), 'MyTestWidgetBottom');
|
||||
$this->assertEquals($page->SideBar()->Widgets()->Count(), 0);
|
||||
|
||||
$_REQUEST = $oldRequest;
|
||||
}
|
||||
|
||||
function testDeletingAWidgetFromEachArea() {
|
||||
$oldRequest = $_REQUEST;
|
||||
|
||||
// First get some widgets in there
|
||||
$_REQUEST = array(
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
'SideBar' => array(
|
||||
'new-1' => array(
|
||||
@ -183,13 +176,15 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
)
|
||||
)
|
||||
);
|
||||
$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);
|
||||
$form->saveInto($page);
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
$page->BottomBar()->flushCache();
|
||||
@ -198,7 +193,7 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
// Save again (after removing the SideBar's widget)
|
||||
$_REQUEST = array(
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
'SideBar' => array(
|
||||
),
|
||||
@ -206,9 +201,9 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$editorSide->saveInto($page);
|
||||
$editorBott->saveInto($page);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
@ -219,15 +214,11 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
|
||||
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 0);
|
||||
$this->assertEquals($page->SideBar()->Widgets()->Count(), 0);
|
||||
|
||||
$_REQUEST = $oldRequest;
|
||||
}
|
||||
|
||||
function testEditingOneWidget() {
|
||||
$oldRequest = $_REQUEST;
|
||||
|
||||
// First get some widgets in there
|
||||
$_REQUEST = array(
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
'SideBar' => array(
|
||||
'new-1' => array(
|
||||
@ -245,13 +236,15 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
)
|
||||
)
|
||||
);
|
||||
$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);
|
||||
$form->saveInto($page);
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
$page->BottomBar()->flushCache();
|
||||
@ -260,7 +253,7 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
// Save again (after removing the SideBar's widget)
|
||||
$_REQUEST = array(
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
'SideBar' => array(
|
||||
$sideWidgets[0]->ID => array(
|
||||
@ -278,10 +271,9 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$editorSide->saveInto($page);
|
||||
$editorBott->saveInto($page);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
@ -294,16 +286,11 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
$this->assertEquals($page->SideBar()->Widgets()->Count(), 1);
|
||||
$this->assertEquals($bottWidgets[0]->Title(), 'MyTestWidgetBottom');
|
||||
$this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide-edited');
|
||||
|
||||
|
||||
$_REQUEST = $oldRequest;
|
||||
}
|
||||
|
||||
function testEditingAWidgetFromEachArea() {
|
||||
$oldRequest = $_REQUEST;
|
||||
|
||||
// First get some widgets in there
|
||||
$_REQUEST = array(
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
'SideBar' => array(
|
||||
'new-1' => array(
|
||||
@ -321,13 +308,15 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
)
|
||||
)
|
||||
);
|
||||
$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);
|
||||
$form->saveInto($page);
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
$page->BottomBar()->flushCache();
|
||||
@ -336,7 +325,7 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
// Save again (after removing the SideBar's widget)
|
||||
$_REQUEST = array(
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
'SideBar' => array(
|
||||
$sideWidgets[0]->ID => array(
|
||||
@ -354,10 +343,9 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$editorSide->saveInto($page);
|
||||
$editorBott->saveInto($page);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
@ -370,16 +358,11 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
$this->assertEquals($page->SideBar()->Widgets()->Count(), 1);
|
||||
$this->assertEquals($bottWidgets[0]->Title(), 'MyTestWidgetBottom-edited');
|
||||
$this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide-edited');
|
||||
|
||||
|
||||
$_REQUEST = $oldRequest;
|
||||
}
|
||||
|
||||
function testEditAWidgetFromOneAreaAndDeleteAWidgetFromAnotherArea() {
|
||||
$oldRequest = $_REQUEST;
|
||||
|
||||
// First get some widgets in there
|
||||
$_REQUEST = array(
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
'SideBar' => array(
|
||||
'new-1' => array(
|
||||
@ -397,9 +380,12 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
)
|
||||
)
|
||||
);
|
||||
$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);
|
||||
@ -412,7 +398,7 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
// Save again (after removing the SideBar's widget)
|
||||
$_REQUEST = array(
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
'SideBar' => array(
|
||||
$sideWidgets[0]->ID => array(
|
||||
@ -425,10 +411,9 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$editorSide->saveInto($page);
|
||||
$editorBott->saveInto($page);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
@ -440,9 +425,6 @@ class WidgetAreaEditorTest extends SapphireTest {
|
||||
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 0);
|
||||
$this->assertEquals($page->SideBar()->Widgets()->Count(), 1);
|
||||
$this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide-edited');
|
||||
|
||||
|
||||
$_REQUEST = $oldRequest;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user