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

ManageableObjectDataExtensionTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 90
Duplicated Lines 46.67 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 42
loc 90
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetEditLink() 0 13 1
A testGetDeleteLink() 0 13 1
A logOut() 0 4 2
A testGetListingPage() 0 4 1
A testGetAddLink() 0 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * Class ManageableObjectDataExtensionTest
5
 */
6
class ManageableObjectDataExtensionTest extends SapphireTest
0 ignored issues
show
Bug introduced by
The type SapphireTest 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
     * Ensure any current member is logged out
24
     */
25
    public function logOut()
26
    {
27
        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...
28
            $member->logOut();
29
        }
30
    }
31
32
    /**
33
     *
34
     */
35
    public function testGetListingPage()
36
    {
37
        $this->assertEquals(SampleManageableObjectPage::class,
38
            Injector::inst()->get(SampleManageableDataObject::class)->getListingPage());
0 ignored issues
show
Bug introduced by
The type Injector 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...
39
    }
40
41
    /**
42
     *
43
     */
44
    public function testGetAddLink()
45
    {
46
        $page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
47
        $object = $this->objFromFixture(SampleManageableDataObject::class, 'one');
48
49
        $this->logOut();
50
        $this->assertFalse($object->getAddLink());
51
52
        $this->logInWithPermission('MDO_Create');
53
54
        $this->assertEquals($page->Link('add'), $object->getAddLink());
55
56
        $this->logOut();
57
    }
58
59
    /**
60
     *
61
     */
62
    public function testGetEditLink()
63
    {
64
        $page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
65
        $object = $this->objFromFixture(SampleManageableDataObject::class, 'one');
66
67
        $this->logOut();
68
        $this->assertFalse($object->getEditLink());
69
70
        $this->logInWithPermission('MDO_Edit');
71
72
        $this->assertEquals(Controller::join_links($page->Link('edit'), $object->ID), $object->getEditLink());
0 ignored issues
show
Bug introduced by
The type 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...
73
74
        $this->logOut();
75
    }
76
77
    /**
78
     *
79
     */
80
    public function testGetDeleteLink()
81
    {
82
        $page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
83
        $object = $this->objFromFixture(SampleManageableDataObject::class, 'one');
84
85
        $this->logOut();
86
        $this->assertFalse($object->getDeleteLink());
87
88
        $this->logInWithPermission('MDO_Delete');
89
90
        $this->assertEquals(Controller::join_links($page->Link('delete'), $object->ID), $object->getDeleteLink());
91
92
        $this->logOut();
93
    }
94
95
}