11
11
use Magento \Bundle \Test \Fixture \OrderItem as OrderItemFixture ;
12
12
use Magento \Bundle \Test \Fixture \Product as BundleProductFixture ;
13
13
use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
14
+ use Magento \Config \Model \ResourceModel \Config as CoreConfig ;
15
+ use Magento \Customer \Api \AccountManagementInterface ;
14
16
use Magento \Customer \Model \Session ;
17
+ use Magento \Customer \Test \Fixture \Customer ;
18
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
15
19
use Magento \Framework \ObjectManagerInterface ;
16
20
use Magento \Framework \View \LayoutInterface ;
17
21
use Magento \Sales \Model \Order ;
22
+ use Magento \Sales \Model \Order \Email \Sender \OrderSender ;
23
+ use Magento \Sales \Model \Order \Address as OrderAddress ;
18
24
use Magento \Store \Model \StoreManagerInterface ;
19
25
use Magento \TestFramework \Fixture \Config ;
20
26
use Magento \TestFramework \Fixture \DataFixture ;
21
27
use Magento \TestFramework \Fixture \DataFixtureStorage ;
22
28
use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
23
29
use Magento \TestFramework \Fixture \DbIsolation ;
24
30
use Magento \TestFramework \Helper \Bootstrap ;
31
+ use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
25
32
use PHPUnit \Framework \TestCase ;
26
33
34
+ /**
35
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
36
+ */
27
37
class RendererTest extends TestCase
28
38
{
29
39
/**
@@ -43,6 +53,21 @@ class RendererTest extends TestCase
43
53
/** @var Renderer */
44
54
private $ block ;
45
55
56
+ /**
57
+ * @var CoreConfig
58
+ */
59
+ protected $ resourceConfig ;
60
+
61
+ /**
62
+ * @var AccountManagementInterface
63
+ */
64
+ private $ accountManagement ;
65
+
66
+ /**
67
+ * @var OrderSender
68
+ */
69
+ private $ orderSender ;
70
+
46
71
/**
47
72
* @defaultDoc
48
73
*/
@@ -52,6 +77,9 @@ protected function setUp(): void
52
77
$ layout = $ this ->objectManager ->get (LayoutInterface::class);
53
78
$ this ->block = $ layout ->createBlock (Renderer::class);
54
79
$ this ->fixtures = Bootstrap::getObjectManager ()->get (DataFixtureStorageManager::class)->getStorage ();
80
+ $ this ->resourceConfig = $ this ->objectManager ->get (CoreConfig::class);
81
+ $ this ->accountManagement = $ this ->objectManager ->get (AccountManagementInterface::class);
82
+ $ this ->orderSender = $ this ->objectManager ->get (OrderSender::class);
55
83
}
56
84
57
85
#[
@@ -99,4 +127,83 @@ public function testOrderEmailContent(): void
99
127
100
128
$ this ->assertStringContainsString ("€99 " , $ priceBlockHtml [0 ]);
101
129
}
130
+
131
+ /**
132
+ * @return void
133
+ * @throws \Magento\Framework\Exception\LocalizedException
134
+ */
135
+ #[
136
+ DbIsolation(true ),
137
+ DataFixture(ProductFixture::class, ['price ' => 10 ], 'p1 ' ),
138
+ DataFixture(ProductFixture::class, ['price ' => 20 ], 'p2 ' ),
139
+ DataFixture(ProductFixture::class, ['price ' => 30 ], 'p3 ' ),
140
+ DataFixture(BundleOptionFixture::class, ['product_links ' => ['$p1$ ' , '$p2$ ' , '$p3$ ' ]], 'opt1 ' ),
141
+ DataFixture(BundleProductFixture::class, ['_options ' => ['$opt1$ ' ]], 'bundle1 ' ),
142
+ DataFixture(OrderItemFixture::class, ['items ' => [['sku ' => '$bundle1.sku$ ' ]]], 'order ' ),
143
+ DataFixture(Customer::class, ['email ' => 'customer@example.com ' ], as: 'customer ' ),
144
+ ]
145
+ public function testPlaceOrderWithOtherThanDefaultCurrencyValidateEmailHasSameCurrency (): void
146
+ {
147
+ $ this ->resourceConfig ->saveConfig (
148
+ 'currency/options/default ' ,
149
+ 'EUR ' ,
150
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
151
+ 0
152
+ );
153
+
154
+ $ this ->resourceConfig ->saveConfig (
155
+ 'currency/options/allow ' ,
156
+ 'EUR ' ,
157
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
158
+ 0
159
+ );
160
+
161
+ $ this ->resourceConfig ->saveConfig (
162
+ 'currency/options/base ' ,
163
+ 'USD ' ,
164
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
165
+ 0
166
+ );
167
+
168
+ // Load customer data
169
+ $ customer = $ this ->fixtures ->get ('customer ' );
170
+ $ customerEmail = $ customer ->getEmail ();
171
+
172
+ // Login to customer
173
+ $ this ->accountManagement ->authenticate ($ customerEmail , 'password ' );
174
+
175
+ // Including address data file
176
+ $ addressData = include __DIR__ . '/../../../../../Sales/_files/address_data.php ' ;
177
+
178
+ // Setting the billing address
179
+ $ billingAddress = $ this ->objectManager ->create (OrderAddress::class, ['data ' => $ addressData ]);
180
+ $ billingAddress ->setAddressType ('billing ' );
181
+
182
+ // Setting the shipping address
183
+ $ shippingAddress = clone $ billingAddress ;
184
+ $ shippingAddress ->setId (null )->setAddressType ('shipping ' );
185
+
186
+ // Place the order
187
+ $ order = $ this ->objectManager ->create (Order::class);
188
+ $ incrementId = $ this ->fixtures ->get ('order ' )->getIncrementId ();
189
+ $ order ->loadByIncrementId ($ incrementId );
190
+ $ storeManager = $ this ->objectManager ->get (StoreManagerInterface::class);
191
+ $ currencyCodeSymbol = $ storeManager ->getWebsite ()->getDefaultStore ()->getDefaultCurrency ()->getCurrencySymbol ();
192
+ $ storeId = $ this ->objectManager ->get (StoreManagerInterface::class)->getStore ()->getId ();
193
+ $ order ->setStoreId ($ storeId );
194
+ $ order ->setCustomerEmail ($ customerEmail );
195
+ $ order ->setBillingAddress ($ billingAddress );
196
+ $ order ->setShippingAddress ($ shippingAddress );
197
+ $ order ->save ();
198
+ $ this ->orderSender ->send ($ order );
199
+ $ this ->assertTrue ($ order ->getSendEmail ());
200
+
201
+ /** @var TransportBuilderMock $transportBuilderMock */
202
+ $ transportBuilderMock = Bootstrap::getObjectManager ()
203
+ ->get (TransportBuilderMock::class);
204
+ $ sentMessage = $ transportBuilderMock ->getSentMessage ();
205
+
206
+ $ this ->assertNotNull ($ sentMessage );
207
+ $ this ->assertStringContainsString ($ currencyCodeSymbol , $ sentMessage ->getBodyText ());
208
+ }
102
209
}
0 commit comments