Total Complexity | 67 |
Total Lines | 881 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
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 |
||
13 | class StandardTest extends \PHPUnit\Framework\TestCase |
||
14 | { |
||
15 | private $object; |
||
16 | private $context; |
||
17 | private $editor = ''; |
||
18 | |||
19 | |||
20 | protected function setUp() : void |
||
21 | { |
||
22 | $this->context = \TestHelperMShop::getContext(); |
||
23 | $this->editor = $this->context->getEditor(); |
||
24 | |||
25 | $this->object = new \Aimeos\MShop\Order\Manager\Base\Standard( $this->context ); |
||
26 | } |
||
27 | |||
28 | |||
29 | protected function tearDown() : void |
||
30 | { |
||
31 | unset( $this->object ); |
||
32 | } |
||
33 | |||
34 | |||
35 | public function testAggregate() |
||
44 | } |
||
45 | |||
46 | |||
47 | public function testAggregateAvg() |
||
48 | { |
||
49 | $search = $this->object->createSearch(); |
||
50 | $search->setConditions( $search->compare( '==', 'order.base.editor', 'core:lib/mshoplib' ) ); |
||
51 | $result = $this->object->aggregate( $search, 'order.base.address.email', 'order.base.price', 'avg' )->toArray(); |
||
52 | |||
53 | $this->assertEquals( 1, count( $result ) ); |
||
54 | $this->assertArrayHasKey( '[email protected]', $result ); |
||
55 | $this->assertEquals( '896.86', round( $result['[email protected]'], 2 ) ); |
||
56 | } |
||
57 | |||
58 | |||
59 | public function testAggregateSum() |
||
68 | } |
||
69 | |||
70 | |||
71 | public function testClear() |
||
72 | { |
||
73 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) ); |
||
74 | } |
||
75 | |||
76 | |||
77 | public function testDeleteItems() |
||
80 | } |
||
81 | |||
82 | |||
83 | public function testGetResourceType() |
||
84 | { |
||
85 | $result = $this->object->getResourceType(); |
||
86 | |||
87 | $this->assertContains( 'order/base', $result ); |
||
88 | $this->assertContains( 'order/base/address', $result ); |
||
89 | $this->assertContains( 'order/base/coupon', $result ); |
||
90 | $this->assertContains( 'order/base/product', $result ); |
||
91 | $this->assertContains( 'order/base/product/attribute', $result ); |
||
92 | $this->assertContains( 'order/base/service', $result ); |
||
93 | $this->assertContains( 'order/base/service/attribute', $result ); |
||
94 | } |
||
95 | |||
96 | |||
97 | public function testCreateItem() |
||
100 | } |
||
101 | |||
102 | |||
103 | public function testGetItem() |
||
119 | } |
||
120 | |||
121 | |||
122 | public function testSaveUpdateDeleteItem() |
||
202 | } |
||
203 | |||
204 | |||
205 | public function testCreateSearch() |
||
206 | { |
||
207 | $this->assertInstanceOf( \Aimeos\MW\Criteria\Iface::class, $this->object->createSearch() ); |
||
208 | } |
||
209 | |||
210 | |||
211 | public function testCreateSearchDefault() |
||
222 | } |
||
223 | |||
224 | |||
225 | public function testCreateSearchSite() |
||
229 | } |
||
230 | |||
231 | |||
232 | public function testSearchItems() |
||
364 | } |
||
365 | |||
366 | |||
367 | public function testSearchItemsRef() |
||
368 | { |
||
369 | $search = $this->object->createSearch()->setSlice( 0, 1 ); |
||
370 | |||
371 | $search->setConditions( $search->compare( '!=', 'order.base.customerid', '' ) ); |
||
372 | $result = $this->object->searchItems( $search, ['customer'] ); |
||
373 | |||
374 | $this->assertEquals( 1, count( $result ) ); |
||
375 | $this->assertNotNull( $result->first()->getCustomerItem() ); |
||
376 | } |
||
377 | |||
378 | |||
379 | public function testSearchItemsTotal() |
||
380 | { |
||
381 | $search = $this->object->createSearch(); |
||
382 | $conditions = array( |
||
383 | $search->compare( '>=', 'order.base.customerid', '' ), |
||
384 | $search->compare( '==', 'order.base.editor', $this->editor ) |
||
385 | ); |
||
386 | $search->setConditions( $search->combine( '&&', $conditions ) ); |
||
387 | $search->setSlice( 0, 1 ); |
||
388 | $total = 0; |
||
389 | $items = $this->object->searchItems( $search, [], $total ); |
||
390 | $this->assertEquals( 1, count( $items ) ); |
||
391 | $this->assertGreaterThanOrEqual( 4, $total ); |
||
392 | |||
393 | foreach( $items as $itemId => $item ) { |
||
394 | $this->assertEquals( $itemId, $item->getId() ); |
||
395 | } |
||
396 | } |
||
397 | |||
398 | |||
399 | public function testSearchItemsDefault() |
||
400 | { |
||
401 | $search = $this->object->createSearch( true ); |
||
402 | $items = $this->object->searchItems( $search ); |
||
403 | |||
404 | $this->assertEquals( 0, count( $items ) ); |
||
405 | } |
||
406 | |||
407 | |||
408 | public function testGetSubManager() |
||
409 | { |
||
410 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'address' ) ); |
||
411 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'address', 'Standard' ) ); |
||
412 | |||
413 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'coupon' ) ); |
||
414 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'coupon', 'Standard' ) ); |
||
415 | |||
416 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'product' ) ); |
||
417 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'product', 'Standard' ) ); |
||
418 | |||
419 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'service' ) ); |
||
420 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'service', 'Standard' ) ); |
||
421 | |||
422 | $this->expectException( \Aimeos\MShop\Exception::class ); |
||
423 | $this->object->getSubManager( 'unknown' ); |
||
424 | } |
||
425 | |||
426 | |||
427 | public function testGetSubManagerInvalidName() |
||
428 | { |
||
429 | $this->expectException( \Aimeos\MShop\Exception::class ); |
||
430 | $this->object->getSubManager( 'address', 'unknown' ); |
||
431 | } |
||
432 | |||
433 | |||
434 | public function testLoad() |
||
435 | { |
||
436 | $item = $this->getOrderItem(); |
||
437 | $order = $this->object->load( $item->getId() ); |
||
438 | |||
439 | |||
440 | foreach( $order->getAddresses() as $addresses ) |
||
441 | { |
||
442 | foreach( $addresses as $address ) |
||
443 | { |
||
444 | $this->assertNotEquals( '', $address->getId() ); |
||
445 | $this->assertNotEquals( '', $address->getId() ); |
||
446 | $this->assertNotEquals( '', $address->getBaseId() ); |
||
447 | } |
||
448 | } |
||
449 | |||
450 | $this->assertEquals( 2, count( $order->getCoupons() ) ); |
||
451 | |||
452 | foreach( $order->getCoupons() as $code => $products ) |
||
453 | { |
||
454 | $this->assertNotEquals( '', $code ); |
||
455 | |||
456 | foreach( $products as $product ) { |
||
457 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Iface::class, $product ); |
||
458 | } |
||
459 | } |
||
460 | |||
461 | foreach( $order->getProducts() as $product ) |
||
462 | { |
||
463 | $this->assertNotEquals( '', $product->getId() ); |
||
464 | $this->assertNotEquals( '', $product->getId() ); |
||
465 | $this->assertNotEquals( '', $product->getBaseId() ); |
||
466 | $this->assertGreaterThan( 0, $product->getPosition() ); |
||
467 | } |
||
468 | |||
469 | foreach( $order->getServices() as $list ) |
||
470 | { |
||
471 | foreach( $list as $service ) |
||
472 | { |
||
473 | $this->assertNotEquals( '', $service->getId() ); |
||
474 | $this->assertNotEquals( '', $service->getId() ); |
||
475 | $this->assertNotEquals( '', $service->getBaseId() ); |
||
476 | } |
||
477 | } |
||
478 | } |
||
479 | |||
480 | |||
481 | public function testLoadNone() |
||
482 | { |
||
483 | $item = $this->getOrderItem(); |
||
484 | $order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_NONE ); |
||
485 | |||
486 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
487 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
488 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
489 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
490 | } |
||
491 | |||
492 | |||
493 | public function testLoadAddress() |
||
494 | { |
||
495 | $item = $this->getOrderItem(); |
||
496 | $order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_ADDRESS ); |
||
497 | |||
498 | $this->assertGreaterThan( 0, count( $order->getAddresses() ) ); |
||
499 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
500 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
501 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
502 | } |
||
503 | |||
504 | |||
505 | public function testLoadProduct() |
||
506 | { |
||
507 | $item = $this->getOrderItem(); |
||
508 | $order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT ); |
||
509 | |||
510 | $this->assertGreaterThan( 0, count( $order->getProducts() ) ); |
||
511 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
512 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
513 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
514 | } |
||
515 | |||
516 | |||
517 | public function testLoadCoupon() |
||
518 | { |
||
519 | $item = $this->getOrderItem(); |
||
520 | $order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_COUPON ); |
||
521 | |||
522 | $this->assertGreaterThan( 0, count( $order->getProducts() ) ); |
||
523 | $this->assertGreaterThan( 0, count( $order->getCoupons() ) ); |
||
524 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
525 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
526 | } |
||
527 | |||
528 | |||
529 | public function testLoadService() |
||
530 | { |
||
531 | $item = $this->getOrderItem(); |
||
532 | $order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE ); |
||
533 | |||
534 | $this->assertGreaterThan( 0, count( $order->getServices() ) ); |
||
535 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
536 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
537 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
538 | } |
||
539 | |||
540 | |||
541 | public function testLoadFresh() |
||
542 | { |
||
543 | $item = $this->getOrderItem(); |
||
544 | $order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL, true ); |
||
545 | |||
546 | |||
547 | $this->assertEquals( 2, count( $order->getCoupons() ) ); |
||
548 | |||
549 | foreach( $order->getAddresses() as $list ) |
||
550 | { |
||
551 | foreach( $list as $address ) |
||
552 | { |
||
553 | $this->assertEquals( null, $address->getId() ); |
||
554 | $this->assertEquals( null, $address->getBaseId() ); |
||
555 | } |
||
556 | } |
||
557 | |||
558 | foreach( $order->getProducts() as $product ) |
||
559 | { |
||
560 | $this->assertEquals( null, $product->getId() ); |
||
561 | $this->assertEquals( null, $product->getBaseId() ); |
||
562 | $this->assertEquals( null, $product->getPosition() ); |
||
563 | } |
||
564 | |||
565 | foreach( $order->getServices() as $list ) |
||
566 | { |
||
567 | foreach( $list as $service ) |
||
568 | { |
||
569 | $this->assertEquals( null, $service->getId() ); |
||
570 | $this->assertEquals( null, $service->getBaseId() ); |
||
571 | } |
||
572 | } |
||
573 | } |
||
574 | |||
575 | |||
576 | public function testLoadFreshNone() |
||
577 | { |
||
578 | $item = $this->getOrderItem(); |
||
579 | $order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_NONE, true ); |
||
580 | |||
581 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
582 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
583 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
584 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
585 | } |
||
586 | |||
587 | |||
588 | public function testLoadFreshAddress() |
||
589 | { |
||
590 | $item = $this->getOrderItem(); |
||
591 | $order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_ADDRESS, true ); |
||
592 | |||
593 | $this->assertGreaterThan( 0, count( $order->getAddresses() ) ); |
||
594 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
595 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
596 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
597 | } |
||
598 | |||
599 | |||
600 | public function testLoadFreshProduct() |
||
601 | { |
||
602 | $item = $this->getOrderItem(); |
||
603 | $order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT, true ); |
||
604 | |||
605 | $this->assertGreaterThan( 0, count( $order->getProducts() ) ); |
||
606 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
607 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
608 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
609 | } |
||
610 | |||
611 | |||
612 | public function testLoadFreshCoupon() |
||
613 | { |
||
614 | $item = $this->getOrderItem(); |
||
615 | $order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_COUPON, true ); |
||
616 | |||
617 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
618 | $this->assertEquals( 2, count( $order->getCoupons() ) ); |
||
619 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
620 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
621 | } |
||
622 | |||
623 | |||
624 | public function testLoadFreshService() |
||
625 | { |
||
626 | $item = $this->getOrderItem(); |
||
627 | $order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE, true ); |
||
628 | |||
629 | $this->assertGreaterThan( 0, count( $order->getServices() ) ); |
||
630 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
631 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
632 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
633 | } |
||
634 | |||
635 | |||
636 | public function testStore() |
||
637 | { |
||
638 | $item = $this->getOrderItem(); |
||
639 | |||
640 | $basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL, true ); |
||
641 | $this->object->store( $basket ); |
||
642 | |||
643 | $newBasketId = $basket->getId(); |
||
644 | |||
645 | $basket = $this->object->load( $newBasketId ); |
||
646 | $this->object->deleteItem( $newBasketId ); |
||
647 | |||
648 | |||
649 | $this->assertEquals( $item->getCustomerId(), $basket->getCustomerId() ); |
||
650 | $this->assertEquals( $basket->getLocale()->getSiteId(), $basket->getSiteId() ); |
||
651 | |||
652 | $this->assertEquals( 6.50, $basket->getPrice()->getCosts() ); |
||
653 | |||
654 | $pos = 0; |
||
655 | $products = $basket->getProducts(); |
||
656 | $this->assertEquals( 2, count( $products ) ); |
||
657 | |||
658 | foreach( $products as $product ) |
||
659 | { |
||
660 | $this->assertGreaterThanOrEqual( 2, count( $product->getAttributeItems() ) ); |
||
661 | $this->assertEquals( $pos++, $product->getPosition() ); |
||
662 | } |
||
663 | |||
664 | $this->assertEquals( 2, count( $basket->getAddresses() ) ); |
||
665 | |||
666 | $services = $basket->getServices(); |
||
667 | $this->assertEquals( 2, count( $services ) ); |
||
668 | |||
669 | $attributes = []; |
||
670 | foreach( $services as $list ) |
||
671 | { |
||
672 | foreach( $list as $service ) { |
||
673 | $attributes[$service->getCode()] = $service->getAttributeItems(); |
||
674 | } |
||
675 | } |
||
676 | |||
677 | $this->assertEquals( 9, count( $attributes['OGONE'] ) ); |
||
678 | $this->assertEquals( 0, count( $attributes['73'] ) ); |
||
679 | |||
680 | $this->expectException( \Aimeos\MShop\Exception::class ); |
||
681 | $this->object->getItem( $newBasketId ); |
||
682 | } |
||
683 | |||
684 | |||
685 | public function testStoreExisting() |
||
686 | { |
||
687 | $item = $this->getOrderItem(); |
||
688 | |||
689 | $basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL, true ); |
||
690 | $this->object->store( $basket ); |
||
691 | $newBasketId = $basket->getId(); |
||
692 | $this->object->store( $basket ); |
||
693 | $newBasket = $this->object->load( $newBasketId ); |
||
694 | |||
695 | $this->object->deleteItem( $newBasketId ); |
||
696 | |||
697 | |||
698 | $newAddresses = $newBasket->getAddresses(); |
||
699 | |||
700 | foreach( $basket->getAddresses() as $key => $list ) |
||
701 | { |
||
702 | foreach( $list as $pos => $address ) { |
||
703 | $this->assertEquals( $address->getId(), $newAddresses[$key][$pos]->getId() ); |
||
704 | } |
||
705 | } |
||
706 | |||
707 | $newProducts = $newBasket->getProducts(); |
||
708 | |||
709 | foreach( $basket->getProducts() as $key => $product ) { |
||
710 | $this->assertEquals( $product->getId(), $newProducts[$key]->getId() ); |
||
711 | } |
||
712 | |||
713 | $newServices = $newBasket->getServices(); |
||
714 | |||
715 | foreach( $basket->getServices() as $key => $list ) |
||
716 | { |
||
717 | foreach( $list as $pos => $service ) { |
||
718 | $this->assertEquals( $service->getId(), $newServices[$key][$pos]->getId() ); |
||
719 | } |
||
720 | } |
||
721 | } |
||
722 | |||
723 | |||
724 | public function testStoreBundles() |
||
725 | { |
||
726 | $search = $this->object->createSearch(); |
||
727 | |||
728 | $expr = []; |
||
729 | $expr[] = $search->compare( '==', 'order.base.sitecode', 'unittest' ); |
||
730 | $expr[] = $search->compare( '==', 'order.base.price', 4800.00 ); |
||
731 | $search->setConditions( $search->combine( '&&', $expr ) ); |
||
732 | $results = $this->object->searchItems( $search )->toArray(); |
||
733 | |||
734 | if( ( $item = reset( $results ) ) == false ) { |
||
735 | throw new \RuntimeException( 'No order found' ); |
||
736 | } |
||
737 | |||
738 | $basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL, true ); |
||
739 | $this->object->store( $basket ); |
||
740 | |||
741 | $newBasketId = $basket->getId(); |
||
742 | |||
743 | $basket = $this->object->load( $newBasketId ); |
||
744 | $this->object->deleteItem( $newBasketId ); |
||
745 | |||
746 | $this->assertEquals( $item->getCustomerId(), $basket->getCustomerId() ); |
||
747 | $this->assertEquals( $basket->getLocale()->getSiteId(), $basket->getSiteId() ); |
||
748 | |||
749 | $pos = 0; |
||
750 | $products = $basket->getProducts(); |
||
751 | |||
752 | $this->assertEquals( 2, count( $products ) ); |
||
753 | foreach( $products as $product ) |
||
754 | { |
||
755 | $this->assertEquals( 2, count( $product->getProducts() ) ); |
||
756 | $this->assertEquals( $pos, $product->getPosition() ); |
||
757 | $pos += 3; // two sub-products in between |
||
758 | } |
||
759 | |||
760 | $this->expectException( \Aimeos\MShop\Exception::class ); |
||
761 | $this->object->getItem( $newBasketId ); |
||
762 | } |
||
763 | |||
764 | |||
765 | public function testStoreNone() |
||
775 | } |
||
776 | |||
777 | |||
778 | public function testStoreAddress() |
||
779 | { |
||
780 | $item = $this->getOrderItem(); |
||
781 | |||
782 | $parts = \Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT | \Aimeos\MShop\Order\Item\Base\Base::PARTS_ADDRESS; |
||
783 | $basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL, true ); |
||
784 | $this->object->store( $basket, $parts ); |
||
785 | |||
786 | $newBasketId = $basket->getId(); |
||
787 | |||
788 | $basket = $this->object->load( $newBasketId, \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL ); |
||
789 | $this->object->deleteItem( $newBasketId ); |
||
790 | |||
791 | $this->assertGreaterThan( 0, count( $basket->getAddresses() ) ); |
||
792 | $this->assertGreaterThan( 0, count( $basket->getProducts() ) ); |
||
793 | $this->assertEquals( [], $basket->getCoupons()->toArray() ); |
||
794 | $this->assertEquals( [], $basket->getServices()->toArray() ); |
||
795 | } |
||
796 | |||
797 | |||
798 | public function testStoreProduct() |
||
799 | { |
||
800 | $item = $this->getOrderItem(); |
||
801 | |||
802 | $basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL, true ); |
||
803 | $this->object->store( $basket, \Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT ); |
||
804 | |||
805 | $newBasketId = $basket->getId(); |
||
806 | |||
807 | $basket = $this->object->load( $newBasketId, \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL ); |
||
808 | $this->object->deleteItem( $newBasketId ); |
||
809 | |||
810 | $this->assertGreaterThan( 0, count( $basket->getProducts() ) ); |
||
811 | $this->assertEquals( [], $basket->getAddresses()->toArray() ); |
||
812 | $this->assertEquals( [], $basket->getCoupons()->toArray() ); |
||
813 | $this->assertEquals( [], $basket->getServices()->toArray() ); |
||
814 | } |
||
815 | |||
816 | |||
817 | public function testStoreService() |
||
818 | { |
||
819 | $item = $this->getOrderItem(); |
||
820 | |||
821 | $parts = \Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT | \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE; |
||
822 | $basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL, true ); |
||
823 | $this->object->store( $basket, $parts ); |
||
824 | |||
825 | $newBasketId = $basket->getId(); |
||
826 | |||
827 | $basket = $this->object->load( $newBasketId, \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL ); |
||
828 | $this->object->deleteItem( $newBasketId ); |
||
829 | |||
830 | $this->assertGreaterThan( 0, count( $basket->getServices() ) ); |
||
831 | $this->assertGreaterThan( 0, count( $basket->getProducts() ) ); |
||
832 | $this->assertEquals( [], $basket->getAddresses()->toArray() ); |
||
833 | $this->assertEquals( [], $basket->getCoupons()->toArray() ); |
||
834 | } |
||
835 | |||
836 | |||
837 | public function testLoadStoreCoupons() |
||
838 | { |
||
839 | $search = $this->object->createSearch(); |
||
840 | $search->setConditions( $search->compare( '==', 'order.base.price', '53.50' ) ); |
||
841 | $results = $this->object->searchItems( $search )->toArray(); |
||
842 | |||
843 | if( ( $item = reset( $results ) ) === false ) { |
||
844 | throw new \RuntimeException( 'No order found' ); |
||
845 | } |
||
846 | |||
847 | $parts = \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL ^ \Aimeos\MShop\Order\Item\Base\Base::PARTS_COUPON; |
||
848 | $basket = $this->object->load( $item->getId(), $parts, true ); |
||
849 | |||
850 | $this->assertEquals( '58.50', $basket->getPrice()->getValue() ); |
||
851 | $this->assertEquals( '6.50', $basket->getPrice()->getCosts() ); |
||
852 | $this->assertEquals( 0, count( $basket->getCoupons() ) ); |
||
853 | |||
854 | $productBasket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL, true ); |
||
|
|||
855 | |||
856 | $basket->addCoupon( 'CDEF' ); |
||
857 | $basket->addCoupon( '90AB' ); |
||
858 | $this->assertEquals( 2, count( $basket->getCoupons() ) ); |
||
859 | |||
860 | $this->object->store( $basket ); |
||
861 | $newBasket = $this->object->load( $basket->getId() ); |
||
862 | $this->object->deleteItem( $newBasket->getId() ); |
||
863 | |||
864 | $this->assertEquals( '52.50', $newBasket->getPrice()->getValue() ); |
||
865 | $this->assertEquals( '1.50', $newBasket->getPrice()->getCosts() ); |
||
866 | $this->assertEquals( '6.00', $newBasket->getPrice()->getRebate() ); |
||
867 | $this->assertEquals( 2, count( $newBasket->getCoupons() ) ); |
||
868 | } |
||
869 | |||
870 | |||
871 | /** |
||
872 | * Returns an order base item |
||
873 | * |
||
874 | * @return \Aimeos\MShop\Order\Item\Base\Iface Order base item |
||
875 | * @throws \Exception If no found |
||
876 | */ |
||
877 | protected function getOrderItem() |
||
894 | } |
||
895 | } |
||
896 |