mirror of
https://github.com/UndefinedOffset/SortableGridField.git
synced 2024-10-22 17:05:38 +02:00
Split unit test classes into separate files
This commit is contained in:
parent
5f37c8a0b4
commit
8ed1621f8b
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
||||
/.project
|
||||
/.settings
|
||||
/.settings/*
|
||||
.phpunit.result.cache
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace UndefinedOffset\SortableGridField\Forms;
|
||||
|
||||
use SilverStripe\Admin\ModelAdmin;
|
||||
@ -30,8 +29,6 @@ use SilverStripe\View\Requirements;
|
||||
|
||||
/**
|
||||
* This component provides a checkbox which when checked enables drag-and-drop re-ordering of elements displayed in a {@link GridField}
|
||||
*
|
||||
* @package forms
|
||||
*/
|
||||
class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionProvider, GridField_DataManipulator
|
||||
{
|
||||
|
19
tests/PHPUnit/Forms/AutoSortTest/BaseObject.php
Normal file
19
tests/PHPUnit/Forms/AutoSortTest/BaseObject.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
|
||||
/**
|
||||
* Class \UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\BaseObject
|
||||
*
|
||||
* @property string Name
|
||||
*/
|
||||
class BaseObject extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_BaseObject';
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Varchar',
|
||||
];
|
||||
}
|
27
tests/PHPUnit/Forms/AutoSortTest/ChildObject.php
Normal file
27
tests/PHPUnit/Forms/AutoSortTest/ChildObject.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\FieldType\DBInt;
|
||||
|
||||
/**
|
||||
* Class \UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\ChildObject
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* @property int SortOrder
|
||||
* @method TestParent Parent
|
||||
*/
|
||||
class ChildObject extends BaseObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_ChildObject';
|
||||
|
||||
private static $db = [
|
||||
'SortOrder' => DBInt::class,
|
||||
];
|
||||
|
||||
private static $has_one = [
|
||||
'Parent' => TestParent::class,
|
||||
];
|
||||
|
||||
private static $default_sort = 'SortOrder';
|
||||
}
|
12
tests/PHPUnit/Forms/AutoSortTest/DummyController.php
Normal file
12
tests/PHPUnit/Forms/AutoSortTest/DummyController.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
|
||||
/**
|
||||
* Class \UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\DummyController
|
||||
*/
|
||||
class DummyController extends Controller
|
||||
{
|
||||
private static $url_segment = 'sortable-grid-field';
|
||||
}
|
23
tests/PHPUnit/Forms/AutoSortTest/Player.php
Normal file
23
tests/PHPUnit/Forms/AutoSortTest/Player.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
|
||||
/**
|
||||
* Class \UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\Player
|
||||
*
|
||||
* @property string Name
|
||||
* @property int SortOrder
|
||||
*/
|
||||
class Player extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_Player';
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Varchar',
|
||||
'SortOrder' => 'Int',
|
||||
];
|
||||
|
||||
private static $default_sort = 'SortOrder';
|
||||
}
|
25
tests/PHPUnit/Forms/AutoSortTest/TestParent.php
Normal file
25
tests/PHPUnit/Forms/AutoSortTest/TestParent.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
|
||||
/**
|
||||
* Class \UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\TestParent
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* @property string Name
|
||||
* @method ChildObject TestRelation
|
||||
*/
|
||||
class TestParent extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_TestParent';
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Varchar',
|
||||
];
|
||||
|
||||
private static $has_many = [
|
||||
'TestRelation' => ChildObject::class,
|
||||
];
|
||||
}
|
28
tests/PHPUnit/Forms/AutoSortTest/VPlayer.php
Normal file
28
tests/PHPUnit/Forms/AutoSortTest/VPlayer.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
/**
|
||||
* Class \UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\VPlayer
|
||||
*
|
||||
* @property string Name
|
||||
* @property int SortOrder
|
||||
*/
|
||||
class VPlayer extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_VPlayer';
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Varchar',
|
||||
'SortOrder' => 'Int',
|
||||
];
|
||||
|
||||
private static $default_sort = 'SortOrder';
|
||||
|
||||
private static $extensions = [
|
||||
Versioned::class,
|
||||
];
|
||||
}
|
@ -1,27 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace UndefinedOffset\SortableGridField\Tests;
|
||||
namespace UndefinedOffset\SortableGridField\Tests\Forms;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldConfig;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\FieldType\DBInt;
|
||||
use SilverStripe\ORM\FieldType\DBVarchar;
|
||||
use SilverStripe\Security\Security;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use UndefinedOffset\SortableGridField\Forms\GridFieldSortableRows;
|
||||
use UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\BaseObject;
|
||||
use UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\ChildObject;
|
||||
use UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\DummyController;
|
||||
use UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\Player;
|
||||
use UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\TestParent;
|
||||
use UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\VPlayer;
|
||||
|
||||
/**
|
||||
* Class GridFieldSortableRowsAutoSortTest
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* Class \UndefinedOffset\SortableGridField\Tests\GridFieldSortableRowsAutoSortTest
|
||||
*/
|
||||
class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
{
|
||||
@ -29,13 +28,13 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
public static $fixture_file = 'GridFieldSortableRowsAutoSortTest.yml';
|
||||
|
||||
/** @var array */
|
||||
protected static $extra_dataobjects = array(
|
||||
GridFieldAction_SortOrder_Player::class,
|
||||
GridFieldAction_SortOrder_VPlayer::class,
|
||||
GridFieldAction_SortOrder_TestParent::class,
|
||||
GridFieldAction_SortOrder_BaseObject::class,
|
||||
GridFieldAction_SortOrder_ChildObject::class
|
||||
);
|
||||
protected static $extra_dataobjects = [
|
||||
Player::class,
|
||||
VPlayer::class,
|
||||
TestParent::class,
|
||||
BaseObject::class,
|
||||
ChildObject::class
|
||||
];
|
||||
|
||||
public function testAutoSort()
|
||||
{
|
||||
@ -43,19 +42,19 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
$this->logOut();
|
||||
}
|
||||
|
||||
$list = GridFieldAction_SortOrder_Player::get();
|
||||
$list = Player::get();
|
||||
$config = GridFieldConfig::create()->addComponent(new GridFieldSortableRows('SortOrder'));
|
||||
$gridField = new GridField('testfield', 'testfield', $list, $config);
|
||||
$form = new Form(new SortableGridField_DummyController(), 'mockform', new FieldList(array($gridField)), new FieldList());
|
||||
$form = new Form(new DummyController(), 'mockform', new FieldList([$gridField]), new FieldList());
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()));
|
||||
$request = new HTTPRequest('POST', 'url', [], ['action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()]);
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set($form->getSecurityToken()->getName(), $form->getSecurityToken()->getValue());
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$session->set($stateID, ['grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => ['GridFieldSortableRows' => ['sortableToggle' => true]]]);
|
||||
$request->setSession($session);
|
||||
|
||||
$gridField->gridFieldAlterAction(array('StateID' => $stateID), $form, $request);
|
||||
$gridField->gridFieldAlterAction(['StateID' => $stateID], $form, $request);
|
||||
|
||||
//Insure sort ran
|
||||
$this->assertEquals(3, $list->last()->SortOrder, 'Auto sort should have run');
|
||||
@ -73,10 +72,10 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
$this->logOut();
|
||||
}
|
||||
|
||||
$list = GridFieldAction_SortOrder_Player::get();
|
||||
$list = Player::get();
|
||||
$config = GridFieldConfig::create()->addComponent(new GridFieldSortableRows('SortOrder'));
|
||||
$gridField = new GridField('testfield', 'testfield', $list, $config);
|
||||
$form = new Form(new SortableGridField_DummyController(), 'mockform', new FieldList(array($gridField)), new FieldList());
|
||||
$form = new Form(new DummyController(), 'mockform', new FieldList([$gridField]), new FieldList());
|
||||
|
||||
/** @var GridFieldSortableRows $sortableRows */
|
||||
$sortableRows = $gridField->getConfig()->getComponentByType(GridFieldSortableRows::class);
|
||||
@ -85,12 +84,12 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
$this->assertEquals(0, $list->last()->SortOrder, 'Auto sort should not have run');
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()));
|
||||
$request = new HTTPRequest('POST', 'url', [], ['action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()]);
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set($form->getSecurityToken()->getName(), $form->getSecurityToken()->getValue());
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$session->set($stateID, ['grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => ['GridFieldSortableRows' => ['sortableToggle' => true]]]);
|
||||
$request->setSession($session);
|
||||
$gridField->gridFieldAlterAction(array('StateID' => $stateID), $form, $request);
|
||||
$gridField->gridFieldAlterAction(['StateID' => $stateID], $form, $request);
|
||||
|
||||
//Insure sort ran
|
||||
$this->assertEquals(3, $list->last()->SortOrder, 'Auto sort should have run');
|
||||
@ -111,7 +110,7 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
//Force versioned to reset
|
||||
Versioned::reset();
|
||||
|
||||
$list = GridFieldAction_SortOrder_VPlayer::get();
|
||||
$list = VPlayer::get();
|
||||
|
||||
//Publish all records
|
||||
foreach ($list as $item) {
|
||||
@ -121,15 +120,15 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
|
||||
$config = GridFieldConfig::create()->addComponent(new GridFieldSortableRows('SortOrder', true, 'Live'));
|
||||
$gridField = new GridField('testfield', 'testfield', $list, $config);
|
||||
$form = new Form(new SortableGridField_DummyController(), 'mockform', new FieldList(array($gridField)), new FieldList());
|
||||
$form = new Form(new DummyController(), 'mockform', new FieldList([$gridField]), new FieldList());
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()));
|
||||
$request = new HTTPRequest('POST', 'url', [], ['action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()]);
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set($form->getSecurityToken()->getName(), $form->getSecurityToken()->getValue());
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$session->set($stateID, ['grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => ['GridFieldSortableRows' => ['sortableToggle' => true]]]);
|
||||
$request->setSession($session);
|
||||
$gridField->gridFieldAlterAction(array('StateID' => $stateID), $form, $request);
|
||||
$gridField->gridFieldAlterAction(['StateID' => $stateID], $form, $request);
|
||||
|
||||
|
||||
//Insure sort ran
|
||||
@ -146,14 +145,14 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
Versioned::set_reading_mode('Live');
|
||||
|
||||
//Get live instance
|
||||
$obj = Versioned::get_one_by_stage(GridFieldAction_SortOrder_VPlayer::class, 'Live', '"ID"=' . $list->last()->ID);
|
||||
$obj = Versioned::get_one_by_stage(VPlayer::class, 'Live', '"ID"=' . $list->last()->ID);
|
||||
|
||||
//Insure sort ran
|
||||
$this->assertEquals(3, $obj->SortOrder, 'Auto sort should have run on Versioned stage "Live"');
|
||||
|
||||
|
||||
//Check for duplicates (there shouldn't be any)
|
||||
$list = Versioned::get_by_stage(GridFieldAction_SortOrder_VPlayer::class, 'Live');
|
||||
$list = Versioned::get_by_stage(VPlayer::class, 'Live');
|
||||
$count = $list->Count();
|
||||
$indexes = count(array_unique($list->column('SortOrder')));
|
||||
$this->assertEquals(0, $count - $indexes, 'Duplicate indexes detected on Versioned stage "Live"');
|
||||
@ -168,7 +167,7 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
//Force versioned to reset
|
||||
Versioned::reset();
|
||||
|
||||
$list = GridFieldAction_SortOrder_VPlayer::get();
|
||||
$list = VPlayer::get();
|
||||
|
||||
//Publish all records
|
||||
foreach ($list as $item) {
|
||||
@ -178,7 +177,7 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
|
||||
$config = GridFieldConfig::create()->addComponent(new GridFieldSortableRows('SortOrder', true, 'Live'));
|
||||
$gridField = new GridField('testfield', 'testfield', $list, $config);
|
||||
$form = new Form(new SortableGridField_DummyController(), 'mockform', new FieldList(array($gridField)), new FieldList());
|
||||
$form = new Form(new DummyController(), 'mockform', new FieldList([$gridField]), new FieldList());
|
||||
|
||||
/** @var GridFieldSortableRows $sortableRows */
|
||||
$sortableRows = $gridField->getConfig()->getComponentByType(GridFieldSortableRows::class);
|
||||
@ -187,12 +186,12 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
$this->assertEquals(0, $list->last()->SortOrder, 'Auto sort should not have run on Versioned stage "Stage"');
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()));
|
||||
$request = new HTTPRequest('POST', 'url', [], ['action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()]);
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set($form->getSecurityToken()->getName(), $form->getSecurityToken()->getValue());
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$session->set($stateID, ['grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => ['GridFieldSortableRows' => ['sortableToggle' => true]]]);
|
||||
$request->setSession($session);
|
||||
$gridField->gridFieldAlterAction(array('StateID' => $stateID), $form, $request);
|
||||
$gridField->gridFieldAlterAction(['StateID' => $stateID], $form, $request);
|
||||
|
||||
|
||||
//Insure sort ran
|
||||
@ -227,15 +226,15 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
//Push the edit date into the past, we're checking this later
|
||||
DB::query('UPDATE "GridFieldAction_SortOrder_BaseObject" SET "LastEdited"=\'' . date('Y-m-d 00:00:00', strtotime('yesterday')) . '\'');
|
||||
|
||||
/** @var GridFieldAction_SortOrder_TestParent $parent */
|
||||
$parent = GridFieldAction_SortOrder_TestParent::get()->first();
|
||||
/** @var TestParent $parent */
|
||||
$parent = TestParent::get()->first();
|
||||
|
||||
/** @var DataList $list */
|
||||
$list = $parent->TestRelation();
|
||||
|
||||
$config = GridFieldConfig::create()->addComponent(new GridFieldSortableRows('SortOrder'));
|
||||
$gridField = new GridField('testfield', 'testfield', $list, $config);
|
||||
$form = new Form(new SortableGridField_DummyController(), 'mockform', new FieldList(array($gridField)), new FieldList());
|
||||
$form = new Form(new DummyController(), 'mockform', new FieldList([$gridField]), new FieldList());
|
||||
$form->loadDataFrom($parent);
|
||||
|
||||
/** @var GridFieldSortableRows $sortableRows */
|
||||
@ -245,12 +244,12 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
$this->assertEquals(0, $list->last()->SortOrder, 'Auto sort should not have run');
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()));
|
||||
$request = new HTTPRequest('POST', 'url', [], ['action_gridFieldAlterAction?StateID=' . $stateID => true, $form->getSecurityToken()->getName() => $form->getSecurityToken()->getValue()]);
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set($form->getSecurityToken()->getName(), $form->getSecurityToken()->getValue());
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$session->set($stateID, ['grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => ['GridFieldSortableRows' => ['sortableToggle' => true]]]);
|
||||
$request->setSession($session);
|
||||
$gridField->gridFieldAlterAction(array('StateID' => $stateID), $form, $request);
|
||||
$gridField->gridFieldAlterAction(['StateID' => $stateID], $form, $request);
|
||||
|
||||
//Insure sort ran
|
||||
$this->assertEquals(3, $list->last()->SortOrder, 'Auto sort should have run');
|
||||
@ -266,112 +265,3 @@ class GridFieldSortableRowsAutoSortTest extends SapphireTest
|
||||
$this->assertEquals(3, $list->filter('LastEdited:GreaterThan', date('Y-m-d 00:00:00'))->count());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class GridFieldAction_SortOrder_Player
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* @property string Name
|
||||
* @property int SortOrder
|
||||
*/
|
||||
class GridFieldAction_SortOrder_Player extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_Player';
|
||||
|
||||
private static $db = array(
|
||||
'Name' => DBVarchar::class,
|
||||
'SortOrder' => DBInt::class
|
||||
);
|
||||
|
||||
private static $default_sort = 'SortOrder';
|
||||
}
|
||||
|
||||
/**
|
||||
* Class GridFieldAction_SortOrder_VPlayer
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* @property string Name
|
||||
* @property int SortOrder
|
||||
*/
|
||||
class GridFieldAction_SortOrder_VPlayer extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_VPlayer';
|
||||
|
||||
private static $db = array(
|
||||
'Name' => DBVarchar::class,
|
||||
'SortOrder' => DBInt::class
|
||||
);
|
||||
|
||||
private static $default_sort = 'SortOrder';
|
||||
|
||||
private static $extensions = array(
|
||||
"SilverStripe\\Versioned\\Versioned('Stage', 'Live')"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class GridFieldAction_SortOrder_TestParent
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* @property string Name
|
||||
* @method GridFieldAction_SortOrder_ChildObject TestRelation
|
||||
*/
|
||||
class GridFieldAction_SortOrder_TestParent extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_TestParent';
|
||||
|
||||
private static $db = array(
|
||||
'Name' => DBVarchar::class
|
||||
);
|
||||
|
||||
private static $has_many = array(
|
||||
'TestRelation' => GridFieldAction_SortOrder_ChildObject::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class GridFieldAction_SortOrder_BaseObject
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* @property string Name
|
||||
*/
|
||||
class GridFieldAction_SortOrder_BaseObject extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_BaseObject';
|
||||
|
||||
private static $db = array(
|
||||
'Name' => DBVarchar::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class GridFieldAction_SortOrder_ChildObject
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* @property int SortOrder
|
||||
* @method GridFieldAction_SortOrder_TestParent Parent
|
||||
*/
|
||||
class GridFieldAction_SortOrder_ChildObject extends GridFieldAction_SortOrder_BaseObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_ChildObject';
|
||||
|
||||
private static $db = array(
|
||||
'SortOrder' => DBInt::class
|
||||
);
|
||||
|
||||
private static $has_one = array(
|
||||
'Parent' => GridFieldAction_SortOrder_TestParent::class
|
||||
);
|
||||
|
||||
private static $default_sort = 'SortOrder';
|
||||
}
|
||||
|
||||
/**
|
||||
* Class SortableGridField_DummyController
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
*/
|
||||
class SortableGridField_DummyController extends Controller
|
||||
{
|
||||
private static $url_segment = 'sortable-grid-field';
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_Player:
|
||||
UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\Player:
|
||||
player1:
|
||||
Name: Player 1
|
||||
SortOrder: 0
|
||||
@ -9,7 +9,7 @@ UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_Player:
|
||||
Name: Player 3
|
||||
SortOrder: 0
|
||||
|
||||
UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_VPlayer:
|
||||
UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\VPlayer:
|
||||
player1:
|
||||
Name: Player 1
|
||||
SortOrder: 0
|
||||
@ -20,20 +20,20 @@ UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_VPlayer:
|
||||
Name: Player 3
|
||||
SortOrder: 0
|
||||
|
||||
UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_TestParent:
|
||||
UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\TestParent:
|
||||
testparent:
|
||||
Name: Test
|
||||
|
||||
UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_ChildObject:
|
||||
UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\ChildObject:
|
||||
testitem1:
|
||||
Name: Test 1
|
||||
SortOrder: 0
|
||||
Parent: =>UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_TestParent.testparent
|
||||
Parent: =>UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\TestParent.testparent
|
||||
testitem2:
|
||||
Name: Test 2
|
||||
SortOrder: 0
|
||||
Parent: =>UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_TestParent.testparent
|
||||
Parent: =>UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\TestParent.testparent
|
||||
testitem3:
|
||||
Name: Test 3
|
||||
SortOrder: 0
|
||||
Parent: =>UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_TestParent.testparent
|
||||
Parent: =>UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\TestParent.testparent
|
||||
|
@ -1,25 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace UndefinedOffset\SortableGridField\Tests;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldConfig_Base;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\FieldType\DBInt;
|
||||
use SilverStripe\ORM\FieldType\DBVarchar;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use UndefinedOffset\SortableGridField\Forms\GridFieldSortableRows;
|
||||
use UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\DummyController;
|
||||
use UndefinedOffset\SortableGridField\Tests\Forms\RowsPageTest\Team;
|
||||
use UndefinedOffset\SortableGridField\Tests\Forms\RowsPageTest\VTeam;
|
||||
|
||||
/**
|
||||
* Class GridFieldSortableRowsPageTest
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* Class \UndefinedOffset\SortableGridField\Tests\GridFieldSortableRowsPageTest
|
||||
*/
|
||||
class GridFieldSortableRowsPageTest extends SapphireTest
|
||||
{
|
||||
@ -36,39 +32,40 @@ class GridFieldSortableRowsPageTest extends SapphireTest
|
||||
public static $fixture_file = 'GridFieldSortableRowsPageTest.yml';
|
||||
|
||||
/** @var array */
|
||||
protected static $extra_dataobjects = array(
|
||||
GridFieldAction_PageSortOrder_Team::class,
|
||||
GridFieldAction_PageSortOrder_VTeam::class
|
||||
);
|
||||
protected static $extra_dataobjects = [
|
||||
Team::class,
|
||||
VTeam::class
|
||||
];
|
||||
|
||||
public function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->list = GridFieldAction_PageSortOrder_Team::get();
|
||||
|
||||
$this->list = Team::get();
|
||||
$config = GridFieldConfig_Base::create(5)->addComponent(new GridFieldSortableRows('SortOrder'));
|
||||
$this->gridField = new GridField('testfield', 'testfield', $this->list, $config);
|
||||
$this->form = new Form(new SortableGridField_DummyController(), 'mockform', FieldList::create(array($this->gridField)), FieldList::create());
|
||||
$this->form = new Form(new DummyController(), 'mockform', FieldList::create([$this->gridField]), FieldList::create());
|
||||
}
|
||||
|
||||
public function testSortToNextPage()
|
||||
{
|
||||
$this->gridField->State->GridFieldPaginator->currentPage = 1;
|
||||
|
||||
$team3 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_Team', 'team3');
|
||||
$team3 = $this->objFromFixture(Team::class, 'team3');
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemID' => $team3->ID, 'Target' => 'nextpage'), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$request = new HTTPRequest('POST', 'url', ['ItemID' => $team3->ID, 'Target' => 'nextpage'], ['action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()]);
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set($this->form->getSecurityToken()->getName(), $this->form->getSecurityToken()->getValue());
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortToPage', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true), 'GridFieldPaginator' => array('currentPage' => 1))));
|
||||
$session->set($stateID, ['grid' => '', 'actionName' => 'sortToPage', 'args' => ['GridFieldSortableRows' => ['sortableToggle' => true], 'GridFieldPaginator' => ['currentPage' => 1]]]);
|
||||
$request->setSession($session);
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
$this->gridField->gridFieldAlterAction(['StateID' => $stateID], $this->form, $request);
|
||||
|
||||
$team6 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_Team', 'team6');
|
||||
$team6 = $this->objFromFixture(Team::class, 'team6');
|
||||
$this->assertEquals(5, $team6->SortOrder, 'Team 6 Should have moved to the bottom of the first page');
|
||||
|
||||
$team3 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_Team', 'team3');
|
||||
$team3 = $this->objFromFixture(Team::class, 'team3');
|
||||
$this->assertEquals(6, $team3->SortOrder, 'Team 3 Should have moved to the top of the second page');
|
||||
}
|
||||
|
||||
@ -76,22 +73,22 @@ class GridFieldSortableRowsPageTest extends SapphireTest
|
||||
{
|
||||
$this->gridField->State->GridFieldPaginator->currentPage = 2;
|
||||
|
||||
$team7 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_Team', 'team7');
|
||||
$team7 = $this->objFromFixture(Team::class, 'team7');
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemID' => $team7->ID, 'Target' => 'previouspage'), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$request = new HTTPRequest('POST', 'url', ['ItemID' => $team7->ID, 'Target' => 'previouspage'], ['action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()]);
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set($this->form->getSecurityToken()->getName(), $this->form->getSecurityToken()->getValue());
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortToPage', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true), 'GridFieldPaginator' => array('currentPage' => 1))));
|
||||
$session->set($stateID, ['grid' => '', 'actionName' => 'sortToPage', 'args' => ['GridFieldSortableRows' => ['sortableToggle' => true], 'GridFieldPaginator' => ['currentPage' => 1]]]);
|
||||
$request->setSession($session);
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
$this->gridField->gridFieldAlterAction(['StateID' => $stateID], $this->form, $request);
|
||||
|
||||
|
||||
$team7 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_Team', 'team7');
|
||||
$team7 = $this->objFromFixture(Team::class, 'team7');
|
||||
$this->assertEquals(5, $team7->SortOrder, 'Team 7 Should have moved to the bottom of the first page');
|
||||
|
||||
$team5 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_Team', 'team5');
|
||||
$team5 = $this->objFromFixture(Team::class, 'team5');
|
||||
$this->assertEquals(6, $team5->SortOrder, 'Team 5 Should have moved to the top of the second page');
|
||||
}
|
||||
|
||||
@ -100,7 +97,7 @@ class GridFieldSortableRowsPageTest extends SapphireTest
|
||||
//Force versioned to reset
|
||||
Versioned::reset();
|
||||
|
||||
$list = GridFieldAction_PageSortOrder_VTeam::get();
|
||||
$list = VTeam::get();
|
||||
$this->gridField->setList($list);
|
||||
|
||||
/** @var GridFieldSortableRows $sortableGrid */
|
||||
@ -114,26 +111,26 @@ class GridFieldSortableRowsPageTest extends SapphireTest
|
||||
}
|
||||
|
||||
|
||||
$team3 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_VTeam', 'team3');
|
||||
$team3 = $this->objFromFixture(VTeam::class, 'team3');
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemID' => $team3->ID, 'Target' => 'nextpage'), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$request = new HTTPRequest('POST', 'url', ['ItemID' => $team3->ID, 'Target' => 'nextpage'], ['action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()]);
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set($this->form->getSecurityToken()->getName(), $this->form->getSecurityToken()->getValue());
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortToPage', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true), 'GridFieldPaginator' => array('currentPage' => 1))));
|
||||
$session->set($stateID, ['grid' => '', 'actionName' => 'sortToPage', 'args' => ['GridFieldSortableRows' => ['sortableToggle' => true], 'GridFieldPaginator' => ['currentPage' => 1]]]);
|
||||
$request->setSession($session);
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
$this->gridField->gridFieldAlterAction(['StateID' => $stateID], $this->form, $request);
|
||||
|
||||
|
||||
$team6 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_VTeam', 'team6');
|
||||
$team6 = $this->objFromFixture(VTeam::class, 'team6');
|
||||
$this->assertEquals(5, $team6->SortOrder, 'Team 6 Should have moved to the bottom of the first page on Versioned stage "Stage"');
|
||||
|
||||
$team3 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_VTeam', 'team3');
|
||||
$team3 = $this->objFromFixture(VTeam::class, 'team3');
|
||||
$this->assertEquals(6, $team3->SortOrder, 'Team 3 Should have moved to the top of the second page on Versioned stage "Stage"');
|
||||
|
||||
|
||||
$list = Versioned::get_by_stage(GridFieldAction_PageSortOrder_VTeam::class, 'Live');
|
||||
$list = Versioned::get_by_stage(VTeam::class, 'Live');
|
||||
|
||||
$team6 = $list->byID($team6->ID);
|
||||
$this->assertEquals(5, $team6->SortOrder, 'Team 6 Should have moved to the bottom of the first page on Versioned stage "Live"');
|
||||
@ -147,7 +144,7 @@ class GridFieldSortableRowsPageTest extends SapphireTest
|
||||
//Force versioned to reset
|
||||
Versioned::reset();
|
||||
|
||||
$list = GridFieldAction_PageSortOrder_VTeam::get();
|
||||
$list = VTeam::get();
|
||||
$this->gridField->setList($list);
|
||||
|
||||
/** @var GridFieldSortableRows $sortableGrid */
|
||||
@ -161,26 +158,26 @@ class GridFieldSortableRowsPageTest extends SapphireTest
|
||||
}
|
||||
|
||||
|
||||
$team7 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_VTeam', 'team7');
|
||||
$team7 = $this->objFromFixture(VTeam::class, 'team7');
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemID' => $team7->ID, 'Target' => 'previouspage'), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$request = new HTTPRequest('POST', 'url', ['ItemID' => $team7->ID, 'Target' => 'previouspage'], ['action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()]);
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set($this->form->getSecurityToken()->getName(), $this->form->getSecurityToken()->getValue());
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'sortToPage', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true), 'GridFieldPaginator' => array('currentPage' => 1))));
|
||||
$session->set($stateID, ['grid' => '', 'actionName' => 'sortToPage', 'args' => ['GridFieldSortableRows' => ['sortableToggle' => true], 'GridFieldPaginator' => ['currentPage' => 1]]]);
|
||||
$request->setSession($session);
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
$this->gridField->gridFieldAlterAction(['StateID' => $stateID], $this->form, $request);
|
||||
|
||||
|
||||
$team7 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_VTeam', 'team7');
|
||||
$team7 = $this->objFromFixture(VTeam::class, 'team7');
|
||||
$this->assertEquals(5, $team7->SortOrder, 'Team 7 Should have moved to the bottom of the first page on Versioned stage "Stage"');
|
||||
|
||||
$team5 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_VTeam', 'team5');
|
||||
$team5 = $this->objFromFixture(VTeam::class, 'team5');
|
||||
$this->assertEquals(6, $team5->SortOrder, 'Team 5 Should have moved to the top of the second page on Versioned stage "Stage"');
|
||||
|
||||
|
||||
$list = Versioned::get_by_stage(GridFieldAction_PageSortOrder_VTeam::class, 'Live');
|
||||
$list = Versioned::get_by_stage(VTeam::class, 'Live');
|
||||
|
||||
$team7 = $list->byID($team7->ID);
|
||||
$this->assertEquals(5, $team7->SortOrder, 'Team 7 Should have moved to the bottom of the first page on Versioned stage "Live"');
|
||||
@ -189,49 +186,3 @@ class GridFieldSortableRowsPageTest extends SapphireTest
|
||||
$this->assertEquals(6, $team5->SortOrder, 'Team 5 Should have moved to the top of the second page on Versioned stage "Live"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class GridFieldAction_PageSortOrder_Team
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* @property string Name
|
||||
* @property string City
|
||||
* @property int SortOrder
|
||||
*/
|
||||
class GridFieldAction_PageSortOrder_Team extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_PageSortOrder_Team';
|
||||
|
||||
private static $db = array(
|
||||
'Name' => DBVarchar::class,
|
||||
'City' => DBVarchar::class,
|
||||
'SortOrder' => DBInt::class
|
||||
);
|
||||
|
||||
private static $default_sort = 'SortOrder';
|
||||
}
|
||||
|
||||
/**
|
||||
* Class GridFieldAction_PageSortOrder_VTeam
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* @property string Name
|
||||
* @property string City
|
||||
* @property int SortOrder
|
||||
*/
|
||||
class GridFieldAction_PageSortOrder_VTeam extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_PageSortOrder_VTeam';
|
||||
|
||||
private static $db = array(
|
||||
'Name' => DBVarchar::class,
|
||||
'City' => DBVarchar::class,
|
||||
'SortOrder' => DBInt::class
|
||||
);
|
||||
|
||||
private static $default_sort = 'SortOrder';
|
||||
|
||||
private static $extensions = array(
|
||||
"SilverStripe\\Versioned\\Versioned('Stage', 'Live')"
|
||||
);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_Team:
|
||||
UndefinedOffset\SortableGridField\Tests\Forms\RowsPageTest\Team:
|
||||
team1:
|
||||
Name: Team 1
|
||||
City: Cologne
|
||||
@ -36,7 +36,7 @@ UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_Team:
|
||||
City: Auckland
|
||||
SortOrder: 9
|
||||
|
||||
UndefinedOffset\SortableGridField\Tests\GridFieldAction_PageSortOrder_VTeam:
|
||||
UndefinedOffset\SortableGridField\Tests\Forms\RowsPageTest\VTeam:
|
||||
team1:
|
||||
Name: Team 1
|
||||
City: Cologne
|
||||
|
@ -1,22 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace UndefinedOffset\SortableGridField\Tests;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldConfig;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\ValidationException;
|
||||
use SilverStripe\ORM\FieldType\DBInt;
|
||||
use SilverStripe\ORM\FieldType\DBVarchar;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use UndefinedOffset\SortableGridField\Forms\GridFieldSortableRows;
|
||||
use UndefinedOffset\SortableGridField\Tests\Forms\AutoSortTest\DummyController;
|
||||
use UndefinedOffset\SortableGridField\Tests\Forms\RowsTest\Team;
|
||||
use UndefinedOffset\SortableGridField\Tests\Forms\RowsTest\VTeam;
|
||||
|
||||
class GridFieldSortableRowsTest extends SapphireTest
|
||||
{
|
||||
@ -33,18 +31,19 @@ class GridFieldSortableRowsTest extends SapphireTest
|
||||
public static $fixture_file = 'GridFieldSortableRowsTest.yml';
|
||||
|
||||
/** @var array */
|
||||
protected static $extra_dataobjects = array(
|
||||
GridFieldAction_SortOrder_Team::class,
|
||||
GridFieldAction_SortOrder_VTeam::class
|
||||
);
|
||||
protected static $extra_dataobjects = [
|
||||
Team::class,
|
||||
VTeam::class
|
||||
];
|
||||
|
||||
public function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->list = GridFieldAction_SortOrder_Team::get();
|
||||
|
||||
$this->list = Team::get();
|
||||
$config = GridFieldConfig::create()->addComponent(new GridFieldSortableRows('SortOrder'));
|
||||
$this->gridField = new GridField('testfield', 'testfield', $this->list, $config);
|
||||
$this->form = new Form(new SortableGridField_DummyController(), 'mockform', new FieldList(array($this->gridField)), new FieldList());
|
||||
$this->form = new Form(new DummyController(), 'mockform', new FieldList([$this->gridField]), new FieldList());
|
||||
}
|
||||
|
||||
public function testSortActionWithoutCorrectPermission()
|
||||
@ -52,34 +51,35 @@ class GridFieldSortableRowsTest extends SapphireTest
|
||||
if (Member::currentUser()) {
|
||||
Member::currentUser()->logOut();
|
||||
}
|
||||
$this->setExpectedException(ValidationException::class);
|
||||
$team1 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_Team', 'team1');
|
||||
$team2 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_Team', 'team2');
|
||||
$team3 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_Team', 'team3');
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$team1 = $this->objFromFixture(Team::class, 'team1');
|
||||
$team2 = $this->objFromFixture(Team::class, 'team2');
|
||||
$team3 = $this->objFromFixture(Team::class, 'team3');
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemIDs' => "$team1->ID, $team3->ID, $team2->ID"), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$request = new HTTPRequest('POST', 'url', ['ItemIDs' => "$team1->ID, $team3->ID, $team2->ID"], ['action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()]);
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set($this->form->getSecurityToken()->getName(), $this->form->getSecurityToken()->getValue());
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'saveGridRowSort', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$session->set($stateID, ['grid' => '', 'actionName' => 'saveGridRowSort', 'args' => ['GridFieldSortableRows' => ['sortableToggle' => true]]]);
|
||||
$request->setSession($session);
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
$this->gridField->gridFieldAlterAction(['StateID' => $stateID], $this->form, $request);
|
||||
$this->assertEquals($team3->ID, $this->list->last()->ID, 'User should\'t be able to sort records without correct permissions.');
|
||||
}
|
||||
|
||||
public function testSortActionWithAdminPermission()
|
||||
{
|
||||
$team1 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_Team', 'team1');
|
||||
$team2 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_Team', 'team2');
|
||||
$team3 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_Team', 'team3');
|
||||
$team1 = $this->objFromFixture(Team::class, 'team1');
|
||||
$team2 = $this->objFromFixture(Team::class, 'team2');
|
||||
$team3 = $this->objFromFixture(Team::class, 'team3');
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemIDs' => "$team1->ID, $team3->ID, $team2->ID"), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$request = new HTTPRequest('POST', 'url', ['ItemIDs' => "$team1->ID, $team3->ID, $team2->ID"], ['action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()]);
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set($this->form->getSecurityToken()->getName(), $this->form->getSecurityToken()->getValue());
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'saveGridRowSort', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$session->set($stateID, ['grid' => '', 'actionName' => 'saveGridRowSort', 'args' => ['GridFieldSortableRows' => ['sortableToggle' => true]]]);
|
||||
$request->setSession($session);
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
$this->gridField->gridFieldAlterAction(['StateID' => $stateID], $this->form, $request);
|
||||
$this->assertEquals($team2->ID, $this->list->last()->ID, 'User should be able to sort records with ADMIN permission.');
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ class GridFieldSortableRowsTest extends SapphireTest
|
||||
//Force versioned to reset
|
||||
Versioned::reset();
|
||||
|
||||
$list = GridFieldAction_SortOrder_VTeam::get();
|
||||
$list = VTeam::get();
|
||||
$this->gridField->setList($list);
|
||||
|
||||
/** @var GridFieldSortableRows $sortableGrid */
|
||||
@ -100,67 +100,22 @@ class GridFieldSortableRowsTest extends SapphireTest
|
||||
$item->publish('Stage', 'Live');
|
||||
}
|
||||
|
||||
$team1 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_VTeam', 'team1');
|
||||
$team2 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_VTeam', 'team2');
|
||||
$team3 = $this->objFromFixture('UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_VTeam', 'team3');
|
||||
$team1 = $this->objFromFixture(VTeam::class, 'team1');
|
||||
$team2 = $this->objFromFixture(VTeam::class, 'team2');
|
||||
$team3 = $this->objFromFixture(VTeam::class, 'team3');
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest('POST', 'url', array('ItemIDs' => "$team1->ID, $team3->ID, $team2->ID"), array('action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()));
|
||||
$request = new HTTPRequest('POST', 'url', ['ItemIDs' => "$team1->ID, $team3->ID, $team2->ID"], ['action_gridFieldAlterAction?StateID=' . $stateID => true, $this->form->getSecurityToken()->getName() => $this->form->getSecurityToken()->getValue()]);
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set($this->form->getSecurityToken()->getName(), $this->form->getSecurityToken()->getValue());
|
||||
$session->set($stateID, array('grid' => '', 'actionName' => 'saveGridRowSort', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
|
||||
$session->set($stateID, ['grid' => '', 'actionName' => 'saveGridRowSort', 'args' => ['GridFieldSortableRows' => ['sortableToggle' => true]]]);
|
||||
$request->setSession($session);
|
||||
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
|
||||
$this->gridField->gridFieldAlterAction(['StateID' => $stateID], $this->form, $request);
|
||||
|
||||
$this->assertEquals($team2->ID, $list->last()->ID, 'Sort should have happened on Versioned stage "Stage"');
|
||||
|
||||
$list = Versioned::get_by_stage(GridFieldAction_SortOrder_VTeam::class, 'Live');
|
||||
$list = Versioned::get_by_stage(VTeam::class, 'Live');
|
||||
$this->assertEquals($team2->ID, $list->last()->ID, 'Sort should have happened on Versioned stage "Live"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class GridFieldAction_SortOrder_Team
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* @property string Name
|
||||
* @property string City
|
||||
* @property int SortOrder
|
||||
*/
|
||||
class GridFieldAction_SortOrder_Team extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_Team';
|
||||
|
||||
private static $db = array(
|
||||
'Name' => DBVarchar::class,
|
||||
'City' => DBVarchar::class,
|
||||
'SortOrder' => 'Int'
|
||||
);
|
||||
|
||||
private static $default_sort = 'SortOrder';
|
||||
}
|
||||
|
||||
/**
|
||||
* Class GridFieldAction_SortOrder_VTeam
|
||||
*
|
||||
* @package SortableGridField\Tests
|
||||
* @property string Name
|
||||
* @property string City
|
||||
* @property int SortOrder
|
||||
*/
|
||||
class GridFieldAction_SortOrder_VTeam extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_VTeam';
|
||||
|
||||
private static $db = array(
|
||||
'Name' => DBVarchar::class,
|
||||
'City' => DBVarchar::class,
|
||||
'SortOrder' => DBInt::class
|
||||
);
|
||||
private static $default_sort = 'SortOrder';
|
||||
|
||||
private static $extensions = array(
|
||||
"SilverStripe\\Versioned\\Versioned('Stage', 'Live')"
|
||||
);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_Team:
|
||||
UndefinedOffset\SortableGridField\Tests\Forms\RowsTest\Team:
|
||||
team1:
|
||||
Name: Team 1
|
||||
City: Cologne
|
||||
@ -12,7 +12,7 @@ UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_Team:
|
||||
City: Auckland
|
||||
SortOrder: 3
|
||||
|
||||
UndefinedOffset\SortableGridField\Tests\GridFieldAction_SortOrder_VTeam:
|
||||
UndefinedOffset\SortableGridField\Tests\Forms\RowsTest\VTeam:
|
||||
team1:
|
||||
Name: Team 1
|
||||
City: Cologne
|
||||
|
25
tests/PHPUnit/Forms/RowsPageTest/Team.php
Normal file
25
tests/PHPUnit/Forms/RowsPageTest/Team.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace UndefinedOffset\SortableGridField\Tests\Forms\RowsPageTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
|
||||
/**
|
||||
* Class \UndefinedOffset\SortableGridField\Tests\Forms\RowsPageTest\Team
|
||||
*
|
||||
* @property string Name
|
||||
* @property string City
|
||||
* @property int SortOrder
|
||||
*/
|
||||
class Team extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_PageSortOrder_Team';
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Varchar',
|
||||
'City' => 'Varchar',
|
||||
'SortOrder' => 'Int',
|
||||
];
|
||||
|
||||
private static $default_sort = 'SortOrder';
|
||||
}
|
30
tests/PHPUnit/Forms/RowsPageTest/VTeam.php
Normal file
30
tests/PHPUnit/Forms/RowsPageTest/VTeam.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace UndefinedOffset\SortableGridField\Tests\Forms\RowsPageTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
/**
|
||||
* Class \UndefinedOffset\SortableGridField\Tests\Forms\RowsPageTest\VTeam
|
||||
*
|
||||
* @property string Name
|
||||
* @property string City
|
||||
* @property int SortOrder
|
||||
*/
|
||||
class VTeam extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_PageSortOrder_VTeam';
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Varchar',
|
||||
'City' => 'Varchar',
|
||||
'SortOrder' => 'Int',
|
||||
];
|
||||
|
||||
private static $default_sort = 'SortOrder';
|
||||
|
||||
private static $extensions = [
|
||||
Versioned::class,
|
||||
];
|
||||
}
|
25
tests/PHPUnit/Forms/RowsTest/Team.php
Normal file
25
tests/PHPUnit/Forms/RowsTest/Team.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace UndefinedOffset\SortableGridField\Tests\Forms\RowsTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
|
||||
/**
|
||||
* Class \UndefinedOffset\SortableGridField\Tests\Forms\RowsTest\Team
|
||||
*
|
||||
* @property string Name
|
||||
* @property string City
|
||||
* @property int SortOrder
|
||||
*/
|
||||
class Team extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_Team';
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Varchar',
|
||||
'City' => 'Varchar',
|
||||
'SortOrder' => 'Int',
|
||||
];
|
||||
|
||||
private static $default_sort = 'SortOrder';
|
||||
}
|
29
tests/PHPUnit/Forms/RowsTest/VTeam.php
Normal file
29
tests/PHPUnit/Forms/RowsTest/VTeam.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace UndefinedOffset\SortableGridField\Tests\Forms\RowsTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
/**
|
||||
* Class \UndefinedOffset\SortableGridField\Tests\Forms\RowsTest\VTeam
|
||||
*
|
||||
* @property string Name
|
||||
* @property string City
|
||||
* @property int SortOrder
|
||||
*/
|
||||
class VTeam extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldAction_SortOrder_VTeam';
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Varchar',
|
||||
'City' => 'Varchar',
|
||||
'SortOrder' => 'Int',
|
||||
];
|
||||
private static $default_sort = 'SortOrder';
|
||||
|
||||
private static $extensions = [
|
||||
Versioned::class,
|
||||
];
|
||||
}
|
Loading…
Reference in New Issue
Block a user