1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Collection\Test; |
4
|
|
|
|
5
|
|
|
use Dynamic\Collection\Test\TestOnly\TestCollection; |
6
|
|
|
use Dynamic\Collection\Test\TestOnly\TestCollectionController; |
7
|
|
|
use Dynamic\Collection\Test\TestOnly\TestCollectionObject; |
8
|
|
|
use SilverStripe\Dev\FunctionalTest; |
9
|
|
|
use SilverStripe\Forms\Form; |
10
|
|
|
use SilverStripe\ORM\DataList; |
11
|
|
|
use SilverStripe\ORM\GroupedList; |
12
|
|
|
use SilverStripe\ORM\PaginatedList; |
13
|
|
|
|
14
|
|
|
class CollectionExtensionTest extends FunctionalTest |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected static $fixture_file = array( |
20
|
|
|
'fixtures.yml', |
21
|
|
|
); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var bool |
25
|
|
|
*/ |
26
|
|
|
protected static $disable_themes = true; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
protected static $use_draft_site = false; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
protected static $extra_dataobjects = array( |
37
|
|
|
TestCollection::class, |
38
|
|
|
TestCollectionController::class, |
39
|
|
|
TestCollectionObject::class, |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* |
44
|
|
|
*/ |
45
|
|
|
public function setUp() |
46
|
|
|
{ |
47
|
|
|
parent::setUp(); |
48
|
|
|
|
49
|
|
|
ini_set('display_errors', 1); |
50
|
|
|
ini_set('log_errors', 1); |
51
|
|
|
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* |
56
|
|
|
*/ |
57
|
|
|
public function logOut() |
58
|
|
|
{ |
59
|
|
|
$this->session()->clear('loggedInAs'); |
60
|
|
|
$this->session()->clear('logInWithPermission'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* |
65
|
|
|
*/ |
66
|
|
|
public function testGetCollection() |
67
|
|
|
{ |
68
|
|
|
$object = $this->objFromFixture(TestCollection::class, 'default'); |
69
|
|
|
$controller = new TestCollectionController($object); |
70
|
|
|
$this->assertInstanceOf(DataList::class, $controller->getCollection()); |
|
|
|
|
71
|
|
|
|
72
|
|
|
$object = $controller->config()->managed_object; |
73
|
|
|
$this->assertInstanceOf($object, $controller->getCollection()->first()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* |
78
|
|
|
*/ |
79
|
|
|
public function testGetManagedObject() |
80
|
|
|
{ |
81
|
|
|
$object = TestCollectionController::create(); |
82
|
|
|
$expected = TestCollectionObject::class; |
83
|
|
|
$this->assertEquals($expected, $object->getCollectionObject()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* |
88
|
|
|
*/ |
89
|
|
|
public function testGetPageSize() |
90
|
|
|
{ |
91
|
|
|
$object = TestCollectionController::create(); |
92
|
|
|
$expected = 10; |
93
|
|
|
$this->assertEquals($expected, $object->getCollectionSize()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* |
98
|
|
|
*/ |
99
|
|
|
public function testPaginatedList() |
100
|
|
|
{ |
101
|
|
|
$object = $this->objFromFixture(TestCollection::class, 'default'); |
102
|
|
|
$controller = new TestCollectionController($object); |
103
|
|
|
$this->assertInstanceOf(PaginatedList::class, $controller->PaginatedList()); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* |
108
|
|
|
*/ |
109
|
|
|
public function testGroupedList() |
110
|
|
|
{ |
111
|
|
|
$object = $this->objFromFixture(TestCollection::class, 'default'); |
112
|
|
|
$controller = new TestCollectionController($object); |
113
|
|
|
$this->assertInstanceOf(GroupedList::class, $controller->GroupedList()); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* |
118
|
|
|
*/ |
119
|
|
|
public function testCollectionSearchForm() |
120
|
|
|
{ |
121
|
|
|
$object = $this->objFromFixture(TestCollection::class, 'default'); |
122
|
|
|
$controller = new TestCollectionController($object); |
123
|
|
|
$this->assertInstanceOf(Form::class, $controller->CollectionSearchForm()); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|