Completed
Pull Request — master (#12)
by Matthew
13:05
created

ManageableDataObjectExtensionTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
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()) {
0 ignored issues
show
Unused Code introduced by
The assignment to $member is dead and can be removed.
Loading history...
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'));
0 ignored issues
show
Bug introduced by
The type Dynamic\ManageableDataOb...leObjectPage_Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
107
        $form = $controller->Form();
0 ignored issues
show
Unused Code introduced by
The assignment to $form is dead and can be removed.
Loading history...
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);
0 ignored issues
show
Unused Code introduced by
The assignment to $responseSubmission is dead and can be removed.
Loading history...
114
115
        $record = SampleManageableDataObject::get()->filter($data)->first();
116
        $this->assertInstanceOf(SampleManageableDataObject::class, $record);
117
        $this->assertTrue($record->exists());//*/
118
    }
119
120
}
121