Completed
Pull Request — master (#1)
by Nic
03:25
created

ProductWishListTest::testProvidePermissions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
/**
4
 * Class ProductWishListTest
5
 */
6
class ProductWishListTest extends SapphireTest
7
{
8
9
    /**
10
     * @var string
11
     */
12
    public static $fixture_file = 'product-wishlist/tests/fixtures.yml';
13
14
    /**
15
     * @var array
16
     */
17
    protected $extraDataObjects = [
18
        'TestWishListPage',
19
        'TestProductWishList',
20
    ];
21
22
    /**
23
     *
24
     */
25 View Code Duplication
    public function testCanCreate()
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...
26
    {
27
        $wishList = $this->objFromFixture('ProductWishList', 'one');
28
        $canAccess = $this->objFromFixture('Member', 'cancreate');
29
        $cantAccess = $this->objFromFixture('Member', 'cantcreate');
30
31
        $this->assertTrue($wishList->canCreate($canAccess));
0 ignored issues
show
Bug introduced by
It seems like $canAccess defined by $this->objFromFixture('Member', 'cancreate') on line 28 can also be of type object<DataObject>; however, DataObject::canCreate() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductWishListTest>.

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...
32
        $this->assertFalse($wishList->canCreate($cantAccess));
0 ignored issues
show
Bug introduced by
It seems like $cantAccess defined by $this->objFromFixture('Member', 'cantcreate') on line 29 can also be of type object<DataObject>; however, DataObject::canCreate() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertFalse() does not seem to exist on object<ProductWishListTest>.

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...
33
    }
34
35
    /**
36
     *
37
     */
38 View Code Duplication
    public function testCanEdit()
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...
39
    {
40
        $wishList = $this->objFromFixture('ProductWishList', 'one');
41
        $canAccess = $this->objFromFixture('Member', 'cancreate');
42
        $cantAccess = $this->objFromFixture('Member', 'cantcreate');
43
44
        $this->assertTrue($wishList->canEdit($canAccess));
0 ignored issues
show
Bug introduced by
It seems like $canAccess defined by $this->objFromFixture('Member', 'cancreate') on line 41 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductWishListTest>.

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...
45
        $this->assertFalse($wishList->canEdit($cantAccess));
0 ignored issues
show
Bug introduced by
It seems like $cantAccess defined by $this->objFromFixture('Member', 'cantcreate') on line 42 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertFalse() does not seem to exist on object<ProductWishListTest>.

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...
46
    }
47
48
    /**
49
     *
50
     */
51 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...
52
    {
53
        $wishList = $this->objFromFixture('ProductWishList', 'one');
54
        $canAccess = $this->objFromFixture('Member', 'cancreate');
55
        $cantAccess = $this->objFromFixture('Member', 'cantcreate');
56
57
        $this->assertTrue($wishList->canDelete($canAccess));
0 ignored issues
show
Bug introduced by
It seems like $canAccess defined by $this->objFromFixture('Member', 'cancreate') on line 54 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductWishListTest>.

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...
58
        $this->assertFalse($wishList->canDelete($cantAccess));
0 ignored issues
show
Bug introduced by
It seems like $cantAccess defined by $this->objFromFixture('Member', 'cantcreate') on line 55 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertFalse() does not seem to exist on object<ProductWishListTest>.

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...
59
    }
60
61
    /**
62
     *
63
     */
64 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...
65
    {
66
        $wishList = $this->objFromFixture('ProductWishList', 'one');
67
        $canAccess = $this->objFromFixture('Member', 'cancreate');
68
        $cantAccess = $this->objFromFixture('Member', 'cantcreate');
69
70
        $this->assertTrue($wishList->canView($canAccess));
0 ignored issues
show
Bug introduced by
It seems like $canAccess defined by $this->objFromFixture('Member', 'cancreate') on line 67 can also be of type object<DataObject>; however, DataObject::canView() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductWishListTest>.

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...
71
        //todo fix following assertion
72
        //$this->assertFalse($wishList->canView($cantAccess));
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
73
74
        $viewableWishList = $this->objFromFixture('ProductWishList', 'three');
75
76
        $this->assertTrue($viewableWishList->canView($cantAccess));
0 ignored issues
show
Bug introduced by
It seems like $cantAccess defined by $this->objFromFixture('Member', 'cantcreate') on line 68 can also be of type object<DataObject>; however, DataObject::canView() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductWishListTest>.

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...
77
    }
78
79
    /**
80
     *
81
     */
82
    public function testProvidePermissions()
83
    {
84
        $expected = [
85
            'WishList_EDIT' => 'Edit a Wish List',
86
            'WishList_DELETE' => 'Delete a Wish List',
87
            'WishList_CREATE' => 'Create a Wish List',
88
            'WishList_VIEW' => 'View a Wish List',
89
        ];
90
91
        $this->assertEquals($expected, Injector::inst()->get('ProductWishList')->providePermissions());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ProductWishListTest>.

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...
92
    }
93
94
    /**
95
     *
96
     */
97
    public function testGetViewAction()
98
    {
99
        $this->assertEquals('view', Injector::inst()->get('ProductWishList')->getViewAction());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ProductWishListTest>.

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...
100
    }
101
102
    public function testGetUpdateLink()
103
    {
104
        $this->assertFalse(Injector::inst()->get('ProductWishList')->getUpdateLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ProductWishListTest>.

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...
105
106
        $hasLink = $this->objFromFixture('ProductWishList', 'one');
107
        $expected = "update/{$hasLink->ID}";
108
109
        $this->assertEquals($expected, $hasLink->getUpdateLink());
0 ignored issues
show
Bug introduced by
The method getUpdateLink() does not exist on DataObject. Did you maybe mean update()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
Bug introduced by
The method assertEquals() does not seem to exist on object<ProductWishListTest>.

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...
110
    }
111
112
    /**
113
     *
114
     */
115
    public function testGetFrontEndRequiredFields()
116
    {
117
        $this->assertInstanceOf('RequiredFields',
118
            Injector::inst()->get('ProductWishList')->getFrontEndRequiredFields());
119
120
        $wishList = $this->objFromFixture('TestProductWishList', 'one');
121
        $this->assertTrue($wishList->getFrontEndRequiredFields()->fieldIsRequired('OtherField'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductWishListTest>.

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...
122
    }
123
124
    /**
125
     *
126
     */
127
    public function testGetFrontEndActions()
128
    {
129
        $this->assertInstanceOf('FieldList', Injector::inst()->get('ProductWishList')->getFrontEndActions());
130
131
        $wishList = $this->objFromFixture('TestProductWishList', 'one');
132
        $this->assertNull($wishList->getFrontEndActions()->dataFieldByName('action_CancelFormAction'));
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<ProductWishListTest>.

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...
133
        $this->assertInstanceOf('CancelFormAction', $wishList->getFrontEndActions(true)->dataFieldByName('action_CancelFormAction'));
134
135
        $this->assertInstanceOf('FormAction', $wishList->getFrontEndActions()->dataFieldByName('action_OtherAction'));
136
    }
137
138
    /**
139
     *
140
     */
141
    public function testGetFrontEndFields()
142
    {
143
        $baseFields = Injector::inst()->get('ProductWishList')->getFrontEndFields();
144
        $this->assertInstanceOf('FieldList', $baseFields);
145
        $this->assertNull($baseFields->fieldByName('MemberID'));
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<ProductWishListTest>.

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...
146
147
        $wishList = $this->objFromFixture('TestProductWishList', 'one');
148
        $updatedFields = $wishList->getFrontEndFields();
149
        $this->assertInstanceOf('FieldList', $updatedFields);
150
        $this->assertInstanceOf('TextareaField', $updatedFields->dataFieldByName('OtherField'));
151
    }
152
153
}