2012-05-15 17:33:00 +02:00
|
|
|
<?php
|
|
|
|
class GridFieldSortableRowsTest extends SapphireTest {
|
|
|
|
|
|
|
|
/** @var ArrayList */
|
|
|
|
protected $list;
|
|
|
|
|
|
|
|
/** @var GridField */
|
|
|
|
protected $gridField;
|
|
|
|
|
|
|
|
/** @var Form */
|
|
|
|
protected $form;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
public static $fixture_file = 'GridFieldSortableRowsTest.yml';
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
protected $extraDataObjects = array('GridFieldAction_SortOrder_Team');
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2012-09-06 17:27:23 +02:00
|
|
|
$this->list = GridFieldAction_SortOrder_Team::get();
|
2012-05-15 17:33:00 +02:00
|
|
|
$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 testSortActionWithoutCorrectPermission() {
|
|
|
|
if(Member::currentUser()) { Member::currentUser()->logOut(); }
|
|
|
|
$this->setExpectedException('ValidationException');
|
|
|
|
|
|
|
|
$stateID = 'testGridStateActionField';
|
|
|
|
Session::set($stateID, array('grid'=>'', 'actionName'=>'saveGridRowSort', 'args'=>array('GridFieldSortableRows'=>array('sortableToggle'=>true))));
|
2013-01-22 14:56:49 +01:00
|
|
|
$request = new SS_HTTPRequest('POST', 'url', array('ItemIDs'=>'1,3,2'), array('action_gridFieldAlterAction?StateID='.$stateID=>true));
|
2012-05-15 17:33:00 +02:00
|
|
|
$this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request);
|
2012-09-06 17:27:23 +02:00
|
|
|
$this->assertEquals(3, $this->list->last()->ID, 'User should\'t be able to sort records without correct permissions.');
|
2012-05-15 17:33:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSortActionWithAdminPermission() {
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
$stateID = 'testGridStateActionField';
|
|
|
|
Session::set($stateID, array('grid'=>'', 'actionName'=>'saveGridRowSort', 'args'=>array('GridFieldSortableRows'=>array('sortableToggle'=>true))));
|
2013-01-22 14:56:49 +01:00
|
|
|
$request = new SS_HTTPRequest('POST', 'url', array('ItemIDs'=>'1,3,2'), array('action_gridFieldAlterAction?StateID='.$stateID=>true));
|
2012-05-15 17:33:00 +02:00
|
|
|
$this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request);
|
2012-09-06 17:27:23 +02:00
|
|
|
$this->assertEquals(2, $this->list->last()->ID, 'User should be able to sort records with ADMIN permission.');
|
2012-05-15 17:33:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class GridFieldAction_SortOrder_Team extends DataObject implements TestOnly {
|
|
|
|
static $db = array(
|
|
|
|
'Name' => 'Varchar',
|
|
|
|
'City' => 'Varchar',
|
|
|
|
'SortOrder' => 'Int'
|
|
|
|
);
|
|
|
|
|
|
|
|
static $default_sort='SortOrder';
|
|
|
|
}
|
|
|
|
?>
|