|
1
|
|
|
<?php |
|
2
|
|
|
Intraface_Doctrine_Intranet::singleton(1); |
|
3
|
|
|
|
|
4
|
|
|
class ProductDoctrineTest extends PHPUnit_Framework_TestCase |
|
5
|
|
|
{ |
|
6
|
|
|
|
|
7
|
|
|
function setUp() |
|
8
|
|
|
{ |
|
9
|
|
|
$connection = Doctrine_Manager::connection(); |
|
10
|
|
|
// $query = $connection->getQuery(); |
|
|
|
|
|
|
11
|
|
|
$connection->exec('TRUNCATE product'); |
|
12
|
|
|
$connection->exec('TRUNCATE product_attribute'); |
|
13
|
|
|
$connection->exec('TRUNCATE product_attribute_group'); |
|
14
|
|
|
$connection->exec('TRUNCATE product_detail'); |
|
15
|
|
|
$connection->exec('TRUNCATE product_detail_translation'); |
|
16
|
|
|
$connection->exec('TRUNCATE product_variation'); |
|
17
|
|
|
$connection->exec('TRUNCATE product_variation_detail'); |
|
18
|
|
|
$connection->exec('TRUNCATE product_variation_x_attribute'); |
|
19
|
|
|
$connection->exec('TRUNCATE product_x_attribute_group'); |
|
20
|
|
|
|
|
21
|
|
|
$connection->clear(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
function createProductObject($id = 0) |
|
25
|
|
|
{ |
|
26
|
|
|
if ($id != 0) { |
|
27
|
|
|
$connection = Doctrine_Manager::connection(); |
|
28
|
|
|
$connection->clear(); // clear repo, so that we are sure data are loaded again. |
|
29
|
|
|
$gateway = new Intraface_modules_product_ProductDoctrineGateway($connection, null); |
|
|
|
|
|
|
30
|
|
|
return $gateway->findById($id); |
|
31
|
|
|
} |
|
32
|
|
|
return new Intraface_modules_product_ProductDoctrine; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
View Code Duplication |
function createNewProduct() |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
$product = $this->createProductObject(); |
|
38
|
|
|
$product->getDetails()->Translation['da']->name = 'Test'; |
|
39
|
|
|
$product->getDetails()->Translation['da']->description = ''; |
|
40
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float(20); |
|
41
|
|
|
$product->getDetails()->unit = 1; |
|
42
|
|
|
$product->save(); |
|
43
|
|
|
$product->refresh(true); |
|
44
|
|
|
return $product; |
|
45
|
|
|
// $product->save(array('name' => 'Test', 'price' => 20, 'unit' => 1)); |
|
|
|
|
|
|
46
|
|
|
// return $product; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function createNewProductWithVariations() |
|
50
|
|
|
{ |
|
51
|
|
|
$product = $this->createNewProduct(); |
|
52
|
|
|
$product->has_variation = 1; |
|
53
|
|
|
$product->save(); |
|
54
|
|
|
$product->refresh(true); |
|
55
|
|
|
return $product; |
|
56
|
|
|
// $product->save(array('name' => 'Test', 'price' => 20, 'unit' => 1, 'has_variation' => true)); |
|
|
|
|
|
|
57
|
|
|
// return $product; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
//////////////////////////////////////////////////////////////////////////// |
|
61
|
|
|
|
|
62
|
|
|
function testSaveProductReturnsIdOfProductOnSuccess() |
|
63
|
|
|
{ |
|
64
|
|
|
$product = $this->createProductObject(); |
|
65
|
|
|
$name = 'Test'; |
|
66
|
|
|
$price = 20; |
|
67
|
|
|
$product->getDetails()->Translation['da']->name = 'Test'; |
|
68
|
|
|
$product->getDetails()->Translation['da']->description = ''; |
|
69
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float(20); |
|
70
|
|
|
|
|
71
|
|
|
try { |
|
72
|
|
|
$product->save(); |
|
73
|
|
|
} catch (Exception $e) { |
|
74
|
|
|
$this->fail($e); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$product->refresh(true); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertEquals(1, $product->getDetails()->getNumber()); |
|
80
|
|
|
$this->assertEquals($name, $product->getDetails()->getTranslation('da')->name); |
|
81
|
|
|
$this->assertEquals($price, $product->getDetails()->getPrice()->getAsIso()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
function testSaveThrowsExceptionOnEmptyProduct() |
|
85
|
|
|
{ |
|
86
|
|
|
$product = $this->createProductObject(); |
|
87
|
|
|
|
|
88
|
|
|
$this->setExpectedException('Exception'); |
|
89
|
|
|
$product->save(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
function testSaveThrowsExceptionOnEmptyProductDetails() |
|
93
|
|
|
{ |
|
94
|
|
|
$product = $this->createProductObject(); |
|
95
|
|
|
$product->getDetails(); |
|
96
|
|
|
|
|
97
|
|
|
$this->setExpectedException('Exception'); |
|
98
|
|
|
$product->save(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
function testSaveThrowsExceptionOnEmptyName() |
|
102
|
|
|
{ |
|
103
|
|
|
$product = $this->createProductObject(); |
|
104
|
|
|
$product->getDetails()->Translation['da']->name = ''; |
|
105
|
|
|
$this->setExpectedException('Doctrine_Validator_Exception'); |
|
106
|
|
|
$product->save(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
function testSaveThrowsExceptionOnNoNameButFilledInPrice() |
|
110
|
|
|
{ |
|
111
|
|
|
$product = $this->createProductObject(); |
|
112
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float(20); |
|
113
|
|
|
$this->setExpectedException('Exception'); |
|
114
|
|
|
$product->save(); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
function testSaveIncreasesNumberOnNewProduct() |
|
118
|
|
|
{ |
|
119
|
|
|
$product = $this->createProductObject(); |
|
120
|
|
|
$name = 'Test'; |
|
121
|
|
|
$price = 20; |
|
122
|
|
|
$product->getDetails()->Translation['da']->name = $name; |
|
123
|
|
|
$product->getDetails()->Translation['da']->description = ''; |
|
124
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float($price); |
|
125
|
|
|
|
|
126
|
|
|
try { |
|
127
|
|
|
$product->save(); |
|
128
|
|
|
} catch (Exception $e) { |
|
129
|
|
|
$this->fail('Exception thrown '.$e->__toString()); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
$product->refresh(true); |
|
133
|
|
|
|
|
134
|
|
|
$this->assertEquals(1, $product->getDetails()->getNumber()); |
|
135
|
|
|
$this->assertEquals($name, $product->getDetails()->getTranslation('da')->name); |
|
136
|
|
|
$this->assertEquals($price, $product->getDetails()->getPrice()->getAsIso()); |
|
137
|
|
|
|
|
138
|
|
|
$product = $this->createProductObject(); |
|
139
|
|
|
$name = 'Test 3'; |
|
140
|
|
|
$price = 30; |
|
141
|
|
|
$product->getDetails()->Translation['da']->name = $name; |
|
142
|
|
|
$product->getDetails()->Translation['da']->description = ''; |
|
143
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float($price); |
|
144
|
|
|
|
|
145
|
|
|
try { |
|
146
|
|
|
$product->save(); |
|
147
|
|
|
} catch (Exception $e) { |
|
148
|
|
|
$this->fail('Exception thrown '.$e->__toString()); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
$product->refresh(true); |
|
152
|
|
|
|
|
153
|
|
|
$this->assertEquals(2, $product->getDetails()->getNumber()); |
|
154
|
|
|
$this->assertEquals($name, $product->getDetails()->getTranslation('da')->name); |
|
155
|
|
|
$this->assertEquals($price, $product->getDetails()->getPrice()->getAsIso()); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
function testSavePersistsItselfAndCanSaveAgainStillHavingTheSameNumber() |
|
159
|
|
|
{ |
|
160
|
|
|
$product = $this->createProductObject(); |
|
161
|
|
|
$name = 'Test'; |
|
162
|
|
|
$price = 20; |
|
163
|
|
|
$product->getDetails()->Translation['da']->name = $name; |
|
164
|
|
|
$product->getDetails()->Translation['da']->description = ''; |
|
165
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float($price); |
|
166
|
|
|
|
|
167
|
|
|
try { |
|
168
|
|
|
$product->save(); |
|
169
|
|
|
} catch (Exception $e) { |
|
170
|
|
|
$this->fail('Exception thrown '.$e->__toString()); |
|
171
|
|
|
} |
|
172
|
|
|
$product->refresh(true); |
|
173
|
|
|
|
|
174
|
|
|
$name = 'Test 2'; |
|
175
|
|
|
$product->getDetails()->Translation['da']->name = $name; |
|
176
|
|
|
try { |
|
177
|
|
|
$product->save(); |
|
178
|
|
|
} catch (Exception $e) { |
|
179
|
|
|
$this->fail('Exception thrown '.$e->__toString()); |
|
180
|
|
|
} |
|
181
|
|
|
$product->refresh(true); |
|
182
|
|
|
|
|
183
|
|
|
$this->assertEquals(1, $product->getDetails()->getNumber()); |
|
184
|
|
|
$this->assertEquals($name, $product->getDetails()->getTranslation('da')->name); |
|
185
|
|
|
$this->assertEquals($price, $product->getDetails()->getPrice()->getAsIso()); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
|
|
189
|
|
|
function testSaveStateAccountIdInProductDetailsDoesntChangeOtherValues() |
|
190
|
|
|
{ |
|
191
|
|
|
$product = $this->createProductObject(); |
|
192
|
|
|
$name = 'Test'; |
|
193
|
|
|
$price = 20; |
|
194
|
|
|
$product->getDetails()->Translation['da']->name = 'Test'; |
|
195
|
|
|
$product->getDetails()->Translation['da']->description = ''; |
|
196
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float(20); |
|
197
|
|
|
$product->getDetails()->state_account_id = 10; |
|
198
|
|
|
|
|
199
|
|
|
try { |
|
200
|
|
|
$product->save(); |
|
201
|
|
|
} catch (Exception $e) { |
|
202
|
|
|
$this->fail('Exception thrown '.$e->__toString()); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
$product->refresh(true); |
|
206
|
|
|
|
|
207
|
|
|
$id = $product->getId(); |
|
208
|
|
|
$this->assertEquals(1, $product->getDetails()->getNumber()); |
|
209
|
|
|
$this->assertEquals($name, $product->getDetails()->getTranslation('da')->name); |
|
210
|
|
|
$this->assertEquals($price, $product->getDetails()->getPrice()->getAsIso()); |
|
211
|
|
|
$this->assertEquals(10, $product->getDetails()->getStateAccountId()); |
|
212
|
|
|
|
|
213
|
|
|
|
|
214
|
|
|
$product = $this->createProductObject($id); |
|
215
|
|
|
$this->assertEquals($id, $product->getId()); |
|
216
|
|
|
$this->assertTrue($product->getDetails()->setStateAccountId(20)); |
|
217
|
|
|
|
|
218
|
|
|
$product->refresh(true); |
|
219
|
|
|
|
|
220
|
|
|
$this->assertEquals(1, $product->getDetails()->getNumber()); |
|
221
|
|
|
$this->assertEquals($name, $product->getDetails()->getTranslation('da')->name); |
|
222
|
|
|
$this->assertEquals(20, $product->getDetails()->getStateAccountId()); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
function testChangeProductNameSavesAsNewDetail() |
|
226
|
|
|
{ |
|
227
|
|
|
$product = $this->createProductObject(); |
|
228
|
|
|
$product->getDetails()->Translation['da']->name = 'Test'; |
|
229
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float(20); |
|
230
|
|
|
|
|
231
|
|
|
try { |
|
232
|
|
|
$product->save(); |
|
233
|
|
|
} catch (Exception $e) { |
|
234
|
|
|
$this->fail('Exception thrown '.$e->__toString()); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
$product->refresh(true); |
|
238
|
|
|
$this->assertEquals(1, $product->getDetails()->getId()); |
|
239
|
|
|
$this->assertEquals('Test', $product->getDetails()->getTranslation('da')->name); |
|
240
|
|
|
|
|
241
|
|
|
$product->getDetails()->Translation['da']->name = 'Test 2'; |
|
242
|
|
|
try { |
|
243
|
|
|
$product->save(); |
|
244
|
|
|
} catch (Exception $e) { |
|
245
|
|
|
$this->fail('Exception thrown '.$e->__toString()); |
|
246
|
|
|
} |
|
247
|
|
|
$product->refresh(true); |
|
248
|
|
|
// $product = $this->createProductObject($product->get('id')); |
|
|
|
|
|
|
249
|
|
|
|
|
250
|
|
|
$this->assertEquals(2, $product->getDetails()->getId()); |
|
251
|
|
|
$this->assertEquals('Test 2', $product->getDetails()->getTranslation('da')->name); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
function testChangeProductPriceSavesAsNewDetail() |
|
255
|
|
|
{ |
|
256
|
|
|
$product = $this->createProductObject(); |
|
257
|
|
|
$product->getDetails()->Translation['da']->name = 'Test'; |
|
258
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float(20); |
|
259
|
|
|
|
|
260
|
|
|
try { |
|
261
|
|
|
$product->save(); |
|
262
|
|
|
} catch (Exception $e) { |
|
263
|
|
|
$this->fail('Exception thrown '.$e->__toString()); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
$product->refresh(true); |
|
267
|
|
|
$this->assertEquals(1, $product->getDetails()->getId()); |
|
268
|
|
|
$this->assertEquals(20, $product->getDetails()->getPrice()->getAsIso()); |
|
269
|
|
|
|
|
270
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float(30); |
|
271
|
|
|
try { |
|
272
|
|
|
$product->save(); |
|
273
|
|
|
} catch (Exception $e) { |
|
274
|
|
|
$this->fail('Exception thrown '.$e->__toString()); |
|
275
|
|
|
} |
|
276
|
|
|
$product->refresh(true); |
|
277
|
|
|
// $product = $this->createProductObject($product->get('id')); |
|
|
|
|
|
|
278
|
|
|
|
|
279
|
|
|
$this->assertEquals(2, $product->getDetails()->getId()); |
|
280
|
|
|
$this->assertEquals(30, $product->getDetails()->getPrice()->getAsIso()); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
function testDetailsIsNotUpdatedWhenErrorInTranslation() |
|
284
|
|
|
{ |
|
285
|
|
|
$product = $this->createProductObject(); |
|
286
|
|
|
$product->getDetails()->Translation['da']->name = 'Test'; |
|
287
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float(20); |
|
288
|
|
|
|
|
289
|
|
|
try { |
|
290
|
|
|
$product->save(); |
|
291
|
|
|
} catch (Exception $e) { |
|
292
|
|
|
$this->fail('Exception thrown '.$e->__toString()); |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
$product->refresh(true); |
|
296
|
|
|
$this->assertEquals(1, $product->getDetails()->getId()); |
|
297
|
|
|
$this->assertEquals(20, $product->getDetails()->getPrice()->getAsIso()); |
|
298
|
|
|
|
|
299
|
|
|
$product->getDetails()->Translation['da']->name = ''; |
|
300
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float(30); |
|
301
|
|
|
try { |
|
302
|
|
|
$product->save(); |
|
303
|
|
|
} catch (Exception $e) { |
|
304
|
|
|
// we excpect error. |
|
305
|
|
|
// $this->fail('Exception thrown '.$e->__toString()); |
|
|
|
|
|
|
306
|
|
|
} |
|
307
|
|
|
$product->refresh(true); |
|
308
|
|
|
// $product = $this->createProductObject($product->get('id')); |
|
|
|
|
|
|
309
|
|
|
|
|
310
|
|
|
$this->assertEquals(1, $product->getDetails()->getId()); |
|
311
|
|
|
$this->assertEquals(20, $product->getDetails()->getPrice()->getAsIso()); |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
public function testLoadEarlierDetails() |
|
315
|
|
|
{ |
|
316
|
|
|
$product = $this->createProductObject(); |
|
317
|
|
|
$product->getDetails()->Translation['da']->name = 'Test'; |
|
318
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float(20); |
|
319
|
|
|
|
|
320
|
|
|
try { |
|
321
|
|
|
$product->save(); |
|
322
|
|
|
} catch (Exception $e) { |
|
323
|
|
|
$this->fail('Exception thrown '.$e->__toString()); |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
$product->refresh(true); |
|
327
|
|
|
$this->assertEquals(1, $product->getDetails()->getId()); |
|
328
|
|
|
$this->assertEquals('Test', $product->getDetails()->getTranslation('da')->name); |
|
329
|
|
|
|
|
330
|
|
|
$product->getDetails()->Translation['da']->name = 'Test 2'; |
|
331
|
|
|
try { |
|
332
|
|
|
$product->save(); |
|
333
|
|
|
} catch (Exception $e) { |
|
334
|
|
|
$this->fail('Exception thrown '.$e->__toString()); |
|
335
|
|
|
} |
|
336
|
|
|
// $product->refresh(true); |
|
|
|
|
|
|
337
|
|
|
$product = $this->createProductObject(1); |
|
338
|
|
|
$this->assertEquals(1, $product->getDetails(1)->getId()); |
|
339
|
|
|
$this->assertEquals('Test', $product->getDetails(1)->getTranslation('da')->name); |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
public function testShowInShop() |
|
343
|
|
|
{ |
|
344
|
|
|
$product = $this->createProductObject(); |
|
345
|
|
|
$product->getDetails()->Translation['da']->name = 'Test'; |
|
346
|
|
|
$product->getDetails()->Translation['da']->description = ''; |
|
347
|
|
|
$product->getDetails()->price = new Ilib_Variable_Float(20); |
|
348
|
|
|
$product->do_show = 1; |
|
349
|
|
|
try { |
|
350
|
|
|
$product->save(); |
|
351
|
|
|
} catch (Exception $e) { |
|
352
|
|
|
foreach ($product->getErrorStack() as $field => $error) { |
|
353
|
|
|
echo $field; |
|
354
|
|
|
var_dump($error); |
|
|
|
|
|
|
355
|
|
|
} |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
$product = $this->createProductObject(1); |
|
359
|
|
|
$this->assertEquals(1, $product->showInShop()); |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
function testSetAttributeGroupThrowsExceptionOnWhenNotSavedWithVariations() |
|
363
|
|
|
{ |
|
364
|
|
|
$product = $this->createNewProduct(); |
|
365
|
|
|
|
|
366
|
|
|
$group = new Intraface_modules_product_Attribute_Group; |
|
367
|
|
|
$group->name = 'Test1'; |
|
368
|
|
|
$group->save(); |
|
369
|
|
|
$group->load(); |
|
370
|
|
|
|
|
371
|
|
|
try { |
|
372
|
|
|
$product->setAttributeGroup($group); |
|
373
|
|
|
$this->assertTrue(false, 'An excpetion is not thrown'); |
|
374
|
|
|
} catch(Exception $e) { |
|
375
|
|
|
$this->assertEquals('You can not set attribute group for a product without variations!', $e->getMessage()); |
|
376
|
|
|
} |
|
377
|
|
|
} |
|
378
|
|
|
|
|
379
|
|
View Code Duplication |
function testSetAttributeGroup() |
|
|
|
|
|
|
380
|
|
|
{ |
|
381
|
|
|
$product = $this->createNewProductWithVariations(); |
|
382
|
|
|
|
|
383
|
|
|
$group = new Intraface_modules_product_Attribute_Group; |
|
384
|
|
|
$group->name = 'Test1'; |
|
385
|
|
|
$group->save(); |
|
386
|
|
|
$group->load(); |
|
387
|
|
|
|
|
388
|
|
|
$this->assertTrue($product->setAttributeGroup($group)); |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
function testGetAttributeGroups() |
|
392
|
|
|
{ |
|
393
|
|
|
$product = $this->createNewProductWithVariations(); |
|
394
|
|
|
|
|
395
|
|
|
$group = new Intraface_modules_product_Attribute_Group; |
|
396
|
|
|
$group->name = 'Test1'; |
|
397
|
|
|
$group->save(); |
|
398
|
|
|
$group->load(); |
|
399
|
|
|
$product->setAttributeGroup($group); |
|
400
|
|
|
|
|
401
|
|
|
$group = new Intraface_modules_product_Attribute_Group; |
|
402
|
|
|
$group->name = 'Test2'; |
|
403
|
|
|
$group->save(); |
|
404
|
|
|
$group->load(); |
|
405
|
|
|
$product->setAttributeGroup($group); |
|
406
|
|
|
|
|
407
|
|
|
$group = new Intraface_modules_product_Attribute_Group; |
|
408
|
|
|
$group->name = 'Test3'; |
|
409
|
|
|
$group->save(); |
|
410
|
|
|
$group->load(); |
|
411
|
|
|
|
|
412
|
|
|
|
|
413
|
|
|
$expected = array( |
|
|
|
|
|
|
414
|
|
|
0 => array( |
|
415
|
|
|
'id' => 1, |
|
416
|
|
|
'intranet_id' => 1, |
|
417
|
|
|
'name' => 'Test1', |
|
418
|
|
|
'_old_deleted' => 0, |
|
419
|
|
|
'deleted_at' => null |
|
420
|
|
|
), |
|
421
|
|
|
1 => array( |
|
422
|
|
|
'id' => 2, |
|
423
|
|
|
'intranet_id' => 1, |
|
424
|
|
|
'name' => 'Test2', |
|
425
|
|
|
'_old_deleted' => 0, |
|
426
|
|
|
'deleted_at' => null |
|
427
|
|
|
) |
|
428
|
|
|
); |
|
429
|
|
|
|
|
430
|
|
|
$groups = $product->getAttributeGroups(); |
|
431
|
|
|
|
|
432
|
|
|
$this->assertEquals(2, $groups->count()); |
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
|
|
/* |
|
|
|
|
|
|
436
|
|
|
function testMaxNumberIncrementsOnePrProductAdded() |
|
437
|
|
|
{ |
|
438
|
|
|
$product = $this->createProductObject(); |
|
439
|
|
|
$this->assertEquals(0, $product->getMaxNumber()); |
|
440
|
|
|
$product = $this->createNewProduct(); |
|
441
|
|
|
$this->assertEquals(1, $product->getMaxNumber()); |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
function testProductCanGetNumberIfOtherProductDontNeedItAnymore() |
|
445
|
|
|
{ |
|
446
|
|
|
$product = new Product($this->kernel); |
|
447
|
|
|
|
|
448
|
|
|
$number = $product->getMaxNumber() + 1; |
|
449
|
|
|
|
|
450
|
|
|
$new_number = $number + 1; |
|
451
|
|
|
if (!$product->save(array('number' => $number, 'name' => 'Test', 'price' => 20, 'unit' => 1))) { |
|
452
|
|
|
$product->error->view(); |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
if (!$product->save(array('number' => $new_number, 'name' => 'Test', 'price' => 20, 'unit' => 1))) { |
|
456
|
|
|
$product->error->view(); |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
$new_product = new Product($this->kernel); |
|
460
|
|
|
$array = array('number' => $number, 'name' => 'Test overtager nummer', 'price' => 20, 'unit' => 1); |
|
461
|
|
|
if (!$new_product->save($array)) { |
|
462
|
|
|
$new_product->error->view(); |
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
|
|
$this->assertEquals($number, $new_product->get('number')); |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
function testDeleteAProduct() |
|
469
|
|
|
{ |
|
470
|
|
|
$product = $this->createNewProduct(); |
|
471
|
|
|
$this->assertTrue($product->delete()); |
|
472
|
|
|
$this->assertFalse($product->isActive()); |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
function testUnDeleteAProduct() |
|
476
|
|
|
{ |
|
477
|
|
|
$product = $this->createNewProduct(); |
|
478
|
|
|
$product->delete(); |
|
479
|
|
|
$this->assertFalse($product->isActive()); |
|
480
|
|
|
$this->assertTrue($product->undelete()); |
|
481
|
|
|
$this->assertTrue($product->isActive()); |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
function testAProductCanStillBeLoadedEvenIfDeleted() |
|
485
|
|
|
{ |
|
486
|
|
|
$product = $this->createNewProduct(); |
|
487
|
|
|
$product_id = $product->get('id'); |
|
488
|
|
|
$product->delete(); |
|
489
|
|
|
|
|
490
|
|
|
$deletedproduct = $this->createProductObject($product_id); |
|
491
|
|
|
|
|
492
|
|
|
$this->assertEquals($product->get('id'), $deletedproduct->get('id')); |
|
493
|
|
|
$this->assertEquals($product->get('name'), $deletedproduct->get('name')); |
|
494
|
|
|
$this->assertEquals($product->get('price'), $deletedproduct->get('price')); |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
function testCopyProduct() |
|
498
|
|
|
{ |
|
499
|
|
|
$product = $this->createNewProduct(); |
|
500
|
|
|
$new_id = $product->copy(); |
|
501
|
|
|
|
|
502
|
|
|
$newproduct = $this->createProductObject($new_id); |
|
503
|
|
|
|
|
504
|
|
|
$this->assertEquals(2, $newproduct->get('number')); |
|
505
|
|
|
$this->assertEquals('Test (kopi)', $newproduct->get('name')); |
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
|
|
function testIsFilledInReturnsZeroWhenNoProductsHasBeenCreated() |
|
509
|
|
|
{ |
|
510
|
|
|
$product = $this->createProductObject(); |
|
511
|
|
|
$this->assertEquals(0, $product->isFilledIn()); |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
function testSetRelatedProductReturnsTrueOnSuccessAndOneProductIsReturned() |
|
515
|
|
|
{ |
|
516
|
|
|
$product = $this->createNewProduct(); |
|
517
|
|
|
$product_to_relate = $this->createNewProduct(); |
|
518
|
|
|
|
|
519
|
|
|
$this->assertTrue($product->setRelatedProduct($product_to_relate->getId())); |
|
520
|
|
|
|
|
521
|
|
|
$this->assertEquals(1, count($product->getRelatedProducts())); |
|
522
|
|
|
} |
|
523
|
|
|
|
|
524
|
|
|
|
|
525
|
|
|
|
|
526
|
|
|
function testRemoveAttributeGroup() |
|
527
|
|
|
{ |
|
528
|
|
|
$product = $this->createNewProductWithVariations(); |
|
529
|
|
|
$product->setAttributeGroup(1); |
|
530
|
|
|
$this->assertTrue($product->removeAttributeGroup(1)); |
|
531
|
|
|
} |
|
532
|
|
|
|
|
533
|
|
|
|
|
534
|
|
|
|
|
535
|
|
|
function testGetVariationThrowsExceptionWhenNoGroupsAdded() |
|
536
|
|
|
{ |
|
537
|
|
|
$product = $this->createNewProductWithVariations(); |
|
538
|
|
|
try { |
|
539
|
|
|
$product->getVariation(); |
|
540
|
|
|
$this->assertTrue(false, 'No exception thrown'); |
|
541
|
|
|
} |
|
542
|
|
|
catch (Exception $e) { |
|
543
|
|
|
$this->assertTrue(true); |
|
544
|
|
|
} |
|
545
|
|
|
|
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
function testGetVariation() |
|
549
|
|
|
{ |
|
550
|
|
|
$product = $this->createNewProductWithVariations(); |
|
551
|
|
|
$group = new Intraface_modules_product_Attribute_Group; |
|
552
|
|
|
$group->name = 'Test1'; |
|
553
|
|
|
$group->save(); |
|
554
|
|
|
$group->load(); |
|
555
|
|
|
$product->setAttributeGroup($group->getId()); |
|
556
|
|
|
|
|
557
|
|
|
$this->assertTrue(is_object($product->getVariation())); |
|
558
|
|
|
|
|
559
|
|
|
|
|
560
|
|
|
} |
|
561
|
|
|
|
|
562
|
|
|
function testGetVariations() |
|
563
|
|
|
{ |
|
564
|
|
|
$product = $this->createNewProductWithVariations(); |
|
565
|
|
|
$group = new Intraface_modules_product_Attribute_Group; |
|
566
|
|
|
$group->name = 'color'; |
|
567
|
|
|
$group->attribute[0]->name = 'red'; |
|
568
|
|
|
$group->attribute[1]->name = 'blue'; |
|
569
|
|
|
$group->save(); |
|
570
|
|
|
$product->setAttributeGroup($group->getId()); |
|
571
|
|
|
|
|
572
|
|
|
|
|
573
|
|
|
$group = new Intraface_modules_product_Attribute_Group; |
|
574
|
|
|
$group->name = 'size'; |
|
575
|
|
|
$group->attribute[0]->name = 'small'; |
|
576
|
|
|
$group->attribute[1]->name = 'medium'; |
|
577
|
|
|
$group->save(); |
|
578
|
|
|
$product->setAttributeGroup($group->getId()); |
|
579
|
|
|
|
|
580
|
|
|
$variation = $product->getVariation(); |
|
581
|
|
|
$variation->product_id = 1; |
|
582
|
|
|
$variation->setAttributesFromArray(array('attribute1' => 1, 'attribute2' => 3)); |
|
583
|
|
|
$variation->save(); |
|
584
|
|
|
$detail = $variation->getDetail(); |
|
585
|
|
|
$detail->price_difference = 0; |
|
586
|
|
|
$detail->weight_difference = 0; |
|
587
|
|
|
$detail->save(); |
|
588
|
|
|
|
|
589
|
|
|
$variation = $product->getVariation(); |
|
590
|
|
|
$variation->product_id = 1; |
|
591
|
|
|
$variation->setAttributesFromArray(array('attribute1' => 2, 'attribute2' => 4)); |
|
592
|
|
|
$variation->save(); |
|
593
|
|
|
$detail = $variation->getDetail(); |
|
594
|
|
|
$detail->price_difference = 0; |
|
595
|
|
|
$detail->weight_difference = 0; |
|
596
|
|
|
$detail->save(); |
|
597
|
|
|
|
|
598
|
|
|
|
|
599
|
|
|
$variations = $product->getVariations(); |
|
600
|
|
|
|
|
601
|
|
|
$this->assertEquals(2, $variations->count()); |
|
602
|
|
|
$variation = $variations->getFirst(); |
|
603
|
|
|
$this->assertEquals(1, $variation->getId()); |
|
604
|
|
|
$this->assertEquals('red', $variation->attribute1->attribute->getName()); |
|
605
|
|
|
$this->assertEquals('color', $variation->attribute1->attribute->group->getName()); |
|
606
|
|
|
|
|
607
|
|
|
$this->assertEquals('small', $variation->attribute2->attribute->getName()); |
|
608
|
|
|
$this->assertEquals('size', $variation->attribute2->attribute->group->getName()); |
|
609
|
|
|
|
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
function testGetPriceInCurrency() |
|
613
|
|
|
{ |
|
614
|
|
|
require_once 'tests/unit/stubs/Fake/Intraface/modules/currency/Currency.php'; |
|
615
|
|
|
$currency = new Fake_Intraface_modules_currency_Currency; |
|
616
|
|
|
require_once 'tests/unit/stubs/Fake/Intraface/modules/currency/Currency/ExchangeRate.php'; |
|
617
|
|
|
$currency->product_price_exchange_rate = new Fake_Intraface_modules_currency_Currency_ExchangeRate; |
|
618
|
|
|
require_once 'tests/unit/stubs/Fake/Ilib/Variable/Float.php'; |
|
619
|
|
|
$currency->product_price_exchange_rate->rate = new Fake_Ilib_Variable_Float; |
|
620
|
|
|
$currency->product_price_exchange_rate->rate->iso = 745.23; |
|
621
|
|
|
|
|
622
|
|
|
$product = new Product($this->kernel); |
|
623
|
|
|
$product->save(array('name' => 'test', 'price' => 200, 'unit' => 1)); |
|
624
|
|
|
$product->load(); |
|
625
|
|
|
|
|
626
|
|
|
$this->assertEquals(26.84, $product->getDetails()->getPriceInCurrency($currency)->getAsIso()); |
|
627
|
|
|
|
|
628
|
|
|
|
|
629
|
|
|
|
|
630
|
|
|
} |
|
631
|
|
|
*/ |
|
632
|
|
|
} |
|
633
|
|
|
|
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.