9
9
10
10
use Magento \Checkout \Model \Session as CheckoutSession ;
11
11
use Magento \Customer \Model \Session ;
12
+ use Magento \Framework \Exception \LocalizedException ;
12
13
use Magento \Framework \Exception \NoSuchEntityException ;
13
14
use Magento \Framework \Message \MessageInterface ;
14
15
use Magento \Framework \Stdlib \CookieManagerInterface ;
15
16
use Magento \Quote \Api \CartRepositoryInterface ;
16
17
use Magento \Sales \Api \Data \OrderInterfaceFactory ;
17
18
use Magento \Sales \Helper \Guest ;
19
+ use Magento \Sales \Model \Order \Creditmemo ;
20
+ use Magento \Sales \Model \Order \Creditmemo \Item ;
21
+ use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
18
22
use Magento \TestFramework \Request ;
19
23
use Magento \TestFramework \TestCase \AbstractController ;
20
24
@@ -42,6 +46,21 @@ class ReorderTest extends AbstractController
42
46
/** @var CartRepositoryInterface */
43
47
private $ quoteRepository ;
44
48
49
+ /**
50
+ * @var string
51
+ */
52
+ private $ testMailbox ;
53
+
54
+ /**
55
+ * @var string
56
+ */
57
+ private $ expectedSubject ;
58
+
59
+ /**
60
+ * @var TransportBuilderMock
61
+ */
62
+ private $ transportBuilder ;
63
+
45
64
/**
46
65
* @inheritdoc
47
66
*/
@@ -54,6 +73,7 @@ protected function setUp(): void
54
73
$ this ->cookieManager = $ this ->_objectManager ->get (CookieManagerInterface::class);
55
74
$ this ->customerSession = $ this ->_objectManager ->get (Session::class);
56
75
$ this ->quoteRepository = $ this ->_objectManager ->get (CartRepositoryInterface::class);
76
+ $ this ->transportBuilder = $ this ->_objectManager ->get (TransportBuilderMock::class);
57
77
}
58
78
59
79
/**
@@ -136,4 +156,63 @@ private function dispatchReorderRequest(): void
136
156
$ this ->getRequest ()->setMethod (Request::METHOD_POST );
137
157
$ this ->dispatch ('sales/guest/reorder/ ' );
138
158
}
159
+
160
+ /**
161
+ * @magentoDbIsolation disabled
162
+ *
163
+ * @magentoDataFixture Magento/Sales/_files/order_by_guest_with_simple_product.php
164
+ *
165
+ * @return void
166
+ * @throws LocalizedException
167
+ */
168
+ public function testOrderNumberIsPresentInCreditMemoEmail (): void
169
+ {
170
+ $ orderIncrementId = 'test_order_1 ' ;
171
+ $ order = $ this ->orderFactory ->create ()->loadByIncrementId ($ orderIncrementId );
172
+ $ storeId = $ order ->getStoreId ();
173
+
174
+ // Create an Invoice for the Order
175
+ $ invoice = $ order ->prepareInvoice ()->register ();
176
+ $ invoice ->pay ();
177
+
178
+ // Submit the Invoice
179
+ $ invoice ->getOrder ()->setIsInProcess (true );
180
+ $ this ->_objectManager ->create (\Magento \Framework \DB \Transaction::class)
181
+ ->addObject ($ invoice )
182
+ ->addObject ($ invoice ->getOrder ())
183
+ ->save ();
184
+
185
+ // Create a Credit Memo
186
+ $ creditmemo = $ this ->_objectManager ->create (Creditmemo::class)
187
+ ->setOrder ($ order );
188
+
189
+ foreach ($ order ->getAllItems () as $ orderItem ) {
190
+ $ creditmemoItem = $ this ->_objectManager ->create (Item::class)
191
+ ->setOrderItem ($ orderItem )
192
+ ->setQty ($ orderItem ->getQtyOrdered ())
193
+ ->setBackToStock (true );
194
+ $ creditmemo ->addItem ($ creditmemoItem );
195
+ }
196
+
197
+ $ this ->_objectManager ->create (\Magento \Framework \DB \Transaction::class)
198
+ ->addObject ($ invoice )
199
+ ->addObject ($ invoice ->getOrder ())
200
+ ->save ();
201
+
202
+ // Set the test mailbox and expected email subject
203
+ $ this ->testMailbox = 'test@example.com ' ;
204
+ $ this ->expectedSubject = 'Credit memo for your Main Website Store order ' ;
205
+
206
+ // Send the Credit Memo email
207
+ $ creditmemo ->setEmailSent (true );
208
+ $ invoice ->setEmailSent (true );
209
+ $ this ->_objectManager ->create (\Magento \Framework \DB \Transaction::class)
210
+ ->addObject ($ invoice )
211
+ ->save ();
212
+
213
+ $ message = $ this ->transportBuilder ->getSentMessage ();
214
+
215
+ // Verify email in the mailbox
216
+ $ this ->assertEquals (this ->expectedSubject , $ message ->getSubject ());
217
+ }
139
218
}
0 commit comments