mirror of
https://github.com/UndefinedOffset/SortableGridField.git
synced 2024-10-22 17:05:38 +02:00
Fixed permissions test
Added test for auto sorting
This commit is contained in:
parent
35f2a5a463
commit
e1435afd80
46
tests/forms/GridFieldSortableRowsAutoSortTest.php
Normal file
46
tests/forms/GridFieldSortableRowsAutoSortTest.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
class GridFieldSortableRowsAutoSortTest extends SapphireTest {
|
||||
|
||||
/** @var ArrayList */
|
||||
protected $list;
|
||||
|
||||
/** @var GridField */
|
||||
protected $gridField;
|
||||
|
||||
/** @var Form */
|
||||
protected $form;
|
||||
|
||||
/** @var string */
|
||||
public static $fixture_file = 'GridFieldSortableRowsAutoSortTest.yml';
|
||||
|
||||
/** @var array */
|
||||
protected $extraDataObjects = array('GridFieldAction_SortOrder_Player');
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->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';
|
||||
}
|
||||
?>
|
@ -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);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user