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