1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Service\Provider\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class QuantityTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
private $servItem; |
17
|
|
|
private $mockProvider; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->context = \TestHelperMShop::getContext(); |
23
|
|
|
|
24
|
|
|
$servManager = \Aimeos\MShop\Service\Manager\Factory::createManager( $this->context ); |
25
|
|
|
$this->servItem = $servManager->createItem(); |
26
|
|
|
|
27
|
|
|
$this->mockProvider = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Decorator\\Example' ) |
28
|
|
|
->disableOriginalConstructor()->getMock(); |
29
|
|
|
|
30
|
|
|
$this->object = new \Aimeos\MShop\Service\Provider\Decorator\Quantity( $this->mockProvider, $this->context, $this->servItem ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
protected function tearDown() |
35
|
|
|
{ |
36
|
|
|
unset( $this->object, $this->context, $this->servItem, $this->mockProvider ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
public function testGetConfigBE() |
41
|
|
|
{ |
42
|
|
|
$this->mockProvider->expects( $this->once() )->method( 'getConfigBE' )->will( $this->returnValue( [] ) ); |
43
|
|
|
|
44
|
|
|
$result = $this->object->getConfigBE(); |
45
|
|
|
|
46
|
|
|
$this->assertArrayHasKey( 'quantity.packagesize', $result ); |
47
|
|
|
$this->assertArrayHasKey( 'quantity.packagecosts', $result ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
public function testCheckConfigBEOK() |
52
|
|
|
{ |
53
|
|
|
$this->mockProvider->expects( $this->once() ) |
54
|
|
|
->method( 'checkConfigBE' ) |
55
|
|
|
->will( $this->returnValue( [] ) ); |
56
|
|
|
|
57
|
|
|
$attributes = array( 'quantity.packagecosts' => '10.0' ); |
58
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
59
|
|
|
|
60
|
|
|
$this->assertEquals( 2, count( $result ) ); |
61
|
|
|
$this->assertInternalType( 'null', $result['quantity.packagecosts'] ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public function testCheckConfigBEFailure() |
66
|
|
|
{ |
67
|
|
|
$this->mockProvider->expects( $this->once() ) |
68
|
|
|
->method( 'checkConfigBE' ) |
69
|
|
|
->will( $this->returnValue( [] ) ); |
70
|
|
|
|
71
|
|
|
$attributes = array( 'quantity.packagecosts' => [] ); |
72
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
73
|
|
|
|
74
|
|
|
$this->assertEquals( 2, count( $result ) ); |
75
|
|
|
$this->assertInternalType( 'string', $result['quantity.packagecosts'] ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
public function testCalcPrice() |
80
|
|
|
{ |
81
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'price' ); |
82
|
|
|
$price = $manager->createItem(); |
83
|
|
|
|
84
|
|
|
$this->mockProvider->expects( $this->once() ) |
85
|
|
|
->method( 'calcPrice' ) |
86
|
|
|
->will( $this->returnValue( $price ) ); |
87
|
|
|
|
88
|
|
|
$this->servItem->setConfig( array( 'quantity.packagecosts' => '1' ) ); |
89
|
|
|
|
90
|
|
|
$this->assertEquals( '14.00', $this->object->calcPrice( $this->getOrderBaseItem( '2008-02-15 12:34:56' ) )->getCosts() ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
public function testCalcPriceBundle() |
95
|
|
|
{ |
96
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'price' ); |
97
|
|
|
$price = $manager->createItem(); |
98
|
|
|
|
99
|
|
|
$this->mockProvider->expects( $this->once() ) |
100
|
|
|
->method( 'calcPrice' ) |
101
|
|
|
->will( $this->returnValue( $price ) ); |
102
|
|
|
|
103
|
|
|
$this->servItem->setConfig( array( 'quantity.packagecosts' => '1.0' ) ); |
104
|
|
|
|
105
|
|
|
$this->assertEquals( '4.00', $this->object->calcPrice( $this->getOrderBaseItem( '2009-03-18 16:14:32' ) )->getCosts() ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
public function testCalcPricePackageHalf() |
110
|
|
|
{ |
111
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'price' ); |
112
|
|
|
$price = $manager->createItem(); |
113
|
|
|
|
114
|
|
|
$this->mockProvider->expects( $this->once() ) |
115
|
|
|
->method( 'calcPrice' ) |
116
|
|
|
->will( $this->returnValue( $price ) ); |
117
|
|
|
|
118
|
|
|
$this->servItem->setConfig( array( 'quantity.packagesize' => '5', 'quantity.packagecosts' => '2.50' ) ); |
119
|
|
|
|
120
|
|
|
$this->assertEquals( '7.50', $this->object->calcPrice( $this->getOrderBaseItem( '2008-02-15 12:34:56' ) )->getCosts() ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
public function testCalcPricePackageFull() |
125
|
|
|
{ |
126
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'price' ); |
127
|
|
|
$price = $manager->createItem(); |
128
|
|
|
|
129
|
|
|
$this->mockProvider->expects( $this->once() ) |
130
|
|
|
->method( 'calcPrice' ) |
131
|
|
|
->will( $this->returnValue( $price ) ); |
132
|
|
|
|
133
|
|
|
$this->servItem->setConfig( array( 'quantity.packagesize' => '7', 'quantity.packagecosts' => '5.00' ) ); |
134
|
|
|
|
135
|
|
|
$this->assertEquals( '10.00', $this->object->calcPrice( $this->getOrderBaseItem( '2008-02-15 12:34:56' ) )->getCosts() ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Iface |
141
|
|
|
*/ |
142
|
|
|
protected function getOrderBaseItem( $paydate ) |
143
|
|
|
{ |
144
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'order' ); |
145
|
|
|
|
146
|
|
|
$search = $manager->createSearch(); |
147
|
|
|
$search->setConditions( $search->compare( '==', 'order.datepayment', $paydate ) ); |
148
|
|
|
$result = $manager->searchItems( $search ); |
149
|
|
|
|
150
|
|
|
if( ( $item = reset( $result ) ) === false ) { |
151
|
|
|
throw new \RuntimeException( 'No order item found' ); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
$baseManager = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base' ); |
155
|
|
|
return $baseManager->load( $item->getBaseId() ); |
156
|
|
|
} |
157
|
|
|
} |