26
26
use Magento \Sales \Model \AdminOrder \Create ;
27
27
use Magento \Sales \Model \AdminOrder \Product ;
28
28
use Magento \Quote \Model \QuoteFactory ;
29
+ use Magento \Sales \Model \Order ;
30
+ use Magento \Sales \Model \Order \Item as OrderItem ;
31
+ use Magento \Sales \Model \ResourceModel \Order \Item \Collection as ItemCollection ;
32
+ use Magento \Store \Api \Data \StoreInterface ;
29
33
use PHPUnit_Framework_MockObject_MockObject as MockObject ;
30
34
31
35
/**
@@ -86,6 +90,11 @@ class CreateTest extends \PHPUnit\Framework\TestCase
86
90
*/
87
91
private $ dataObjectHelper ;
88
92
93
+ /**
94
+ * @var Order|MockObject
95
+ */
96
+ private $ orderMock ;
97
+
89
98
protected function setUp ()
90
99
{
91
100
$ this ->formFactory = $ this ->createPartialMock (FormFactory::class, ['create ' ]);
@@ -101,9 +110,29 @@ protected function setUp()
101
110
102
111
$ this ->sessionQuote = $ this ->getMockBuilder (\Magento \Backend \Model \Session \Quote::class)
103
112
->disableOriginalConstructor ()
104
- ->setMethods (['getQuote ' , 'getStoreId ' , 'getCustomerId ' ])
113
+ ->setMethods (
114
+ [
115
+ 'getQuote ' ,
116
+ 'getStoreId ' ,
117
+ 'getCustomerId ' ,
118
+ 'setData ' ,
119
+ 'setCurrencyId ' ,
120
+ 'setCustomerId ' ,
121
+ 'setStoreId ' ,
122
+ 'setCustomerGroupId ' ,
123
+ 'getData ' ,
124
+ 'getStore ' ,
125
+ 'getUseOldShippingMethod ' ,
126
+ ]
127
+ )
105
128
->getMock ();
106
129
130
+ $ storeMock = $ this ->getMockBuilder (StoreInterface::class)
131
+ ->setMethods (['getId ' ])
132
+ ->getMockForAbstractClass ();
133
+ $ this ->sessionQuote ->method ('getStore ' )
134
+ ->willReturn ($ storeMock );
135
+
107
136
$ this ->customerMapper = $ this ->getMockBuilder (Mapper::class)
108
137
->setMethods (['toFlatArray ' ])
109
138
->disableOriginalConstructor ()
@@ -114,6 +143,24 @@ protected function setUp()
114
143
->disableOriginalConstructor ()
115
144
->getMock ();
116
145
146
+ $ this ->orderMock = $ this ->getMockBuilder (Order::class)
147
+ ->disableOriginalConstructor ()
148
+ ->setMethods (
149
+ [
150
+ 'getEntityId ' ,
151
+ 'getId ' ,
152
+ 'setReordered ' ,
153
+ 'getReordered ' ,
154
+ 'getOrderCurrencyCode ' ,
155
+ 'getCustomerGroupId ' ,
156
+ 'getItemsCollection ' ,
157
+ 'getShippingAddress ' ,
158
+ 'getBillingAddress ' ,
159
+ 'getCouponCode ' ,
160
+ ]
161
+ )
162
+ ->getMock ();
163
+
117
164
$ objectManagerHelper = new ObjectManagerHelper ($ this );
118
165
$ this ->adminOrderCreate = $ objectManagerHelper ->getObject (
119
166
Create::class,
@@ -312,4 +359,85 @@ public function testGetCustomerCart()
312
359
313
360
$ this ->assertEquals ($ cartResult , $ this ->adminOrderCreate ->getCustomerCart ());
314
361
}
362
+
363
+ public function testInitFromOrder ()
364
+ {
365
+ $ this ->sessionQuote ->method ('getData ' )
366
+ ->with ('reordered ' )
367
+ ->willReturn (true );
368
+
369
+ $ address = $ this ->createPartialMock (
370
+ Address::class,
371
+ [
372
+ 'setSameAsBilling ' ,
373
+ 'setCustomerAddressId ' ,
374
+ 'getSameAsBilling '
375
+ ]
376
+ );
377
+ $ address ->method ('getSameAsBilling ' )
378
+ ->willReturn (true );
379
+ $ address ->method ('setCustomerAddressId ' )
380
+ ->willReturnSelf ();
381
+
382
+ $ quote = $ this ->getMockBuilder (Quote::class)
383
+ ->disableOriginalConstructor ()
384
+ ->setMethods (
385
+ [
386
+ 'setCustomerGroupId ' ,
387
+ 'getBillingAddress ' ,
388
+ 'getShippingAddress ' ,
389
+ 'isVirtual ' ,
390
+ 'collectTotals ' ,
391
+ ]
392
+ )
393
+ ->getMock ();
394
+
395
+ $ quote ->method ('getBillingAddress ' )
396
+ ->willReturn ($ address );
397
+ $ quote ->method ('getShippingAddress ' )
398
+ ->willReturn ($ address );
399
+
400
+ $ this ->sessionQuote
401
+ ->method ('getQuote ' )
402
+ ->willReturn ($ quote );
403
+
404
+ $ orderItem = $ this ->createPartialMock (
405
+ OrderItem::class,
406
+ [
407
+ 'getParentItem ' ,
408
+ 'getQtyOrdered ' ,
409
+ 'getQtyShipped ' ,
410
+ 'getQtyInvoiced ' ,
411
+ ]
412
+ );
413
+ $ orderItem ->method ('getQtyOrdered ' )
414
+ ->willReturn (2 );
415
+ $ orderItem ->method ('getParentItem ' )
416
+ ->willReturn (false );
417
+
418
+ $ iterator = new \ArrayIterator ([$ orderItem ]);
419
+
420
+ $ itemCollectionMock = $ this ->getMockBuilder (ItemCollection::class)
421
+ ->disableOriginalConstructor ()
422
+ ->setMethods (['getIterator ' ])
423
+ ->getMock ();
424
+ $ itemCollectionMock ->method ('getIterator ' )
425
+ ->willReturn ($ iterator );
426
+
427
+ $ this ->orderMock ->method ('getItemsCollection ' )
428
+ ->willReturn ($ itemCollectionMock );
429
+ $ this ->orderMock ->method ('getReordered ' )
430
+ ->willReturn (false );
431
+ $ this ->orderMock ->method ('getShippingAddress ' )
432
+ ->willReturn ($ address );
433
+ $ this ->orderMock ->method ('getBillingAddress ' )
434
+ ->willReturn ($ address );
435
+ $ this ->orderMock ->method ('getCouponCode ' )
436
+ ->willReturn (true );
437
+
438
+ $ quote ->expects ($ this ->once ())
439
+ ->method ('setCustomerGroupId ' );
440
+
441
+ $ this ->adminOrderCreate ->initFromOrder ($ this ->orderMock );
442
+ }
315
443
}
0 commit comments