1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
5
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2018 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Common\Order; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
protected function setUp() |
15
|
|
|
{ |
16
|
|
|
\Aimeos\MShop::cache( true ); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function tearDown() |
21
|
|
|
{ |
22
|
|
|
\Aimeos\MShop::cache( false ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
public function testBlock() |
27
|
|
|
{ |
28
|
|
|
$context = \TestHelperCntl::getContext(); |
29
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
30
|
|
|
|
31
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Common\Order\Standard::class ) |
32
|
|
|
->setConstructorArgs( array( $context ) ) |
33
|
|
|
->setMethods( 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 = \TestHelperCntl::getContext(); |
46
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
47
|
|
|
|
48
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Common\Order\Standard::class ) |
49
|
|
|
->setConstructorArgs( array( $context ) ) |
50
|
|
|
->setMethods( 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 = \TestHelperCntl::getContext(); |
63
|
|
|
|
64
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
65
|
|
|
$orderItem->setPaymentStatus( \Aimeos\MShop\Order\Item\Base::PAY_PENDING ); |
|
|
|
|
66
|
|
|
|
67
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Common\Order\Standard::class ) |
68
|
|
|
->setConstructorArgs( array( $context ) ) |
69
|
|
|
->setMethods( 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 = \TestHelperCntl::getContext(); |
81
|
|
|
|
82
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
83
|
|
|
$orderItem->setPaymentStatus( \Aimeos\MShop\Order\Item\Base::PAY_DELETED ); |
84
|
|
|
|
85
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Common\Order\Standard::class ) |
86
|
|
|
->setConstructorArgs( array( $context ) ) |
87
|
|
|
->setMethods( 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 = \TestHelperCntl::getContext(); |
99
|
|
|
|
100
|
|
|
$statusStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Status\Standard::class ) |
101
|
|
|
->setConstructorArgs( array( $context ) ) |
102
|
|
|
->setMethods( array( 'saveItem' ) ) |
103
|
|
|
->getMock(); |
104
|
|
|
|
105
|
|
|
$statusStub->expects( $this->once() )->method( 'saveItem' ); |
106
|
|
|
|
107
|
|
|
\Aimeos\MShop::inject( 'order/status', $statusStub ); |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
111
|
|
|
$method = $class->getMethod( 'addStatusItem' ); |
112
|
|
|
$method->setAccessible( true ); |
113
|
|
|
|
114
|
|
|
$object = new \Aimeos\Controller\Common\Order\Standard( $context ); |
115
|
|
|
$method->invokeArgs( $object, array( 1, 2, 3 ) ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testGetBundleMap() |
120
|
|
|
{ |
121
|
|
|
$context = \TestHelperCntl::getContext(); |
122
|
|
|
$prodId = \Aimeos\MShop::create( $context, 'product' )->findItem( 'CNC' )->getId(); |
123
|
|
|
|
124
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
125
|
|
|
$method = $class->getMethod( 'getBundleMap' ); |
126
|
|
|
$method->setAccessible( true ); |
127
|
|
|
|
128
|
|
|
$object = new \Aimeos\Controller\Common\Order\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 = \TestHelperCntl::getContext(); |
138
|
|
|
|
139
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
140
|
|
|
$method = $class->getMethod( 'getContext' ); |
141
|
|
|
$method->setAccessible( true ); |
142
|
|
|
|
143
|
|
|
$object = new \Aimeos\Controller\Common\Order\Standard( $context ); |
144
|
|
|
$result = $method->invokeArgs( $object, [] ); |
145
|
|
|
|
146
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Context\Item\Iface::class, $result ); |
147
|
|
|
$this->assertSame( $context, $result ); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
public function testGetLastStatusItem() |
152
|
|
|
{ |
153
|
|
|
$context = \TestHelperCntl::getContext(); |
154
|
|
|
$orderItem = $this->getOrderItem( '2008-02-15 12:34:56' ); |
155
|
|
|
|
156
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
157
|
|
|
$method = $class->getMethod( 'getLastStatusItem' ); |
158
|
|
|
$method->setAccessible( true ); |
159
|
|
|
|
160
|
|
|
$object = new \Aimeos\Controller\Common\Order\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 = \TestHelperCntl::getContext(); |
172
|
|
|
|
173
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
174
|
|
|
$method = $class->getMethod( 'getLastStatusItem' ); |
175
|
|
|
$method->setAccessible( true ); |
176
|
|
|
|
177
|
|
|
$object = new \Aimeos\Controller\Common\Order\Standard( $context ); |
178
|
|
|
$result = $method->invokeArgs( $object, array( -1, 0, 0 ) ); |
179
|
|
|
|
180
|
|
|
$this->assertFalse( $result ); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
public function testGetStockItems() |
185
|
|
|
{ |
186
|
|
|
$context = \TestHelperCntl::getContext(); |
187
|
|
|
|
188
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
189
|
|
|
$method = $class->getMethod( 'getStockItems' ); |
190
|
|
|
$method->setAccessible( true ); |
191
|
|
|
|
192
|
|
|
$object = new \Aimeos\Controller\Common\Order\Standard( $context ); |
193
|
|
|
$result = $method->invokeArgs( $object, array( array( 'CNE' ), 'default' ) ); |
194
|
|
|
|
195
|
|
|
$this->assertEquals( 1, count( $result ) ); |
196
|
|
|
|
197
|
|
|
foreach( $result as $item ) { |
198
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Stock\Item\Iface::class, $item ); |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
|
203
|
|
|
public function testUpdateCoupons() |
204
|
|
|
{ |
205
|
|
|
$context = \TestHelperCntl::getContext(); |
206
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
207
|
|
|
|
208
|
|
|
|
209
|
|
|
$orderCouponStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Base\Coupon\Standard::class ) |
210
|
|
|
->setConstructorArgs( array( $context ) ) |
211
|
|
|
->setMethods( array( 'searchItems' ) ) |
212
|
|
|
->getMock(); |
213
|
|
|
|
214
|
|
|
$orderCouponStub->expects( $this->once() )->method( 'searchItems' ) |
215
|
|
|
->will( $this->returnValue( array( $orderCouponStub->createItem() ) ) ); |
216
|
|
|
|
217
|
|
|
\Aimeos\MShop::inject( 'order/base/coupon', $orderCouponStub ); |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
$couponCodeStub = $this->getMockBuilder( \Aimeos\MShop\Coupon\Manager\Code\Standard::class ) |
221
|
|
|
->setConstructorArgs( array( $context ) ) |
222
|
|
|
->setMethods( array( 'increase' ) ) |
223
|
|
|
->getMock(); |
224
|
|
|
|
225
|
|
|
$couponCodeStub->expects( $this->once() )->method( 'increase' ); |
226
|
|
|
|
227
|
|
|
\Aimeos\MShop::inject( 'coupon/code', $couponCodeStub ); |
228
|
|
|
|
229
|
|
|
|
230
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
231
|
|
|
$method = $class->getMethod( 'updateCoupons' ); |
232
|
|
|
$method->setAccessible( true ); |
233
|
|
|
|
234
|
|
|
$object = new \Aimeos\Controller\Common\Order\Standard( $context ); |
235
|
|
|
$method->invokeArgs( $object, array( $orderItem, 1 ) ); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
|
239
|
|
|
public function testUpdateCouponsException() |
240
|
|
|
{ |
241
|
|
|
$context = \TestHelperCntl::getContext(); |
242
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
243
|
|
|
|
244
|
|
|
|
245
|
|
|
$orderCouponStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Base\Coupon\Standard::class ) |
246
|
|
|
->setConstructorArgs( array( $context ) ) |
247
|
|
|
->setMethods( array( 'searchItems' ) ) |
248
|
|
|
->getMock(); |
249
|
|
|
|
250
|
|
|
$orderCouponStub->expects( $this->once() )->method( 'searchItems' ) |
251
|
|
|
->will( $this->returnValue( array( $orderCouponStub->createItem() ) ) ); |
252
|
|
|
|
253
|
|
|
\Aimeos\MShop::inject( 'order/base/coupon', $orderCouponStub ); |
254
|
|
|
|
255
|
|
|
|
256
|
|
|
$couponCodeStub = $this->getMockBuilder( \Aimeos\MShop\Coupon\Manager\Code\Standard::class ) |
257
|
|
|
->setConstructorArgs( array( $context ) ) |
258
|
|
|
->setMethods( array( 'increase' ) ) |
259
|
|
|
->getMock(); |
260
|
|
|
|
261
|
|
|
$couponCodeStub->expects( $this->once() )->method( 'increase' ) |
262
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
263
|
|
|
|
264
|
|
|
\Aimeos\MShop::inject( 'coupon/code', $couponCodeStub ); |
265
|
|
|
|
266
|
|
|
|
267
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
268
|
|
|
$method = $class->getMethod( 'updateCoupons' ); |
269
|
|
|
$method->setAccessible( true ); |
270
|
|
|
|
271
|
|
|
$object = new \Aimeos\Controller\Common\Order\Standard( $context ); |
272
|
|
|
|
273
|
|
|
$this->setExpectedException( \Exception::class ); |
274
|
|
|
$method->invokeArgs( $object, array( $orderItem, 1 ) ); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
|
278
|
|
|
public function testUpdateStatus() |
279
|
|
|
{ |
280
|
|
|
$context = \TestHelperCntl::getContext(); |
281
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
282
|
|
|
$statusItem = \Aimeos\MShop::create( $context, 'order/status' )->createItem(); |
283
|
|
|
$statusItem->setValue( 1 ); |
|
|
|
|
284
|
|
|
|
285
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Common\Order\Standard::class ) |
286
|
|
|
->setConstructorArgs( array( $context ) ) |
287
|
|
|
->setMethods( array( 'addStatusItem', 'getLastStatusItem' ) ) |
288
|
|
|
->getMock(); |
289
|
|
|
|
290
|
|
|
$object->expects( $this->never() )->method( 'addStatusItem' ); |
291
|
|
|
|
292
|
|
|
$object->expects( $this->once() )->method( 'getLastStatusItem' ) |
293
|
|
|
->will( $this->returnValue( $statusItem ) ); |
294
|
|
|
|
295
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
296
|
|
|
$method = $class->getMethod( 'updateStatus' ); |
297
|
|
|
$method->setAccessible( true ); |
298
|
|
|
$method->invokeArgs( $object, array( $orderItem, 'type', 1, 0 ) ); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
|
302
|
|
|
public function testUpdateStatusStock() |
303
|
|
|
{ |
304
|
|
|
$context = \TestHelperCntl::getContext(); |
305
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
306
|
|
|
$statusItem = \Aimeos\MShop::create( $context, 'order/status' )->createItem(); |
307
|
|
|
|
308
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Common\Order\Standard::class ) |
309
|
|
|
->setConstructorArgs( array( $context ) ) |
310
|
|
|
->setMethods( array( 'addStatusItem', 'getLastStatusItem', 'updateStock' ) ) |
311
|
|
|
->getMock(); |
312
|
|
|
|
313
|
|
|
$object->expects( $this->once() )->method( 'getLastStatusItem' ) |
314
|
|
|
->will( $this->returnValue( $statusItem ) ); |
315
|
|
|
|
316
|
|
|
$object->expects( $this->once() )->method( 'updateStock' ); |
317
|
|
|
$object->expects( $this->once() )->method( 'addStatusItem' ); |
318
|
|
|
|
319
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
320
|
|
|
$method = $class->getMethod( 'updateStatus' ); |
321
|
|
|
$method->setAccessible( true ); |
322
|
|
|
$method->invokeArgs( $object, array( $orderItem, \Aimeos\MShop\Order\Item\Status\Base::STOCK_UPDATE, 1, 0 ) ); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
|
326
|
|
|
public function testUpdateStatusCoupons() |
327
|
|
|
{ |
328
|
|
|
$context = \TestHelperCntl::getContext(); |
329
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
330
|
|
|
$statusItem = \Aimeos\MShop::create( $context, 'order/status' )->createItem(); |
331
|
|
|
|
332
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Common\Order\Standard::class ) |
333
|
|
|
->setConstructorArgs( array( $context ) ) |
334
|
|
|
->setMethods( array( 'addStatusItem', 'getLastStatusItem', 'updateCoupons' ) ) |
335
|
|
|
->getMock(); |
336
|
|
|
|
337
|
|
|
$object->expects( $this->once() )->method( 'getLastStatusItem' ) |
338
|
|
|
->will( $this->returnValue( $statusItem ) ); |
339
|
|
|
|
340
|
|
|
$object->expects( $this->once() )->method( 'updateCoupons' ); |
341
|
|
|
$object->expects( $this->once() )->method( 'addStatusItem' ); |
342
|
|
|
|
343
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
344
|
|
|
$method = $class->getMethod( 'updateStatus' ); |
345
|
|
|
$method->setAccessible( true ); |
346
|
|
|
$method->invokeArgs( $object, array( $orderItem, \Aimeos\MShop\Order\Item\Status\Base::COUPON_UPDATE, 1, 0 ) ); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
|
350
|
|
|
public function testUpdateStock() |
351
|
|
|
{ |
352
|
|
|
$context = \TestHelperCntl::getContext(); |
353
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
354
|
|
|
|
355
|
|
|
|
356
|
|
|
$orderProductStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Base\Product\Standard::class ) |
357
|
|
|
->setConstructorArgs( array( $context ) ) |
358
|
|
|
->setMethods( array( 'searchItems' ) ) |
359
|
|
|
->getMock(); |
360
|
|
|
|
361
|
|
|
$orderProductStub->expects( $this->once() )->method( 'searchItems' ) |
362
|
|
|
->will( $this->returnValue( array( $orderProductStub->createItem() ) ) ); |
363
|
|
|
|
364
|
|
|
\Aimeos\MShop::inject( 'order/base/product', $orderProductStub ); |
365
|
|
|
|
366
|
|
|
|
367
|
|
|
$stockStub = $this->getMockBuilder( \Aimeos\MShop\Stock\Manager\Standard::class ) |
368
|
|
|
->setConstructorArgs( array( $context ) ) |
369
|
|
|
->setMethods( array( 'decrease' ) ) |
370
|
|
|
->getMock(); |
371
|
|
|
|
372
|
|
|
$stockStub->expects( $this->once() )->method( 'decrease' ); |
373
|
|
|
|
374
|
|
|
\Aimeos\MShop::inject( 'stock', $stockStub ); |
375
|
|
|
|
376
|
|
|
|
377
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Common\Order\Standard::class ) |
378
|
|
|
->setConstructorArgs( array( $context ) ) |
379
|
|
|
->setMethods( array( 'updateStockBundle', 'updateStockSelection' ) ) |
380
|
|
|
->getMock(); |
381
|
|
|
|
382
|
|
|
$object->expects( $this->never() )->method( 'updateStockBundle' ); |
383
|
|
|
$object->expects( $this->never() )->method( 'updateStockSelection' ); |
384
|
|
|
|
385
|
|
|
|
386
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
387
|
|
|
$method = $class->getMethod( 'updateStock' ); |
388
|
|
|
$method->setAccessible( true ); |
389
|
|
|
$method->invokeArgs( $object, array( $orderItem, 1 ) ); |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
|
393
|
|
|
public function testUpdateStockArticle() |
394
|
|
|
{ |
395
|
|
|
$context = \TestHelperCntl::getContext(); |
396
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
397
|
|
|
|
398
|
|
|
|
399
|
|
|
$orderProductStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Base\Product\Standard::class ) |
400
|
|
|
->setConstructorArgs( array( $context ) ) |
401
|
|
|
->setMethods( array( 'searchItems' ) ) |
402
|
|
|
->getMock(); |
403
|
|
|
|
404
|
|
|
$orderProductItem = $orderProductStub->createItem(); |
405
|
|
|
$orderProductItem->setType( 'default' ); |
406
|
|
|
|
407
|
|
|
$orderProductStub->expects( $this->once() )->method( 'searchItems' ) |
408
|
|
|
->will( $this->returnValue( array( $orderProductItem ) ) ); |
409
|
|
|
|
410
|
|
|
\Aimeos\MShop::inject( 'order/base/product', $orderProductStub ); |
411
|
|
|
|
412
|
|
|
|
413
|
|
|
$stockStub = $this->getMockBuilder( \Aimeos\MShop\Stock\Manager\Standard::class ) |
414
|
|
|
->setConstructorArgs( array( $context ) ) |
415
|
|
|
->setMethods( array( 'decrease' ) ) |
416
|
|
|
->getMock(); |
417
|
|
|
|
418
|
|
|
$stockStub->expects( $this->once() )->method( 'decrease' ); |
419
|
|
|
|
420
|
|
|
\Aimeos\MShop::inject( 'stock', $stockStub ); |
421
|
|
|
|
422
|
|
|
|
423
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Common\Order\Standard::class ) |
424
|
|
|
->setConstructorArgs( array( $context ) ) |
425
|
|
|
->setMethods( array( 'updateStockBundle', 'updateStockSelection' ) ) |
426
|
|
|
->getMock(); |
427
|
|
|
|
428
|
|
|
$object->expects( $this->once() )->method( 'updateStockBundle' ); |
429
|
|
|
$object->expects( $this->never() )->method( 'updateStockSelection' ); |
430
|
|
|
|
431
|
|
|
|
432
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
433
|
|
|
$method = $class->getMethod( 'updateStock' ); |
434
|
|
|
$method->setAccessible( true ); |
435
|
|
|
$method->invokeArgs( $object, array( $orderItem, 1 ) ); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
|
439
|
|
|
public function testUpdateStockSelect() |
440
|
|
|
{ |
441
|
|
|
$context = \TestHelperCntl::getContext(); |
442
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
443
|
|
|
|
444
|
|
|
|
445
|
|
|
$orderProductStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Base\Product\Standard::class ) |
446
|
|
|
->setConstructorArgs( array( $context ) ) |
447
|
|
|
->setMethods( array( 'searchItems' ) ) |
448
|
|
|
->getMock(); |
449
|
|
|
|
450
|
|
|
$orderProductItem = $orderProductStub->createItem(); |
451
|
|
|
$orderProductItem->setType( 'select' ); |
452
|
|
|
|
453
|
|
|
$orderProductStub->expects( $this->once() )->method( 'searchItems' ) |
454
|
|
|
->will( $this->returnValue( array( $orderProductItem ) ) ); |
455
|
|
|
|
456
|
|
|
\Aimeos\MShop::inject( 'order/base/product', $orderProductStub ); |
457
|
|
|
|
458
|
|
|
|
459
|
|
|
$stockStub = $this->getMockBuilder( \Aimeos\MShop\Stock\Manager\Standard::class ) |
460
|
|
|
->setConstructorArgs( array( $context ) ) |
461
|
|
|
->setMethods( array( 'decrease' ) ) |
462
|
|
|
->getMock(); |
463
|
|
|
|
464
|
|
|
$stockStub->expects( $this->once() )->method( 'decrease' ); |
465
|
|
|
|
466
|
|
|
\Aimeos\MShop::inject( 'stock', $stockStub ); |
467
|
|
|
|
468
|
|
|
|
469
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Common\Order\Standard::class ) |
470
|
|
|
->setConstructorArgs( array( $context ) ) |
471
|
|
|
->setMethods( array( 'updateStockBundle', 'updateStockSelection' ) ) |
472
|
|
|
->getMock(); |
473
|
|
|
|
474
|
|
|
$object->expects( $this->never() )->method( 'updateStockBundle' ); |
475
|
|
|
$object->expects( $this->once() )->method( 'updateStockSelection' ); |
476
|
|
|
|
477
|
|
|
|
478
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
479
|
|
|
$method = $class->getMethod( 'updateStock' ); |
480
|
|
|
$method->setAccessible( true ); |
481
|
|
|
$method->invokeArgs( $object, array( $orderItem, 1 ) ); |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
|
485
|
|
|
public function testUpdateStockException() |
486
|
|
|
{ |
487
|
|
|
$context = \TestHelperCntl::getContext(); |
488
|
|
|
$orderItem = \Aimeos\MShop::create( $context, 'order' )->createItem(); |
489
|
|
|
|
490
|
|
|
|
491
|
|
|
$orderProductStub = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Base\Product\Standard::class ) |
492
|
|
|
->setConstructorArgs( array( $context ) ) |
493
|
|
|
->setMethods( array( 'searchItems' ) ) |
494
|
|
|
->getMock(); |
495
|
|
|
|
496
|
|
|
$orderProductStub->expects( $this->once() )->method( 'searchItems' ) |
497
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
498
|
|
|
|
499
|
|
|
\Aimeos\MShop::inject( 'order/base/product', $orderProductStub ); |
500
|
|
|
|
501
|
|
|
|
502
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
503
|
|
|
$method = $class->getMethod( 'updateStock' ); |
504
|
|
|
$method->setAccessible( true ); |
505
|
|
|
|
506
|
|
|
$object = new \Aimeos\Controller\Common\Order\Standard( $context ); |
507
|
|
|
|
508
|
|
|
$this->setExpectedException( \Exception::class ); |
509
|
|
|
$method->invokeArgs( $object, array( $orderItem, 1 ) ); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
|
513
|
|
|
public function testUpdateStockBundle() |
514
|
|
|
{ |
515
|
|
|
$context = \TestHelperCntl::getContext(); |
516
|
|
|
|
517
|
|
|
|
518
|
|
|
$stockStub = $this->getMockBuilder( \Aimeos\MShop\Stock\Manager\Standard::class ) |
519
|
|
|
->setConstructorArgs( array( $context ) ) |
520
|
|
|
->setMethods( array( 'saveItem' ) ) |
521
|
|
|
->getMock(); |
522
|
|
|
|
523
|
|
|
$stockStub->expects( $this->once() )->method( 'saveItem' )->with( $this->callback( function( $item ) { |
524
|
|
|
return $item->getStocklevel() === 10; |
525
|
|
|
} ) ); |
526
|
|
|
|
527
|
|
|
\Aimeos\MShop::inject( 'stock', $stockStub ); |
528
|
|
|
|
529
|
|
|
|
530
|
|
|
$stockItem = $stockStub->createItem(); |
531
|
|
|
|
532
|
|
|
$stockItem1 = clone $stockItem; |
533
|
|
|
$stockItem1->setProductCode( 'X2' ); |
534
|
|
|
$stockItem1->setStocklevel( 10 ); |
535
|
|
|
|
536
|
|
|
$stockItem2 = clone $stockItem; |
537
|
|
|
$stockItem2->setProductCode( 'X3' ); |
538
|
|
|
$stockItem2->setStocklevel( 20 ); |
539
|
|
|
|
540
|
|
|
$stockItem3 = clone $stockItem; |
541
|
|
|
$stockItem3->setProductCode( 'X1' ); |
542
|
|
|
$stockItem3->setStocklevel( 30 ); |
543
|
|
|
|
544
|
|
|
|
545
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Common\Order\Standard::class ) |
546
|
|
|
->setConstructorArgs( array( $context ) ) |
547
|
|
|
->setMethods( array( 'getBundleMap', 'getStockItems' ) ) |
548
|
|
|
->getMock(); |
549
|
|
|
|
550
|
|
|
$object->expects( $this->once() )->method( 'getBundleMap' ) |
551
|
|
|
->will( $this->returnValue( array( 'X2' => array( 'X1' ), 'X3' => array( 'X1' ) ) ) ); |
552
|
|
|
|
553
|
|
|
$object->expects( $this->exactly( 2 ) )->method( 'getStockItems' ) |
554
|
|
|
->will( $this->onConsecutiveCalls( array( $stockItem2, $stockItem1 ), array( $stockItem3 ) ) ); |
555
|
|
|
|
556
|
|
|
|
557
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
558
|
|
|
$method = $class->getMethod( 'updateStockBundle' ); |
559
|
|
|
$method->setAccessible( true ); |
560
|
|
|
$method->invokeArgs( $object, array( 1, 'default' ) ); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
|
564
|
|
|
public function testUpdateStockSelection() |
565
|
|
|
{ |
566
|
|
|
$context = \TestHelperCntl::getContext(); |
567
|
|
|
$prodId = \Aimeos\MShop::create( $context, 'product' )->findItem( 'U:TEST' )->getId(); |
568
|
|
|
|
569
|
|
|
|
570
|
|
|
$stockStub = $this->getMockBuilder( \Aimeos\MShop\Stock\Manager\Standard::class ) |
571
|
|
|
->setConstructorArgs( array( $context ) ) |
572
|
|
|
->setMethods( array( 'saveItem' ) ) |
573
|
|
|
->getMock(); |
574
|
|
|
|
575
|
|
|
$stockStub->expects( $this->once() )->method( 'saveItem' )->with( $this->callback( function( $item ) { |
576
|
|
|
return $item->getStocklevel() === 300; |
577
|
|
|
} ) ); |
578
|
|
|
|
579
|
|
|
\Aimeos\MShop::inject( 'stock', $stockStub ); |
580
|
|
|
|
581
|
|
|
|
582
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Common\Order\Standard::class ); |
583
|
|
|
$method = $class->getMethod( 'updateStockSelection' ); |
584
|
|
|
$method->setAccessible( true ); |
585
|
|
|
|
586
|
|
|
$object = new \Aimeos\Controller\Common\Order\Standard( $context ); |
587
|
|
|
$method->invokeArgs( $object, array( $prodId, 'default' ) ); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
|
591
|
|
|
protected function getOrderItem( $datepayment ) |
592
|
|
|
{ |
593
|
|
|
$manager = \Aimeos\MShop::create( \TestHelperCntl::getContext(), 'order' ); |
594
|
|
|
|
595
|
|
|
$search = $manager->createSearch(); |
596
|
|
|
$search->setConditions( $search->compare( '==', 'order.datepayment', $datepayment ) ); |
597
|
|
|
|
598
|
|
|
$result = $manager->searchItems( $search ); |
599
|
|
|
|
600
|
|
|
if( ( $item = reset( $result ) ) === false ) { |
601
|
|
|
throw new \RuntimeException( sprintf( 'No order item for payment date "%1$s" found', $datepayment ) ); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
return $item; |
605
|
|
|
} |
606
|
|
|
} |
607
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.