Skip to content

Commit e820545

Browse files
MC-38498: "Save to Address Book" in Admin checkout causes duplicate address book entries
1 parent c02fa44 commit e820545

File tree

1 file changed

+81
-24
lines changed
  • dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create

1 file changed

+81
-24
lines changed

dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/ReorderTest.php

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,77 @@
77

88
namespace Magento\Sales\Controller\Adminhtml\Order\Create;
99

10-
use Magento\Backend\Model\Session\Quote;
10+
use Magento\Framework\Api\SearchCriteriaBuilder;
11+
use Magento\Quote\Api\CartRepositoryInterface;
12+
use Magento\Quote\Api\Data\CartInterface;
13+
use Magento\Sales\Api\Data\OrderInterfaceFactory;
14+
use Magento\TestFramework\Request;
15+
use Magento\TestFramework\TestCase\AbstractBackendController;
1116
use Magento\Customer\Api\AccountManagementInterface;
1217
use Magento\Customer\Api\Data\CustomerInterface;
1318
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
1419
use Magento\Framework\App\Request\Http;
15-
use Magento\Framework\Registry;
1620
use Magento\Sales\Api\OrderRepositoryInterface;
1721
use Magento\Sales\Model\Order;
1822
use Magento\Sales\Model\OrderFactory;
19-
use Magento\Store\Model\StoreManagerInterface;
2023
use Magento\TestFramework\Helper\Xpath;
21-
use Magento\TestFramework\TestCase\AbstractBackendController;
2224
use Magento\Sales\Api\Data\OrderInterface;
2325
use Magento\Customer\Api\CustomerRepositoryInterface;
2426
use Magento\Framework\Exception\NoSuchEntityException;
2527

2628
/**
27-
* Test load block for order create controller.
28-
*
29-
* @see \Magento\Sales\Controller\Adminhtml\Order\Create\Index
29+
* Test for reorder controller.
3030
*
31+
* @see \Magento\Sales\Controller\Adminhtml\Order\Create\Reorder
3132
* @magentoAppArea adminhtml
32-
* @magentoDbIsolation enabled
3333
*/
3434
class ReorderTest extends AbstractBackendController
3535
{
36-
/**
37-
* @var OrderRepositoryInterface
38-
*/
39-
private $orderRepository;
36+
/** @var OrderInterfaceFactory */
37+
private $orderFactory;
38+
39+
/** @var CartRepositoryInterface */
40+
private $quoteRepository;
41+
42+
/** @var CartInterface */
43+
private $quote;
4044

4145
/**
42-
* @var CustomerInterfaceFactory
46+
* @var CustomerRepositoryInterface
4347
*/
44-
private $customerFactory;
48+
private $customerRepository;
4549

4650
/**
47-
* @var AccountManagementInterface
51+
* @var array
4852
*/
49-
private $accountManagement;
53+
private $customerIds = [];
5054

5155
/**
52-
* @var OrderFactory
56+
* @var OrderRepositoryInterface
5357
*/
54-
private $orderFactory;
58+
private $orderRepository;
5559

5660
/**
57-
* @var CustomerRepositoryInterface
61+
* @var CustomerInterfaceFactory
5862
*/
59-
private $customerRepository;
63+
private $customerFactory;
6064

6165
/**
62-
* @var array
66+
* @var AccountManagementInterface
6367
*/
64-
private $customerIds = [];
68+
private $accountManagement;
6569

6670
/**
6771
* @inheritdoc
6872
*/
6973
protected function setUp(): void
7074
{
7175
parent::setUp();
76+
$this->orderFactory = $this->_objectManager->get(OrderInterfaceFactory::class);
77+
$this->quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class);
7278
$this->orderRepository = $this->_objectManager->get(OrderRepositoryInterface::class);
7379
$this->customerFactory = $this->_objectManager->get(CustomerInterfaceFactory::class);
7480
$this->accountManagement = $this->_objectManager->get(AccountManagementInterface::class);
75-
$this->orderFactory = $this->_objectManager->get(OrderFactory::class);
7681
$this->customerRepository = $this->_objectManager->get(CustomerRepositoryInterface::class);
7782
}
7883

@@ -81,14 +86,34 @@ protected function setUp(): void
8186
*/
8287
protected function tearDown(): void
8388
{
84-
parent::tearDown();
89+
if ($this->quote instanceof CartInterface) {
90+
$this->quoteRepository->delete($this->quote);
91+
}
8592
foreach ($this->customerIds as $customerId) {
8693
try {
8794
$this->customerRepository->deleteById($customerId);
8895
} catch (NoSuchEntityException $e) {
8996
//customer already deleted
9097
}
9198
}
99+
parent::tearDown();
100+
}
101+
102+
/**
103+
* Reorder with JS calendar options
104+
*
105+
* @magentoConfigFixture current_store catalog/custom_options/use_calendar 1
106+
* @magentoDataFixture Magento/Sales/_files/order_with_date_time_option_product.php
107+
*
108+
* @return void
109+
*/
110+
public function testReorderAfterJSCalendarEnabled(): void
111+
{
112+
$order = $this->orderFactory->create()->loadByIncrementId('100000001');
113+
$this->dispatchReorderRequest((int)$order->getId());
114+
$this->assertRedirect($this->stringContains('backend/sales/order_create'));
115+
$this->quote = $this->getQuote('customer@example.com');
116+
$this->assertTrue(!empty($this->quote));
92117
}
93118

94119
/**
@@ -150,4 +175,36 @@ private function getOrderWithDelegatingCustomer(): OrderInterface
150175

151176
return $this->orderRepository->save($orderModel);
152177
}
178+
179+
/**
180+
* Dispatch reorder request.
181+
*
182+
* @param null|int $orderId
183+
* @return void
184+
*/
185+
private function dispatchReorderRequest(?int $orderId = null): void
186+
{
187+
$this->getRequest()->setMethod(Request::METHOD_GET);
188+
$this->getRequest()->setParam('order_id', $orderId);
189+
$this->dispatch('backend/sales/order_create/reorder');
190+
}
191+
192+
/**
193+
* Gets quote by reserved order id.
194+
*
195+
* @return \Magento\Quote\Api\Data\CartInterface
196+
*/
197+
private function getQuote(string $customerEmail): \Magento\Quote\Api\Data\CartInterface
198+
{
199+
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
200+
$searchCriteriaBuilder = $this->_objectManager->get(SearchCriteriaBuilder::class);
201+
$searchCriteria = $searchCriteriaBuilder->addFilter('customer_email', $customerEmail)
202+
->create();
203+
204+
/** @var CartRepositoryInterface $quoteRepository */
205+
$quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class);
206+
$items = $quoteRepository->getList($searchCriteria)->getItems();
207+
208+
return array_pop($items);
209+
}
153210
}

0 commit comments

Comments
 (0)