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 ;
14
15
use Magento \Customer \Api \AccountManagementInterface ;
15
16
use Magento \Customer \Model \Session ;
16
17
use Magento \Customer \Test \Fixture \Customer ;
18
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
17
19
use Magento \Framework \ObjectManagerInterface ;
18
20
use Magento \Framework \View \LayoutInterface ;
19
21
use Magento \Sales \Model \Order ;
22
+ use Magento \Sales \Model \Order \Email \Sender \OrderSender ;
23
+ use Magento \Sales \Model \Order \Address as OrderAddress ;
20
24
use Magento \Store \Model \StoreManagerInterface ;
21
25
use Magento \TestFramework \Fixture \Config ;
22
26
use Magento \TestFramework \Fixture \DataFixture ;
23
27
use Magento \TestFramework \Fixture \DataFixtureStorage ;
24
28
use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
25
29
use Magento \TestFramework \Fixture \DbIsolation ;
26
30
use Magento \TestFramework \Helper \Bootstrap ;
31
+ use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
27
32
use PHPUnit \Framework \TestCase ;
28
33
29
34
class RendererTest extends TestCase
@@ -45,11 +50,21 @@ class RendererTest extends TestCase
45
50
/** @var Renderer */
46
51
private $ block ;
47
52
53
+ /**
54
+ * @var CoreConfig
55
+ */
56
+ protected $ resourceConfig ;
57
+
48
58
/**
49
59
* @var AccountManagementInterface
50
60
*/
51
61
private $ accountManagement ;
52
62
63
+ /**
64
+ * @var OrderSender
65
+ */
66
+ private $ orderSender ;
67
+
53
68
/**
54
69
* @defaultDoc
55
70
*/
@@ -59,7 +74,9 @@ protected function setUp(): void
59
74
$ layout = $ this ->objectManager ->get (LayoutInterface::class);
60
75
$ this ->block = $ layout ->createBlock (Renderer::class);
61
76
$ this ->fixtures = Bootstrap::getObjectManager ()->get (DataFixtureStorageManager::class)->getStorage ();
77
+ $ this ->resourceConfig = $ this ->objectManager ->get (CoreConfig::class);
62
78
$ this ->accountManagement = $ this ->objectManager ->get (AccountManagementInterface::class);
79
+ $ this ->orderSender = $ this ->objectManager ->get (OrderSender::class);
63
80
}
64
81
65
82
#[
@@ -113,10 +130,7 @@ public function testOrderEmailContent(): void
113
130
* @throws \Magento\Framework\Exception\LocalizedException
114
131
*/
115
132
#[
116
- DbIsolation(false ),
117
- Config('default/currency/options/base ' , 'USD ' , 'store ' , 'default ' ),
118
- Config('currency/options/default ' , 'EUR ' , 'store ' , 'default ' ),
119
- Config('currency/options/allow ' , 'USD, EUR ' , 'store ' , 'default ' ),
133
+ DbIsolation(true ),
120
134
DataFixture(ProductFixture::class, ['price ' => 10 ], 'p1 ' ),
121
135
DataFixture(ProductFixture::class, ['price ' => 20 ], 'p2 ' ),
122
136
DataFixture(ProductFixture::class, ['price ' => 30 ], 'p3 ' ),
@@ -127,42 +141,67 @@ public function testOrderEmailContent(): void
127
141
]
128
142
public function testPlaceOrderWithOtherThanDefaultCurrencyValidateEmailHasSameCurrency (): void
129
143
{
144
+ $ this ->resourceConfig ->saveConfig (
145
+ 'currency/options/default ' ,
146
+ 'EUR ' ,
147
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
148
+ 0
149
+ );
150
+
151
+ $ this ->resourceConfig ->saveConfig (
152
+ 'currency/options/allow ' ,
153
+ 'EUR ' ,
154
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
155
+ 0
156
+ );
157
+
158
+ $ this ->resourceConfig ->saveConfig (
159
+ 'currency/options/base ' ,
160
+ 'USD ' ,
161
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
162
+ 0
163
+ );
164
+
130
165
// Load customer data
131
166
$ customer = $ this ->fixtures ->get ('customer ' );
132
167
$ customerEmail = $ customer ->getEmail ();
168
+ $ customerAdd = $ customer ->getAddresses ();
133
169
134
170
// Login to customer
135
171
$ this ->accountManagement ->authenticate ($ customerEmail , 'password ' );
136
172
173
+ // Including address data file
174
+ $ addressData = include __DIR__ . '/../../../../../Sales/_files/address_data.php ' ;
175
+
176
+ // Setting the billing address
177
+ $ billingAddress = $ this ->objectManager ->create (OrderAddress::class, ['data ' => $ addressData ]);
178
+ $ billingAddress ->setAddressType ('billing ' );
179
+
180
+ // Setting the shipping address
181
+ $ shippingAddress = clone $ billingAddress ;
182
+ $ shippingAddress ->setId (null )->setAddressType ('shipping ' );
183
+
137
184
// Place the order
138
185
$ order = $ this ->objectManager ->create (Order::class);
139
186
$ incrementId = $ this ->fixtures ->get ('order ' )->getIncrementId ();
140
187
$ order ->loadByIncrementId ($ incrementId );
141
188
$ storeManager = $ this ->objectManager ->get (StoreManagerInterface::class);
142
- $ currencyCode = $ storeManager ->getWebsite ()->getDefaultStore ()->getDefaultCurrency ()->getCode ();
189
+ $ currencyCodeSymbol = $ storeManager ->getWebsite ()->getDefaultStore ()->getDefaultCurrency ()->getCurrencySymbol ();
143
190
$ storeId = $ this ->objectManager ->get (StoreManagerInterface::class)->getStore ()->getId ();
144
191
$ order ->setStoreId ($ storeId );
145
- $ order ->setOrderCurrencyCode ($ currencyCode );
192
+ $ order ->setCustomerEmail ($ customerEmail );
193
+ $ order ->setBillingAddress ($ billingAddress );
194
+ $ order ->setShippingAddress ($ shippingAddress );
146
195
$ order ->save ();
196
+ $ this ->orderSender ->send ($ order );
197
+ $ this ->assertTrue ($ order ->getSendEmail ());
147
198
148
- $ priceBlockHtml = [];
149
-
150
- $ items = $ order ->getAllItems ();
151
- foreach ($ items as $ item ) {
152
- $ item ->setProductOptions ([
153
- 'bundle_options ' => [
154
- [
155
- 'value ' => [
156
- ['title ' => '' ]
157
- ],
158
- ],
159
- ],
160
- 'bundle_selection_attributes ' => '{"qty":5 ,"price":99} '
161
- ]);
162
- $ this ->block ->setItem ($ item );
163
- $ priceBlockHtml [] = $ this ->block ->getValueHtml ($ item );
164
- }
199
+ /** @var TransportBuilderMock $transportBuilderMock */
200
+ $ transportBuilderMock = Bootstrap::getObjectManager ()
201
+ ->get (TransportBuilderMock::class);
202
+ $ sentMessage = $ transportBuilderMock ->getSentMessage ();
165
203
166
- $ this ->assertStringContainsString ("€99 " , $ priceBlockHtml [0 ]);
204
+ $ this ->assertNotNull ($ sentMessage );
205
+ $ this ->assertStringContainsString ($ currencyCodeSymbol , $ sentMessage ->getBodyText ());
167
206
}
168
207
}
0 commit comments