mirror of
https://github.com/UndefinedOffset/SortableGridField.git
synced 2024-10-22 17:05:38 +02:00
Fixed test failures related to changes in the session api
This commit is contained in:
parent
f0fbbd5650
commit
e5d442cabe
@ -1,10 +1,9 @@
|
||||
has_many Example
|
||||
=================
|
||||
Please note this example is written with 3.0.x in mind, if you are using 3.1.x make sure you scope all static properties to private not public.
|
||||
```php
|
||||
/*** TestPage.php ***/
|
||||
class TestPage extends Page {
|
||||
public static $has_many=array(
|
||||
private static $has_many=array(
|
||||
'TestObjects'=>'TestObject'
|
||||
);
|
||||
|
||||
@ -23,15 +22,15 @@ class TestPage extends Page {
|
||||
|
||||
/*** TestObject.php ***/
|
||||
class TestObject extends DataObject {
|
||||
public static $db=array(
|
||||
private static $db=array(
|
||||
'Title'=>'Text',
|
||||
'SortOrder'=>'Int'
|
||||
);
|
||||
|
||||
public static $has_one=array(
|
||||
private static $has_one=array(
|
||||
'Parent'=>'TestPage'
|
||||
);
|
||||
|
||||
public static $default_sort='SortOrder';
|
||||
private static $default_sort='SortOrder';
|
||||
}
|
||||
```
|
@ -1,14 +1,13 @@
|
||||
many_many Example
|
||||
=================
|
||||
Please note this example is written with 3.0.x in mind, if you are using 3.1.x make sure you scope all static properties to private not public.
|
||||
```php
|
||||
/*** TestPage.php ***/
|
||||
class TestPage extends Page {
|
||||
public static $many_many=array(
|
||||
private static $many_many=array(
|
||||
'TestObjects'=>'TestObject'
|
||||
);
|
||||
|
||||
public static $many_many_extraFields=array(
|
||||
private static $many_many_extraFields=array(
|
||||
'TestObjects'=>array(
|
||||
'SortOrder'=>'Int'
|
||||
)
|
||||
@ -34,11 +33,11 @@ class TestPage extends Page {
|
||||
|
||||
/*** TestObject.php ***/
|
||||
class TestObject extends DataObject {
|
||||
public static $db=array(
|
||||
private static $db=array(
|
||||
'Title'=>'Text'
|
||||
);
|
||||
|
||||
public static $belongs_many_many=array(
|
||||
private static $belongs_many_many=array(
|
||||
'TestPages'=>'TestPage'
|
||||
);
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
ModelAdmin implementation Example
|
||||
=================
|
||||
Please note this example is written with 3.0.x in mind, if you are using 3.1.x make sure you scope all static properties to private not public.
|
||||
```php
|
||||
/**** MyModelAdmin.php ****/
|
||||
class MyModelAdmin extends ModelAdmin {
|
||||
public static $menu_title='My Model Admin';
|
||||
public static $url_segment='my-model-admin';
|
||||
private static $menu_title='My Model Admin';
|
||||
private static $url_segment='my-model-admin';
|
||||
|
||||
public static $managed_models=array(
|
||||
private static $managed_models=array(
|
||||
'MATestObject'
|
||||
);
|
||||
|
||||
@ -28,11 +27,11 @@ class MyModelAdmin extends ModelAdmin {
|
||||
|
||||
/**** MATestObject.php ****/
|
||||
class MATestObject extends DataObject {
|
||||
public static $db=array(
|
||||
private static $db=array(
|
||||
'Title'=>'Varchar',
|
||||
'SortOrder'=>'Int'
|
||||
);
|
||||
|
||||
public static $default_sort='SortOrder';
|
||||
private static $default_sort='SortOrder';
|
||||
}
|
||||
```
|
@ -5,6 +5,7 @@ namespace UndefinedOffset\SortableGridField\Tests;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
@ -49,8 +50,12 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
$form = new Form(new SortableGridField_DummyController(), 'mockform', new FieldList(array($gridField)), new FieldList());
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$request = new HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()));
|
||||
$session = Injector::inst()->create(Session::class, []);
|
||||
$request->setSession($session);
|
||||
$session->init($request);
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
|
||||
$gridField->gridFieldAlterAction(array('StateID' => $stateID), $form, $request);
|
||||
|
||||
//Insure sort ran
|
||||
@ -81,8 +86,11 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
$this->assertEquals(0, $list->last()->SortOrder, 'Auto sort should not have run');
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$request = new HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()));
|
||||
$session = Injector::inst()->create(Session::class, []);
|
||||
$request->setSession($session);
|
||||
$session->init($request);
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$gridField->gridFieldAlterAction(array('StateID' => $stateID), $form, $request);
|
||||
|
||||
//Insure sort ran
|
||||
@ -117,8 +125,11 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
$form = new Form(new SortableGridField_DummyController(), 'mockform', new FieldList(array($gridField)), new FieldList());
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$request = new HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()));
|
||||
$session = Injector::inst()->create(Session::class, []);
|
||||
$request->setSession($session);
|
||||
$session->init($request);
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$gridField->gridFieldAlterAction(array('StateID' => $stateID), $form, $request);
|
||||
|
||||
|
||||
@ -177,8 +188,11 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
$this->assertEquals(0, $list->last()->SortOrder, 'Auto sort should not have run on Versioned stage "Stage"');
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$request = new HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()));
|
||||
$session = Injector::inst()->create(Session::class, []);
|
||||
$request->setSession($session);
|
||||
$session->init($request);
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$gridField->gridFieldAlterAction(array('StateID' => $stateID), $form, $request);
|
||||
|
||||
|
||||
@ -232,8 +246,11 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
$this->assertEquals(0, $list->last()->SortOrder, 'Auto sort should not have run');
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$request = new HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()));
|
||||
$session = Injector::inst()->create(Session::class, []);
|
||||
$request->setSession($session);
|
||||
$session->init($request);
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$gridField->gridFieldAlterAction(array('StateID' => $stateID), $form, $request);
|
||||
|
||||
//Insure sort ran
|
||||
|
@ -5,6 +5,7 @@ namespace UndefinedOffset\SortableGridField\Tests;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
@ -58,8 +59,11 @@ class GridFieldSortableRowsPageTest extends SapphireTest
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set($stateID, array('grid' => '', 'actionName' => 'sortToPage', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true), 'GridFieldPaginator' => array('currentPage' => 1))));
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemID' => $team3->ID, 'Target' => 'nextpage'), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$session = Injector::inst()->create(Session::class, []);
|
||||
$request->setSession($session);
|
||||
$session->init($request);
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortToPage', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true), 'GridFieldPaginator' => array('currentPage' => 1))));
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
|
||||
$team6 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_Team', 'team6');
|
||||
@ -77,8 +81,11 @@ class GridFieldSortableRowsPageTest extends SapphireTest
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set($stateID, array('grid' => '', 'actionName' => 'sortToPage', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true), 'GridFieldPaginator' => array('currentPage' => 1))));
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemID' => $team7->ID, 'Target' => 'previouspage'), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$session = Injector::inst()->create(Session::class, []);
|
||||
$request->setSession($session);
|
||||
$session->init($request);
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortToPage', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true), 'GridFieldPaginator' => array('currentPage' => 1))));
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
|
||||
|
||||
@ -112,8 +119,11 @@ class GridFieldSortableRowsPageTest extends SapphireTest
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set($stateID, array('grid' => '', 'actionName' => 'sortToPage', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true), 'GridFieldPaginator' => array('currentPage' => 1))));
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemID' => $team3->ID, 'Target' => 'nextpage'), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$session = Injector::inst()->create(Session::class, []);
|
||||
$request->setSession($session);
|
||||
$session->init($request);
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortToPage', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true), 'GridFieldPaginator' => array('currentPage' => 1))));
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
|
||||
|
||||
@ -156,8 +166,11 @@ class GridFieldSortableRowsPageTest extends SapphireTest
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set($stateID, array('grid' => '', 'actionName' => 'sortToPage', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true), 'GridFieldPaginator' => array('currentPage' => 1))));
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemID' => $team7->ID, 'Target' => 'previouspage'), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$session = Injector::inst()->create(Session::class, []);
|
||||
$request->setSession($session);
|
||||
$session->init($request);
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortToPage', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true), 'GridFieldPaginator' => array('currentPage' => 1))));
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace UndefinedOffset\SortableGridField\Tests;
|
||||
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
@ -57,8 +58,11 @@ class GridFieldSortableRowsTest extends SapphireTest
|
||||
$team3 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_Team', 'team3');
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set($stateID, array('grid' => '', 'actionName' => 'saveGridRowSort', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemIDs' => "$team1->ID, $team3->ID, $team2->ID"), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$session = Injector::inst()->create(Session::class, []);
|
||||
$request->setSession($session);
|
||||
$session->init($request);
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'saveGridRowSort', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
$this->assertEquals($team3->ID, $this->list->last()->ID, 'User should\'t be able to sort records without correct permissions.');
|
||||
}
|
||||
@ -70,8 +74,11 @@ class GridFieldSortableRowsTest extends SapphireTest
|
||||
$team3 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_Team', 'team3');
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set($stateID, array('grid' => '', 'actionName' => 'saveGridRowSort', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemIDs' => "$team1->ID, $team3->ID, $team2->ID"), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$session = Injector::inst()->create(Session::class, []);
|
||||
$request->setSession($session);
|
||||
$session->init($request);
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'saveGridRowSort', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
$this->assertEquals($team2->ID, $this->list->last()->ID, 'User should be able to sort records with ADMIN permission.');
|
||||
}
|
||||
@ -99,8 +106,11 @@ class GridFieldSortableRowsTest extends SapphireTest
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set($stateID, array('grid' => '', 'actionName' => 'saveGridRowSort', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemIDs' => "$team1->ID, $team3->ID, $team2->ID"), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$session = Injector::inst()->create(Session::class, []);
|
||||
$request->setSession($session);
|
||||
$session->init($request);
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'saveGridRowSort', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
|
||||
$this->assertEquals($team2->ID, $list->last()->ID, 'Sort should have happened on Versioned stage "Stage"');
|
||||
|
Loading…
Reference in New Issue
Block a user