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

ManageableDataObjectExtensionTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 41
dl 0
loc 104
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A logOut() 0 4 2
A testDoSaveObject() 0 16 1
A setUp() 0 5 1
A testAdd() 0 6 1
A testEdit() 0 10 1
A testDelete() 0 18 1
1
<?php
2
3
/**
4
 * Class ManageableDataObjectExtensionTest
5
 */
6
class ManageableDataObjectExtensionTest extends FunctionalTest
0 ignored issues
show
Bug introduced by
The type FunctionalTest 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...
7
{
8
9
    /**
10
     * @var string
11
     */
12
    protected static $fixture_file = 'fixtures.yml';
13
14
    /**
15
     * @var array
16
     */
17
    protected $extraDataObjects = [
18
        SampleManageableDataObject::class,
19
        SampleManageableObjectPage::class,
20
    ];
21
22
    /**
23
     *
24
     */
25
    public function setUp()
26
    {
27
        parent::setUp();
28
        // Suppress themes
29
        Config::inst()->remove(SSViewer::class, 'theme');
0 ignored issues
show
Bug introduced by
The type Config 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...
Bug introduced by
The type SSViewer 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...
30
    }//*/
31
32
    /**
33
     * Ensure any current member is logged out
34
     */
35
    public function logOut()
36
    {
37
        if ($member = Member::currentUser()) {
0 ignored issues
show
Bug introduced by
The type Member 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...
38
            $member->logOut();
39
        }
40
    }
41
42
    /**
43
     *
44
     */
45
    public function testAdd()
46
    {
47
        $this->logInWithPermission('MDO_Create');
48
        $response = $this->get('/SampleManageableObjectPage_Controller/add');
49
        $this->assertEquals(200, $response->getStatusCode());
50
        $this->logOut();
51
    }
52
53
    /**
54
     *
55
     */
56
    public function testEdit()
57
    {
58
        $this->logInWithPermission('MDO_Edit');
59
        $object = $this->objFromFixture(SampleManageableDataObject::class, 'one');
60
        $response = $this->get('/SampleManageableObjectPage_Controller/edit/' . $object->ID);
61
        $this->assertEquals(200, $response->getStatusCode());
62
        $this->logOut();
63
64
        $response2 = $this->get('/SampleManageableObjectPage_Controller/edit/' . 0);
65
        $this->assertEquals(404, $response2->getStatusCode());
66
    }
67
68
    /**
69
     *
70
     */
71
    public function testDelete()
72
    {
73
        $newObject = SampleManageableDataObject::create();
74
        $newObject->Title = 'Foo';
75
        $newObject->write();
76
77
        $id = $newObject->ID;
78
79
        $this->logInWithPermission('MDO_Delete');
80
81
        $response404 = $this->get('/SampleManageableObjectPage_Controller/delete/' . 0);
82
        $this->assertEquals(404, $response404->getStatusCode());
83
84
        $success = $this->get('/SampleManageableObjectPage_Controller/delete/' . $id);
85
        $this->assertEquals(200, $success->getStatusCode());
86
        $this->assertNull(SampleManageableDataObject::get()->byID($id));
87
88
        $this->logOut();
89
    }
90
91
    /**
92
     *
93
     */
94
    public function testDoSaveObject()
95
    {
96
        $this->logInWithPermission('MDO_Create');
97
98
        $controller = SamplemanageableObjectPage_Controller::create($this->objFromFixture(SampleManageableObjectPage::class, 'one'));
99
        $form = $controller->Form();
0 ignored issues
show
Unused Code introduced by
The assignment to $form is dead and can be removed.
Loading history...
100
101
        $response = $this->get('/SampleManageableObjectPage_Controller/add');
102
        $this->assertEquals(200, $response->getStatusCode(), 'Submission successful');
103
104
        $data = ['Title' => 'Foobar'];
105
        $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...
106
107
        $record = SampleManageableDataObject::get()->filter($data)->first();
108
        $this->assertInstanceOf(SampleManageableDataObject::class, $record);
109
        $this->assertTrue($record->exists());//*/
110
    }
111
112
}