FIX Do not use hardcoded IDs in tests, as records from fixture might not start at 1

This commit is contained in:
jean 2013-02-11 15:38:56 +13:00
parent b0e116076e
commit 0e5426c0d7

View File

@ -27,21 +27,27 @@ class GridFieldSortableRowsTest extends SapphireTest {
public function testSortActionWithoutCorrectPermission() { public function testSortActionWithoutCorrectPermission() {
if(Member::currentUser()) { Member::currentUser()->logOut(); } if(Member::currentUser()) { Member::currentUser()->logOut(); }
$this->setExpectedException('ValidationException'); $this->setExpectedException('ValidationException');
$team1 = $this->objFromFixture('GridFieldAction_SortOrder_Team', 'team1');
$team2 = $this->objFromFixture('GridFieldAction_SortOrder_Team', 'team2');
$team3 = $this->objFromFixture('GridFieldAction_SortOrder_Team', 'team3');
$stateID = 'testGridStateActionField'; $stateID = 'testGridStateActionField';
Session::set($stateID, array('grid'=>'', 'actionName'=>'saveGridRowSort', 'args'=>array('GridFieldSortableRows'=>array('sortableToggle'=>true)))); Session::set($stateID, array('grid'=>'', 'actionName'=>'saveGridRowSort', 'args'=>array('GridFieldSortableRows'=>array('sortableToggle'=>true))));
$request = new SS_HTTPRequest('POST', 'url', array('ItemIDs'=>'1,3,2'), array('action_gridFieldAlterAction?StateID='.$stateID=>true)); $request = new SS_HTTPRequest('POST', 'url', array('ItemIDs'=>"$team1->ID, $team3->ID, $team2->ID"), array('action_gridFieldAlterAction?StateID='.$stateID=>true));
$this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request); $this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request);
$this->assertEquals(3, $this->list->last()->ID, 'User should\'t be able to sort records without correct permissions.'); $this->assertEquals($team3->ID, $this->list->last()->ID, 'User should\'t be able to sort records without correct permissions.');
} }
public function testSortActionWithAdminPermission() { public function testSortActionWithAdminPermission() {
$team1 = $this->objFromFixture('GridFieldAction_SortOrder_Team', 'team1');
$team2 = $this->objFromFixture('GridFieldAction_SortOrder_Team', 'team2');
$team3 = $this->objFromFixture('GridFieldAction_SortOrder_Team', 'team3');
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$stateID = 'testGridStateActionField'; $stateID = 'testGridStateActionField';
Session::set($stateID, array('grid'=>'', 'actionName'=>'saveGridRowSort', 'args'=>array('GridFieldSortableRows'=>array('sortableToggle'=>true)))); Session::set($stateID, array('grid'=>'', 'actionName'=>'saveGridRowSort', 'args'=>array('GridFieldSortableRows'=>array('sortableToggle'=>true))));
$request = new SS_HTTPRequest('POST', 'url', array('ItemIDs'=>'1,3,2'), array('action_gridFieldAlterAction?StateID='.$stateID=>true)); $request = new SS_HTTPRequest('POST', 'url', array('ItemIDs'=>"$team1->ID, $team3->ID, $team2->ID"), array('action_gridFieldAlterAction?StateID='.$stateID=>true));
$this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request); $this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request);
$this->assertEquals(2, $this->list->last()->ID, 'User should be able to sort records with ADMIN permission.'); $this->assertEquals($team2->ID, $this->list->last()->ID, 'User should be able to sort records with ADMIN permission.');
} }
} }