17
17
use Magento \Sales \Api \Data \OrderAddressExtensionInterfaceFactory ;
18
18
use Magento \Sales \Api \OrderManagementInterface ;
19
19
use Magento \Sales \Model \Order ;
20
+ use Magento \Sales \Model \AdminOrder \EmailSender ;
20
21
use Magento \TestFramework \Helper \Bootstrap ;
21
22
use Magento \TestFramework \ObjectManager ;
23
+ use PHPUnit \Framework \MockObject \MockObject ;
22
24
23
25
/**
24
26
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -37,6 +39,11 @@ class CreateTest extends \PHPUnit\Framework\TestCase
37
39
*/
38
40
private $ messageManager ;
39
41
42
+ /**
43
+ * @var EmailSender|MockObject
44
+ */
45
+ private $ emailSenderMock ;
46
+
40
47
/**
41
48
* @var ObjectManager
42
49
*/
@@ -46,7 +53,13 @@ protected function setUp(): void
46
53
{
47
54
$ this ->objectManager = Bootstrap::getObjectManager ();
48
55
$ this ->messageManager = $ this ->objectManager ->get (ManagerInterface::class);
49
- $ this ->model =$ this ->objectManager ->create (Create::class, ['messageManager ' => $ this ->messageManager ]);
56
+ $ this ->emailSenderMock = $ this ->getMockBuilder (EmailSender::class)
57
+ ->disableOriginalConstructor ()
58
+ ->getMock ();
59
+ $ this ->model =$ this ->objectManager ->create (
60
+ Create::class,
61
+ ['messageManager ' => $ this ->messageManager , 'emailSender ' => $ this ->emailSenderMock ]
62
+ );
50
63
}
51
64
52
65
/**
@@ -599,8 +612,11 @@ public function testCreateOrderExistingCustomerDifferentAddresses()
599
612
* @magentoDataFixture Magento/Customer/_files/customer.php
600
613
* @magentoDbIsolation disabled
601
614
* @magentoAppIsolation enabled
615
+ * @dataProvider emailCheckProvider
616
+ * @param bool $sendConfirmation
617
+ * @param bool $emailSent
602
618
*/
603
- public function testCreateOrderExistingCustomer ()
619
+ public function testCreateOrderExistingCustomer ($ sendConfirmation , $ emailSent )
604
620
{
605
621
$ productIdFromFixture = 1 ;
606
622
$ customerIdFromFixture = 1 ;
@@ -613,7 +629,7 @@ public function testCreateOrderExistingCustomer()
613
629
'billing_address ' => array_merge ($ this ->getValidAddressData (), ['save_in_address_book ' => '1 ' ]),
614
630
'shipping_method ' => $ shippingMethod ,
615
631
'comment ' => ['customer_note ' => '' ],
616
- 'send_confirmation ' => false ,
632
+ 'send_confirmation ' => $ sendConfirmation ,
617
633
];
618
634
$ paymentData = ['method ' => $ paymentMethod ];
619
635
@@ -628,12 +644,32 @@ public function testCreateOrderExistingCustomer()
628
644
$ customerIdFromFixture
629
645
);
630
646
$ customerMock = $ this ->getMockedCustomer ();
647
+ if ($ customerIdFromFixture && !$ emailSent ) {
648
+ $ this ->emailSenderMock ->expects ($ this ->once ())
649
+ ->method ('send ' )
650
+ ->willReturn (true );
651
+ } else {
652
+ $ this ->emailSenderMock ->expects ($ this ->never ())->method ('send ' );
653
+ }
631
654
632
655
$ this ->model ->getQuote ()->setCustomer ($ customerMock );
633
656
$ order = $ this ->model ->createOrder ();
634
657
$ this ->verifyCreatedOrder ($ order , $ shippingMethod );
635
658
}
636
659
660
+ /**
661
+ * Data provider for testApplySelectionOnTargetProvider.
662
+ *
663
+ * @return array
664
+ */
665
+ public function emailCheckProvider (): array
666
+ {
667
+ return [
668
+ [false , true ],
669
+ [true , false ]
670
+ ];
671
+ }
672
+
637
673
/**
638
674
* @magentoDataFixture Magento/Sales/_files/quote.php
639
675
* @magentoDataFixture Magento/Customer/_files/customer.php
0 commit comments