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 testAddProductAttributeNotAssigned() |
225
|
|
|
{ |
226
|
|
|
$attributeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
227
|
|
|
|
228
|
|
|
$search = $attributeManager->createSearch(); |
229
|
|
|
$expr = array( |
230
|
|
|
$search->compare( '==', 'attribute.code', '30' ), |
231
|
|
|
$search->compare( '==', 'attribute.type.code', 'width' ), |
232
|
|
|
); |
233
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
234
|
|
|
|
235
|
|
|
$attribute = $attributeManager->searchItems( $search ); |
236
|
|
|
|
237
|
|
|
if( empty( $attribute ) ) { |
238
|
|
|
throw new \RuntimeException( 'Attribute not found' ); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
$hiddenAttrIds = array_keys( $attribute ); |
242
|
|
|
$configAttrIds = array_keys( $attribute ); |
243
|
|
|
|
244
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
245
|
|
|
$this->object->addProduct( self::$testItem->getId(), 1, [], [], $configAttrIds, $hiddenAttrIds ); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
|
249
|
|
|
public function testAddProductNegativeQuantityException() |
250
|
|
|
{ |
251
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Order\\Exception' ); |
252
|
|
|
$this->object->addProduct( self::$testItem->getId(), -1 ); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
|
256
|
|
|
public function testAddProductNoPriceException() |
257
|
|
|
{ |
258
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'product' )->findItem( 'MNOP' ); |
259
|
|
|
|
260
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Price\\Exception' ); |
261
|
|
|
$this->object->addProduct( $item->getId(), 1 ); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
public function testAddProductConfigAttributeException() |
266
|
|
|
{ |
267
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
268
|
|
|
$this->object->addProduct( self::$testItem->getId(), 1, [], [], array( -1 ) ); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
|
272
|
|
|
public function testAddProductLowQuantityPriceException() |
273
|
|
|
{ |
274
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'product' )->findItem( 'IJKL' ); |
275
|
|
|
|
276
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Price\\Exception' ); |
277
|
|
|
$this->object->addProduct( $item->getId(), 1 ); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
|
281
|
|
|
public function testAddProductHigherQuantities() |
282
|
|
|
{ |
283
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'product' )->findItem( 'IJKL' ); |
284
|
|
|
|
285
|
|
|
$this->object->addProduct( $item->getId(), 2, [], [], [], [], [], 'unit_type3' ); |
286
|
|
|
|
287
|
|
|
$this->assertEquals( 2, $this->object->get()->getProduct( 0 )->getQuantity() ); |
288
|
|
|
$this->assertEquals( 'IJKL', $this->object->get()->getProduct( 0 )->getProductCode() ); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
|
292
|
|
|
public function testDeleteProductFlagError() |
293
|
|
|
{ |
294
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
295
|
|
|
|
296
|
|
|
$item = $this->object->get()->getProduct( 0 ); |
297
|
|
|
$item->setFlags( \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE ); |
298
|
|
|
|
299
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
300
|
|
|
$this->object->deleteProduct( 0 ); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
|
304
|
|
|
public function testEditProduct() |
305
|
|
|
{ |
306
|
|
|
$this->object->addProduct( self::$testItem->getId(), 1 ); |
307
|
|
|
|
308
|
|
|
$item = $this->object->get()->getProduct( 0 ); |
309
|
|
|
$this->assertEquals( 1, $item->getQuantity() ); |
310
|
|
|
|
311
|
|
|
$this->object->editProduct( 0, 4 ); |
312
|
|
|
|
313
|
|
|
$item = $this->object->get()->getProduct( 0 ); |
314
|
|
|
$this->assertEquals( 4, $item->getQuantity() ); |
315
|
|
|
$this->assertEquals( 'U:TESTP', $item->getProductCode() ); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
|
319
|
|
|
public function testEditProductAttributes() |
320
|
|
|
{ |
321
|
|
|
$attributeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
322
|
|
|
|
323
|
|
|
$search = $attributeManager->createSearch(); |
324
|
|
|
$conditions = array( |
325
|
|
|
$search->compare( '==', 'attribute.domain', 'product' ), |
326
|
|
|
$search->combine( '||', array( |
327
|
|
|
$search->combine( '&&', array( |
328
|
|
|
$search->compare( '==', 'attribute.code', 'xs' ), |
329
|
|
|
$search->compare( '==', 'attribute.type.code', 'size' ), |
330
|
|
|
) ), |
331
|
|
|
$search->combine( '&&', array( |
332
|
|
|
$search->compare( '==', 'attribute.code', 'white' ), |
333
|
|
|
$search->compare( '==', 'attribute.type.code', 'color' ), |
334
|
|
|
) ), |
335
|
|
|
) ) |
336
|
|
|
); |
337
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
338
|
|
|
$attributes = $attributeManager->searchItems( $search ); |
339
|
|
|
|
340
|
|
|
if( ( $attribute = reset( $attributes ) ) === false ) { |
341
|
|
|
throw new \RuntimeException( 'No attributes available' ); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
|
345
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'product' )->findItem( 'U:TESTP' ); |
346
|
|
|
|
347
|
|
|
$this->object->addProduct( $item->getId(), 1, [], [], array_keys( $attributes ) ); |
348
|
|
|
$this->object->editProduct( 0, 4 ); |
349
|
|
|
|
350
|
|
|
$item = $this->object->get()->getProduct( 0 ); |
351
|
|
|
$this->assertEquals( 2, count( $item->getAttributes() ) ); |
352
|
|
|
$this->assertEquals( 4, $item->getQuantity() ); |
353
|
|
|
|
354
|
|
|
|
355
|
|
|
$this->object->editProduct( 0, 3, [], array( $attribute->getType() ) ); |
356
|
|
|
|
357
|
|
|
$item = $this->object->get()->getProduct( 0 ); |
358
|
|
|
$this->assertEquals( 3, $item->getQuantity() ); |
359
|
|
|
$this->assertEquals( 1, count( $item->getAttributes() ) ); |
360
|
|
|
$this->assertEquals( 'U:TESTP', $item->getProductCode() ); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
|
364
|
|
|
public function testEditProductFlagError() |
365
|
|
|
{ |
366
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
367
|
|
|
|
368
|
|
|
$item = $this->object->get()->getProduct( 0 ); |
369
|
|
|
$item->setFlags( \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE ); |
370
|
|
|
|
371
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
372
|
|
|
$this->object->editProduct( 0, 4 ); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
|
376
|
|
|
public function testAddCoupon() |
377
|
|
|
{ |
378
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
379
|
|
|
$this->object->addCoupon( 'GHIJ' ); |
380
|
|
|
|
381
|
|
|
$basket = $this->object->get(); |
382
|
|
|
|
383
|
|
|
$this->assertEquals( 1, count( $basket->getCoupons() ) ); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
|
387
|
|
|
public function testAddCouponExceedCount() |
388
|
|
|
{ |
389
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
390
|
|
|
$this->object->addCoupon( 'GHIJ' ); |
391
|
|
|
|
392
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
393
|
|
|
$this->object->addCoupon( 'GHIJ' ); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
|
397
|
|
|
public function testAddCouponInvalidCode() |
398
|
|
|
{ |
399
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
400
|
|
|
$this->object->addCoupon( 'invalid' ); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
|
404
|
|
|
public function testAddCouponMissingRequirements() |
405
|
|
|
{ |
406
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
407
|
|
|
$this->object->addCoupon( 'OPQR' ); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
|
411
|
|
|
public function testDeleteCoupon() |
412
|
|
|
{ |
413
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
414
|
|
|
$this->object->addCoupon( '90AB' ); |
415
|
|
|
$this->object->deleteCoupon( '90AB' ); |
416
|
|
|
|
417
|
|
|
$basket = $this->object->get(); |
418
|
|
|
|
419
|
|
|
$this->assertEquals( 0, count( $basket->getCoupons() ) ); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
|
423
|
|
|
public function testSetAddressDelete() |
424
|
|
|
{ |
425
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, null ); |
426
|
|
|
|
427
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Order\Exception' ); |
428
|
|
|
$this->object->get()->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT ); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
|
432
|
|
|
public function testSetBillingAddressByItem() |
433
|
|
|
{ |
434
|
|
|
$item = $this->getAddress( 'Example company' ); |
435
|
|
|
|
436
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, $item ); |
437
|
|
|
|
438
|
|
|
$address = $this->object->get()->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT ); |
439
|
|
|
$this->assertEquals( 'Example company', $address->getCompany() ); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
|
443
|
|
|
public function testSetBillingAddressByArray() |
444
|
|
|
{ |
445
|
|
|
$fixture = array( |
446
|
|
|
'order.base.address.company' => '<p onclick="javascript: alert(\'gotcha\');">Example company</p>', |
447
|
|
|
'order.base.address.vatid' => 'DE999999999', |
448
|
|
|
'order.base.address.title' => '<br/>Dr.', |
449
|
|
|
'order.base.address.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR, |
450
|
|
|
'order.base.address.firstname' => 'firstunit', |
451
|
|
|
'order.base.address.lastname' => 'lastunit', |
452
|
|
|
'order.base.address.address1' => 'unit str.', |
453
|
|
|
'order.base.address.address2' => ' 166', |
454
|
|
|
'order.base.address.address3' => '4.OG', |
455
|
|
|
'order.base.address.postal' => '22769', |
456
|
|
|
'order.base.address.city' => 'Hamburg', |
457
|
|
|
'order.base.address.state' => 'Hamburg', |
458
|
|
|
'order.base.address.countryid' => 'de', |
459
|
|
|
'order.base.address.languageid' => 'de', |
460
|
|
|
'order.base.address.telephone' => '05554433221', |
461
|
|
|
'order.base.address.email' => '[email protected]', |
462
|
|
|
'order.base.address.telefax' => '05554433222', |
463
|
|
|
'order.base.address.website' => 'www.example.com', |
464
|
|
|
'order.base.address.flag' => 0, |
465
|
|
|
); |
466
|
|
|
|
467
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, $fixture ); |
468
|
|
|
|
469
|
|
|
$address = $this->object->get()->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT ); |
470
|
|
|
$this->assertEquals( 'Example company', $address->getCompany() ); |
471
|
|
|
$this->assertEquals( 'Dr.', $address->getTitle() ); |
472
|
|
|
$this->assertEquals( 'firstunit', $address->getFirstname() ); |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
|
476
|
|
|
public function testSetBillingAddressByArrayError() |
477
|
|
|
{ |
478
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
479
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, array( 'error' => false ) ); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
|
483
|
|
|
public function testSetBillingAddressParameterError() |
484
|
|
|
{ |
485
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
486
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, 'error' ); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
|
490
|
|
|
public function testSetDeliveryAddressByItem() |
491
|
|
|
{ |
492
|
|
|
$item = $this->getAddress( 'Example company' ); |
493
|
|
|
|
494
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY, $item ); |
495
|
|
|
|
496
|
|
|
$address = $this->object->get()->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY ); |
497
|
|
|
$this->assertEquals( 'Example company', $address->getCompany() ); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
|
501
|
|
|
public function testSetDeliveryAddressByArray() |
502
|
|
|
{ |
503
|
|
|
$fixture = array( |
504
|
|
|
'order.base.address.company' => '<p onclick="javascript: alert(\'gotcha\');">Example company</p>', |
505
|
|
|
'order.base.address.vatid' => 'DE999999999', |
506
|
|
|
'order.base.address.title' => '<br/>Dr.', |
507
|
|
|
'order.base.address.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR, |
508
|
|
|
'order.base.address.firstname' => 'firstunit', |
509
|
|
|
'order.base.address.lastname' => 'lastunit', |
510
|
|
|
'order.base.address.address1' => 'unit str.', |
511
|
|
|
'order.base.address.address2' => ' 166', |
512
|
|
|
'order.base.address.address3' => '4.OG', |
513
|
|
|
'order.base.address.postal' => '22769', |
514
|
|
|
'order.base.address.city' => 'Hamburg', |
515
|
|
|
'order.base.address.state' => 'Hamburg', |
516
|
|
|
'order.base.address.countryid' => 'de', |
517
|
|
|
'order.base.address.languageid' => 'de', |
518
|
|
|
'order.base.address.telephone' => '05554433221', |
519
|
|
|
'order.base.address.email' => '[email protected]', |
520
|
|
|
'order.base.address.telefax' => '05554433222', |
521
|
|
|
'order.base.address.website' => 'www.example.com', |
522
|
|
|
'order.base.address.flag' => 0, |
523
|
|
|
); |
524
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY, $fixture ); |
525
|
|
|
|
526
|
|
|
$address = $this->object->get()->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY ); |
527
|
|
|
$this->assertEquals( 'Example company', $address->getCompany() ); |
528
|
|
|
$this->assertEquals( 'Dr.', $address->getTitle() ); |
529
|
|
|
$this->assertEquals( 'firstunit', $address->getFirstname() ); |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
|
533
|
|
|
public function testSetDeliveryAddressByArrayError() |
534
|
|
|
{ |
535
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
536
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY, array( 'error' => false ) ); |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
|
540
|
|
|
public function testSetDeliveryAddressTypeError() |
541
|
|
|
{ |
542
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
543
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY, 'error' ); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
|
547
|
|
|
public function testSetServicePayment() |
548
|
|
|
{ |
549
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'service' ); |
550
|
|
|
$service = $manager->findItem( 'unitpaymentcode', [], 'service', 'payment' ); |
551
|
|
|
|
552
|
|
|
$this->object->setService( 'payment', $service->getId(), [] ); |
553
|
|
|
$this->assertEquals( 'unitpaymentcode', $this->object->get()->getService( 'payment' )->getCode() ); |
554
|
|
|
|
555
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
556
|
|
|
$this->object->setService( 'payment', $service->getId(), array( 'prepay' => true ) ); |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
|
560
|
|
|
public function testSetDeliveryOption() |
561
|
|
|
{ |
562
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'service' ); |
563
|
|
|
$service = $manager->findItem( 'unitcode', [], 'service', 'delivery' ); |
564
|
|
|
|
565
|
|
|
$this->object->setService( 'delivery', $service->getId(), [] ); |
566
|
|
|
$this->assertEquals( 'unitcode', $this->object->get()->getService( 'delivery' )->getCode() ); |
567
|
|
|
|
568
|
|
|
$this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
569
|
|
|
$this->object->setService( 'delivery', $service->getId(), array( 'fast shipping' => true, 'air shipping' => false ) ); |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
|
573
|
|
|
public function testCheckLocale() |
574
|
|
|
{ |
575
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'service' ); |
576
|
|
|
$payment = $manager->findItem( 'unitpaymentcode', [], 'service', 'payment' ); |
577
|
|
|
$delivery = $manager->findItem( 'unitcode', [], 'service', 'delivery' ); |
578
|
|
|
|
579
|
|
|
$this->object->addProduct( self::$testItem->getId(), 2 ); |
580
|
|
|
$this->object->addCoupon( 'OPQR' ); |
581
|
|
|
|
582
|
|
|
$this->object->setService( 'payment', $payment->getId() ); |
583
|
|
|
$this->object->setService( 'delivery', $delivery->getId() ); |
584
|
|
|
|
585
|
|
|
$basket = $this->object->get(); |
586
|
|
|
$price = $basket->getPrice(); |
587
|
|
|
|
588
|
|
|
foreach( $basket->getProducts() as $product ) |
589
|
|
|
{ |
590
|
|
|
$this->assertEquals( 2, $product->getQuantity() ); |
591
|
|
|
$product->getPrice()->setCurrencyId( 'CHF' ); |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
$basket->getService( 'delivery' )->getPrice()->setCurrencyId( 'CHF' ); |
595
|
|
|
$basket->getService( 'payment' )->getPrice()->setCurrencyId( 'CHF' ); |
596
|
|
|
$basket->getLocale()->setCurrencyId( 'CHF' ); |
597
|
|
|
$price->setCurrencyId( 'CHF' ); |
598
|
|
|
|
599
|
|
|
$this->context->getLocale()->setCurrencyId( 'CHF' ); |
600
|
|
|
$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, $this->getAddress( 'Example company' ) ); |
601
|
|
|
|
602
|
|
|
$this->context->getSession()->set( 'aimeos/basket/currency', 'CHF' ); |
603
|
|
|
$this->context->getLocale()->setCurrencyId( 'EUR' ); |
604
|
|
|
|
605
|
|
|
$this->context->getSession()->set( 'aimeos/basket/content-unittest-en-EUR-', null ); |
606
|
|
|
|
607
|
|
|
$object = new \Aimeos\Controller\Frontend\Basket\Standard( $this->context ); |
608
|
|
|
$basket = $object->get(); |
609
|
|
|
|
610
|
|
|
foreach( $basket->getProducts() as $product ) |
611
|
|
|
{ |
612
|
|
|
$this->assertEquals( 'EUR', $product->getPrice()->getCurrencyId() ); |
613
|
|
|
$this->assertEquals( 2, $product->getQuantity() ); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
$this->assertEquals( 'EUR', $basket->getService( 'payment' )->getPrice()->getCurrencyId() ); |
617
|
|
|
$this->assertEquals( 'EUR', $basket->getService( 'delivery' )->getPrice()->getCurrencyId() ); |
618
|
|
|
$this->assertEquals( 'EUR', $basket->getLocale()->getCurrencyId() ); |
619
|
|
|
$this->assertEquals( 'EUR', $basket->getPrice()->getCurrencyId() ); |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
|
623
|
|
|
/** |
624
|
|
|
* @param string $company |
625
|
|
|
*/ |
626
|
|
|
protected function getAddress( $company ) |
627
|
|
|
{ |
628
|
|
|
$customer = \Aimeos\MShop\Customer\Manager\Factory::createManager( \TestHelperFrontend::getContext(), 'Standard' ); |
629
|
|
|
$addressManager = $customer->getSubManager( 'address', 'Standard' ); |
630
|
|
|
|
631
|
|
|
$search = $addressManager->createSearch(); |
632
|
|
|
$search->setConditions( $search->compare( '==', 'customer.address.company', $company ) ); |
633
|
|
|
$items = $addressManager->searchItems( $search ); |
634
|
|
|
|
635
|
|
|
if( ( $item = reset( $items ) ) === false ) { |
636
|
|
|
throw new \RuntimeException( sprintf( 'No address item with company "%1$s" found', $company ) ); |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
return $item; |
640
|
|
|
} |
641
|
|
|
} |
642
|
|
|
|