Completed
Pull Request — master (#287)
by Nic
07:49
created

FoxyStripeProductTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * Class FoxyStripeProductTest
5
 */
6
class FoxyStripeProductTest extends SapphireTest
7
{
8
9
    /**
10
     * @var string
11
     */
12
    protected static $fixture_file = 'foxystripe/tests/FoxyStripeTest.yml';
13
14
    /**
15
     *
16
     */
17
    function setUp()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
18
    {
19
        parent::setUp();
20
21
    }
22
23
    /**
24
     *
25
     */
26
    function testProductCreation()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
27
    {
28
29
        //$this->logInWithPermission('Product_CANCRUD');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
30
        $default = $this->objFromFixture('FoxyCartProductCategory', 'default');
31
        $default->write();
32
33
    }
34
35
    /**
36
     *
37
     */
38
    function testProductDeletion()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
39
    {
40
41
        //$this->logInWithPermission('Product_CANCRUD');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
42
        $product2 = $this->objFromFixture('ShippableProduct', 'product2');
43
        $product2->ParentID = ProductHolder::get()->first()->ID;
44
        $productID = $product2->ID;
45
46
        $product2->doPublish();
47
        $this->assertTrue($product2->isPublished());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<FoxyStripeProductTest>.

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...
48
49
        $versions = DB::query('Select * FROM "ShippableProduct_versions" WHERE "RecordID" = ' . $productID);
50
        $versionsPostPublish = array();
51
        foreach ($versions as $versionRow) $versionsPostPublish[] = $versionRow;
52
53
        $product2->delete();
54
        $this->assertTrue(!$product2->isPublished());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<FoxyStripeProductTest>.

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...
55
56
        $versions = DB::query('Select * FROM "ShippableProduct_versions" WHERE "RecordID" = ' . $productID);
57
        $versionsPostDelete = array();
58
        foreach ($versions as $versionRow) $versionsPostDelete[] = $versionRow;
59
60
        $this->assertEquals($versionsPostPublish, $versionsPostDelete);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<FoxyStripeProductTest>.

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...
61
62
    }
63
64
    /**
65
     *
66
     */
67 View Code Duplication
    function testProductTitleLeadingWhiteSpace()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
68
    {
69
70
        //$this->logInWithPermission('ADMIN');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
71
        $product = $this->objFromFixture('ShippableProduct', 'product1');
72
        $product->Title = " Test with leading space";
73
        $product->ParentID = ProductHolder::get()->first()->ID;
74
        $product->write();
75
76
        $this->assertEquals($product->Title, 'Test with leading space');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<FoxyStripeProductTest>.

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
     */
83 View Code Duplication
    function testProductTitleTrailingWhiteSpace()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
84
    {
85
86
        //$this->logInWithPermission('ADMIN');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
87
        $product = $this->objFromFixture('ShippableProduct', 'product1');
88
        $product->Title = "Test with trailing space ";
89
        $product->ParentID = ProductHolder::get()->first()->ID;
90
        $product->write();
91
92
        $this->assertEquals($product->Title, 'Test with trailing space');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<FoxyStripeProductTest>.

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...
93
94
    }
95
96
    /**
97
     *
98
     */
99
    function testFoxyCartProductCategoryCreation()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
100
    {
101
102
        //$this->logInWithPermission('Product_CANCRUD');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
103
        $category = $this->objFromFixture('FoxyCartProductCategory', 'apparel');
104
        $category->write();
105
        $categoryID = $category->ID;
106
107
        $FoxyCartProductCategory = FoxyCartProductCategory::get()->filter(array('Code' => 'APPAREL'))->first();
108
109
        $this->assertEquals($categoryID, $FoxyCartProductCategory->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<FoxyStripeProductTest>.

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
     */
116
    function testFoxyCartProductCategoryDeletion()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
117
    {
118
119
        //$this->logInWithPermission('Product_CANCRUD');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
120
        $category = $this->objFromFixture('FoxyCartProductCategory', 'default');
121
        $category->write();
122
123
        $this->assertFalse($category->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<FoxyStripeProductTest>.

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
        $category2 = $this->objFromFixture('FoxyCartProductCategory', 'apparel');
126
        $category2->write();
127
        $category2ID = $category2->ID;
128
129
        $this->assertTrue($category2->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<FoxyStripeProductTest>.

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...
130
131
        //$this->logOut();
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...
132
133
        //$this->logInWithPermission('ADMIN');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
134
135
        $this->assertFalse($category->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<FoxyStripeProductTest>.

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...
136
        $this->assertTrue($category2->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<FoxyStripeProductTest>.

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...
137
138
        //$this->logOut();
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...
139
        //$this->logInWithPermission('Product_CANCRUD');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
140
141
        $category2->delete();
142
143
        $this->assertFalse(in_array($category2ID, FoxyCartProductCategory::get()->column('ID')));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<FoxyStripeProductTest>.

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...
144
145
    }
146
147
    /**
148
     *
149
     */
150
    function testOptionGroupCreation()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
151
    {
152
153
        //$this->logInWithPermission('Product_CANCRUD');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
154
        $group = $this->objFromFixture('OptionGroup', 'size');
155
        $group->write();
156
157
        $this->assertNotNull(OptionGroup::get()->first());
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<FoxyStripeProductTest>.

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...
158
159
    }
160
161
    /**
162
     *
163
     */
164
    function testOptionGroupDeletion()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
165
    {
166
167
        //$this->logInWithPermission('ADMIN');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
168
        $group = $this->objFromFixture('OptionGroup', 'color');
169
        $group->write();
170
        $groupID = $group->ID;
171
172
        $this->assertTrue($group->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<FoxyStripeProductTest>.

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...
173
174
        //$this->logOut();
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...
175
        //$this->logInWithPermission('Product_CANCRUD');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
176
177
        $this->assertTrue($group->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<FoxyStripeProductTest>.

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...
178
        $group->delete();
179
180
        $this->assertFalse(in_array($groupID, OptionGroup::get()->column('ID')));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<FoxyStripeProductTest>.

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...
181
182
    }
183
184
    /**
185
     *
186
     */
187
    function testOptionItemCreation()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
188
    {
189
190
        //$this->logInWithPermission('Product_CANCRUD');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
191
        $optionGroup = $this->objFromFixture('OptionGroup', 'size');
192
        $option = OptionItem::create();
193
        $option->Title = 'My New Option';
194
        $option->ProductOptionGroupID = $optionGroup->ID;
195
        $option->write();
196
        $optionID = $option->ID;
197
198
        $optionItem = OptionItem::get()->filter(['ProductOptionGroupID' => $optionGroup->ID, 'Title' => 'My New Option'])->first();
199
200
        $this->assertEquals($optionID, $optionItem->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<FoxyStripeProductTest>.

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...
201
202
    }
203
204
    /**
205
     *
206
     */
207
    function testOptionItemDeletion()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
208
    {
209
210
        //$this->logInWithPermission('ADMIN');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
211
        $optionGroup = (OptionGroup::get()->first())
212
            ? OptionGroup::get()->first()
213
            : OptionGroup::create();
214
        if ($optionGroup->ID == 0) {
215
            $optionGroup->Title = 'Size';
216
            $optionGroup->write();
217
        }
218
        $option = $this->objFromFixture('OptionItem', 'small');
219
        $option->ProductOptionGroupID = $optionGroup->ID;
220
        $option->write();
221
        $optionID = $option->ID;
222
223
        $this->assertTrue($option->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<FoxyStripeProductTest>.

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...
224
225
        //$this->logOut();
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...
226
        //$this->logInWithPermission('Product_CANCRUD');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
227
228
        $this->assertTrue($option->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<FoxyStripeProductTest>.

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...
229
        $option->delete();
230
231
        $this->assertFalse(in_array($optionID, OptionItem::get()->column('ID')));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<FoxyStripeProductTest>.

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...
232
233
    }
234
235
}
236