7
7
8
8
namespace Magento \Sales \Controller \Adminhtml \Order \Create ;
9
9
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 ;
11
16
use Magento \Customer \Api \AccountManagementInterface ;
12
17
use Magento \Customer \Api \Data \CustomerInterface ;
13
18
use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
14
19
use Magento \Framework \App \Request \Http ;
15
- use Magento \Framework \Registry ;
16
20
use Magento \Sales \Api \OrderRepositoryInterface ;
17
21
use Magento \Sales \Model \Order ;
18
22
use Magento \Sales \Model \OrderFactory ;
19
- use Magento \Store \Model \StoreManagerInterface ;
20
23
use Magento \TestFramework \Helper \Xpath ;
21
- use Magento \TestFramework \TestCase \AbstractBackendController ;
22
24
use Magento \Sales \Api \Data \OrderInterface ;
23
25
use Magento \Customer \Api \CustomerRepositoryInterface ;
24
26
use Magento \Framework \Exception \NoSuchEntityException ;
25
27
26
28
/**
27
- * Test load block for order create controller.
28
- *
29
- * @see \Magento\Sales\Controller\Adminhtml\Order\Create\Index
29
+ * Test for reorder controller.
30
30
*
31
+ * @see \Magento\Sales\Controller\Adminhtml\Order\Create\Reorder
31
32
* @magentoAppArea adminhtml
32
- * @magentoDbIsolation enabled
33
33
*/
34
34
class ReorderTest extends AbstractBackendController
35
35
{
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 ;
40
44
41
45
/**
42
- * @var CustomerInterfaceFactory
46
+ * @var CustomerRepositoryInterface
43
47
*/
44
- private $ customerFactory ;
48
+ private $ customerRepository ;
45
49
46
50
/**
47
- * @var AccountManagementInterface
51
+ * @var array
48
52
*/
49
- private $ accountManagement ;
53
+ private $ customerIds = [] ;
50
54
51
55
/**
52
- * @var OrderFactory
56
+ * @var OrderRepositoryInterface
53
57
*/
54
- private $ orderFactory ;
58
+ private $ orderRepository ;
55
59
56
60
/**
57
- * @var CustomerRepositoryInterface
61
+ * @var CustomerInterfaceFactory
58
62
*/
59
- private $ customerRepository ;
63
+ private $ customerFactory ;
60
64
61
65
/**
62
- * @var array
66
+ * @var AccountManagementInterface
63
67
*/
64
- private $ customerIds = [] ;
68
+ private $ accountManagement ;
65
69
66
70
/**
67
71
* @inheritdoc
68
72
*/
69
73
protected function setUp (): void
70
74
{
71
75
parent ::setUp ();
76
+ $ this ->orderFactory = $ this ->_objectManager ->get (OrderInterfaceFactory::class);
77
+ $ this ->quoteRepository = $ this ->_objectManager ->get (CartRepositoryInterface::class);
72
78
$ this ->orderRepository = $ this ->_objectManager ->get (OrderRepositoryInterface::class);
73
79
$ this ->customerFactory = $ this ->_objectManager ->get (CustomerInterfaceFactory::class);
74
80
$ this ->accountManagement = $ this ->_objectManager ->get (AccountManagementInterface::class);
75
- $ this ->orderFactory = $ this ->_objectManager ->get (OrderFactory::class);
76
81
$ this ->customerRepository = $ this ->_objectManager ->get (CustomerRepositoryInterface::class);
77
82
}
78
83
@@ -81,14 +86,34 @@ protected function setUp(): void
81
86
*/
82
87
protected function tearDown (): void
83
88
{
84
- parent ::tearDown ();
89
+ if ($ this ->quote instanceof CartInterface) {
90
+ $ this ->quoteRepository ->delete ($ this ->quote );
91
+ }
85
92
foreach ($ this ->customerIds as $ customerId ) {
86
93
try {
87
94
$ this ->customerRepository ->deleteById ($ customerId );
88
95
} catch (NoSuchEntityException $ e ) {
89
96
//customer already deleted
90
97
}
91
98
}
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 ));
92
117
}
93
118
94
119
/**
@@ -150,4 +175,36 @@ private function getOrderWithDelegatingCustomer(): OrderInterface
150
175
151
176
return $ this ->orderRepository ->save ($ orderModel );
152
177
}
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
+ }
153
210
}
0 commit comments