1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\ManageableDataObject\Test\Extensions; |
4
|
|
|
|
5
|
|
|
use Dynamic\ManageableDataObject\Test\Model\SampleManageableDataObject; |
6
|
|
|
use Dynamic\ManageableDataObject\Test\Model\SampleManageableObjectPage; |
7
|
|
|
use SilverStripe\Control\Controller; |
8
|
|
|
use SilverStripe\Core\Injector\Injector; |
9
|
|
|
use SilverStripe\Dev\SapphireTest; |
10
|
|
|
use SilverStripe\Security\Security; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class ManageableObjectDataExtensionTest |
14
|
|
|
*/ |
15
|
|
|
class ManageableObjectDataExtensionTest extends SapphireTest |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected static $fixture_file = '../fixtures.yml'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected static $extra_dataobjects = [ |
27
|
|
|
SampleManageableDataObject::class, |
28
|
|
|
SampleManageableObjectPage::class, |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Ensure any current member is logged out |
33
|
|
|
*/ |
34
|
|
|
public function logOut() |
35
|
|
|
{ |
36
|
|
|
if ($member = Security::getCurrentUser()) { |
|
|
|
|
37
|
|
|
Security::setCurrentUser(null); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* |
43
|
|
|
*/ |
44
|
|
|
public function testGetListingPage() |
45
|
|
|
{ |
46
|
|
|
$this->assertEquals(SampleManageableObjectPage::class, |
47
|
|
|
Injector::inst()->get(SampleManageableDataObject::class)->getListingPage()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* |
52
|
|
|
*/ |
53
|
|
|
public function testGetAddLink() |
54
|
|
|
{ |
55
|
|
|
/** @var SampleManageableObjectPage $page */ |
56
|
|
|
$page = $this->objFromFixture(SampleManageableObjectPage::class, 'one'); |
57
|
|
|
/** @var SampleManageableDataObject $object */ |
58
|
|
|
$object = $this->objFromFixture(SampleManageableDataObject::class, 'one'); |
59
|
|
|
|
60
|
|
|
$this->logOut(); |
61
|
|
|
$this->assertFalse($object->getAddLink()); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$this->logInWithPermission('MDO_Create'); |
64
|
|
|
|
65
|
|
|
$this->assertEquals($page->Link('add'), $object->getAddLink()); |
66
|
|
|
|
67
|
|
|
$this->logOut(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* |
72
|
|
|
*/ |
73
|
|
|
public function testGetEditLink() |
74
|
|
|
{ |
75
|
|
|
/** @var SampleManageableObjectPage $page */ |
76
|
|
|
$page = $this->objFromFixture(SampleManageableObjectPage::class, 'one'); |
77
|
|
|
/** @var SampleManageableDataObject $object */ |
78
|
|
|
$object = $this->objFromFixture(SampleManageableDataObject::class, 'one'); |
79
|
|
|
|
80
|
|
|
$this->logOut(); |
81
|
|
|
$this->assertFalse($object->getEditLink()); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$this->logInWithPermission('MDO_Edit'); |
84
|
|
|
|
85
|
|
|
$this->assertEquals(Controller::join_links($page->Link('edit'), $object->ID), $object->getEditLink()); |
86
|
|
|
|
87
|
|
|
$this->logOut(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* |
92
|
|
|
*/ |
93
|
|
|
public function testGetDeleteLink() |
94
|
|
|
{ |
95
|
|
|
/** @var SampleManageableObjectPage $page */ |
96
|
|
|
$page = $this->objFromFixture(SampleManageableObjectPage::class, 'one'); |
97
|
|
|
/** @var SampleManageableDataObject $object */ |
98
|
|
|
$object = $this->objFromFixture(SampleManageableDataObject::class, 'one'); |
99
|
|
|
|
100
|
|
|
$this->logOut(); |
101
|
|
|
$this->assertFalse($object->getDeleteLink()); |
|
|
|
|
102
|
|
|
|
103
|
|
|
$this->logInWithPermission('MDO_Delete'); |
104
|
|
|
|
105
|
|
|
$this->assertEquals(Controller::join_links($page->Link('delete'), $object->ID), $object->getDeleteLink()); |
106
|
|
|
|
107
|
|
|
$this->logOut(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|