|
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\Dev\FunctionalTest; |
|
8
|
|
|
use SilverStripe\Security\Security; |
|
9
|
|
|
use SilverStripe\View\SSViewer; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class ManageableDataObjectExtensionTest |
|
13
|
|
|
*/ |
|
14
|
|
|
class ManageableDataObjectExtensionTest extends FunctionalTest |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected static $fixture_file = '../fixtures.yml'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $extraDataObjects = [ |
|
26
|
|
|
SampleManageableDataObject::class, |
|
27
|
|
|
SampleManageableObjectPage::class, |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* |
|
32
|
|
|
*/ |
|
33
|
|
|
public function setUp() |
|
34
|
|
|
{ |
|
35
|
|
|
parent::setUp(); |
|
36
|
|
|
// Suppress themes |
|
37
|
|
|
SSViewer::config()->update('theme_enabled', false); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Ensure any current member is logged out |
|
42
|
|
|
*/ |
|
43
|
|
|
public function logOut() |
|
44
|
|
|
{ |
|
45
|
|
|
if ($member = Security::getCurrentUser()) { |
|
|
|
|
|
|
46
|
|
|
Security::setCurrentUser(null); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testAdd() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->logInWithPermission('MDO_Create'); |
|
56
|
|
|
$response = $this->get('/SampleManageableObjectPage_Controller/add'); |
|
57
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
58
|
|
|
$this->logOut(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testEdit() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->logInWithPermission('MDO_Edit'); |
|
67
|
|
|
$object = $this->objFromFixture(SampleManageableDataObject::class, 'one'); |
|
68
|
|
|
$response = $this->get('/SampleManageableObjectPage_Controller/edit/' . $object->ID); |
|
69
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
70
|
|
|
$this->logOut(); |
|
71
|
|
|
|
|
72
|
|
|
$response2 = $this->get('/SampleManageableObjectPage_Controller/edit/' . 0); |
|
73
|
|
|
$this->assertEquals(404, $response2->getStatusCode()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testDelete() |
|
80
|
|
|
{ |
|
81
|
|
|
$newObject = SampleManageableDataObject::create(); |
|
82
|
|
|
$newObject->Title = 'Foo'; |
|
83
|
|
|
$newObject->write(); |
|
84
|
|
|
|
|
85
|
|
|
$id = $newObject->ID; |
|
86
|
|
|
|
|
87
|
|
|
$this->logInWithPermission('MDO_Delete'); |
|
88
|
|
|
|
|
89
|
|
|
$response404 = $this->get('/SampleManageableObjectPage_Controller/delete/' . 0); |
|
90
|
|
|
$this->assertEquals(404, $response404->getStatusCode()); |
|
91
|
|
|
|
|
92
|
|
|
$success = $this->get('/SampleManageableObjectPage_Controller/delete/' . $id); |
|
93
|
|
|
$this->assertEquals(200, $success->getStatusCode()); |
|
94
|
|
|
$this->assertNull(SampleManageableDataObject::get()->byID($id)); |
|
95
|
|
|
|
|
96
|
|
|
$this->logOut(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* |
|
101
|
|
|
*/ |
|
102
|
|
|
public function testDoSaveObject() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->logInWithPermission('MDO_Create'); |
|
105
|
|
|
|
|
106
|
|
|
$controller = SamplemanageableObjectPage_Controller::create($this->objFromFixture(SampleManageableObjectPage::class, 'one')); |
|
|
|
|
|
|
107
|
|
|
$form = $controller->Form(); |
|
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
$response = $this->get('/SampleManageableObjectPage_Controller/add'); |
|
110
|
|
|
$this->assertEquals(200, $response->getStatusCode(), 'Submission successful'); |
|
111
|
|
|
|
|
112
|
|
|
$data = ['Title' => 'Foobar']; |
|
113
|
|
|
$responseSubmission = $this->submitForm('ManageableDataObjectForm_Form', 'action_doSaveObject', $data); |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
$record = SampleManageableDataObject::get()->filter($data)->first(); |
|
116
|
|
|
$this->assertInstanceOf(SampleManageableDataObject::class, $record); |
|
117
|
|
|
$this->assertTrue($record->exists());//*/ |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
|