77
88namespace Magento \Sales \Controller \Adminhtml \Order \Create ;
99
10- use Magento \Customer \Model \Session ;
1110use Magento \Framework \Api \SearchCriteriaBuilder ;
12- use Magento \Framework \Escaper ;
13- use Magento \Framework \Registry ;
1411use Magento \Quote \Api \CartRepositoryInterface ;
1512use Magento \Quote \Api \Data \CartInterface ;
1613use Magento \Sales \Api \Data \OrderInterfaceFactory ;
17- use Magento \TestFramework \Core \Version \View ;
1814use Magento \TestFramework \Request ;
1915use 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 ;
2027
2128/**
2229 * Test for reorder controller.
2330 *
2431 * @see \Magento\Sales\Controller\Adminhtml\Order\Create\Reorder
2532 * @magentoAppArea adminhtml
33+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2634 */
2735class ReorderTest extends AbstractBackendController
2836{
@@ -35,6 +43,31 @@ class ReorderTest extends AbstractBackendController
3543 /** @var CartInterface */
3644 private $ quote ;
3745
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+
3871 /**
3972 * @inheritdoc
4073 */
@@ -43,6 +76,10 @@ protected function setUp(): void
4376 parent ::setUp ();
4477 $ this ->orderFactory = $ this ->_objectManager ->get (OrderInterfaceFactory::class);
4578 $ 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);
4683 }
4784
4885 /**
@@ -53,7 +90,13 @@ protected function tearDown(): void
5390 if ($ this ->quote instanceof CartInterface) {
5491 $ this ->quoteRepository ->delete ($ this ->quote );
5592 }
56-
93+ foreach ($ this ->customerIds as $ customerId ) {
94+ try {
95+ $ this ->customerRepository ->deleteById ($ customerId );
96+ } catch (NoSuchEntityException $ e ) {
97+ //customer already deleted
98+ }
99+ }
57100 parent ::tearDown ();
58101 }
59102
@@ -74,6 +117,66 @@ public function testReorderAfterJSCalendarEnabled(): void
74117 $ this ->assertTrue (!empty ($ this ->quote ));
75118 }
76119
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+
77180 /**
78181 * Dispatch reorder request.
79182 *
0 commit comments