|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ilateral\SilverStripe\ModelAdminPlus\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Control\Session; |
|
6
|
|
|
use SilverStripe\Core\Config\Config; |
|
7
|
|
|
use SilverStripe\Dev\FunctionalTest; |
|
8
|
|
|
use SilverStripe\Control\HTTPRequest; |
|
9
|
|
|
use SilverStripe\Security\Permission; |
|
10
|
|
|
use ilateral\SilverStripe\ModelAdminPlus\Tests\Contact; |
|
11
|
|
|
use ilateral\SilverStripe\ModelAdminPlus\ModelAdminPlus; |
|
12
|
|
|
use ilateral\SilverStripe\ModelAdminPlus\Tests\ContactAdmin; |
|
13
|
|
|
|
|
14
|
|
|
class ModelAdminPlusTest extends FunctionalTest |
|
15
|
|
|
{ |
|
16
|
|
|
protected static $fixture_file = 'ModelAdminPlusTest.yml'; |
|
17
|
|
|
|
|
18
|
|
|
protected static $extra_dataobjects = [ |
|
19
|
|
|
Contact::class |
|
20
|
|
|
]; |
|
21
|
|
|
|
|
22
|
|
|
protected static $extra_controllers = [ |
|
23
|
|
|
ContactAdmin::class |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The currently instantiated ModeAdmin instance |
|
28
|
|
|
* |
|
29
|
|
|
* @var ModelAdminPlus |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $curr_admin; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Add some extra functionality on construction |
|
35
|
|
|
* |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
|
|
public function setUp() |
|
39
|
|
|
{ |
|
40
|
|
|
parent::setUp(); |
|
41
|
|
|
|
|
42
|
|
|
$admin = ContactAdmin::create(); |
|
43
|
|
|
$request = new HTTPRequest('GET', '/'); |
|
44
|
|
|
$request->setSession(new Session([])); |
|
45
|
|
|
$admin->setRequest($request); |
|
46
|
|
|
$admin->doInit(); |
|
47
|
|
|
$this->curr_admin = $admin; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testExportFields() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->assertEquals( |
|
53
|
|
|
$this->curr_admin->getExportFields(), |
|
54
|
|
|
Config::inst()->get(Contact::class, ModelAdminPlus::EXPORT_FIELDS) |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testGetSearchSessionName() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->assertEquals( |
|
61
|
|
|
$this->curr_admin->getSearchSessionName(), |
|
62
|
|
|
str_replace( |
|
63
|
|
|
'\\', |
|
64
|
|
|
'-', |
|
65
|
|
|
ModelAdminPlus::class . "." . Contact::class |
|
66
|
|
|
) |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testSearchSession() |
|
71
|
|
|
{ |
|
72
|
|
|
// First check session is empty |
|
73
|
|
|
$this->assertNull( |
|
74
|
|
|
$this->curr_admin->getSearchSession() |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
// Now set the search session |
|
78
|
|
|
$data = ["Name" => "Mark"]; |
|
79
|
|
|
$this->curr_admin->setSearchSession($data); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertEquals( |
|
82
|
|
|
$this->curr_admin->getSearchSession(), |
|
83
|
|
|
$data |
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
// Finally check clearing the session works |
|
87
|
|
|
$this->curr_admin->clearSearchSession(); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertNull( |
|
90
|
|
|
$this->curr_admin->getSearchSession() |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testSearchData() |
|
95
|
|
|
{ |
|
96
|
|
|
// First check session is empty |
|
97
|
|
|
$this->assertEquals( |
|
98
|
|
|
$this->curr_admin->getSearchData(), |
|
99
|
|
|
[] |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
// Now set the search session |
|
103
|
|
|
$data = ["Name" => "Mark"]; |
|
104
|
|
|
$this->curr_admin->setSearchSession($data); |
|
105
|
|
|
|
|
106
|
|
|
$this->assertEquals( |
|
107
|
|
|
$this->curr_admin->getSearchData(), |
|
108
|
|
|
$data |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|