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
|
|
View Code Duplication |
function setUp() |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
parent::setUp(); |
20
|
|
|
|
21
|
|
|
$groupForItem = OptionGroup::create(); |
22
|
|
|
$groupForItem->Title = 'Sample-Group'; |
|
|
|
|
23
|
|
|
$groupForItem->write(); |
24
|
|
|
|
25
|
|
|
$productHolder = ProductHolder::create(); |
26
|
|
|
$productHolder->Title = 'Product Holder'; |
27
|
|
|
$productHolder->write(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* |
32
|
|
|
*/ |
33
|
|
|
function testProductCreation() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
|
36
|
|
|
//$this->logInWithPermission('Product_CANCRUD'); |
|
|
|
|
37
|
|
|
$default = $this->objFromFixture('FoxyCartProductCategory', 'default'); |
38
|
|
|
$default->write(); |
39
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* |
44
|
|
|
*/ |
45
|
|
|
function testProductDeletion() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
|
48
|
|
|
//$this->logInWithPermission('Product_CANCRUD'); |
|
|
|
|
49
|
|
|
$product2 = $this->objFromFixture('ShippableProduct', 'product2'); |
50
|
|
|
$product2->ParentID = ProductHolder::get()->first()->ID; |
51
|
|
|
$productID = $product2->ID; |
52
|
|
|
|
53
|
|
|
$product2->doPublish(); |
54
|
|
|
$this->assertTrue($product2->isPublished()); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$versions = DB::query('Select * FROM "ShippableProduct_versions" WHERE "RecordID" = ' . $productID); |
57
|
|
|
$versionsPostPublish = array(); |
58
|
|
|
foreach ($versions as $versionRow) $versionsPostPublish[] = $versionRow; |
59
|
|
|
|
60
|
|
|
$product2->delete(); |
61
|
|
|
$this->assertTrue(!$product2->isPublished()); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$versions = DB::query('Select * FROM "ShippableProduct_versions" WHERE "RecordID" = ' . $productID); |
64
|
|
|
$versionsPostDelete = array(); |
65
|
|
|
foreach ($versions as $versionRow) $versionsPostDelete[] = $versionRow; |
66
|
|
|
|
67
|
|
|
$this->assertEquals($versionsPostPublish, $versionsPostDelete); |
|
|
|
|
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* |
73
|
|
|
*/ |
74
|
|
View Code Duplication |
function testProductTitleLeadingWhiteSpace() |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
|
77
|
|
|
//$this->logInWithPermission('ADMIN'); |
|
|
|
|
78
|
|
|
$product = $this->objFromFixture('ShippableProduct', 'product1'); |
79
|
|
|
$product->Title = " Test with leading space"; |
80
|
|
|
$product->ParentID = ProductHolder::get()->first()->ID; |
81
|
|
|
$product->write(); |
82
|
|
|
|
83
|
|
|
$this->assertEquals($product->Title, 'Test with leading space'); |
|
|
|
|
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* |
89
|
|
|
*/ |
90
|
|
View Code Duplication |
function testProductTitleTrailingWhiteSpace() |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
|
93
|
|
|
//$this->logInWithPermission('ADMIN'); |
|
|
|
|
94
|
|
|
$product = $this->objFromFixture('ShippableProduct', 'product1'); |
95
|
|
|
$product->Title = "Test with trailing space "; |
96
|
|
|
$product->ParentID = ProductHolder::get()->first()->ID; |
97
|
|
|
$product->write(); |
98
|
|
|
|
99
|
|
|
$this->assertEquals($product->Title, 'Test with trailing space'); |
|
|
|
|
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* |
105
|
|
|
*/ |
106
|
|
|
function testFoxyCartProductCategoryCreation() |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
|
109
|
|
|
//$this->logInWithPermission('Product_CANCRUD'); |
|
|
|
|
110
|
|
|
$category = $this->objFromFixture('FoxyCartProductCategory', 'apparel'); |
111
|
|
|
$category->write(); |
112
|
|
|
$categoryID = $category->ID; |
113
|
|
|
|
114
|
|
|
$FoxyCartProductCategory = FoxyCartProductCategory::get()->filter(array('Code' => 'APPAREL'))->first(); |
115
|
|
|
|
116
|
|
|
$this->assertEquals($categoryID, $FoxyCartProductCategory->ID); |
|
|
|
|
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* |
122
|
|
|
*/ |
123
|
|
|
function testFoxyCartProductCategoryDeletion() |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
|
126
|
|
|
//$this->logInWithPermission('Product_CANCRUD'); |
|
|
|
|
127
|
|
|
$category = $this->objFromFixture('FoxyCartProductCategory', 'default'); |
128
|
|
|
$category->write(); |
129
|
|
|
|
130
|
|
|
$this->assertFalse($category->canDelete()); |
|
|
|
|
131
|
|
|
|
132
|
|
|
$category2 = $this->objFromFixture('FoxyCartProductCategory', 'apparel'); |
133
|
|
|
$category2->write(); |
134
|
|
|
$category2ID = $category2->ID; |
135
|
|
|
|
136
|
|
|
$this->assertTrue($category2->canDelete()); |
|
|
|
|
137
|
|
|
|
138
|
|
|
//$this->logOut(); |
|
|
|
|
139
|
|
|
|
140
|
|
|
//$this->logInWithPermission('ADMIN'); |
|
|
|
|
141
|
|
|
|
142
|
|
|
$this->assertFalse($category->canDelete()); |
|
|
|
|
143
|
|
|
$this->assertTrue($category2->canDelete()); |
|
|
|
|
144
|
|
|
|
145
|
|
|
//$this->logOut(); |
|
|
|
|
146
|
|
|
//$this->logInWithPermission('Product_CANCRUD'); |
|
|
|
|
147
|
|
|
|
148
|
|
|
$category2->delete(); |
149
|
|
|
|
150
|
|
|
$this->assertFalse(in_array($category2ID, FoxyCartProductCategory::get()->column('ID'))); |
|
|
|
|
151
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* |
156
|
|
|
*/ |
157
|
|
|
function testOptionGroupCreation() |
|
|
|
|
158
|
|
|
{ |
159
|
|
|
|
160
|
|
|
//$this->logInWithPermission('Product_CANCRUD'); |
|
|
|
|
161
|
|
|
$group = $this->objFromFixture('OptionGroup', 'size'); |
162
|
|
|
$group->write(); |
163
|
|
|
|
164
|
|
|
$this->assertNotNull(OptionGroup::get()->first()); |
|
|
|
|
165
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* |
170
|
|
|
*/ |
171
|
|
|
function testOptionGroupDeletion() |
|
|
|
|
172
|
|
|
{ |
173
|
|
|
|
174
|
|
|
//$this->logInWithPermission('ADMIN'); |
|
|
|
|
175
|
|
|
$group = $this->objFromFixture('OptionGroup', 'color'); |
176
|
|
|
$group->write(); |
177
|
|
|
$groupID = $group->ID; |
178
|
|
|
|
179
|
|
|
$this->assertTrue($group->canDelete()); |
|
|
|
|
180
|
|
|
|
181
|
|
|
//$this->logOut(); |
|
|
|
|
182
|
|
|
//$this->logInWithPermission('Product_CANCRUD'); |
|
|
|
|
183
|
|
|
|
184
|
|
|
$this->assertTrue($group->canDelete()); |
|
|
|
|
185
|
|
|
$group->delete(); |
186
|
|
|
|
187
|
|
|
$this->assertFalse(in_array($groupID, OptionGroup::get()->column('ID'))); |
|
|
|
|
188
|
|
|
|
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* |
193
|
|
|
*/ |
194
|
|
|
function testOptionItemCreation() |
|
|
|
|
195
|
|
|
{ |
196
|
|
|
|
197
|
|
|
//$this->logInWithPermission('Product_CANCRUD'); |
|
|
|
|
198
|
|
|
$optionGroup = OptionGroup::get()->filter(array('Title' => 'Sample-Group'))->first(); |
199
|
|
|
$option = $this->objFromFixture('OptionItem', 'large'); |
200
|
|
|
$option->ProductOptionGroupID = $optionGroup->ID; |
201
|
|
|
$option->write(); |
202
|
|
|
$optionID = $option->ID; |
203
|
|
|
|
204
|
|
|
$optionItem = OptionItem::get()->filter(array('ProductOptionGroupID' => $optionGroup->ID))->first(); |
205
|
|
|
|
206
|
|
|
$this->assertEquals($optionID, $optionItem->ID); |
|
|
|
|
207
|
|
|
|
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* |
212
|
|
|
*/ |
213
|
|
|
function testOptionItemDeletion() |
|
|
|
|
214
|
|
|
{ |
215
|
|
|
|
216
|
|
|
//$this->logInWithPermission('ADMIN'); |
|
|
|
|
217
|
|
|
$optionGroup = (OptionGroup::get()->first()) |
218
|
|
|
? OptionGroup::get()->first() |
219
|
|
|
: OptionGroup::create(); |
220
|
|
|
if ($optionGroup->ID == 0) { |
221
|
|
|
$optionGroup->Title = 'Size'; |
222
|
|
|
$optionGroup->write(); |
223
|
|
|
} |
224
|
|
|
$option = $this->objFromFixture('OptionItem', 'small'); |
225
|
|
|
$option->ProductOptionGroupID = $optionGroup->ID; |
226
|
|
|
$option->write(); |
227
|
|
|
$optionID = $option->ID; |
228
|
|
|
|
229
|
|
|
$this->assertTrue($option->canDelete()); |
|
|
|
|
230
|
|
|
|
231
|
|
|
//$this->logOut(); |
|
|
|
|
232
|
|
|
//$this->logInWithPermission('Product_CANCRUD'); |
|
|
|
|
233
|
|
|
|
234
|
|
|
$this->assertTrue($option->canDelete()); |
|
|
|
|
235
|
|
|
$option->delete(); |
236
|
|
|
|
237
|
|
|
$this->assertFalse(in_array($optionID, OptionItem::get()->column('ID'))); |
|
|
|
|
238
|
|
|
|
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
} |
242
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.