1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2020 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Service\Provider\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class NocostsTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $basket; |
16
|
|
|
private $context; |
17
|
|
|
private $servItem; |
18
|
|
|
private $mockProvider; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
protected function setUp() : void |
22
|
|
|
{ |
23
|
|
|
$this->context = \TestHelperMShop::getContext(); |
24
|
|
|
|
25
|
|
|
$servManager = \Aimeos\MShop::create( $this->context, 'service' ); |
26
|
|
|
$this->servItem = $servManager->createItem()->setId( -1 ); |
27
|
|
|
|
28
|
|
|
$this->mockProvider = $this->getMockBuilder( \Aimeos\MShop\Service\Provider\Decorator\Nocosts::class ) |
29
|
|
|
->disableOriginalConstructor()->getMock(); |
30
|
|
|
|
31
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::create( $this->context ); |
32
|
|
|
$this->basket = $orderManager->getSubManager( 'base' )->createItem()->off(); // remove plugins |
33
|
|
|
|
34
|
|
|
$this->object = new \Aimeos\MShop\Service\Provider\Decorator\Nocosts( $this->mockProvider, $this->context, $this->servItem ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
protected function tearDown() : void |
39
|
|
|
{ |
40
|
|
|
unset( $this->object, $this->basket, $this->mockProvider, $this->servItem, $this->context ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testCalcPrice() |
45
|
|
|
{ |
46
|
|
|
$this->basket->addProduct( $this->getOrderProduct() ); |
47
|
|
|
$priceItem = \Aimeos\MShop::create( $this->context, 'price' )->createItem(); |
48
|
|
|
|
49
|
|
|
$this->mockProvider->expects( $this->once() )->method( 'calcPrice' )->will( $this->returnValue( $priceItem ) ); |
50
|
|
|
|
51
|
|
|
$price = $this->object->calcPrice( $this->basket ); |
52
|
|
|
$this->assertEquals( '0.00', $price->getValue() ); |
53
|
|
|
$this->assertEquals( '-5.00', $price->getCosts() ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Returns an order product item |
59
|
|
|
* |
60
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Product\Iface Order product item |
61
|
|
|
*/ |
62
|
|
|
protected function getOrderProduct() |
63
|
|
|
{ |
64
|
|
|
$priceManager = \Aimeos\MShop::create( $this->context, 'price' ); |
65
|
|
|
$productManager = \Aimeos\MShop::create( $this->context, 'product' ); |
66
|
|
|
$orderProductManager = \Aimeos\MShop::create( $this->context, 'order/base/product' ); |
67
|
|
|
|
68
|
|
|
$price = $priceManager->createItem(); |
69
|
|
|
$price->setValue( '20.00' )->setCosts( '5.00' ); |
70
|
|
|
|
71
|
|
|
$product = $productManager->createItem()->setId( '-1' ); |
72
|
|
|
$product->setCode( 'test' )->setType( 'test' ); |
73
|
|
|
|
74
|
|
|
$orderProduct = $orderProductManager->createItem(); |
75
|
|
|
$orderProduct->copyFrom( $product ); |
76
|
|
|
$orderProduct->setPrice( $price ); |
77
|
|
|
|
78
|
|
|
return $orderProduct; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|