1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeKoala\Tabulator\Tests; |
4
|
|
|
|
5
|
|
|
use LeKoala\Tabulator\TabulatorGrid; |
6
|
|
|
use LeKoala\Tabulator\TabulatorGrid_ItemRequest; |
7
|
|
|
use SilverStripe\Dev\SapphireTest; |
8
|
|
|
use SilverStripe\Control\Controller; |
9
|
|
|
use SilverStripe\Security\Group; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Tests for Cms Actions module |
13
|
|
|
*/ |
14
|
|
|
class TabulatorTest extends SapphireTest |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Defines the fixture file to use for this test class |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected static $fixture_file = 'TabulatorTest.yml'; |
21
|
|
|
|
22
|
|
|
protected static $extra_dataobjects = []; |
23
|
|
|
|
24
|
|
|
public function setUp(): void |
25
|
|
|
{ |
26
|
|
|
parent::setUp(); |
27
|
|
|
$controller = Controller::curr(); |
28
|
|
|
$controller->config()->set('url_segment', 'test_controller'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function tearDown(): void |
32
|
|
|
{ |
33
|
|
|
parent::tearDown(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testItSorts() |
37
|
|
|
{ |
38
|
|
|
// delete groups without sort |
39
|
|
|
$noSortGroup = Group::get()->filter('Sort', 0); |
40
|
|
|
$noSortGroup->removeAll(); |
41
|
|
|
|
42
|
|
|
$list = Group::get(); |
43
|
|
|
$t = new TabulatorGrid('Groups', 'Groups', $list); |
44
|
|
|
$rec = Group::get()->first(); |
45
|
|
|
$controller = Controller::curr(); |
46
|
|
|
$tir = new TabulatorGrid_ItemRequest($t, $rec, $controller); |
47
|
|
|
|
48
|
|
|
// { |
49
|
|
|
// "1": 1, |
50
|
|
|
// "2": 2, |
51
|
|
|
// "3": 3 |
52
|
|
|
// } |
53
|
|
|
$CurrentOrder = []; |
54
|
|
|
foreach ($list as $record) { |
55
|
|
|
$CurrentOrder[$record->ID] = $record->Sort; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// The record being edited |
59
|
|
|
$Data = [ |
60
|
|
|
'ID' => 1, |
61
|
|
|
'Sort' => 1, |
62
|
|
|
]; |
63
|
|
|
// The new sort order |
64
|
|
|
$Sort = 2; |
65
|
|
|
|
66
|
|
|
$newSort = $tir->executeSort($Data, $Sort); |
67
|
|
|
|
68
|
|
|
$list = Group::get(); |
69
|
|
|
|
70
|
|
|
// { |
71
|
|
|
// "1": 2, |
72
|
|
|
// "2": 1, |
73
|
|
|
// "3": 3 |
74
|
|
|
// } |
75
|
|
|
$NewOrder = []; |
76
|
|
|
foreach ($list as $record) { |
77
|
|
|
$NewOrder[$record->ID] = $record->Sort; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$this->assertEquals($Sort, $newSort); |
81
|
|
|
$this->assertNotEquals($CurrentOrder, $NewOrder); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|