1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Basket; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
private static $testItem; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
public static function setUpBeforeClass() |
20
|
|
|
{ |
21
|
|
|
$context = \TestHelperFrontend::getContext(); |
22
|
|
|
self::$testItem = \Aimeos\MShop\Factory::createManager( $context, 'product' )->findItem( 'U:TESTP' ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
protected function setUp() |
27
|
|
|
{ |
28
|
|
|
\Aimeos\MShop\Factory::setCache( true ); |
29
|
|
|
|
30
|
|
|
$this->context = \TestHelperFrontend::getContext(); |
31
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Basket\Standard( $this->context ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
protected function tearDown() |
36
|
|
|
{ |
37
|
|
|
\Aimeos\MShop\Factory::setCache( false ); |
38
|
|
|
\Aimeos\MShop\Factory::clear(); |
39
|
|
|
|
40
|
|
|
$this->object->clear(); |
41
|
|
|
$this->context->getSession()->set( 'aimeos', [] ); |
42
|
|
|
|
43
|
|
|
unset( $this->context, $this->object ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
public function testClear() |
48
|
|
|
{ |
49
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
50
|
|
|
$this->object->clear(); |
51
|
|
|
|
52
|
|
|
$this->assertEquals( 0, count( $this->object->get()->getProducts() ) ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
public function testGet() |
57
|
|
|
{ |
58
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Base\Iface', $this->object->get() ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testSave() |
63
|
|
|
{ |
64
|
|
|
$stub = $this->getMockBuilder( '\Aimeos\MShop\Order\Manager\Base\Standard' ) |
65
|
|
|
->setConstructorArgs( [$this->context] ) |
66
|
|
|
->setMethods( ['setSession'] ) |
67
|
|
|
->getMock(); |
68
|
|
|
|
69
|
|
|
\Aimeos\MShop\Factory::injectManager( $this->context, 'order/base', $stub ); |
70
|
|
|
|
71
|
|
|
$stub->expects( $this->exactly( 2 ) )->method( 'setSession' ); |
72
|
|
|
|
73
|
|
|
$object = new \Aimeos\Controller\Frontend\Basket\Standard( $this->context ); |
74
|
|
|
$object->addProduct( self::$testItem->getId(), 2 ); |
75
|
|
|
$object->save(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
public function testSetType() |
80
|
|
|
{ |
81
|
|
|
$this->assertInstanceOf( '\Aimeos\Controller\Frontend\Basket\Iface', $this->object->setType( 'test' ) ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
public function testStore() |
86
|
|
|
{ |
87
|
|
|
$stub = $this->getMockBuilder( '\Aimeos\MShop\Order\Manager\Base\Standard' ) |
88
|
|
|
->setConstructorArgs( [$this->context] ) |
89
|
|
|
->setMethods( ['store'] ) |
90
|
|
|
->getMock(); |
91
|
|
|
|
92
|
|
|
\Aimeos\MShop\Factory::injectManager( $this->context, 'order/base', $stub ); |
93
|
|
|
|
94
|
|
|
$stub->expects( $this->once() )->method( 'store' ); |
95
|
|
|
|
96
|
|
|
$object = new \Aimeos\Controller\Frontend\Basket\Standard( $this->context ); |
97
|
|
|
$object->store(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function testStoreLimit() |
102
|
|
|
{ |
103
|
|
|
$this->context->setEditor( 'core:unittest' ); |
104
|
|
|
$config = $this->context->getConfig(); |
105
|
|
|
$config->set( 'controller/frontend/basket/limit-count', 0 ); |
106
|
|
|
$config->set( 'controller/frontend/basket/limit-seconds', 86400 * 365 ); |
107
|
|
|
|
108
|
|
|
$object = new \Aimeos\Controller\Frontend\Basket\Standard( $this->context ); |
109
|
|
|
|
110
|
|
|
$this->setExpectedException( '\Aimeos\Controller\Frontend\Basket\Exception' ); |
111
|
|
|
$object->store(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
public function testLoad() |
116
|
|
|
{ |
117
|
|
|
$stub = $this->getMockBuilder( '\Aimeos\MShop\Order\Manager\Base\Standard' ) |
118
|
|
|
->setConstructorArgs( [$this->context] ) |
119
|
|
|
->setMethods( ['load'] ) |
120
|
|
|
->getMock(); |
121
|
|
|
|
122
|
|
|
\Aimeos\MShop\Factory::injectManager( $this->context, 'order/base', $stub ); |
123
|
|
|
|
124
|
|
|
$stub->expects( $this->once() )->method( 'load' ) |
125
|
|
|
->will( $this->returnValue( $stub->createItem() ) ); |
126
|
|
|
|
127
|
|
|
$object = new \Aimeos\Controller\Frontend\Basket\Standard( $this->context ); |
128
|
|
|
$object->load( -1 ); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
public function testAddDeleteProduct() |
133
|
|
|
{ |
134
|
|
|
$basket = $this->object->get(); |
135
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'product' )->findItem( 'CNC' ); |
136
|
|
|
|
137
|
|
|
$this->object->addProduct( $item->getId(), 2, [], [], [], [], [], 'default' ); |
138
|
|
|
$item2 = $this->object->get()->getProduct( 0 ); |
139
|
|
|
$this->object->deleteProduct( 0 ); |
140
|
|
|
|
141
|
|
|
$this->assertEquals( 0, count( $basket->getProducts() ) ); |
142
|
|
|
$this->assertEquals( 'CNC', $item2->getProductCode() ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
public function testAddProductCustomAttribute() |
147
|
|
|
{ |
148
|
|
|
$attributeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
149
|
|
|
|
150
|
|
|
$search = $attributeManager->createSearch(); |
151
|
|
|
$expr = array( |
152
|
|
|
$search->compare( '==', 'attribute.code', 'custom' ), |
153
|
|
|
$search->compare( '==', 'attribute.type.code', 'date' ), |
154
|
|
|
); |
155
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
156
|
|
|
|
157
|
|
|
$attributes = $attributeManager->searchItems( $search ); |
158
|
|
|
|
159
|
|
|
if( ( $attrItem = reset( $attributes ) ) === false ) { |
160
|
|
|
throw new \RuntimeException( 'Attribute not found' ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
$attrValues = array( $attrItem->getId() => '2000-01-01' ); |
164
|
|
|
|
165
|
|
|
$this->object->addProduct( self::$testItem->getId(), 1, [], [], [], [], $attrValues ); |
166
|
|
|
$basket = $this->object->get(); |
167
|
|
|
|
168
|
|
|
$this->assertEquals( 1, count( $basket->getProducts() ) ); |
169
|
|
|
$this->assertEquals( '2000-01-01', $basket->getProduct( 0 )->getAttribute( 'date', 'custom' ) ); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
public function testAddProductCustomPrice() |
174
|
|
|
{ |
175
|
|
|
$attributeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
176
|
|
|
|
177
|
|
|
$search = $attributeManager->createSearch(); |
178
|
|
|
$expr = array( |
179
|
|
|
$search->compare( '==', 'attribute.code', 'custom' ), |
180
|
|
|
$search->compare( '==', 'attribute.type.code', 'price' ), |
181
|
|
|
); |
182
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
183
|
|
|
|
184
|
|
|
$attributes = $attributeManager->searchItems( $search ); |
185
|
|
|
|
186
|
|
|
if( ( $attrItem = reset( $attributes ) ) === false ) { |
187
|
|
|
throw new \RuntimeException( 'Attribute not found' ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
$attrValues = array( $attrItem->getId() => '0.01' ); |
191
|
|
|
|
192
|
|
|
$this->object->addProduct( self::$testItem->getId(), 1, [], [], [], [], $attrValues ); |
193
|
|
|
$basket = $this->object->get(); |
194
|
|
|
|
195
|
|
|
$this->assertEquals( 1, count( $basket->getProducts() ) ); |
196
|
|
|
$this->assertEquals( '0.01', $basket->getProduct( 0 )->getPrice()->getValue() ); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
|
200
|
|
|
public function testAddProductCustomPriceException() |
201
|
|
|
{ |
202
|
|
|
$attributeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
203
|
|
|
|
204
|
|
|
$search = $attributeManager->createSearch(); |
205
|
|
|
$expr = array( |
206
|
|
|
$search->compare( '==', 'attribute.code', 'custom' ), |
207
|
|
|
$search->compare( '==', 'attribute.type.code', 'price' ), |
208
|
|
|
); |
209
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
210
|
|
|
|
211
|
|
|
$attributes = $attributeManager->searchItems( $search ); |
212
|
|
|
|
213
|
|
|
if( ( $attrItem = reset( $attributes ) ) === false ) { |
214
|
|
|
throw new \RuntimeException( 'Attribute not found' ); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
$attrValues = array( $attrItem->getId() => ',' ); |
218
|
|
|
|
219
|
|
|
$this->setExpectedException( '\Aimeos\Controller\Frontend\Basket\Exception' ); |
220
|
|
|
$this->object->addProduct( self::$testItem->getId(), 1, [], [], [], [], $attrValues ); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
|
224
|
|
|
public function testAddProductAttributePrice() |
225
|
|
|
{ |
226
|
|
|
$configAttrIds = []; |
|
|
|
|
227
|
|
|
$attributeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
228
|
|
|
|
229
|
|
|
$search = $attributeManager->createSearch(); |
230
|
|
|
$expr = array( |
231
|
|
|
$search->compare( '==', 'attribute.code', 'xs' ), |
232
|
|
|
$search->compare( '==', 'attribute.type.code', 'size' ), |
233
|
|
|
); |
234
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
235
|
|
|
|
236
|
|
|
$attributes = $attributeManager->searchItems( $search ); |
237
|
|
|
|
238
|
|
|
if( ( $attribute = reset( $attributes ) ) === false ) { |
239
|
|
|
throw new \RuntimeException( 'Attribute not found' ); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
$this->object->addProduct( self::$testItem->getId(), 1, [], [], [$attribute->getId() => 2] ); |
243
|
|
|
|
244
|
|
|
$this->assertEquals( '43.90', $this->object->get()->getPrice()->getValue() ); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
|
248
|
|
|
public function testAddProductAttributeNotAssigned() |
249
|
|
|
{ |
250
|
|
|
$attributeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
251
|
|
|
|
252
|
|
|
$search = $attributeManager->createSearch(); |
253
|
|
|
$expr = array( |
254
|
|
|
$search->compare( '==', 'attribute.code', '30' ), |
255
|
|
|
$search->compare( '==', 'attribute.type.code', 'width' ), |
256
|
|
|
); |
257
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
258
|
|
|
|
259
|
|
|
$attribute = $attributeManager->searchItems( $search ); |
260
|
|
|
|
261
|
|
|
if( empty( $attribute ) ) { |
262
|
|
|
throw new \RuntimeException( 'Attribute not found' ); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
$hiddenAttrIds = array_keys( $attribute ); |
266
|
|
|
$configAttrIds = array_keys( $attribute ); |
267
|
|
|
|
268
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
269
|
|
|
$this->object->addProduct( self::$testItem->getId(), 1, [], [], $configAttrIds, $hiddenAttrIds ); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
|
273
|
|
|
public function testAddProductNegativeQuantityException() |
274
|
|
|
{ |
275
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Order\\Exception' ); |
276
|
|
|
$this->object->addProduct( self::$testItem->getId(), -1 ); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
|
280
|
|
|
public function testAddProductNoPriceException() |
281
|
|
|
{ |
282
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'product' )->findItem( 'MNOP' ); |
283
|
|
|
|
284
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Price\\Exception' ); |
285
|
|
|
$this->object->addProduct( $item->getId(), 1 ); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
|
289
|
|
|
public function testAddProductConfigAttributeException() |
290
|
|
|
{ |
291
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
292
|
|
|
$this->object->addProduct( self::$testItem->getId(), 1, [], [], array( -1 ) ); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
|
296
|
|
|
public function testAddProductLowQuantityPriceException() |
297
|
|
|
{ |
298
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'product' )->findItem( 'IJKL' ); |
299
|
|
|
|
300
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Price\\Exception' ); |
301
|
|
|
$this->object->addProduct( $item->getId(), 1 ); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
|
305
|
|
|
public function testAddProductHigherQuantities() |
306
|
|
|
{ |
307
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'product' )->findItem( 'IJKL' ); |
308
|
|
|
|
309
|
|
|
$this->object->addProduct( $item->getId(), 2, [], [], [], [], [], 'unit_type3' ); |
310
|
|
|
|
311
|
|
|
$this->assertEquals( 2, $this->object->get()->getProduct( 0 )->getQuantity() ); |
312
|
|
|
$this->assertEquals( 'IJKL', $this->object->get()->getProduct( 0 )->getProductCode() ); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
|
316
|
|
|
public function testDeleteProductFlagError() |
317
|
|
|
{ |
318
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
319
|
|
|
|
320
|
|
|
$item = $this->object->get()->getProduct( 0 ); |
321
|
|
|
$item->setFlags( \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE ); |
322
|
|
|
|
323
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
324
|
|
|
$this->object->deleteProduct( 0 ); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
|
328
|
|
|
public function testEditProduct() |
329
|
|
|
{ |
330
|
|
|
$this->object->addProduct( self::$testItem->getId(), 1 ); |
331
|
|
|
|
332
|
|
|
$item = $this->object->get()->getProduct( 0 ); |
333
|
|
|
$this->assertEquals( 1, $item->getQuantity() ); |
334
|
|
|
|
335
|
|
|
$this->object->editProduct( 0, 4 ); |
336
|
|
|
|
337
|
|
|
$item = $this->object->get()->getProduct( 0 ); |
338
|
|
|
$this->assertEquals( 4, $item->getQuantity() ); |
339
|
|
|
$this->assertEquals( 'U:TESTP', $item->getProductCode() ); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
|
343
|
|
|
public function testEditProductAttributes() |
344
|
|
|
{ |
345
|
|
|
$configAttrIds = []; |
346
|
|
|
$attributeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
347
|
|
|
|
348
|
|
|
$search = $attributeManager->createSearch(); |
349
|
|
|
$conditions = array( |
350
|
|
|
$search->compare( '==', 'attribute.domain', 'product' ), |
351
|
|
|
$search->combine( '||', array( |
352
|
|
|
$search->combine( '&&', array( |
353
|
|
|
$search->compare( '==', 'attribute.code', 'xs' ), |
354
|
|
|
$search->compare( '==', 'attribute.type.code', 'size' ), |
355
|
|
|
) ), |
356
|
|
|
$search->combine( '&&', array( |
357
|
|
|
$search->compare( '==', 'attribute.code', 'white' ), |
358
|
|
|
$search->compare( '==', 'attribute.type.code', 'color' ), |
359
|
|
|
) ), |
360
|
|
|
) ) |
361
|
|
|
); |
362
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
363
|
|
|
$attributes = $attributeManager->searchItems( $search ); |
364
|
|
|
|
365
|
|
|
if( empty( $attributes ) ) { |
366
|
|
|
throw new \RuntimeException( 'No attributes available' ); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
foreach( $attributes as $id => $attribute ) { |
370
|
|
|
$configAttrIds[$id] = 1; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'product' )->findItem( 'U:TESTP' ); |
374
|
|
|
|
375
|
|
|
$this->object->addProduct( $item->getId(), 1, [], [], $configAttrIds ); |
376
|
|
|
$this->object->editProduct( 0, 4 ); |
377
|
|
|
|
378
|
|
|
$item = $this->object->get()->getProduct( 0 ); |
379
|
|
|
$this->assertEquals( 2, count( $item->getAttributes() ) ); |
380
|
|
|
$this->assertEquals( 4, $item->getQuantity() ); |
381
|
|
|
|
382
|
|
|
|
383
|
|
|
$this->object->editProduct( 0, 3, [], array( $attribute->getType() ) ); |
|
|
|
|
384
|
|
|
|
385
|
|
|
$item = $this->object->get()->getProduct( 0 ); |
386
|
|
|
$this->assertEquals( 3, $item->getQuantity() ); |
387
|
|
|
$this->assertEquals( 1, count( $item->getAttributes() ) ); |
388
|
|
|
$this->assertEquals( 'U:TESTP', $item->getProductCode() ); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
|
392
|
|
|
public function testEditProductFlagError() |
393
|
|
|
{ |
394
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
395
|
|
|
|
396
|
|
|
$item = $this->object->get()->getProduct( 0 ); |
397
|
|
|
$item->setFlags( \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE ); |
398
|
|
|
|
399
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
400
|
|
|
$this->object->editProduct( 0, 4 ); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
|
404
|
|
|
public function testAddCoupon() |
405
|
|
|
{ |
406
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
407
|
|
|
$this->object->addCoupon( 'GHIJ' ); |
408
|
|
|
|
409
|
|
|
$basket = $this->object->get(); |
410
|
|
|
|
411
|
|
|
$this->assertEquals( 1, count( $basket->getCoupons() ) ); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
|
415
|
|
|
public function testAddCouponExceedCount() |
416
|
|
|
{ |
417
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
418
|
|
|
$this->object->addCoupon( 'GHIJ' ); |
419
|
|
|
|
420
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
421
|
|
|
$this->object->addCoupon( 'GHIJ' ); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
|
425
|
|
|
public function testAddCouponInvalidCode() |
426
|
|
|
{ |
427
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
428
|
|
|
$this->object->addCoupon( 'invalid' ); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
|
432
|
|
|
public function testAddCouponMissingRequirements() |
433
|
|
|
{ |
434
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
435
|
|
|
$this->object->addCoupon( 'OPQR' ); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
|
439
|
|
|
public function testDeleteCoupon() |
440
|
|
|
{ |
441
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
442
|
|
|
$this->object->addCoupon( '90AB' ); |
443
|
|
|
$this->object->deleteCoupon( '90AB' ); |
444
|
|
|
|
445
|
|
|
$basket = $this->object->get(); |
446
|
|
|
|
447
|
|
|
$this->assertEquals( 0, count( $basket->getCoupons() ) ); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
|
451
|
|
|
public function testSetAddressDelete() |
452
|
|
|
{ |
453
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, null ); |
454
|
|
|
|
455
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Order\Exception' ); |
456
|
|
|
$this->object->get()->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT ); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
|
460
|
|
|
public function testSetBillingAddressByItem() |
461
|
|
|
{ |
462
|
|
|
$item = $this->getAddress( 'Example company' ); |
463
|
|
|
|
464
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, $item ); |
465
|
|
|
|
466
|
|
|
$address = $this->object->get()->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT ); |
467
|
|
|
$this->assertEquals( 'Example company', $address->getCompany() ); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
|
471
|
|
|
public function testSetBillingAddressByArray() |
472
|
|
|
{ |
473
|
|
|
$fixture = array( |
474
|
|
|
'order.base.address.company' => '<p onclick="javascript: alert(\'gotcha\');">Example company</p>', |
475
|
|
|
'order.base.address.vatid' => 'DE999999999', |
476
|
|
|
'order.base.address.title' => '<br/>Dr.', |
477
|
|
|
'order.base.address.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR, |
478
|
|
|
'order.base.address.firstname' => 'firstunit', |
479
|
|
|
'order.base.address.lastname' => 'lastunit', |
480
|
|
|
'order.base.address.address1' => 'unit str.', |
481
|
|
|
'order.base.address.address2' => ' 166', |
482
|
|
|
'order.base.address.address3' => '4.OG', |
483
|
|
|
'order.base.address.postal' => '22769', |
484
|
|
|
'order.base.address.city' => 'Hamburg', |
485
|
|
|
'order.base.address.state' => 'Hamburg', |
486
|
|
|
'order.base.address.countryid' => 'de', |
487
|
|
|
'order.base.address.languageid' => 'de', |
488
|
|
|
'order.base.address.telephone' => '05554433221', |
489
|
|
|
'order.base.address.email' => '[email protected]', |
490
|
|
|
'order.base.address.telefax' => '05554433222', |
491
|
|
|
'order.base.address.website' => 'www.example.com', |
492
|
|
|
'order.base.address.flag' => 0, |
493
|
|
|
); |
494
|
|
|
|
495
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, $fixture ); |
496
|
|
|
|
497
|
|
|
$address = $this->object->get()->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT ); |
498
|
|
|
$this->assertEquals( 'Example company', $address->getCompany() ); |
499
|
|
|
$this->assertEquals( 'Dr.', $address->getTitle() ); |
500
|
|
|
$this->assertEquals( 'firstunit', $address->getFirstname() ); |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
|
504
|
|
|
public function testSetBillingAddressByArrayError() |
505
|
|
|
{ |
506
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
507
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, array( 'error' => false ) ); |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
|
511
|
|
|
public function testSetBillingAddressParameterError() |
512
|
|
|
{ |
513
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
514
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, 'error' ); |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
|
518
|
|
|
public function testSetDeliveryAddressByItem() |
519
|
|
|
{ |
520
|
|
|
$item = $this->getAddress( 'Example company' ); |
521
|
|
|
|
522
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY, $item ); |
523
|
|
|
|
524
|
|
|
$address = $this->object->get()->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY ); |
525
|
|
|
$this->assertEquals( 'Example company', $address->getCompany() ); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
|
529
|
|
|
public function testSetDeliveryAddressByArray() |
530
|
|
|
{ |
531
|
|
|
$fixture = array( |
532
|
|
|
'order.base.address.company' => '<p onclick="javascript: alert(\'gotcha\');">Example company</p>', |
533
|
|
|
'order.base.address.vatid' => 'DE999999999', |
534
|
|
|
'order.base.address.title' => '<br/>Dr.', |
535
|
|
|
'order.base.address.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR, |
536
|
|
|
'order.base.address.firstname' => 'firstunit', |
537
|
|
|
'order.base.address.lastname' => 'lastunit', |
538
|
|
|
'order.base.address.address1' => 'unit str.', |
539
|
|
|
'order.base.address.address2' => ' 166', |
540
|
|
|
'order.base.address.address3' => '4.OG', |
541
|
|
|
'order.base.address.postal' => '22769', |
542
|
|
|
'order.base.address.city' => 'Hamburg', |
543
|
|
|
'order.base.address.state' => 'Hamburg', |
544
|
|
|
'order.base.address.countryid' => 'de', |
545
|
|
|
'order.base.address.languageid' => 'de', |
546
|
|
|
'order.base.address.telephone' => '05554433221', |
547
|
|
|
'order.base.address.email' => '[email protected]', |
548
|
|
|
'order.base.address.telefax' => '05554433222', |
549
|
|
|
'order.base.address.website' => 'www.example.com', |
550
|
|
|
'order.base.address.flag' => 0, |
551
|
|
|
); |
552
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY, $fixture ); |
553
|
|
|
|
554
|
|
|
$address = $this->object->get()->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY ); |
555
|
|
|
$this->assertEquals( 'Example company', $address->getCompany() ); |
556
|
|
|
$this->assertEquals( 'Dr.', $address->getTitle() ); |
557
|
|
|
$this->assertEquals( 'firstunit', $address->getFirstname() ); |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
|
561
|
|
|
public function testSetDeliveryAddressByArrayError() |
562
|
|
|
{ |
563
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
564
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY, array( 'error' => false ) ); |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
|
568
|
|
|
public function testSetDeliveryAddressTypeError() |
569
|
|
|
{ |
570
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
571
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY, 'error' ); |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
|
575
|
|
|
public function testSetServicePayment() |
576
|
|
|
{ |
577
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'service' ); |
578
|
|
|
$service = $manager->findItem( 'unitpaymentcode', [], 'service', 'payment' ); |
579
|
|
|
|
580
|
|
|
$this->object->addService( 'payment', $service->getId(), [] ); |
581
|
|
|
$item = $this->object->get()->getService( 'payment', 'unitpaymentcode' )->getCode(); |
|
|
|
|
582
|
|
|
$this->assertEquals( 'unitpaymentcode', $item ); |
583
|
|
|
|
584
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
585
|
|
|
$this->object->addService( 'payment', $service->getId(), array( 'prepay' => true ) ); |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
|
589
|
|
|
public function testSetDeliveryOption() |
590
|
|
|
{ |
591
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'service' ); |
592
|
|
|
$service = $manager->findItem( 'unitcode', [], 'service', 'delivery' ); |
593
|
|
|
|
594
|
|
|
$this->object->addService( 'delivery', $service->getId(), [] ); |
595
|
|
|
$item = $this->object->get()->getService( 'delivery', 'unitcode' ); |
|
|
|
|
596
|
|
|
$this->assertEquals( 'unitcode', $item->getCode() ); |
597
|
|
|
|
598
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
599
|
|
|
$this->object->addService( 'delivery', $service->getId(), array( 'fast shipping' => true, 'air shipping' => false ) ); |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
|
603
|
|
|
public function testCheckLocale() |
604
|
|
|
{ |
605
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'service' ); |
606
|
|
|
$payment = $manager->findItem( 'unitpaymentcode', [], 'service', 'payment' ); |
607
|
|
|
$delivery = $manager->findItem( 'unitcode', [], 'service', 'delivery' ); |
608
|
|
|
|
609
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
610
|
|
|
$this->object->addCoupon( 'OPQR' ); |
611
|
|
|
|
612
|
|
|
$this->object->addService( 'payment', $payment->getId() ); |
613
|
|
|
$this->object->addService( 'delivery', $delivery->getId() ); |
614
|
|
|
|
615
|
|
|
$basket = $this->object->get(); |
616
|
|
|
$price = $basket->getPrice(); |
617
|
|
|
|
618
|
|
|
foreach( $basket->getProducts() as $product ) |
619
|
|
|
{ |
620
|
|
|
$this->assertEquals( 2, $product->getQuantity() ); |
621
|
|
|
$product->getPrice()->setCurrencyId( 'CHF' ); |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
$basket->getService( 'delivery', 'unitcode' )->getPrice()->setCurrencyId( 'CHF' ); |
|
|
|
|
625
|
|
|
$basket->getService( 'payment', 'unitpaymentcode' )->getPrice()->setCurrencyId( 'CHF' ); |
|
|
|
|
626
|
|
|
$basket->getLocale()->setCurrencyId( 'CHF' ); |
627
|
|
|
$price->setCurrencyId( 'CHF' ); |
628
|
|
|
|
629
|
|
|
$this->context->getLocale()->setCurrencyId( 'CHF' ); |
630
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, $this->getAddress( 'Example company' ) ); |
631
|
|
|
|
632
|
|
|
$this->context->getSession()->set( 'aimeos/basket/currency', 'CHF' ); |
633
|
|
|
$this->context->getLocale()->setCurrencyId( 'EUR' ); |
634
|
|
|
|
635
|
|
|
$this->context->getSession()->set( 'aimeos/basket/content-unittest-en-EUR-', null ); |
636
|
|
|
|
637
|
|
|
$object = new \Aimeos\Controller\Frontend\Basket\Standard( $this->context ); |
638
|
|
|
$basket = $object->get(); |
639
|
|
|
|
640
|
|
|
foreach( $basket->getProducts() as $product ) |
641
|
|
|
{ |
642
|
|
|
$this->assertEquals( 'EUR', $product->getPrice()->getCurrencyId() ); |
643
|
|
|
$this->assertEquals( 2, $product->getQuantity() ); |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
$this->assertEquals( 'EUR', $basket->getService( 'payment', 'unitpaymentcode' )->getPrice()->getCurrencyId() ); |
|
|
|
|
647
|
|
|
$this->assertEquals( 'EUR', $basket->getService( 'delivery', 'unitcode' )->getPrice()->getCurrencyId() ); |
|
|
|
|
648
|
|
|
$this->assertEquals( 'EUR', $basket->getLocale()->getCurrencyId() ); |
649
|
|
|
$this->assertEquals( 'EUR', $basket->getPrice()->getCurrencyId() ); |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
|
653
|
|
|
/** |
654
|
|
|
* @param string $company |
655
|
|
|
*/ |
656
|
|
|
protected function getAddress( $company ) |
657
|
|
|
{ |
658
|
|
|
$customer = \Aimeos\MShop\Customer\Manager\Factory::createManager( \TestHelperFrontend::getContext(), 'Standard' ); |
659
|
|
|
$addressManager = $customer->getSubManager( 'address', 'Standard' ); |
660
|
|
|
|
661
|
|
|
$search = $addressManager->createSearch(); |
662
|
|
|
$search->setConditions( $search->compare( '==', 'customer.address.company', $company ) ); |
663
|
|
|
$items = $addressManager->searchItems( $search ); |
664
|
|
|
|
665
|
|
|
if( ( $item = reset( $items ) ) === false ) { |
666
|
|
|
throw new \RuntimeException( sprintf( 'No address item with company "%1$s" found', $company ) ); |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
return $item; |
670
|
|
|
} |
671
|
|
|
} |
672
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.