From e1435afd8018b6c0cb4aec17c62f18829643870f Mon Sep 17 00:00:00 2001 From: UndefinedOffset Date: Thu, 6 Sep 2012 12:27:23 -0300 Subject: [PATCH] Fixed permissions test Added test for auto sorting --- .../GridFieldSortableRowsAutoSortTest.php | 46 +++++++++++++++++++ tests/forms/GridFieldSortableRowsTest.php | 14 ++---- 2 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 tests/forms/GridFieldSortableRowsAutoSortTest.php diff --git a/tests/forms/GridFieldSortableRowsAutoSortTest.php b/tests/forms/GridFieldSortableRowsAutoSortTest.php new file mode 100644 index 0000000..fcabbca --- /dev/null +++ b/tests/forms/GridFieldSortableRowsAutoSortTest.php @@ -0,0 +1,46 @@ +list = GridFieldAction_SortOrder_Player::get(); + $config = GridFieldConfig::create()->addComponent(new GridFieldSortableRows('SortOrder')); + $this->gridField = new GridField('testfield', 'testfield', $this->list, $config); + $this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField)), new FieldList()); + } + + public function testAutoSort() { + if(Member::currentUser()) { Member::currentUser()->logOut(); } + + $stateID = 'testGridStateActionField'; + Session::set($stateID, array('grid'=>'', 'actionName'=>'sortableRowsDisablePaginator', 'args'=>array('GridFieldSortableRows'=>array('sortableToggle'=>true)))); + $request = new SS_HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID='.$stateID=>true)); + $this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request); + $this->assertEquals(3, $this->list->last()->SortOrder, 'Auto sort should have run'); + } +} + +class GridFieldAction_SortOrder_Player extends DataObject implements TestOnly { + static $db = array( + 'Name' => 'Varchar', + 'SortOrder' => 'Int' + ); + + static $default_sort='SortOrder'; +} +?> \ No newline at end of file diff --git a/tests/forms/GridFieldSortableRowsTest.php b/tests/forms/GridFieldSortableRowsTest.php index 5cf7fcd..057f86e 100644 --- a/tests/forms/GridFieldSortableRowsTest.php +++ b/tests/forms/GridFieldSortableRowsTest.php @@ -18,7 +18,7 @@ class GridFieldSortableRowsTest extends SapphireTest { public function setUp() { parent::setUp(); - $this->list = DataList::create('GridFieldAction_SortOrder_Team'); + $this->list = GridFieldAction_SortOrder_Team::get(); $config = GridFieldConfig::create()->addComponent(new GridFieldSortableRows('SortOrder')); $this->gridField = new GridField('testfield', 'testfield', $this->list, $config); $this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField)), new FieldList()); @@ -32,7 +32,7 @@ class GridFieldSortableRowsTest extends SapphireTest { Session::set($stateID, array('grid'=>'', 'actionName'=>'saveGridRowSort', 'args'=>array('GridFieldSortableRows'=>array('sortableToggle'=>true)))); $request = new SS_HTTPRequest('POST', 'url', array('Items'=>'1,3,2'), array('action_gridFieldAlterAction?StateID='.$stateID=>true)); $this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request); - $this->assertEquals(3, $this->list->count(), 'User should\'t be able to sort records without correct permissions.'); + $this->assertEquals(3, $this->list->last()->ID, 'User should\'t be able to sort records without correct permissions.'); } public function testSortActionWithAdminPermission() { @@ -41,7 +41,7 @@ class GridFieldSortableRowsTest extends SapphireTest { Session::set($stateID, array('grid'=>'', 'actionName'=>'saveGridRowSort', 'args'=>array('GridFieldSortableRows'=>array('sortableToggle'=>true)))); $request = new SS_HTTPRequest('POST', 'url', array('Items'=>'1,3,2'), array('action_gridFieldAlterAction?StateID='.$stateID=>true)); $this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request); - $this->assertEquals(3, $this->list->count(), 'User should be able to sort records with ADMIN permission.'); + $this->assertEquals(2, $this->list->last()->ID, 'User should be able to sort records with ADMIN permission.'); } } @@ -53,13 +53,5 @@ class GridFieldAction_SortOrder_Team extends DataObject implements TestOnly { ); static $default_sort='SortOrder'; - - public function canView($member = null) { - return true; - } - - public function canDelete($member = null) { - return parent::canDelete($member); - } } ?> \ No newline at end of file