diff --git a/docs/HasManyExample.md b/docs/HasManyExample.md index d740330..a0ba2ff 100644 --- a/docs/HasManyExample.md +++ b/docs/HasManyExample.md @@ -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'; } ``` \ No newline at end of file diff --git a/docs/ManyManyExample.md b/docs/ManyManyExample.md index 90c9ae0..d6f62b9 100644 --- a/docs/ManyManyExample.md +++ b/docs/ManyManyExample.md @@ -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' ); } diff --git a/docs/ModelAdminExample.md b/docs/ModelAdminExample.md index 04082a4..b4bdad5 100644 --- a/docs/ModelAdminExample.md +++ b/docs/ModelAdminExample.md @@ -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'; } ``` \ No newline at end of file diff --git a/tests/forms/GridFieldSortableRowsAutoSortTest.php b/tests/forms/GridFieldSortableRowsAutoSortTest.php index 0356b9e..e6d6a89 100644 --- a/tests/forms/GridFieldSortableRowsAutoSortTest.php +++ b/tests/forms/GridFieldSortableRowsAutoSortTest.php @@ -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 diff --git a/tests/forms/GridFieldSortableRowsPageTest.php b/tests/forms/GridFieldSortableRowsPageTest.php index 70491b6..2a43970 100644 --- a/tests/forms/GridFieldSortableRowsPageTest.php +++ b/tests/forms/GridFieldSortableRowsPageTest.php @@ -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); diff --git a/tests/forms/GridFieldSortableRowsTest.php b/tests/forms/GridFieldSortableRowsTest.php index c4c49e8..78f30fb 100644 --- a/tests/forms/GridFieldSortableRowsTest.php +++ b/tests/forms/GridFieldSortableRowsTest.php @@ -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"');