Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed permissions test

Added test for auto sorting
  • Loading branch information...
commit e1435afd8018b6c0cb4aec17c62f18829643870f 1 parent 35f2a5a
@UndefinedOffset authored
View
46 tests/forms/GridFieldSortableRowsAutoSortTest.php
@@ -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';
+}
+?>
View
14 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 @@ public function testSortActionWithoutCorrectPermission() {
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 @@ public function testSortActionWithAdminPermission() {
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);
- }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.