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