Completed
Push — master ( 3228c3...282357 )
by Jason
14:05
created

testProductTitleTrailingWhiteSpace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
class ProductPageTest extends FS_Test{
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
		parent::setUp();
9
10
		$groupForItem = OptionGroup::create();
11
		$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...
12
		$groupForItem->write();
13
14
		/*$productHolder = ProductHolder::create();
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
15
		$productHolder->Title = 'Product Holder';
16
		$productHolder->write();*/
17
	}
18
19
	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...
20
21
		$this->logInWithPermission('Product_CANCRUD');
22
		$default = $this->objFromFixture('ProductCategory', 'default');
23
		$default->write();
24
		$holder = $this->objFromFixture('ProductHolder', 'holder');
25
		$holder->doPublish();
26
		$product1 = $this->objFromFixture('ProductPage', 'product1');
27
		//$product1->ParentID = ProductHolder::get()->first()->ID;
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
28
29
		$product1->doPublish();
30
		$this->assertTrue($product1->isPublished());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductPageTest>.

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...
31
32
	}
33
34
	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...
35
36
		$this->logInWithPermission('Product_CANCRUD');
37
		$holder = $this->objFromFixture('ProductHolder', 'holder');
38
		$holder->doPublish();
39
		$product2 = $this->objFromFixture('ProductPage', 'product2');
40
		$productID = $product2->ID;
41
42
		$product2->doPublish();
43
		$this->assertTrue($product2->isPublished());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductPageTest>.

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

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...
51
52
		$versions = DB::query('Select * FROM "ProductPage_versions" WHERE "RecordID" = '. $productID);
53
		$versionsPostDelete = array();
54
		foreach($versions as $versionRow) $versionsPostDelete[] = $versionRow;
55
56
		$this->assertTrue($versionsPostPublish == $versionsPostDelete);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductPageTest>.

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...
57
58
	}
59
60 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...
61
62
		$this->logInWithPermission('ADMIN');
63
64
		$holder = $this->objFromFixture('ProductHolder', 'holder');
65
		$holder->doPublish();
66
67
		$product = $this->objFromFixture('ProductPage', 'product1');
68
		$product->Title = " Test with leading space";
69
		$product->doPublish();
70
71
		$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<ProductPageTest>.

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...
72
73
	}
74
75 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...
76
77
		$this->logInWithPermission('ADMIN');
78
79
		$holder = $this->objFromFixture('ProductHolder', 'holder');
80
		$holder->doPublish();
81
82
		$product = $this->objFromFixture('ProductPage', 'product1');
83
		$product->Title = "Test with trailing space ";
84
		$product->doPublish();
85
86
		$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<ProductPageTest>.

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...
87
88
	}
89
90
	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...
91
92
		$this->logInWithPermission('Product_CANCRUD');
93
		$category = $this->objFromFixture('ProductCategory', 'apparel');
94
		$category->write();
95
		$categoryID = $category->ID;
96
97
		$productCategory = ProductCategory::get()->filter(array('Code'=>'APPAREL'))->first();
98
99
		$this->assertTrue($categoryID == $productCategory->ID);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductPageTest>.

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
103
	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...
104
105
		$this->logInWithPermission('Product_CANCRUD');
106
107
		$category = $this->objFromFixture('ProductCategory', 'default');
108
		$category->write();
109
110
		$this->assertFalse($category->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ProductPageTest>.

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...
111
112
		$category2 = $this->objFromFixture('ProductCategory', 'apparel');
113
		$category2->write();
114
		$category2ID = $category2->ID;
115
116
		$this->assertTrue($category2->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductPageTest>.

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...
117
118
		$this->logOut();
119
120
		$this->logInWithPermission('ADMIN');
121
122
		$this->assertFalse($category->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ProductPageTest>.

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

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->logOut();
126
		$this->logInWithPermission('Product_CANCRUD');
127
128
		$category2->delete();
129
130
		$this->assertFalse(in_array($category2ID,ProductCategory::get()->column('ID')));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ProductPageTest>.

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...
131
132
	}
133
134
	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...
135
136
		$this->logInWithPermission('Product_CANCRUD');
137
138
		$group = $this->objFromFixture('OptionGroup', 'size');
139
		$group->write();
140
141
		$this->assertNotNull(OptionGroup::get()->first());
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<ProductPageTest>.

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...
142
143
	}
144
145
	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...
146
147
		$this->logInWithPermission('ADMIN');
148
		$group = $this->objFromFixture('OptionGroup', 'color');
149
		$group->write();
150
		$groupID = $group->ID;
151
152
		$this->assertTrue($group->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductPageTest>.

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...
153
154
		$this->logOut();
155
		$this->logInWithPermission('Product_CANCRUD');
156
157
		$this->assertTrue($group->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductPageTest>.

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
		$group->delete();
159
160
		$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<ProductPageTest>.

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...
161
162
	}
163
164
	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...
165
166
		$this->logInWithPermission('Product_CANCRUD');
167
168
		$optionGroup = OptionGroup::get()->filter(array('Title' => 'Sample-Group'))->first();
169
170
		$option = $this->objFromFixture('OptionItem', 'large');
171
		$option->ProductOptionGroupID = $optionGroup->ID;
172
		$option->write();
173
174
		$optionID = $option->ID;
175
176
		$optionItem = OptionItem::get()->filter(array('ProductOptionGroupID' => $optionGroup->ID))->first();
177
178
		$this->assertEquals($optionID, $optionItem->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ProductPageTest>.

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...
179
180
	}
181
182
	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...
183
184
		$this->logInWithPermission('ADMIN');
185
186
		$optionGroup = $this->objFromFixture('OptionGroup', 'size');
187
		$optionGroup->write();
188
189
		$option = $this->objFromFixture('OptionItem', 'small');
190
		$option->write();
191
192
		$optionID = $option->ID;
193
194
		$this->assertTrue($option->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductPageTest>.

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...
195
196
		$this->logOut();
197
		$this->logInWithPermission('Product_CANCRUD');
198
199
		$this->assertTrue($option->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductPageTest>.

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...
200
		$option->delete();
201
202
		$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<ProductPageTest>.

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...
203
204
	}
205
206
	public function testProductDraftOptionDeletion(){
207
208
		self::$use_draft_site = false;//make sure we can publish
209
210
		$this->logInWithPermission('ADMIN');
211
212
		$holder = $this->objFromFixture('ProductHolder', 'holder');//build holder page, ProductPage can't be on root level
213
		$holder->doPublish();
214
215
		$product = $this->objFromFixture('ProductPage', 'product1');//build product page
216
		$product->doPublish();
217
218
		$productID = $product->ID;
219
220
221
		$optionGroup = $this->objFromFixture('OptionGroup', 'size');//build the group for the options
222
		$optionGroup->write();
223
		$option = $this->objFromFixture('OptionItem', 'small');//build first option
224
		$option->write();
225
		$option2 = $this->objFromFixture('OptionItem', 'large');//build second option
226
		$option2->write();
227
228
		$this->assertTrue($product->isPublished());//check that product is published
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductPageTest>.

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
230
		$product->deleteFromStage('Stage');//remove product from draft site
231
232
		$this->assertTrue($product->isPublished());//check product is still published
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProductPageTest>.

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...
233
234
		$testOption = OptionItem::get()->filter(array('Title' => 'Large', 'ProductID' => $productID))->first();
235
236
		$this->assertThat($testOption->ID, $this->logicalNot($this->equalTo(0)));//make sure the first option still exists
0 ignored issues
show
Bug introduced by
The method equalTo() does not seem to exist on object<ProductPageTest>.

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...
Bug introduced by
The method logicalNot() does not seem to exist on object<ProductPageTest>.

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...
Bug introduced by
The method assertThat() does not seem to exist on object<ProductPageTest>.

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...
237
238
		$product->doRestoreToStage();//restore page to draft site
239
		$product->doUnpublish();//unpublish page
240
		$product->deleteFromStage('Stage');//remove product from draft site
241
242
		$checkDeleted = OptionItem::get()->filter(array('Title' => 'Large', 'ProductID' => $productID))->first();//query same option as above
243
244
		$this->assertEquals($checkDeleted->ID, 0);//check that the ID is 0 (empty object/non-existent)
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ProductPageTest>.

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...
245
246
	}
247
248
}
249