Passed
Push — master ( 3d7239...40a1f5 )
by Aimeos
02:03
created

StandardTest   B

Complexity

Total Complexity 52

Size/Duplication

Total Lines 647
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 52
eloc 316
dl 0
loc 647
rs 7.44
c 0
b 0
f 0

42 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 8 1
A testAddProductConfigAttributeException() 0 4 1
A testAddCouponInvalidCode() 0 4 1
A testAddProductNegativeQuantityException() 0 4 1
A testAddCoupon() 0 8 1
A testEditProduct() 0 12 1
A testAddProductCustomPrice() 0 24 2
A testAddProductAttributeNotAssigned() 0 22 2
A testAddProductHigherQuantities() 0 8 1
A testLoad() 0 14 1
A testAddProductLowQuantityPriceException() 0 6 1
A testClear() 0 6 1
A testAddProductAttributePrice() 0 20 2
A testEditProductAttributes() 0 46 3
A testEditProductFlagError() 0 9 1
A testAddCouponExceedCount() 0 7 1
A testGet() 0 3 1
A setUp() 0 6 1
A testAddProductNoPriceException() 0 6 1
A testSave() 0 14 1
A testStore() 0 13 1
A testAddDeleteProduct() 0 11 1
A testStoreLimit() 0 11 1
A testAddProductCustomAttribute() 0 24 2
A testDeleteProductFlagError() 0 9 1
A setUpBeforeClass() 0 4 1
A testSetType() 0 3 1
A testAddProductCustomPriceException() 0 21 2
A testSetBillingAddressByArrayError() 0 4 1
A testCheckLocale() 0 47 3
A testSetAddressDelete() 0 6 1
A testSetBillingAddressParameterError() 0 4 1
A testSetDeliveryAddressTypeError() 0 4 1
A testSetServicePayment() 0 11 1
A getAddress() 0 14 2
A testSetDeliveryOption() 0 11 1
A testSetDeliveryAddressByItem() 0 8 1
A testSetBillingAddressByArray() 0 29 1
A testSetBillingAddressByItem() 0 8 1
A testDeleteCoupon() 0 9 1
A testSetDeliveryAddressByArrayError() 0 4 1
A testSetDeliveryAddressByArray() 0 28 1

How to fix   Complexity   

Complex Class

Complex classes like StandardTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use StandardTest, and based on these observations, apply Extract Interface, too.

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-2018
7
 */
8
9
namespace Aimeos\Controller\Frontend\Basket;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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