Completed
Pull Request — master (#287)
by Nic
04:16
created

testProductCategoryDeletion()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
class FoxyStripeProductTest extends FunctionalTest {
4
5
	protected static $use_draft_site = true;
6
7
	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...
8
9
		$groupForItem = OptionGroup::create();
10
		$groupForItem->Title = 'Sample-Group';
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<OptionGroup>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
11
		$groupForItem->write();
12
13
		$productHolder = ProductHolder::create();
14
		$productHolder->Title = 'Product Holder';
15
		$productHolder->write();
16
	}
17
18
	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...
19
20
		$this->logInWithPermission('Product_CANCRUD');
21
		$default = $this->objFromFixture('ProductCategory', 'default');
22
		$default->write();
23
		$product1 = $this->objFromFixture('FoxyStripeProduct', 'product1');
24
		$product1->ParentID = ProductHolder::get()->first()->ID;
25
26
		$product1->doPublish();
27
		$this->assertTrue($product1->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...
28
29
	}
30
31
	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...
32
33
		$this->logInWithPermission('Product_CANCRUD');
34
		$product2 = $this->objFromFixture('FoxyStripeProduct', 'product2');
35
		$product2->ParentID = ProductHolder::get()->first()->ID;
36
		$productID = $product2->ID;
37
38
		$product2->doPublish();
39
		$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...
40
41
		$versions = DB::query('Select * FROM "FoxyStripeProduct_versions" WHERE "RecordID" = '. $productID);
42
		$versionsPostPublish = array();
43
		foreach($versions as $versionRow) $versionsPostPublish[] = $versionRow;
44
45
		$product2->delete();
46
		$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...
47
48
		$versions = DB::query('Select * FROM "FoxyStripeProduct_versions" WHERE "RecordID" = '. $productID);
49
		$versionsPostDelete = array();
50
		foreach($versions as $versionRow) $versionsPostDelete[] = $versionRow;
51
52
		$this->assertTrue($versionsPostPublish == $versionsPostDelete);
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...
53
54
	}
55
56 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...
57
58
		$this->logInWithPermission('ADMIN');
59
		$product = $this->objFromFixture('FoxyStripeProduct', 'product1');
60
		$product->Title = " Test with leading space";
61
		$product->ParentID = ProductHolder::get()->first()->ID;
62
		$product->doPublish();
63
64
		$this->assertTrue($product->Title == 'Test with leading space');
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...
65
66
	}
67
68 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...
69
70
		$this->logInWithPermission('ADMIN');
71
		$product = $this->objFromFixture('FoxyStripeProduct', 'product1');
72
		$product->Title = "Test with trailing space ";
73
		$product->ParentID = ProductHolder::get()->first()->ID;
74
		$product->doPublish();
75
76
		$this->assertTrue($product->Title == 'Test with trailing space');
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...
77
78
	}
79
80
	function testProductCategoryCreation(){
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...
81
82
		$this->logInWithPermission('Product_CANCRUD');
83
		$category = $this->objFromFixture('ProductCategory', 'apparel');
84
		$category->write();
85
		$categoryID = $category->ID;
86
87
		$productCategory = ProductCategory::get()->filter(array('Code'=>'APPAREL'))->first();
88
89
		$this->assertTrue($categoryID == $productCategory->ID);
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...
90
91
	}
92
93
	function testProductCategoryDeletion(){
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...
94
95
		$this->logInWithPermission('Product_CANCRUD');
96
		$category = $this->objFromFixture('ProductCategory', 'default');
97
		$category->write();
98
99
		$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...
100
101
		$category2 = $this->objFromFixture('ProductCategory', 'apparel');
102
		$category2->write();
103
		$category2ID = $category2->ID;
104
105
		$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...
106
107
		$this->logOut();
0 ignored issues
show
Bug introduced by
The method logOut() 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...
108
109
		$this->logInWithPermission('ADMIN');
110
111
		$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...
112
		$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...
113
114
		$this->logOut();
0 ignored issues
show
Bug introduced by
The method logOut() 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...
115
		$this->logInWithPermission('Product_CANCRUD');
116
117
		$category2->delete();
118
119
		$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...
120
121
	}
122
123
	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...
124
125
		$this->logInWithPermission('Product_CANCRUD');
126
		$group = $this->objFromFixture('OptionGroup', 'size');
127
		$group->write();
128
129
		$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...
130
131
	}
132
133
	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...
134
135
		$this->logInWithPermission('ADMIN');
136
		$group = $this->objFromFixture('OptionGroup', 'color');
137
		$group->write();
138
		$groupID = $group->ID;
139
140
		$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...
141
142
		$this->logOut();
0 ignored issues
show
Bug introduced by
The method logOut() 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...
143
		$this->logInWithPermission('Product_CANCRUD');
144
145
		$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...
146
		$group->delete();
147
148
		$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...
149
150
	}
151
152
	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...
153
154
		$this->logInWithPermission('Product_CANCRUD');
155
		$optionGroup = OptionGroup::get()->filter(array('Title' => 'Sample-Group'))->first();
156
		$option = $this->objFromFixture('OptionItem', 'large');
157
		$option->ProductOptionGroupID = $optionGroup->ID;
158
		$option->write();
159
		$optionID = $option->ID;
160
161
		$optionItem = OptionItem::get()->filter(array('ProductOptionGroupID' => $optionGroup->ID))->first();
162
163
		$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...
164
165
	}
166
167
	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...
168
169
		$this->logInWithPermission('ADMIN');
170
		$optionGroup = (OptionGroup::get()->first())
171
			? OptionGroup::get()->first()
172
			: OptionGroup::create();
173
		if($optionGroup->ID == 0){
174
			$optionGroup->Title = 'Size';
175
			$optionGroup->write();
176
		}
177
		$option = $this->objFromFixture('OptionItem', 'small');
178
		$option->ProductOptionGroupID = $optionGroup->ID;
179
		$option->write();
180
		$optionID = $option->ID;
181
182
		$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...
183
184
		$this->logOut();
0 ignored issues
show
Bug introduced by
The method logOut() 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...
185
		$this->logInWithPermission('Product_CANCRUD');
186
187
		$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...
188
		$option->delete();
189
190
		$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...
191
192
	}
193
194
}
195