Completed
Pull Request — 1.0 (#28)
by Nic
13:11
created

CatalogProductInquiryTest   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 126
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 3
dl 28
loc 126
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A logOut() 0 6 2
A testGetCMSFields() 0 4 1
A testGetFrontEndFields() 0 9 2
A testGetFrontEndActions() 0 6 1
A testGetFrontEndRequiredFields() 0 7 1
A testProvidePermissions() 0 15 1
A testCanCreate() 0 4 1
A testCanEdit() 0 4 1
A testCanView() 14 14 2
A testCanDelete() 14 14 2

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 CatalogProductInquiryTest
5
 */
6
class CatalogProductInquiryTest extends SapphireTest
7
{
8
9
    /**
10
     * @var string
11
     */
12
    protected static $fixture_file = 'product-catalog/tests/fixtures.yml';
13
14
    /**
15
     * Ensure any current member is logged out
16
     */
17
    public function logOut()
18
    {
19
        if ($member = Member::currentUser()) {
20
            $member->logOut();
21
        }
22
    }
23
24
    /**
25
     *
26
     */
27
    public function testGetCMSFields()
28
    {
29
        $this->assertInstanceOf('FieldList', Injector::inst()->get('CatalogProductInquiry')->getCMSFields());
30
    }
31
32
    /**
33
     *
34
     */
35
    public function testGetFrontEndFields()
36
    {
37
        $fields = Injector::inst()->get('CatalogProductInquiry')->getFrontEndFields();
38
        $this->assertInstanceOf('FieldList', $fields);
39
        if ($fields->dataFieldByName('ProductID')) {
40
            $fields->dataFieldByName('ProductID')->setValue(2);
41
        }
42
        $this->assertInstanceOf('HiddenField', $fields->dataFieldByName('ProductID'));
43
    }
44
45
    /**
46
     *
47
     */
48
    public function testGetFrontEndActions()
49
    {
50
        $actions = Injector::inst()->get('CatalogProductInquiry')->getFrontEndActions();
51
        $this->assertInstanceOf('FieldList', $actions);
52
        $this->assertInstanceOf('FormAction', $actions->fieldByName('action_doProductInquiry'));
53
    }
54
55
    /**
56
     *
57
     */
58
    public function testGetFrontEndRequiredFields()
59
    {
60
        $requiredFields = Injector::inst()->get('CatalogProductInquiry')->getFrontEndRequiredFields();
61
        $this->assertInstanceOf('RequiredFields', $requiredFields);
62
        $this->assertTrue($requiredFields->fieldIsRequired('Name'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<CatalogProductInquiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
        $this->assertTrue($requiredFields->fieldIsRequired('Email'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<CatalogProductInquiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
    }
65
66
    /**
67
     *
68
     */
69
    public function testProvidePermissions()
70
    {
71
        $expected = [
72
            'CatalogProductInquiry_delete' => [
73
                'name' => 'Delete a Product Inquiry',
74
                'category' => 'Product InquiryPermissions',
75
            ],
76
            'CatalogProductInquiry_view' => [
77
                'name' => 'View a Product Inquiry',
78
                'category' => 'Product InquiryPermissions',
79
            ],
80
        ];
81
82
        $this->assertEquals($expected, Injector::inst()->get('CatalogProductInquiry')->providePermissions());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CatalogProductInquiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
    }
84
85
    /**
86
     *
87
     */
88
    public function testCanCreate()
89
    {
90
        $this->assertTrue(Injector::inst()->get('CatalogProductInquiry')->canCreate());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<CatalogProductInquiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
    }
92
93
    /**
94
     *
95
     */
96
    public function testCanEdit()
97
    {
98
        $this->assertFalse(Injector::inst()->get('CatalogProductInquiry')->canEdit());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<CatalogProductInquiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
    }
100
101 View Code Duplication
    public function testCanView()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
    {
103
        if ($member = Member::currentUser()) {
0 ignored issues
show
Unused Code introduced by
$member is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
104
            $this->logOut();
105
        }
106
107
        $inquiry = Injector::inst()->get('CatalogProductInquiry');
108
        $this->assertFalse($inquiry->canView());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<CatalogProductInquiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
109
110
        $this->logInWithPermission('CatalogProductInquiry_view');
111
        $this->assertTrue($inquiry->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<CatalogProductInquiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
112
113
        $this->logOut();
114
    }
115
116 View Code Duplication
    public function testCanDelete()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
    {
118
        if ($member = Member::currentUser()) {
0 ignored issues
show
Unused Code introduced by
$member is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
119
            $this->logOut();
120
        }
121
122
        $inquiry = Injector::inst()->get('CatalogProductInquiry');
123
        $this->assertFalse($inquiry->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<CatalogProductInquiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
124
125
        $this->logInWithPermission('CatalogProductInquiry_delete');
126
        $this->assertTrue($inquiry->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<CatalogProductInquiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
127
128
        $this->logOut();
129
    }
130
131
}