20
20
use Magento \Framework \App \RequestInterface ;
21
21
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
22
22
use Magento \Quote \Api \CartRepositoryInterface ;
23
+ use Magento \Quote \Api \CartManagementInterface ;
23
24
use Magento \Quote \Model \Quote ;
25
+ use Magento \Quote \Model \Quote \Payment ;
26
+ use Magento \Payment \Model \MethodInterface ;
24
27
use Magento \Quote \Model \Quote \Address ;
25
28
use Magento \Quote \Model \Quote \Item ;
29
+ use Magento \Catalog \Model \Product ;
30
+ use Magento \Catalog \Model \Product \Type \AbstractType ;
26
31
use Magento \Quote \Model \Quote \Item \Updater ;
27
32
use Magento \Quote \Model \QuoteFactory ;
28
33
use Magento \Sales \Model \AdminOrder \Create ;
@@ -51,6 +56,11 @@ class CreateTest extends TestCase
51
56
*/
52
57
private $ quoteRepository ;
53
58
59
+ /**
60
+ * @var CartManagementInterface|MockObject
61
+ */
62
+ private $ quoteManagement ;
63
+
54
64
/**
55
65
* @var QuoteFactory|MockObject
56
66
*/
@@ -104,6 +114,10 @@ protected function setUp(): void
104
114
$ this ->formFactory = $ this ->createPartialMock (FormFactory::class, ['create ' ]);
105
115
$ this ->quoteFactory = $ this ->createPartialMock (QuoteFactory::class, ['create ' ]);
106
116
$ this ->customerFactory = $ this ->createPartialMock (CustomerInterfaceFactory::class, ['create ' ]);
117
+ $ this ->quoteManagement = $ this ->getMockBuilder (CartManagementInterface::class)
118
+ ->disableOriginalConstructor ()
119
+ ->setMethods (['submit ' ])
120
+ ->getMockForAbstractClass ();
107
121
108
122
$ this ->itemUpdater = $ this ->createMock (Updater::class);
109
123
@@ -117,6 +131,7 @@ protected function setUp(): void
117
131
->setMethods (
118
132
[
119
133
'getQuote ' ,
134
+ 'getOrder ' ,
120
135
'getStoreId ' ,
121
136
'getCustomerId ' ,
122
137
'setData ' ,
@@ -134,6 +149,8 @@ protected function setUp(): void
134
149
$ storeMock = $ this ->getMockBuilder (StoreInterface::class)
135
150
->setMethods (['getId ' ])
136
151
->getMockForAbstractClass ();
152
+ $ storeMock ->method ('getId ' )
153
+ ->willReturn (1 );
137
154
$ this ->sessionQuote ->method ('getStore ' )
138
155
->willReturn ($ storeMock );
139
156
@@ -161,6 +178,15 @@ protected function setUp(): void
161
178
'getShippingAddress ' ,
162
179
'getBillingAddress ' ,
163
180
'getCouponCode ' ,
181
+ 'getCustomerFirstname ' ,
182
+ 'getCustomerLastname ' ,
183
+ 'getCustomerMiddlename ' ,
184
+ 'getIncrementId ' ,
185
+ 'getOriginalIncrementId ' ,
186
+ 'getEditIncrement ' ,
187
+ 'setRelationChildId ' ,
188
+ 'setRelationChildRealId ' ,
189
+ 'save ' ,
164
190
]
165
191
)
166
192
->getMock ();
@@ -178,6 +204,7 @@ protected function setUp(): void
178
204
'dataObjectHelper ' => $ this ->dataObjectHelper ,
179
205
'quoteRepository ' => $ this ->quoteRepository ,
180
206
'quoteFactory ' => $ this ->quoteFactory ,
207
+ 'quoteManagement ' => $ this ->quoteManagement ,
181
208
]
182
209
);
183
210
}
@@ -461,4 +488,141 @@ public function testInitFromOrder()
461
488
462
489
$ this ->adminOrderCreate ->initFromOrder ($ this ->orderMock );
463
490
}
491
+
492
+ public function testCreateOrder ()
493
+ {
494
+ $ method = $ this ->getMockBuilder (MethodInterface::class)
495
+ ->disableOriginalConstructor ()
496
+ ->setMethods (
497
+ [
498
+ 'isAvailable ' ,
499
+ 'validate ' ,
500
+ ]
501
+ )
502
+ ->getMockForAbstractClass ();
503
+ $ method ->method ('isAvailable ' )
504
+ ->willReturn (true );
505
+ $ method ->method ('validate ' )
506
+ ->willReturn (true );
507
+ $ payment = $ this ->getMockBuilder (Payment::class)
508
+ ->disableOriginalConstructor ()
509
+ ->setMethods (
510
+ [
511
+ 'getMethod ' ,
512
+ 'getMethodInstance ' ,
513
+ ]
514
+ )
515
+ ->getMock ();
516
+ $ payment ->method ('getMethod ' )
517
+ ->willReturn ('checkmo ' );
518
+ $ payment ->method ('getMethodInstance ' )
519
+ ->willReturn ($ method );
520
+
521
+ $ type = $ this ->getMockBuilder (AbstractType::class)
522
+ ->disableOriginalConstructor ()
523
+ ->setMethods (
524
+ [
525
+ 'getOrderOptions ' ,
526
+ ]
527
+ )
528
+ ->getMockForAbstractClass ();
529
+ $ type ->method ('getOrderOptions ' )
530
+ ->willReturn (false );
531
+
532
+ $ product = $ this ->getMockBuilder (Product::class)
533
+ ->disableOriginalConstructor ()
534
+ ->setMethods (
535
+ [
536
+ 'getTypeInstance ' ,
537
+ ]
538
+ )
539
+ ->getMockForAbstractClass ();
540
+ $ product ->method ('getTypeInstance ' )
541
+ ->willReturn ($ type );
542
+
543
+ $ item = $ this ->getMockBuilder (Item::class)
544
+ ->disableOriginalConstructor ()
545
+ ->setMethods (
546
+ [
547
+ 'getHasError ' ,
548
+ 'getProduct ' ,
549
+ 'getOptionByCode ' ,
550
+ ]
551
+ )
552
+ ->getMockForAbstractClass ();
553
+ $ item ->method ('getHasError ' )
554
+ ->willReturn (false );
555
+ $ item ->method ('getProduct ' )
556
+ ->willReturn ($ product );
557
+ $ item ->method ('getOptionByCode ' )
558
+ ->willReturn (false );
559
+ $ items = [
560
+ $ item
561
+ ];
562
+
563
+ $ quote = $ this ->getMockBuilder (Quote::class)
564
+ ->disableOriginalConstructor ()
565
+ ->setMethods (
566
+ [
567
+ 'getCustomerIsGuest ' ,
568
+ 'getAllItems ' ,
569
+ 'isVirtual ' ,
570
+ 'getPayment ' ,
571
+ 'getItemById ' ,
572
+ ]
573
+ )
574
+ ->getMock ();
575
+ $ quote ->method ('getCustomerIsGuest ' )
576
+ ->willReturn (true );
577
+ $ quote ->method ('getAllItems ' )
578
+ ->willReturn ($ items );
579
+ $ quote ->method ('isVirtual ' )
580
+ ->willReturn (true );
581
+ $ quote ->method ('getPayment ' )
582
+ ->willReturn ($ payment );
583
+ $ quote ->method ('getItemById ' )
584
+ ->willReturn ($ item );
585
+
586
+ $ this ->sessionQuote
587
+ ->method ('getQuote ' )
588
+ ->willReturn ($ quote );
589
+ $ this ->orderMock ->method ('getId ' )
590
+ ->willReturn (1 );
591
+ $ this ->orderMock ->method ('getCustomerFirstname ' )
592
+ ->willReturn ('firstname ' );
593
+ $ this ->orderMock ->method ('getCustomerLastname ' )
594
+ ->willReturn ('lastname ' );
595
+ $ this ->orderMock ->method ('getCustomerMiddlename ' )
596
+ ->willReturn ('middlename ' );
597
+ $ this ->orderMock ->method ('getIncrementId ' )
598
+ ->willReturn ('100000001 ' );
599
+ $ this ->orderMock ->method ('getEditIncrement ' )
600
+ ->willReturn (0 );
601
+ $ this ->sessionQuote
602
+ ->method ('getOrder ' )
603
+ ->willReturn ($ this ->orderMock );
604
+
605
+ $ guestOrder = $ this ->getMockBuilder (Order::class)
606
+ ->disableOriginalConstructor ()
607
+ ->setMethods (
608
+ [
609
+ 'getId ' ,
610
+ 'getIncrementId ' ,
611
+ 'getCustomerIsGuest ' ,
612
+ 'save ' ,
613
+ ]
614
+ )
615
+ ->getMock ();
616
+ $ guestOrder ->method ('getId ' )
617
+ ->willReturn (2 );
618
+ $ guestOrder ->method ('getIncrementId ' )
619
+ ->willReturn ('100000001-1 ' );
620
+ $ guestOrder ->method ('getCustomerIsGuest ' )
621
+ ->willReturn (true );
622
+ $ this ->quoteManagement ->method ('submit ' )
623
+ ->willReturn ($ guestOrder );
624
+
625
+ $ object = $ this ->adminOrderCreate ->createOrder ();
626
+ self ::assertEquals ($ this ->orderMock ->getCustomerFirstname (), $ object ->getCustomerFirstname ());
627
+ }
464
628
}
0 commit comments