Completed
Push — master ( fb1da0...84ba9e )
by Nic
10s
created

ProductWishListTest::testGetFrontEndActions()   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 TestProductWishListTest
5
 */
6
class ProductWishListTest extends SapphireTest
7
{
8
9
    /**
10
     * @var string
11
     */
12
    protected 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('TestProductWishList', '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('TestProductWishList', 'one');
41
        $canAccess = $this->objFromFixture('Member', 'cancreate');
42
        $cantAccess = $this->objFromFixture('Member', 'cantcreate');
0 ignored issues
show
Unused Code introduced by
$cantAccess 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...
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
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...
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('TestProductWishList', 'one');
54
        $canAccess = $this->objFromFixture('Member', 'cancreate');
55
        $cantAccess = $this->objFromFixture('Member', 'cantcreate');
0 ignored issues
show
Unused Code introduced by
$cantAccess 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...
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
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...
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('TestProductWishList', '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('TestProductWishList', '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' => [
86
                'name' => 'Edit a Wish List',
87
                'category' => 'Wish List Permissions',
88
            ],
89
            'WishList_DELETE' => [
90
                'name' => 'Delete a Wish List',
91
                'category' => 'Wish List Permissions',
92
            ],
93
            'WishList_CREATE' => [
94
                'name' => 'Create a Wish List',
95
                'category' => 'Wish List Permissions',
96
            ],
97
            'WishList_VIEW' => [
98
                'name' => 'View a Wish List',
99
                'category' => 'Wish List Permissions',
100
            ],
101
        ];
102
103
        $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...
104
    }
105
106
    /**
107
     *
108
     */
109
    public function testGetViewAction()
110
    {
111
        $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...
112
    }
113
114
    /**
115
     *
116
     */
117
    public function testGetFrontEndRequiredFields()
118
    {
119
        $this->assertInstanceOf('RequiredFields',
120
            Injector::inst()->get('ProductWishList')->getFrontEndRequiredFields());
121
122
        $wishList = $this->objFromFixture('TestProductWishList', 'one');
123
        $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...
124
    }
125
126
    /**
127
     *
128
     */
129
    public function testGetFrontEndActions()
130
    {
131
        $this->assertInstanceOf('FieldList', Injector::inst()->get('ProductWishList')->getFrontEndActions());
132
133
        $wishList = $this->objFromFixture('TestProductWishList', 'one');
134
        $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...
135
        $this->assertInstanceOf('CancelFormAction',
136
            $wishList->getFrontEndActions(true)->dataFieldByName('action_CancelFormAction'));
137
138
        $this->assertInstanceOf('FormAction', $wishList->getFrontEndActions()->dataFieldByName('action_OtherAction'));
139
    }
140
141
    /**
142
     *
143
     */
144
    public function testGetFrontEndFields()
145
    {
146
        $baseFields = Injector::inst()->get('ProductWishList')->getFrontEndFields();
147
        $this->assertInstanceOf('FieldList', $baseFields);
148
        $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...
149
150
        $wishList = $this->objFromFixture('TestProductWishList', 'four');
151
        $updatedFields = $wishList->getFrontEndFields();
152
        $this->assertInstanceOf('FieldList', $updatedFields);
153
        $this->assertInstanceOf('TextareaField', $updatedFields->dataFieldByName('OtherField'));
154
    }
155
156
}