7
7
8
8
namespace Magento \Sales \Controller \Adminhtml \Order \Create ;
9
9
10
- use Magento \Customer \Model \Session ;
11
10
use Magento \Framework \Api \SearchCriteriaBuilder ;
12
- use Magento \Framework \Escaper ;
13
- use Magento \Framework \Registry ;
14
11
use Magento \Quote \Api \CartRepositoryInterface ;
15
12
use Magento \Quote \Api \Data \CartInterface ;
16
13
use Magento \Sales \Api \Data \OrderInterfaceFactory ;
17
- use Magento \TestFramework \Core \Version \View ;
18
14
use Magento \TestFramework \Request ;
19
15
use Magento \TestFramework \TestCase \AbstractBackendController ;
16
+ use Magento \Customer \Api \AccountManagementInterface ;
17
+ use Magento \Customer \Api \Data \CustomerInterface ;
18
+ use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
19
+ use Magento \Framework \App \Request \Http ;
20
+ use Magento \Sales \Api \OrderRepositoryInterface ;
21
+ use Magento \Sales \Model \Order ;
22
+ use Magento \Sales \Model \OrderFactory ;
23
+ use Magento \TestFramework \Helper \Xpath ;
24
+ use Magento \Sales \Api \Data \OrderInterface ;
25
+ use Magento \Customer \Api \CustomerRepositoryInterface ;
26
+ use Magento \Framework \Exception \NoSuchEntityException ;
20
27
21
28
/**
22
29
* Test for reorder controller.
23
30
*
24
31
* @see \Magento\Sales\Controller\Adminhtml\Order\Create\Reorder
25
32
* @magentoAppArea adminhtml
33
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26
34
*/
27
35
class ReorderTest extends AbstractBackendController
28
36
{
@@ -35,6 +43,31 @@ class ReorderTest extends AbstractBackendController
35
43
/** @var CartInterface */
36
44
private $ quote ;
37
45
46
+ /**
47
+ * @var CustomerRepositoryInterface
48
+ */
49
+ private $ customerRepository ;
50
+
51
+ /**
52
+ * @var array
53
+ */
54
+ private $ customerIds = [];
55
+
56
+ /**
57
+ * @var OrderRepositoryInterface
58
+ */
59
+ private $ orderRepository ;
60
+
61
+ /**
62
+ * @var CustomerInterfaceFactory
63
+ */
64
+ private $ customerFactory ;
65
+
66
+ /**
67
+ * @var AccountManagementInterface
68
+ */
69
+ private $ accountManagement ;
70
+
38
71
/**
39
72
* @inheritdoc
40
73
*/
@@ -43,6 +76,10 @@ protected function setUp(): void
43
76
parent ::setUp ();
44
77
$ this ->orderFactory = $ this ->_objectManager ->get (OrderInterfaceFactory::class);
45
78
$ this ->quoteRepository = $ this ->_objectManager ->get (CartRepositoryInterface::class);
79
+ $ this ->orderRepository = $ this ->_objectManager ->get (OrderRepositoryInterface::class);
80
+ $ this ->customerFactory = $ this ->_objectManager ->get (CustomerInterfaceFactory::class);
81
+ $ this ->accountManagement = $ this ->_objectManager ->get (AccountManagementInterface::class);
82
+ $ this ->customerRepository = $ this ->_objectManager ->get (CustomerRepositoryInterface::class);
46
83
}
47
84
48
85
/**
@@ -53,7 +90,13 @@ protected function tearDown(): void
53
90
if ($ this ->quote instanceof CartInterface) {
54
91
$ this ->quoteRepository ->delete ($ this ->quote );
55
92
}
56
-
93
+ foreach ($ this ->customerIds as $ customerId ) {
94
+ try {
95
+ $ this ->customerRepository ->deleteById ($ customerId );
96
+ } catch (NoSuchEntityException $ e ) {
97
+ //customer already deleted
98
+ }
99
+ }
57
100
parent ::tearDown ();
58
101
}
59
102
@@ -74,6 +117,66 @@ public function testReorderAfterJSCalendarEnabled(): void
74
117
$ this ->assertTrue (!empty ($ this ->quote ));
75
118
}
76
119
120
+ /**
121
+ * Test load billing address by reorder for delegating customer
122
+ *
123
+ * @magentoDataFixture Magento/Customer/_files/attribute_user_defined_address.php
124
+ * @magentoDataFixture Magento/Sales/_files/order.php
125
+ *
126
+ * @return void
127
+ */
128
+ public function testLoadBillingAddressAfterReorderWithDelegatingCustomer (): void
129
+ {
130
+ $ orderId = $ this ->getOrderWithDelegatingCustomer ()->getId ();
131
+ $ this ->getRequest ()->setMethod (Http::METHOD_GET );
132
+ $ this ->getRequest ()->setParam ('order_id ' , $ orderId );
133
+ $ this ->dispatch ('backend/sales/order_create/loadBlock/block/billing_address ' );
134
+ $ html = $ this ->getResponse ()->getBody ();
135
+ $ this ->assertEquals (
136
+ 0 ,
137
+ Xpath::getElementsCountForXpath (
138
+ '//*[@id="order-billing_address_save_in_address_book" and contains(@checked, "checked")] ' ,
139
+ $ html
140
+ ),
141
+ 'Billing address checked "Save in address book" '
142
+ );
143
+ }
144
+
145
+ /**
146
+ * Get Order with delegating customer
147
+ *
148
+ * @return OrderInterface
149
+ */
150
+ private function getOrderWithDelegatingCustomer (): OrderInterface
151
+ {
152
+ $ orderAutoincrementId = '100000001 ' ;
153
+ /** @var Order $orderModel */
154
+ $ orderModel = $ this ->orderFactory ->create ();
155
+ $ orderModel ->loadByIncrementId ($ orderAutoincrementId );
156
+ //Saving new customer with prepared data from order.
157
+ /** @var CustomerInterface $customer */
158
+ $ customer = $ this ->customerFactory ->create ();
159
+ $ customer ->setWebsiteId (1 )
160
+ ->setEmail ('customer_order_delegate@example.com ' )
161
+ ->setGroupId (1 )
162
+ ->setStoreId (1 )
163
+ ->setPrefix ('Mr. ' )
164
+ ->setFirstname ('John ' )
165
+ ->setMiddlename ('A ' )
166
+ ->setLastname ('Smith ' )
167
+ ->setSuffix ('Esq. ' )
168
+ ->setTaxvat ('12 ' )
169
+ ->setGender (0 );
170
+ $ createdCustomer = $ this ->accountManagement ->createAccount (
171
+ $ customer ,
172
+ '12345abcD '
173
+ );
174
+ $ this ->customerIds [] = $ createdCustomer ->getId ();
175
+ $ orderModel ->setCustomerId ($ createdCustomer ->getId ());
176
+
177
+ return $ this ->orderRepository ->save ($ orderModel );
178
+ }
179
+
77
180
/**
78
181
* Dispatch reorder request.
79
182
*
0 commit comments