|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2023 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Order\Manager; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class UpdateTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
protected function setUp() : void |
|
15
|
|
|
{ |
|
16
|
|
|
\Aimeos\MShop::cache( true ); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
protected function tearDown() : void |
|
21
|
|
|
{ |
|
22
|
|
|
\Aimeos\MShop::cache( false ); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
public function testBlock() |
|
27
|
|
|
{ |
|
28
|
|
|
$context = \TestHelper::context(); |
|
29
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create(); |
|
30
|
|
|
|
|
31
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class ) |
|
32
|
|
|
->setConstructorArgs( array( $context ) ) |
|
33
|
|
|
->onlyMethods( array( 'updateStatus' ) ) |
|
34
|
|
|
->getMock(); |
|
35
|
|
|
|
|
36
|
|
|
$object->expects( $this->exactly( 2 ) )->method( 'updateStatus' ) |
|
37
|
|
|
->with( $this->equalTo( $orderItem ), $this->anything(), $this->equalTo( 1 ), $this->equalTo( -1 ) ); |
|
38
|
|
|
|
|
39
|
|
|
$object->block( $orderItem ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
public function testUnblock() |
|
44
|
|
|
{ |
|
45
|
|
|
$context = \TestHelper::context(); |
|
46
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create(); |
|
47
|
|
|
|
|
48
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class ) |
|
49
|
|
|
->setConstructorArgs( array( $context ) ) |
|
50
|
|
|
->onlyMethods( array( 'updateStatus' ) ) |
|
51
|
|
|
->getMock(); |
|
52
|
|
|
|
|
53
|
|
|
$object->expects( $this->exactly( 2 ) )->method( 'updateStatus' ) |
|
54
|
|
|
->with( $this->equalTo( $orderItem ), $this->anything(), $this->equalTo( 0 ), $this->equalTo( +1 ) ); |
|
55
|
|
|
|
|
56
|
|
|
$object->unblock( $orderItem ); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
public function testUpdateBlock() |
|
61
|
|
|
{ |
|
62
|
|
|
$context = \TestHelper::context(); |
|
63
|
|
|
|
|
64
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create(); |
|
65
|
|
|
$orderItem->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_PENDING ); |
|
66
|
|
|
|
|
67
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class ) |
|
68
|
|
|
->setConstructorArgs( array( $context ) ) |
|
69
|
|
|
->onlyMethods( array( 'block' ) ) |
|
70
|
|
|
->getMock(); |
|
71
|
|
|
|
|
72
|
|
|
$object->expects( $this->once() )->method( 'block' )->with( $this->equalTo( $orderItem ) ); |
|
73
|
|
|
|
|
74
|
|
|
$object->update( $orderItem ); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
public function testUpdateUnblock() |
|
79
|
|
|
{ |
|
80
|
|
|
$context = \TestHelper::context(); |
|
81
|
|
|
|
|
82
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create(); |
|
83
|
|
|
$orderItem->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_DELETED ); |
|
84
|
|
|
|
|
85
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class ) |
|
86
|
|
|
->setConstructorArgs( array( $context ) ) |
|
87
|
|
|
->onlyMethods( array( 'unblock' ) ) |
|
88
|
|
|
->getMock(); |
|
89
|
|
|
|
|
90
|
|
|
$object->expects( $this->once() )->method( 'unblock' )->with( $this->equalTo( $orderItem ) ); |
|
91
|
|
|
|
|
92
|
|
|
$object->update( $orderItem ); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
public function testAddStatusItem() |
|
97
|
|
|
{ |
|
98
|
|
|
$context = \TestHelper::context(); |
|
99
|
|
|
|
|
100
|
|
|
$statusStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Status\Standard::class ) |
|
101
|
|
|
->setConstructorArgs( array( $context ) ) |
|
102
|
|
|
->onlyMethods( array( 'save' ) ) |
|
103
|
|
|
->getMock(); |
|
104
|
|
|
|
|
105
|
|
|
$statusStub->expects( $this->once() )->method( 'save' ); |
|
106
|
|
|
|
|
107
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Order\Manager\Status\Standard::class, $statusStub ); |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
111
|
|
|
$method = $class->getMethod( 'addStatusItem' ); |
|
112
|
|
|
$method->setAccessible( true ); |
|
113
|
|
|
|
|
114
|
|
|
$object = new \Aimeos\MShop\Order\Manager\Standard( $context ); |
|
115
|
|
|
$method->invokeArgs( $object, array( 1, 2, 3 ) ); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
public function testGetBundleMap() |
|
120
|
|
|
{ |
|
121
|
|
|
$context = \TestHelper::context(); |
|
122
|
|
|
$prodId = \Aimeos\MShop::create( $context, 'product' )->find( 'CNC' )->getId(); |
|
123
|
|
|
|
|
124
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
125
|
|
|
$method = $class->getMethod( 'getBundleMap' ); |
|
126
|
|
|
$method->setAccessible( true ); |
|
127
|
|
|
|
|
128
|
|
|
$object = new \Aimeos\MShop\Order\Manager\Standard( $context ); |
|
129
|
|
|
$result = $method->invokeArgs( $object, array( $prodId ) ); |
|
130
|
|
|
|
|
131
|
|
|
$this->assertEquals( 2, count( $result ) ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
public function testGetContext() |
|
136
|
|
|
{ |
|
137
|
|
|
$context = \TestHelper::context(); |
|
138
|
|
|
|
|
139
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
140
|
|
|
$method = $class->getMethod( 'context' ); |
|
141
|
|
|
$method->setAccessible( true ); |
|
142
|
|
|
|
|
143
|
|
|
$object = new \Aimeos\MShop\Order\Manager\Standard( $context ); |
|
144
|
|
|
$result = $method->invokeArgs( $object, [] ); |
|
145
|
|
|
|
|
146
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $result ); |
|
147
|
|
|
$this->assertSame( $context, $result ); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
public function testGetLastStatusItem() |
|
152
|
|
|
{ |
|
153
|
|
|
$context = \TestHelper::context(); |
|
154
|
|
|
$orderItem = $this->getOrderItem( '2008-02-15 12:34:56' ); |
|
155
|
|
|
|
|
156
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
157
|
|
|
$method = $class->getMethod( 'getLastStatusItem' ); |
|
158
|
|
|
$method->setAccessible( true ); |
|
159
|
|
|
|
|
160
|
|
|
$object = new \Aimeos\MShop\Order\Manager\Standard( $context ); |
|
161
|
|
|
$result = $method->invokeArgs( $object, array( $orderItem->getId(), 'typestatus', 'shipped' ) ); |
|
162
|
|
|
|
|
163
|
|
|
$this->assertNotEquals( false, $result ); |
|
164
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Status\Iface::class, $result ); |
|
165
|
|
|
$this->assertEquals( 'shipped', $result->getValue() ); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
|
|
169
|
|
|
public function testGetLastStatusItemFalse() |
|
170
|
|
|
{ |
|
171
|
|
|
$context = \TestHelper::context(); |
|
172
|
|
|
|
|
173
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
174
|
|
|
$method = $class->getMethod( 'getLastStatusItem' ); |
|
175
|
|
|
$method->setAccessible( true ); |
|
176
|
|
|
|
|
177
|
|
|
$object = new \Aimeos\MShop\Order\Manager\Standard( $context ); |
|
178
|
|
|
$result = $method->invokeArgs( $object, array( -1, 0, 0 ) ); |
|
179
|
|
|
|
|
180
|
|
|
$this->assertNull( $result ); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
|
|
184
|
|
|
public function testGetStockItems() |
|
185
|
|
|
{ |
|
186
|
|
|
$context = \TestHelper::context(); |
|
187
|
|
|
$prodid = \Aimeos\MShop::create( $context, 'product' )->find( 'CNE' )->getId(); |
|
188
|
|
|
|
|
189
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
190
|
|
|
$method = $class->getMethod( 'getStockItems' ); |
|
191
|
|
|
$method->setAccessible( true ); |
|
192
|
|
|
|
|
193
|
|
|
$object = new \Aimeos\MShop\Order\Manager\Standard( $context ); |
|
194
|
|
|
$result = $method->invokeArgs( $object, [[$prodid], 'default'] ); |
|
195
|
|
|
|
|
196
|
|
|
$this->assertEquals( 1, count( $result ) ); |
|
197
|
|
|
|
|
198
|
|
|
foreach( $result as $item ) { |
|
199
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Stock\Item\Iface::class, $item ); |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
|
|
204
|
|
|
public function testUpdateCoupons() |
|
205
|
|
|
{ |
|
206
|
|
|
$context = \TestHelper::context(); |
|
207
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create(); |
|
208
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
$orderCouponStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Coupon\Standard::class ) |
|
211
|
|
|
->setConstructorArgs( array( $context ) ) |
|
212
|
|
|
->onlyMethods( ['search'] ) |
|
213
|
|
|
->getMock(); |
|
214
|
|
|
|
|
215
|
|
|
$orderCouponStub->expects( $this->once() )->method( 'search' ) |
|
216
|
|
|
->will( $this->returnValue( map( [$orderCouponStub->create()->setCode( 'test' )] ) ) ); |
|
217
|
|
|
|
|
218
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Order\Manager\Coupon\Standard::class, $orderCouponStub ); |
|
219
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
$couponCodeStub = $this->getMockBuilder( \Aimeos\MShop\Coupon\Manager\Code\Standard::class ) |
|
222
|
|
|
->setConstructorArgs( array( $context ) ) |
|
223
|
|
|
->onlyMethods( array( 'increase' ) ) |
|
224
|
|
|
->getMock(); |
|
225
|
|
|
|
|
226
|
|
|
$couponCodeStub->expects( $this->once() )->method( 'increase' ); |
|
227
|
|
|
|
|
228
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Coupon\Manager\Code\Standard::class, $couponCodeStub ); |
|
229
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
232
|
|
|
$method = $class->getMethod( 'updateCoupons' ); |
|
233
|
|
|
$method->setAccessible( true ); |
|
234
|
|
|
|
|
235
|
|
|
$object = new \Aimeos\MShop\Order\Manager\Standard( $context ); |
|
236
|
|
|
$method->invokeArgs( $object, array( $orderItem, 1 ) ); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
|
|
240
|
|
|
public function testUpdateCouponsException() |
|
241
|
|
|
{ |
|
242
|
|
|
$context = \TestHelper::context(); |
|
243
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create(); |
|
244
|
|
|
|
|
245
|
|
|
|
|
246
|
|
|
$orderCouponStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Coupon\Standard::class ) |
|
247
|
|
|
->setConstructorArgs( array( $context ) ) |
|
248
|
|
|
->onlyMethods( ['search'] ) |
|
249
|
|
|
->getMock(); |
|
250
|
|
|
|
|
251
|
|
|
$orderCouponStub->expects( $this->once() )->method( 'search' ) |
|
252
|
|
|
->will( $this->returnValue( map( [$orderCouponStub->create()->setCode( 'test' )] ) ) ); |
|
253
|
|
|
|
|
254
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Order\Manager\Coupon\Standard::class, $orderCouponStub ); |
|
255
|
|
|
|
|
256
|
|
|
|
|
257
|
|
|
$couponCodeStub = $this->getMockBuilder( \Aimeos\MShop\Coupon\Manager\Code\Standard::class ) |
|
258
|
|
|
->setConstructorArgs( array( $context ) ) |
|
259
|
|
|
->onlyMethods( array( 'increase' ) ) |
|
260
|
|
|
->getMock(); |
|
261
|
|
|
|
|
262
|
|
|
$couponCodeStub->expects( $this->once() )->method( 'increase' ) |
|
263
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
|
264
|
|
|
|
|
265
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Coupon\Manager\Code\Standard::class, $couponCodeStub ); |
|
266
|
|
|
|
|
267
|
|
|
|
|
268
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
269
|
|
|
$method = $class->getMethod( 'updateCoupons' ); |
|
270
|
|
|
$method->setAccessible( true ); |
|
271
|
|
|
|
|
272
|
|
|
$object = new \Aimeos\MShop\Order\Manager\Standard( $context ); |
|
273
|
|
|
|
|
274
|
|
|
$this->expectException( \Exception::class ); |
|
275
|
|
|
$method->invokeArgs( $object, array( $orderItem, 1 ) ); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
|
|
279
|
|
|
public function testUpdateStatus() |
|
280
|
|
|
{ |
|
281
|
|
|
$context = \TestHelper::context(); |
|
282
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create()->setId( -1 ); |
|
283
|
|
|
$statusItem = \Aimeos\MShop::create( $context, 'order/status' )->create(); |
|
284
|
|
|
$statusItem->setValue( 1 ); |
|
285
|
|
|
|
|
286
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class ) |
|
287
|
|
|
->setConstructorArgs( array( $context ) ) |
|
288
|
|
|
->onlyMethods( array( 'addStatusItem', 'getLastStatusItem' ) ) |
|
289
|
|
|
->getMock(); |
|
290
|
|
|
|
|
291
|
|
|
$object->expects( $this->never() )->method( 'addStatusItem' ); |
|
292
|
|
|
|
|
293
|
|
|
$object->expects( $this->once() )->method( 'getLastStatusItem' ) |
|
294
|
|
|
->will( $this->returnValue( $statusItem ) ); |
|
295
|
|
|
|
|
296
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
297
|
|
|
$method = $class->getMethod( 'updateStatus' ); |
|
298
|
|
|
$method->setAccessible( true ); |
|
299
|
|
|
$method->invokeArgs( $object, array( $orderItem, 'type', 1, 0 ) ); |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
|
|
303
|
|
|
public function testUpdateStatusStock() |
|
304
|
|
|
{ |
|
305
|
|
|
$context = \TestHelper::context(); |
|
306
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create()->setId( -1 ); |
|
307
|
|
|
$statusItem = \Aimeos\MShop::create( $context, 'order/status' )->create(); |
|
308
|
|
|
|
|
309
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class ) |
|
310
|
|
|
->setConstructorArgs( array( $context ) ) |
|
311
|
|
|
->onlyMethods( array( 'addStatusItem', 'getLastStatusItem', 'updateStock' ) ) |
|
312
|
|
|
->getMock(); |
|
313
|
|
|
|
|
314
|
|
|
$object->expects( $this->once() )->method( 'getLastStatusItem' ) |
|
315
|
|
|
->will( $this->returnValue( $statusItem ) ); |
|
316
|
|
|
|
|
317
|
|
|
$object->expects( $this->once() )->method( 'updateStock' ); |
|
318
|
|
|
$object->expects( $this->once() )->method( 'addStatusItem' ); |
|
319
|
|
|
|
|
320
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
321
|
|
|
$method = $class->getMethod( 'updateStatus' ); |
|
322
|
|
|
$method->setAccessible( true ); |
|
323
|
|
|
$method->invokeArgs( $object, array( $orderItem, \Aimeos\MShop\Order\Item\Status\Base::STOCK_UPDATE, 1, 0 ) ); |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
|
|
327
|
|
|
public function testUpdateStatusCoupons() |
|
328
|
|
|
{ |
|
329
|
|
|
$context = \TestHelper::context(); |
|
330
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create()->setId( -1 ); |
|
331
|
|
|
$statusItem = \Aimeos\MShop::create( $context, 'order/status' )->create(); |
|
332
|
|
|
|
|
333
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class ) |
|
334
|
|
|
->setConstructorArgs( array( $context ) ) |
|
335
|
|
|
->onlyMethods( array( 'addStatusItem', 'getLastStatusItem', 'updateCoupons' ) ) |
|
336
|
|
|
->getMock(); |
|
337
|
|
|
|
|
338
|
|
|
$object->expects( $this->once() )->method( 'getLastStatusItem' ) |
|
339
|
|
|
->will( $this->returnValue( $statusItem ) ); |
|
340
|
|
|
|
|
341
|
|
|
$object->expects( $this->once() )->method( 'updateCoupons' ); |
|
342
|
|
|
$object->expects( $this->once() )->method( 'addStatusItem' ); |
|
343
|
|
|
|
|
344
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
345
|
|
|
$method = $class->getMethod( 'updateStatus' ); |
|
346
|
|
|
$method->setAccessible( true ); |
|
347
|
|
|
$method->invokeArgs( $object, array( $orderItem, \Aimeos\MShop\Order\Item\Status\Base::COUPON_UPDATE, 1, 0 ) ); |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
|
|
351
|
|
|
public function testUpdateStock() |
|
352
|
|
|
{ |
|
353
|
|
|
$context = \TestHelper::context(); |
|
354
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create(); |
|
355
|
|
|
|
|
356
|
|
|
|
|
357
|
|
|
$orderProductStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Product\Standard::class ) |
|
358
|
|
|
->setConstructorArgs( array( $context ) ) |
|
359
|
|
|
->onlyMethods( ['search'] ) |
|
360
|
|
|
->getMock(); |
|
361
|
|
|
|
|
362
|
|
|
$orderProductStub->expects( $this->once() )->method( 'search' ) |
|
363
|
|
|
->will( $this->returnValue( map( [$orderProductStub->create()] ) ) ); |
|
364
|
|
|
|
|
365
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Order\Manager\Product\Standard::class, $orderProductStub ); |
|
366
|
|
|
|
|
367
|
|
|
|
|
368
|
|
|
$stockStub = $this->getMockBuilder( \Aimeos\MShop\Stock\Manager\Standard::class ) |
|
369
|
|
|
->setConstructorArgs( array( $context ) ) |
|
370
|
|
|
->onlyMethods( array( 'decrease' ) ) |
|
371
|
|
|
->getMock(); |
|
372
|
|
|
|
|
373
|
|
|
$stockStub->expects( $this->once() )->method( 'decrease' ); |
|
374
|
|
|
|
|
375
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Stock\Manager\Standard::class, $stockStub ); |
|
376
|
|
|
|
|
377
|
|
|
|
|
378
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class ) |
|
379
|
|
|
->setConstructorArgs( array( $context ) ) |
|
380
|
|
|
->onlyMethods( array( 'updateStockBundle', 'updateStockSelection' ) ) |
|
381
|
|
|
->getMock(); |
|
382
|
|
|
|
|
383
|
|
|
$object->expects( $this->never() )->method( 'updateStockBundle' ); |
|
384
|
|
|
$object->expects( $this->never() )->method( 'updateStockSelection' ); |
|
385
|
|
|
|
|
386
|
|
|
|
|
387
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
388
|
|
|
$method = $class->getMethod( 'updateStock' ); |
|
389
|
|
|
$method->setAccessible( true ); |
|
390
|
|
|
$method->invokeArgs( $object, array( $orderItem, 1 ) ); |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
|
|
394
|
|
|
public function testUpdateStockArticle() |
|
395
|
|
|
{ |
|
396
|
|
|
$context = \TestHelper::context(); |
|
397
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create(); |
|
398
|
|
|
|
|
399
|
|
|
|
|
400
|
|
|
$orderProductStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Product\Standard::class ) |
|
401
|
|
|
->setConstructorArgs( array( $context ) ) |
|
402
|
|
|
->onlyMethods( ['search'] ) |
|
403
|
|
|
->getMock(); |
|
404
|
|
|
|
|
405
|
|
|
$orderProductItem = $orderProductStub->create(); |
|
406
|
|
|
$orderProductItem->setType( 'default' ); |
|
407
|
|
|
|
|
408
|
|
|
$orderProductStub->expects( $this->once() )->method( 'search' ) |
|
409
|
|
|
->will( $this->returnValue( map( [$orderProductItem] ) ) ); |
|
410
|
|
|
|
|
411
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Order\Manager\Product\Standard::class, $orderProductStub ); |
|
412
|
|
|
|
|
413
|
|
|
|
|
414
|
|
|
$stockStub = $this->getMockBuilder( \Aimeos\MShop\Stock\Manager\Standard::class ) |
|
415
|
|
|
->setConstructorArgs( array( $context ) ) |
|
416
|
|
|
->onlyMethods( array( 'decrease' ) ) |
|
417
|
|
|
->getMock(); |
|
418
|
|
|
|
|
419
|
|
|
$stockStub->expects( $this->once() )->method( 'decrease' ); |
|
420
|
|
|
|
|
421
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Stock\Manager\Standard::class, $stockStub ); |
|
422
|
|
|
|
|
423
|
|
|
|
|
424
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class ) |
|
425
|
|
|
->setConstructorArgs( array( $context ) ) |
|
426
|
|
|
->onlyMethods( array( 'updateStockBundle', 'updateStockSelection' ) ) |
|
427
|
|
|
->getMock(); |
|
428
|
|
|
|
|
429
|
|
|
$object->expects( $this->once() )->method( 'updateStockBundle' ); |
|
430
|
|
|
$object->expects( $this->never() )->method( 'updateStockSelection' ); |
|
431
|
|
|
|
|
432
|
|
|
|
|
433
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
434
|
|
|
$method = $class->getMethod( 'updateStock' ); |
|
435
|
|
|
$method->setAccessible( true ); |
|
436
|
|
|
$method->invokeArgs( $object, array( $orderItem, 1 ) ); |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
|
|
440
|
|
|
public function testUpdateStockSelect() |
|
441
|
|
|
{ |
|
442
|
|
|
$context = \TestHelper::context(); |
|
443
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create(); |
|
444
|
|
|
|
|
445
|
|
|
|
|
446
|
|
|
$orderProductStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Product\Standard::class ) |
|
447
|
|
|
->setConstructorArgs( array( $context ) ) |
|
448
|
|
|
->onlyMethods( ['search'] ) |
|
449
|
|
|
->getMock(); |
|
450
|
|
|
|
|
451
|
|
|
$orderProductItem = $orderProductStub->create(); |
|
452
|
|
|
$orderProductItem->setType( 'select' ); |
|
453
|
|
|
|
|
454
|
|
|
$orderProductStub->expects( $this->once() )->method( 'search' ) |
|
455
|
|
|
->will( $this->returnValue( map( [$orderProductItem] ) ) ); |
|
456
|
|
|
|
|
457
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Order\Manager\Product\Standard::class, $orderProductStub ); |
|
458
|
|
|
|
|
459
|
|
|
|
|
460
|
|
|
$stockStub = $this->getMockBuilder( \Aimeos\MShop\Stock\Manager\Standard::class ) |
|
461
|
|
|
->setConstructorArgs( array( $context ) ) |
|
462
|
|
|
->onlyMethods( array( 'decrease' ) ) |
|
463
|
|
|
->getMock(); |
|
464
|
|
|
|
|
465
|
|
|
$stockStub->expects( $this->once() )->method( 'decrease' ); |
|
466
|
|
|
|
|
467
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Stock\Manager\Standard::class, $stockStub ); |
|
468
|
|
|
|
|
469
|
|
|
|
|
470
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class ) |
|
471
|
|
|
->setConstructorArgs( array( $context ) ) |
|
472
|
|
|
->onlyMethods( array( 'updateStockBundle', 'updateStockSelection' ) ) |
|
473
|
|
|
->getMock(); |
|
474
|
|
|
|
|
475
|
|
|
$object->expects( $this->never() )->method( 'updateStockBundle' ); |
|
476
|
|
|
$object->expects( $this->once() )->method( 'updateStockSelection' ); |
|
477
|
|
|
|
|
478
|
|
|
|
|
479
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
480
|
|
|
$method = $class->getMethod( 'updateStock' ); |
|
481
|
|
|
$method->setAccessible( true ); |
|
482
|
|
|
$method->invokeArgs( $object, array( $orderItem, 1 ) ); |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
|
|
486
|
|
|
public function testUpdateStockException() |
|
487
|
|
|
{ |
|
488
|
|
|
$context = \TestHelper::context(); |
|
489
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->create(); |
|
490
|
|
|
|
|
491
|
|
|
|
|
492
|
|
|
$orderProductStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Product\Standard::class ) |
|
493
|
|
|
->setConstructorArgs( array( $context ) ) |
|
494
|
|
|
->onlyMethods( ['search'] ) |
|
495
|
|
|
->getMock(); |
|
496
|
|
|
|
|
497
|
|
|
$orderProductStub->expects( $this->once() )->method( 'search' ) |
|
498
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
|
499
|
|
|
|
|
500
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Order\Manager\Product\Standard::class, $orderProductStub ); |
|
501
|
|
|
|
|
502
|
|
|
|
|
503
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
504
|
|
|
$method = $class->getMethod( 'updateStock' ); |
|
505
|
|
|
$method->setAccessible( true ); |
|
506
|
|
|
|
|
507
|
|
|
$object = new \Aimeos\MShop\Order\Manager\Standard( $context ); |
|
508
|
|
|
|
|
509
|
|
|
$this->expectException( \Exception::class ); |
|
510
|
|
|
$method->invokeArgs( $object, array( $orderItem, 1 ) ); |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
|
|
514
|
|
|
public function testUpdateStockBundle() |
|
515
|
|
|
{ |
|
516
|
|
|
$context = \TestHelper::context(); |
|
517
|
|
|
|
|
518
|
|
|
|
|
519
|
|
|
$stockStub = $this->getMockBuilder( \Aimeos\MShop\Stock\Manager\Standard::class ) |
|
520
|
|
|
->setConstructorArgs( array( $context ) ) |
|
521
|
|
|
->onlyMethods( array( 'save' ) ) |
|
522
|
|
|
->getMock(); |
|
523
|
|
|
|
|
524
|
|
|
$stockStub->expects( $this->once() )->method( 'save' )->with( $this->callback( function( $item ) { |
|
525
|
|
|
return $item->getStockLevel() === 10; |
|
526
|
|
|
} ) ); |
|
527
|
|
|
|
|
528
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Stock\Manager\Standard::class, $stockStub ); |
|
529
|
|
|
|
|
530
|
|
|
|
|
531
|
|
|
$stockItem = $stockStub->create(); |
|
532
|
|
|
|
|
533
|
|
|
$stockItem1 = clone $stockItem; |
|
534
|
|
|
$stockItem1->setProductId( '123' ); |
|
535
|
|
|
$stockItem1->setStockLevel( 10 ); |
|
536
|
|
|
|
|
537
|
|
|
$stockItem2 = clone $stockItem; |
|
538
|
|
|
$stockItem2->setProductId( '456' ); |
|
539
|
|
|
$stockItem2->setStockLevel( 20 ); |
|
540
|
|
|
|
|
541
|
|
|
$stockItem3 = clone $stockItem; |
|
542
|
|
|
$stockItem3->setProductId( '789' ); |
|
543
|
|
|
$stockItem3->setStockLevel( 30 ); |
|
544
|
|
|
|
|
545
|
|
|
|
|
546
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class ) |
|
547
|
|
|
->setConstructorArgs( [$context] ) |
|
548
|
|
|
->onlyMethods( ['getBundleMap', 'getStockItems'] ) |
|
549
|
|
|
->getMock(); |
|
550
|
|
|
|
|
551
|
|
|
$object->expects( $this->once() )->method( 'getBundleMap' ) |
|
552
|
|
|
->will( $this->returnValue( ['123' => ['789'], '456' => ['789']] ) ); |
|
553
|
|
|
|
|
554
|
|
|
$object->expects( $this->exactly( 2 ) )->method( 'getStockItems' ) |
|
555
|
|
|
->will( $this->onConsecutiveCalls( |
|
556
|
|
|
map( [$stockItem2, $stockItem1] ), |
|
557
|
|
|
map( [$stockItem3] ) |
|
558
|
|
|
) ); |
|
559
|
|
|
|
|
560
|
|
|
|
|
561
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
562
|
|
|
$method = $class->getMethod( 'updateStockBundle' ); |
|
563
|
|
|
$method->setAccessible( true ); |
|
564
|
|
|
$method->invokeArgs( $object, [1, 'default'] ); |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
|
|
568
|
|
|
public function testUpdateStockSelection() |
|
569
|
|
|
{ |
|
570
|
|
|
$context = \TestHelper::context(); |
|
571
|
|
|
$prodId = \Aimeos\MShop::create( $context, 'product' )->find( 'U:TEST' )->getId(); |
|
572
|
|
|
|
|
573
|
|
|
|
|
574
|
|
|
$stockStub = $this->getMockBuilder( \Aimeos\MShop\Stock\Manager\Standard::class ) |
|
575
|
|
|
->setConstructorArgs( array( $context ) ) |
|
576
|
|
|
->onlyMethods( array( 'save' ) ) |
|
577
|
|
|
->getMock(); |
|
578
|
|
|
|
|
579
|
|
|
$stockStub->expects( $this->once() )->method( 'save' )->with( $this->callback( function( $item ) { |
|
580
|
|
|
return $item->getStockLevel() === 300; |
|
581
|
|
|
} ) ); |
|
582
|
|
|
|
|
583
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Stock\Manager\Standard::class, $stockStub ); |
|
584
|
|
|
|
|
585
|
|
|
|
|
586
|
|
|
$class = new \ReflectionClass( \Aimeos\MShop\Order\Manager\Standard::class ); |
|
587
|
|
|
$method = $class->getMethod( 'updateStockSelection' ); |
|
588
|
|
|
$method->setAccessible( true ); |
|
589
|
|
|
|
|
590
|
|
|
$object = new \Aimeos\MShop\Order\Manager\Standard( $context ); |
|
591
|
|
|
$method->invokeArgs( $object, array( $prodId, 'default' ) ); |
|
592
|
|
|
} |
|
593
|
|
|
|
|
594
|
|
|
|
|
595
|
|
|
protected function getOrderItem( $datepayment ) : \Aimeos\MShop\Order\Item\Iface |
|
596
|
|
|
{ |
|
597
|
|
|
$manager = \Aimeos\MShop::create( \TestHelper::context(), 'order' ); |
|
598
|
|
|
|
|
599
|
|
|
$search = $manager->filter(); |
|
600
|
|
|
$search->setConditions( $search->compare( '==', 'order.datepayment', $datepayment ) ); |
|
601
|
|
|
|
|
602
|
|
|
return $manager->search( $search )->first(); |
|
603
|
|
|
} |
|
604
|
|
|
} |
|
605
|
|
|
|