StandardTest::testSetQuantityOpenDecimal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2025
6
 */
7
8
9
namespace Aimeos\MShop\Order\Item\Product;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $values;
16
	private $price;
17
	private $attributes;
18
	private $subProducts;
19
20
21
	protected function setUp() : void
22
	{
23
		$this->price = \Aimeos\MShop::create( \TestHelper::context(), 'price' )->create();
24
25
		$this->subProducts = map( [
26
			new \Aimeos\MShop\Order\Item\Product\Standard( 'order.product.', ['.price' => clone $this->price] ),
27
			new \Aimeos\MShop\Order\Item\Product\Standard( 'order.product.', ['.price' => clone $this->price] )
28
		] );
29
30
		$attrValues = array(
31
			'order.product.attribute.id' => 4,
32
			'order.product.attribute.siteid' => '99',
33
			'order.product.attribute.parentid' => 11,
34
			'order.product.attribute.type' => 'default',
35
			'order.product.attribute.code' => 'size',
36
			'order.product.attribute.value' => '30',
37
			'order.product.attribute.name' => 'small',
38
			'order.product.attribute.mtime' => '2011-01-06 13:20:34',
39
			'order.product.attribute.ctime' => '2011-01-01 00:00:01',
40
			'order.product.attribute.editor' => 'unitTestUser'
41
		);
42
		$this->attributes = map( [new \Aimeos\MShop\Order\Item\Product\Attribute\Standard( 'order.product.attribute.', $attrValues )] );
43
44
		$this->values = array(
45
			'order.product.id' => 1,
46
			'order.product.parentid' => 42,
47
			'order.product.siteid' => '99',
48
			'order.product.orderproductid' => 10,
49
			'order.product.orderaddressid' => 11,
50
			'order.product.type' => 'bundle',
51
			'order.product.productid' => '100',
52
			'order.product.parentproductid' => '99',
53
			'order.product.vendor' => 'UnitSupplier',
54
			'order.product.prodcode' => 'UnitProd',
55
			'order.product.stocktype' => 'unittype',
56
			'order.product.timeframe' => '1-2w',
57
			'order.product.name' => 'UnitProduct',
58
			'order.product.description' => 'Unit product description',
59
			'order.product.mediaurl' => 'testurl',
60
			'order.product.target' => 'testtarget',
61
			'order.product.quantity' => 11,
62
			'order.product.qtyopen' => 5,
63
			'order.product.scale' => 0.1,
64
			'order.product.flags' => \Aimeos\MShop\Order\Item\Product\Base::FLAG_NONE,
65
			'order.product.statuspayment' => \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED,
66
			'order.product.statusdelivery' => \Aimeos\MShop\Order\Item\Base::STAT_PROGRESS,
67
			'order.product.position' => 1,
68
			'order.product.notes' => 'test note',
69
			'order.product.price' => '0.00',
70
			'order.product.costs' => '0.00',
71
			'order.product.rebate' => '0.00',
72
			'order.product.taxrates' => ['' => '0.00'],
73
			'order.product.taxvalue' => '0.0000',
74
			'order.product.taxflag' => 1,
75
			'order.product.mtime' => '2000-12-31 23:59:59',
76
			'order.product.ctime' => '2011-01-01 00:00:01',
77
			'order.product.editor' => 'unitTestUser',
78
			'.supplier' => \Aimeos\MShop::create( \TestHelper::context(), 'supplier' )->create(),
79
			'.parentproduct' => \Aimeos\MShop::create( \TestHelper::context(), 'product' )->create(),
80
			'.product' => \Aimeos\MShop::create( \TestHelper::context(), 'product' )->create(),
81
			'.attributes' => $this->attributes,
82
			'.products' => $this->subProducts,
83
			'.price' => $this->price,
84
		);
85
86
		$this->object = new \Aimeos\MShop\Order\Item\Product\Standard( 'order.product.', $this->values );
87
	}
88
89
90
	protected function tearDown() : void
91
	{
92
		unset( $this->object );
93
	}
94
95
96
	public function testGetParentProductItem()
97
	{
98
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $this->object->getParentProductItem() );
99
		$this->assertNull( ( new \Aimeos\MShop\Order\Item\Product\Standard( 'order.product.' ) )->getParentProductItem() );
100
	}
101
102
103
	public function testGetProductItem()
104
	{
105
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $this->object->getProductItem() );
106
		$this->assertNull( ( new \Aimeos\MShop\Order\Item\Product\Standard( 'order.product.' ) )->getProductItem() );
107
	}
108
109
110
	public function testGetSupplierItem()
111
	{
112
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Iface::class, $this->object->getSupplierItem() );
113
		$this->assertNull( ( new \Aimeos\MShop\Order\Item\Product\Standard( 'order.product.' ) )->getSupplierItem() );
114
	}
115
116
117
	public function testCompare()
118
	{
119
		$product = new \Aimeos\MShop\Order\Item\Product\Standard( 'order.product.', $this->values );
120
		$this->assertTrue( $this->object->compare( $product ) );
121
	}
122
123
124
	public function testCompareFail()
125
	{
126
		$this->values['order.product.stocktype'] = 'default';
127
128
		$product = new \Aimeos\MShop\Order\Item\Product\Standard( 'order.product.', $this->values );
129
		$this->assertFalse( $this->object->compare( $product ) );
130
	}
131
132
133
	public function testGetId()
134
	{
135
		$this->assertEquals( 1, $this->object->getId() );
136
	}
137
138
139
	public function testSetId()
140
	{
141
		$return = $this->object->setId( null );
142
143
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
144
		$this->assertEquals( null, $this->object->getId() );
145
		$this->assertTrue( $this->object->isModified() );
146
147
		$return = $this->object->setId( 5 );
148
149
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
150
		$this->assertEquals( 5, $this->object->getId() );
151
		$this->assertFalse( $this->object->isModified() );
152
	}
153
154
155
	public function testGetSiteId()
156
	{
157
		$this->assertEquals( 99, $this->object->getSiteId() );
158
	}
159
160
161
	public function testSetSiteId()
162
	{
163
		$this->object->setSiteId( 100 );
164
		$this->assertEquals( 100, $this->object->getSiteId() );
165
		$this->assertTrue( $this->object->isModified() );
166
	}
167
168
169
	public function testGetOrderProductId()
170
	{
171
		$this->assertEquals( 10, $this->object->getOrderProductId() );
172
	}
173
174
175
	public function testSetOrderProductId()
176
	{
177
		$return = $this->object->setOrderProductId( 1001 );
178
179
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
180
		$this->assertEquals( 1001, $this->object->getOrderProductId() );
181
		$this->assertTrue( $this->object->isModified() );
182
183
		$return = $this->object->setOrderProductId( null );
184
185
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
186
		$this->assertEquals( null, $this->object->getOrderProductId() );
187
		$this->assertTrue( $this->object->isModified() );
188
	}
189
190
191
	public function testGetOrderAddressId()
192
	{
193
		$this->assertEquals( 11, $this->object->getOrderAddressId() );
194
	}
195
196
197
	public function testSetOrderAddressId()
198
	{
199
		$return = $this->object->setOrderAddressId( 1011 );
200
201
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
202
		$this->assertEquals( 1011, $this->object->getOrderAddressId() );
203
		$this->assertTrue( $this->object->isModified() );
204
205
		$return = $this->object->setOrderAddressId( null );
206
207
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
208
		$this->assertEquals( null, $this->object->getOrderAddressId() );
209
		$this->assertTrue( $this->object->isModified() );
210
	}
211
212
213
	public function testGetType()
214
	{
215
		$this->assertEquals( 'bundle', $this->object->getType() );
216
	}
217
218
219
	public function testSetType()
220
	{
221
		$return = $this->object->setType( 'default' );
222
223
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
224
		$this->assertEquals( 'default', $this->object->getType() );
225
		$this->assertTrue( $this->object->isModified() );
226
	}
227
228
229
	public function testGetVendor()
230
	{
231
		$this->assertEquals( 'UnitSupplier', $this->object->getVendor() );
232
	}
233
234
235
	public function testSetVendor()
236
	{
237
		$return = $this->object->setVendor( 'test supplier' );
238
239
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
240
		$this->assertEquals( 'test supplier', $this->object->getVendor() );
241
		$this->assertTrue( $this->object->isModified() );
242
	}
243
244
245
	public function testGetProductId()
246
	{
247
		$this->assertEquals( 100, $this->object->getProductId() );
248
	}
249
250
251
	public function testSetProductId()
252
	{
253
		$return = $this->object->setProductId( 'testProdId' );
254
255
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
256
		$this->assertEquals( 'testProdId', $this->object->getProductId() );
257
		$this->assertTrue( $this->object->isModified() );
258
	}
259
260
261
	public function testGetParentProductId()
262
	{
263
		$this->assertEquals( 99, $this->object->getParentProductId() );
264
	}
265
266
267
	public function testSetParentProductId()
268
	{
269
		$return = $this->object->setParentProductId( 'testParentProdId' );
270
271
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
272
		$this->assertEquals( 'testParentProdId', $this->object->getParentProductId() );
273
		$this->assertTrue( $this->object->isModified() );
274
	}
275
276
277
	public function testGetProductCode()
278
	{
279
		$this->assertEquals( 'UnitProd', $this->object->getProductCode() );
280
	}
281
282
283
	public function testSetProductCode()
284
	{
285
		$return = $this->object->setProductCode( 'testProdCode' );
286
287
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
288
		$this->assertEquals( 'testProdCode', $this->object->getProductCode() );
289
		$this->assertTrue( $this->object->isModified() );
290
	}
291
292
293
	public function testGetStockType()
294
	{
295
		$this->assertEquals( 'unittype', $this->object->getStockType() );
296
	}
297
298
299
	public function testSetStockType()
300
	{
301
		$return = $this->object->setStockType( 'testStockType' );
302
303
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
304
		$this->assertEquals( 'testStockType', $this->object->getStockType() );
305
		$this->assertTrue( $this->object->isModified() );
306
	}
307
308
309
	public function testGetName()
310
	{
311
		$this->assertEquals( 'UnitProduct', $this->object->getName() );
312
	}
313
314
315
	public function testGetNameUrl()
316
	{
317
		$this->assertEquals( 'unitproduct', $this->object->getName( 'url' ) );
318
	}
319
320
321
	public function testSetName()
322
	{
323
		$return = $this->object->setName( 'Testname2' );
324
325
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
326
		$this->assertEquals( 'Testname2', $this->object->getName() );
327
		$this->assertTrue( $this->object->isModified() );
328
	}
329
330
331
	public function testGetDescription()
332
	{
333
		$this->assertEquals( 'Unit product description', $this->object->getDescription() );
334
	}
335
336
337
	public function testSetDescription()
338
	{
339
		$return = $this->object->setDescription( 'Test description' );
340
341
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
342
		$this->assertEquals( 'Test description', $this->object->getDescription() );
343
		$this->assertTrue( $this->object->isModified() );
344
	}
345
346
347
	public function testGetMediaUrl()
348
	{
349
		$this->assertEquals( 'testurl', $this->object->getMediaUrl() );
350
	}
351
352
353
	public function testSetMediaUrl()
354
	{
355
		$return = $this->object->setMediaUrl( 'testUrl' );
356
357
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
358
		$this->assertEquals( 'testUrl', $this->object->getMediaUrl() );
359
		$this->assertTrue( $this->object->isModified() );
360
	}
361
362
363
	public function testGetTarget()
364
	{
365
		$this->assertEquals( 'testtarget', $this->object->getTarget() );
366
	}
367
368
369
	public function testSetTarget()
370
	{
371
		$return = $this->object->setTarget( 'ttarget' );
372
373
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
374
		$this->assertEquals( 'ttarget', $this->object->getTarget() );
375
		$this->assertTrue( $this->object->isModified() );
376
	}
377
378
379
	public function testGetTimeFrame()
380
	{
381
		$this->assertEquals( '1-2w', $this->object->getTimeFrame() );
382
	}
383
384
385
	public function testSetTimeFrame()
386
	{
387
		$return = $this->object->setTimeFrame( '3-4d' );
388
389
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
390
		$this->assertEquals( '3-4d', $this->object->getTimeFrame() );
391
		$this->assertTrue( $this->object->isModified() );
392
	}
393
394
395
	public function testGetScale()
396
	{
397
		$this->assertEquals( 0.1, $this->object->getScale() );
398
	}
399
400
401
	public function testSetScale()
402
	{
403
		$return = $this->object->setScale( 2.5 );
404
405
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
406
		$this->assertEquals( 2.5, $this->object->getScale() );
407
		$this->assertTrue( $this->object->isModified() );
408
	}
409
410
411
	public function testGetQuantity()
412
	{
413
		$this->assertEquals( 11, $this->object->getQuantity() );
414
	}
415
416
417
	public function testSetQuantity()
418
	{
419
		$return = $this->object->setQuantity( 20 );
420
421
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
422
		$this->assertEquals( 20, $this->object->getQuantity() );
423
		$this->assertTrue( $this->object->isModified() );
424
	}
425
426
427
	public function testSetQuantityDecimal()
428
	{
429
		$return = $this->object->setQuantity( 1.5 );
430
431
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
432
		$this->assertEquals( 1.5, $this->object->getQuantity() );
433
		$this->assertTrue( $this->object->isModified() );
434
	}
435
436
437
	public function testSetQuantityNegative()
438
	{
439
		$this->expectException( \Aimeos\MShop\Order\Exception::class );
440
		$this->object->setQuantity( -5 );
441
	}
442
443
444
	public function testSetQuantityZero()
445
	{
446
		$this->expectException( \Aimeos\MShop\Order\Exception::class );
447
		$this->object->setQuantity( 0 );
448
	}
449
450
451
	public function testSetQuantityOverflow()
452
	{
453
		$this->expectException( \Aimeos\MShop\Order\Exception::class );
454
		$this->object->setQuantity( 2147483648 );
455
	}
456
457
458
	public function testGetQuantityOpen()
459
	{
460
		$this->assertEquals( 5, $this->object->getQuantityOpen() );
461
	}
462
463
464
	public function testSetQuantityOpen()
465
	{
466
		$return = $this->object->setQuantityOpen( 3 );
467
468
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
469
		$this->assertEquals( 3, $this->object->getQuantityOpen() );
470
		$this->assertTrue( $this->object->isModified() );
471
	}
472
473
474
	public function testSetQuantityOpenDecimal()
475
	{
476
		$return = $this->object->setQuantityOpen( 1.5 );
477
478
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
479
		$this->assertEquals( 1.5, $this->object->getQuantityOpen() );
480
		$this->assertTrue( $this->object->isModified() );
481
	}
482
483
484
	public function testSetQuantityOpenNegative()
485
	{
486
		$this->expectException( \Aimeos\MShop\Order\Exception::class );
487
		$this->object->setQuantityOpen( -5 );
488
	}
489
490
491
	public function testSetQuantityOpenZero()
492
	{
493
		$return = $this->object->setQuantityOpen( 0 );
494
495
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
496
		$this->assertEquals( 0, $this->object->getQuantityOpen() );
497
		$this->assertTrue( $this->object->isModified() );
498
	}
499
500
501
	public function testSetQuantityOpenOverflow()
502
	{
503
		$this->expectException( \Aimeos\MShop\Order\Exception::class );
504
		$this->object->setQuantityOpen( 12 );
505
	}
506
507
508
	public function testGetNotes()
509
	{
510
		$this->assertEquals( 'test note', $this->object->getNotes() );
511
	}
512
513
514
	public function testSetNotes()
515
	{
516
		$return = $this->object->setNotes( 'some notes' );
517
518
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
519
		$this->assertEquals( 'some notes', $this->object->getNotes() );
520
		$this->assertTrue( $this->object->isModified() );
521
	}
522
523
524
	public function testGetPrice()
525
	{
526
		$this->assertSame( $this->price, $this->object->getPrice() );
527
	}
528
529
530
	public function testSetPrice()
531
	{
532
		$this->price->setValue( '5.00' );
533
		$return = $this->object->setPrice( $this->price );
534
535
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
536
		$this->assertSame( $this->price, $this->object->getPrice() );
537
		$this->assertFalse( $this->object->isModified() );
538
	}
539
540
541
	public function testGetFlags()
542
	{
543
		$this->assertEquals( \Aimeos\MShop\Order\Item\Product\Base::FLAG_NONE, $this->object->getFlags() );
544
	}
545
546
547
	public function testSetFlags()
548
	{
549
		$return = $this->object->setFlags( \Aimeos\MShop\Order\Item\Product\Base::FLAG_IMMUTABLE );
550
551
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
552
		$this->assertEquals( \Aimeos\MShop\Order\Item\Product\Base::FLAG_IMMUTABLE, $this->object->getFlags() );
553
		$this->assertTrue( $this->object->isModified() );
554
	}
555
556
557
	public function testGetPosition()
558
	{
559
		$this->assertEquals( 1, $this->object->getPosition() );
560
	}
561
562
563
	public function testSetPosition()
564
	{
565
		$return = $this->object->setPosition( 2 );
566
567
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
568
		$this->assertEquals( 2, $this->object->getPosition() );
569
		$this->assertTrue( $this->object->isModified() );
570
	}
571
572
573
	public function testSetPositionReset()
574
	{
575
		$return = $this->object->setPosition( null );
576
577
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
578
		$this->assertEquals( null, $this->object->getPosition() );
579
		$this->assertTrue( $this->object->isModified() );
580
	}
581
582
583
	public function testSetPositionInvalid()
584
	{
585
		$this->expectException( \Aimeos\MShop\Order\Exception::class );
586
		$this->object->setPosition( -1 );
587
	}
588
589
590
	public function testGetStatusDelivery()
591
	{
592
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::STAT_PROGRESS, $this->object->getStatusDelivery() );
593
	}
594
595
596
	public function testSetStatusDelivery()
597
	{
598
		$return = $this->object->setStatusDelivery( \Aimeos\MShop\Order\Item\Base::STAT_LOST );
599
600
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
601
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::STAT_LOST, $this->object->getStatusDelivery() );
602
		$this->assertTrue( $this->object->isModified() );
603
	}
604
605
606
	public function testGetStatusPayment()
607
	{
608
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED, $this->object->getStatusPayment() );
609
	}
610
611
612
	public function testSetStatusPayment()
613
	{
614
		$return = $this->object->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_PENDING );
615
616
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
617
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_PENDING, $this->object->getStatusPayment() );
618
		$this->assertTrue( $this->object->isModified() );
619
	}
620
621
622
	public function testGetParentId()
623
	{
624
		$this->assertEquals( 42, $this->object->getParentId() );
625
	}
626
627
628
	public function testSetParentId()
629
	{
630
		$return = $this->object->setParentId( 111 );
631
632
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
633
		$this->assertEquals( 111, $this->object->getParentId() );
634
		$this->assertTrue( $this->object->isModified() );
635
	}
636
637
638
	public function testSetParentIdReset()
639
	{
640
		$return = $this->object->setParentId( null );
641
642
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
643
		$this->assertEquals( null, $this->object->getParentId() );
644
		$this->assertTrue( $this->object->isModified() );
645
	}
646
647
648
	public function testGetTimeModified()
649
	{
650
		$regexp = '/^[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/';
651
		$this->assertMatchesRegularExpression( $regexp, $this->object->getTimeModified() );
652
		$this->assertEquals( '2000-12-31 23:59:59', $this->object->getTimeModified() );
653
	}
654
655
656
	public function testGetTimeCreated()
657
	{
658
		$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() );
659
	}
660
661
662
	public function testGetEditor()
663
	{
664
		$this->assertEquals( 'unitTestUser', $this->object->editor() );
665
	}
666
667
668
	public function testAddAttributeItems()
669
	{
670
		$item = \Aimeos\MShop::create( \TestHelper::context(), 'order/product' )->createAttributeItem();
671
672
		$return = $this->object->addAttributeItems( [$item] );
673
674
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
675
		$this->assertEquals( 2, count( $this->object->getAttributeItems() ) );
676
		$this->assertTrue( $this->object->isModified() );
677
	}
678
679
680
	public function testGetAttribute()
681
	{
682
		$attManager = \Aimeos\MShop::create( \TestHelper::context(), 'order/product/attribute' );
683
684
		$attrItem001 = $attManager->create();
685
		$attrItem001->setAttributeId( '1' );
686
		$attrItem001->setCode( 'code_001' );
687
		$attrItem001->setValue( 'value_001' );
688
689
		$attrItem002 = $attManager->create();
690
		$attrItem002->setAttributeId( '2' );
691
		$attrItem002->setCode( 'code_002' );
692
		$attrItem002->setType( 'test_002' );
693
		$attrItem002->setValue( 'value_002' );
694
695
		$this->object->setAttributeItems( array( $attrItem001, $attrItem002 ) );
696
697
		$result = $this->object->getAttribute( 'code_001' );
698
		$this->assertEquals( 'value_001', $result );
699
700
		$result = $this->object->getAttribute( 'code_002', ['test_002'] );
701
		$this->assertEquals( 'value_002', $result );
702
703
		$result = $this->object->getAttribute( 'code_002', 'test_002' );
704
		$this->assertEquals( 'value_002', $result );
705
706
		$result = $this->object->getAttribute( 'code_002' );
707
		$this->assertEquals( null, $result );
708
709
		$result = $this->object->getAttribute( 'code_003' );
710
		$this->assertEquals( null, $result );
711
712
		$this->object->setAttributeItems( [] );
713
714
		$result = $this->object->getAttribute( 'code_001' );
715
		$this->assertEquals( null, $result );
716
	}
717
718
719
	public function testGetAttributeList()
720
	{
721
		$attManager = \Aimeos\MShop::create( \TestHelper::context(), 'order/product/attribute' );
722
723
		$attrItem001 = $attManager->create();
724
		$attrItem001->setAttributeId( '1' );
725
		$attrItem001->setCode( 'code_001' );
726
		$attrItem001->setType( 'test_001' );
727
		$attrItem001->setValue( 'value_001' );
728
729
		$attrItem002 = $attManager->create();
730
		$attrItem002->setAttributeId( '2' );
731
		$attrItem002->setCode( 'code_001' );
732
		$attrItem002->setType( 'test_001' );
733
		$attrItem002->setValue( 'value_002' );
734
735
		$this->object->setAttributeItems( array( $attrItem001, $attrItem002 ) );
736
737
		$result = $this->object->getAttribute( 'code_001', 'test_001' );
738
		$this->assertEquals( ['value_001', 'value_002'], $result );
739
	}
740
741
742
	public function testGetAttributeItem()
743
	{
744
		$attManager = \Aimeos\MShop::create( \TestHelper::context(), 'order/product/attribute' );
745
746
		$attrItem001 = $attManager->create();
747
		$attrItem001->setAttributeId( '1' );
748
		$attrItem001->setCode( 'code_001' );
749
		$attrItem001->setValue( 'value_001' );
750
751
		$attrItem002 = $attManager->create();
752
		$attrItem002->setAttributeId( '2' );
753
		$attrItem002->setCode( 'code_002' );
754
		$attrItem002->setType( 'test_002' );
755
		$attrItem002->setValue( 'value_002' );
756
757
		$this->object->setAttributeItems( array( $attrItem001, $attrItem002 ) );
758
759
		$result = $this->object->getAttributeItem( 'code_001' );
760
		$this->assertEquals( 'value_001', $result->getValue() );
761
762
		$result = $this->object->getAttributeItem( 'code_002', 'test_002' );
763
		$this->assertEquals( 'value_002', $result->getValue() );
764
765
		$result = $this->object->getAttributeItem( 'code_002' );
766
		$this->assertEquals( null, $result );
767
768
		$result = $this->object->getAttribute( 'code_003' );
769
		$this->assertEquals( null, $result );
770
771
		$this->object->setAttributeItems( [] );
772
773
		$result = $this->object->getAttribute( 'code_001' );
774
		$this->assertEquals( null, $result );
775
	}
776
777
778
	public function testGetAttributeItemList()
779
	{
780
		$attManager = \Aimeos\MShop::create( \TestHelper::context(), 'order/product/attribute' );
781
782
		$attrItem001 = $attManager->create();
783
		$attrItem001->setAttributeId( '1' );
784
		$attrItem001->setCode( 'code_001' );
785
		$attrItem001->setType( 'test_001' );
786
		$attrItem001->setValue( 'value_001' );
787
788
		$attrItem002 = $attManager->create();
789
		$attrItem002->setAttributeId( '2' );
790
		$attrItem002->setCode( 'code_001' );
791
		$attrItem002->setType( 'test_001' );
792
		$attrItem002->setValue( 'value_002' );
793
794
		$this->object->setAttributeItems( array( $attrItem001, $attrItem002 ) );
795
796
		$result = $this->object->getAttributeItem( 'code_001', 'test_001' );
797
		$this->assertEquals( 2, count( $result ) );
798
	}
799
800
801
	public function testGetAttributeItems()
802
	{
803
		$this->assertEquals( $this->attributes, $this->object->getAttributeItems() );
804
	}
805
806
807
	public function testGetAttributeItemsByType()
808
	{
809
		$this->assertEquals( $this->attributes, $this->object->getAttributeItems( 'default' ) );
810
	}
811
812
813
	public function testGetAttributeItemsInvalidType()
814
	{
815
		$this->assertEquals( map(), $this->object->getAttributeItems( 'invalid' ) );
816
	}
817
818
819
	public function testGetAttributeItemsDeleted()
820
	{
821
		$this->object->setAttributeItems( $this->attributes );
822
		$this->object->setAttributeItems( [] );
823
824
		$this->assertEquals( $this->attributes, $this->object->getAttributeItemsDeleted() );
825
	}
826
827
828
	public function testSetAttributeItem()
829
	{
830
		$attManager = \Aimeos\MShop::create( \TestHelper::context(), 'order/product/attribute' );
831
832
		$item = $attManager->create();
833
		$item->setAttributeId( '1' );
834
		$item->setCode( 'test_code' );
835
		$item->setType( 'test_type' );
836
		$item->setValue( 'test_value' );
837
838
		$return = $this->object->setAttributeItem( $item );
839
840
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
841
		$this->assertEquals( 'test_value', $this->object->getAttributeItem( 'test_code', 'test_type' )->getValue() );
842
		$this->assertTrue( $this->object->isModified() );
843
844
845
		$item = $attManager->create();
846
		$item->setAttributeId( '1' );
847
		$item->setCode( 'test_code' );
848
		$item->setType( 'test_type' );
849
		$item->setValue( 'test_value2' );
850
851
		$return = $this->object->setAttributeItem( $item );
852
853
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
854
		$this->assertEquals( 'test_value2', $this->object->getAttributeItem( 'test_code', 'test_type' )->getValue() );
855
		$this->assertTrue( $this->object->isModified() );
856
	}
857
858
859
	public function testSetAttributeItems()
860
	{
861
		$attManager = \Aimeos\MShop::create( \TestHelper::context(), 'order/product/attribute' );
862
863
		$list = array(
864
			$attManager->create(),
865
			$attManager->create(),
866
		);
867
868
		$return = $this->object->setAttributeItems( $list );
869
870
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
871
		$this->assertEquals( $list, $this->object->getAttributeItems()->toArray() );
872
		$this->assertTrue( $this->object->isModified() );
873
	}
874
875
876
	public function testGetProducts()
877
	{
878
		$this->assertEquals( $this->subProducts, $this->object->getProducts() );
879
	}
880
881
882
	public function testSetProducts()
883
	{
884
		$return = $this->object->setProducts( [] );
885
886
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
887
		$this->assertEquals( map(), $this->object->getProducts() );
888
889
		$return = $this->object->setProducts( $this->subProducts );
890
891
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
892
		$this->assertEquals( $this->subProducts, $this->object->getProducts() );
893
		$this->assertTrue( $this->object->isModified() );
894
	}
895
896
897
	public function testGetResourceType()
898
	{
899
		$this->assertEquals( 'order/product', $this->object->getResourceType() );
900
	}
901
902
903
	public function testFromArray()
904
	{
905
		$item = new \Aimeos\MShop\Order\Item\Product\Standard( 'order.product.', ['.price' => clone $this->price] );
906
907
		$list = $entries = array(
908
			'order.product.id' => 1,
909
			'order.product.parentid' => 2,
910
			'order.product.siteid' => 123,
911
			'order.product.orderproductid' => 10,
912
			'order.product.orderaddressid' => 11,
913
			'order.product.parentproductid' => 3,
914
			'order.product.productid' => 4,
915
			'order.product.prodcode' => 'test',
916
			'order.product.currencyid' => 'EUR',
917
			'order.product.price' => '10.00',
918
			'order.product.costs' => '5.00',
919
			'order.product.rebate' => '2.00',
920
			'order.product.taxrates' => ['tax' => '20.00'],
921
			'order.product.taxvalue' => '2.5000',
922
			'order.product.taxflag' => 1,
923
			'order.product.name' => 'test item',
924
			'order.product.description' => 'test description',
925
			'order.product.stocktype' => 'stocktype',
926
			'order.product.vendor' => 'testsup',
927
			'order.product.mediaurl' => '/path/to/image.jpg',
928
			'order.product.target' => 'ttarget',
929
			'order.product.timeframe' => '1-2d',
930
			'order.product.position' => 4,
931
			'order.product.quantity' => 5,
932
			'order.product.qtyopen' => 3,
933
			'order.product.scale' => 0.5,
934
			'order.product.statuspayment' => 6,
935
			'order.product.statusdelivery' => 0,
936
			'order.product.flags' => 1,
937
			'order.product.notes' => 'note',
938
		);
939
940
		$item = $item->fromArray( $entries, true );
941
942
		$this->assertEquals( [], $entries );
943
		$this->assertEquals( $list['order.product.id'], $item->getId() );
944
		$this->assertEquals( $list['order.product.parentid'], $item->getParentId() );
945
		$this->assertEquals( $list['order.product.siteid'], $item->getSiteId() );
946
		$this->assertEquals( $list['order.product.orderproductid'], $item->getOrderProductId() );
947
		$this->assertEquals( $list['order.product.orderaddressid'], $item->getOrderAddressId() );
948
		$this->assertEquals( $list['order.product.parentproductid'], $item->getParentProductId() );
949
		$this->assertEquals( $list['order.product.productid'], $item->getProductId() );
950
		$this->assertEquals( $list['order.product.prodcode'], $item->getProductCode() );
951
		$this->assertEquals( $list['order.product.name'], $item->getName() );
952
		$this->assertEquals( $list['order.product.description'], $item->getDescription() );
953
		$this->assertEquals( $list['order.product.stocktype'], $item->getStockType() );
954
		$this->assertEquals( $list['order.product.vendor'], $item->getVendor() );
955
		$this->assertEquals( $list['order.product.prodcode'], $item->getProductCode() );
956
		$this->assertEquals( $list['order.product.mediaurl'], $item->getMediaUrl() );
957
		$this->assertEquals( $list['order.product.timeframe'], $item->getTimeFrame() );
958
		$this->assertEquals( $list['order.product.target'], $item->getTarget() );
959
		$this->assertEquals( $list['order.product.position'], $item->getPosition() );
960
		$this->assertEquals( $list['order.product.scale'], $item->getScale() );
961
		$this->assertEquals( $list['order.product.quantity'], $item->getQuantity() );
962
		$this->assertEquals( $list['order.product.qtyopen'], $item->getQuantityOpen() );
963
		$this->assertEquals( $list['order.product.statuspayment'], $item->getStatusPayment() );
964
		$this->assertEquals( $list['order.product.statusdelivery'], $item->getStatusDelivery() );
965
		$this->assertEquals( $list['order.product.flags'], $item->getFlags() );
966
		$this->assertEquals( $list['order.product.notes'], $item->getNotes() );
967
		$this->assertEquals( $list['order.product.currencyid'], $item->getPrice()->getCurrencyId() );
968
		$this->assertEquals( $list['order.product.price'], $item->getPrice()->getValue() );
969
		$this->assertEquals( $list['order.product.costs'], $item->getPrice()->getCosts() );
970
		$this->assertEquals( $list['order.product.rebate'], $item->getPrice()->getRebate() );
971
		$this->assertEquals( $list['order.product.taxrates'], $item->getPrice()->getTaxRates() );
972
		$this->assertEquals( $list['order.product.taxvalue'], $item->getPrice()->getTaxValue() );
973
		$this->assertEquals( $list['order.product.taxflag'], $item->getPrice()->getTaxFlag() );
974
	}
975
976
977
	public function testToArray()
978
	{
979
		$arrayObject = $this->object->toArray( true );
980
981
		$this->assertEquals( $this->object->getId(), $arrayObject['order.product.id'] );
982
		$this->assertEquals( $this->object->getSiteId(), $arrayObject['order.product.siteid'] );
983
		$this->assertEquals( $this->object->getParentId(), $arrayObject['order.product.parentid'] );
984
		$this->assertEquals( $this->object->getOrderProductId(), $arrayObject['order.product.orderproductid'] );
985
		$this->assertEquals( $this->object->getOrderAddressId(), $arrayObject['order.product.orderaddressid'] );
986
		$this->assertEquals( $this->object->getStockType(), $arrayObject['order.product.stocktype'] );
987
		$this->assertEquals( $this->object->getVendor(), $arrayObject['order.product.vendor'] );
988
		$this->assertEquals( $this->object->getParentProductId(), $arrayObject['order.product.parentproductid'] );
989
		$this->assertEquals( $this->object->getProductId(), $arrayObject['order.product.productid'] );
990
		$this->assertEquals( $this->object->getProductCode(), $arrayObject['order.product.prodcode'] );
991
		$this->assertEquals( $this->object->getName(), $arrayObject['order.product.name'] );
992
		$this->assertEquals( $this->object->getDescription(), $arrayObject['order.product.description'] );
993
		$this->assertEquals( $this->object->getMediaUrl(), $arrayObject['order.product.mediaurl'] );
994
		$this->assertEquals( $this->object->getTimeFrame(), $arrayObject['order.product.timeframe'] );
995
		$this->assertEquals( $this->object->getTarget(), $arrayObject['order.product.target'] );
996
		$this->assertEquals( $this->object->getPosition(), $arrayObject['order.product.position'] );
997
		$this->assertEquals( $this->object->getPrice()->getCurrencyId(), $arrayObject['order.product.currencyid'] );
998
		$this->assertEquals( $this->object->getPrice()->getValue(), $arrayObject['order.product.price'] );
999
		$this->assertEquals( $this->object->getPrice()->getCosts(), $arrayObject['order.product.costs'] );
1000
		$this->assertEquals( $this->object->getPrice()->getRebate(), $arrayObject['order.product.rebate'] );
1001
		$this->assertEquals( $this->object->getPrice()->getTaxRate(), '0.00' );
1002
		$this->assertEquals( $this->object->getPrice()->getTaxRates(), $arrayObject['order.product.taxrates'] );
1003
		$this->assertEquals( $this->object->getPrice()->getTaxValue(), $arrayObject['order.product.taxvalue'] );
1004
		$this->assertEquals( $this->object->getPrice()->getTaxFlag(), $arrayObject['order.product.taxflag'] );
1005
		$this->assertEquals( $this->object->getQuantityOpen(), $arrayObject['order.product.qtyopen'] );
1006
		$this->assertEquals( $this->object->getQuantity(), $arrayObject['order.product.quantity'] );
1007
		$this->assertEquals( $this->object->getScale(), $arrayObject['order.product.scale'] );
1008
		$this->assertEquals( $this->object->getStatusPayment(), $arrayObject['order.product.statuspayment'] );
1009
		$this->assertEquals( $this->object->getStatusDelivery(), $arrayObject['order.product.statusdelivery'] );
1010
		$this->assertEquals( $this->object->getFlags(), $arrayObject['order.product.flags'] );
1011
		$this->assertEquals( $this->object->getNotes(), $arrayObject['order.product.notes'] );
1012
		$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['order.product.ctime'] );
1013
		$this->assertEquals( $this->object->getTimeModified(), $arrayObject['order.product.mtime'] );
1014
		$this->assertEquals( $this->object->editor(), $arrayObject['order.product.editor'] );
1015
	}
1016
1017
1018
	public function testIsModified()
1019
	{
1020
		$this->assertFalse( $this->object->isModified() );
1021
	}
1022
1023
1024
	public function testCopyFrom()
1025
	{
1026
		$manager = \Aimeos\MShop::create( \TestHelper::context(), 'product' );
1027
		$product = $manager->find( 'CNE', ['text'] );
1028
1029
		$productCopy = new \Aimeos\MShop\Order\Item\Product\Standard( 'order.product.', ['.price' => clone $this->price] );
1030
		$return = $productCopy->copyFrom( $product->set( 'customprop', 'abc' ) );
1031
1032
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $return );
1033
		$this->assertEquals( 'default', $productCopy->getType() );
1034
		$this->assertEquals( 'CNE', $productCopy->getProductCode() );
1035
		$this->assertEquals( 'Cafe Noire Expresso', $productCopy->getName() );
1036
		$this->assertEquals( 'Cafe Noire Expresso for basket', $productCopy->getDescription() );
1037
		$this->assertEquals( $product->getId(), $productCopy->getProductId() );
1038
		$this->assertEquals( -1, $productCopy->getStatusDelivery() );
1039
		$this->assertEquals( 0.1, $productCopy->getScale() );
1040
		$this->assertEquals( '', $productCopy->getVendor() );
1041
		$this->assertEquals( '', $productCopy->getTarget() );
1042
		$this->assertEquals( '', $productCopy->getMediaUrl() );
1043
		$this->assertEquals( 'abc', $productCopy->get( 'customprop' ) );
1044
1045
		$this->assertTrue( $productCopy->isModified() );
1046
	}
1047
}
1048