@@ -51,7 +51,6 @@ class CreateCustomerTest extends TestCase
51
51
public function setUp (): void
52
52
{
53
53
$ this ->objectManager = Bootstrap::getObjectManager ();
54
-
55
54
$ this ->graphQlRequest = $ this ->objectManager ->create (GraphQlRequest::class);
56
55
$ this ->json = $ this ->objectManager ->get (SerializerInterface::class);
57
56
@@ -109,11 +108,10 @@ public function testCreateCustomerSendsEmail()
109
108
$ this ->assertStringContainsString ('Welcome to Main Website Store. ' , $ messageRaw );
110
109
}
111
110
112
-
113
111
/**
114
112
* Test that creating a customer on an alternative store sends an email
115
113
*
116
- * @magentoDataFixture Magento/Store /_files/second_website_with_store_group_and_store .php
114
+ * @magentoDataFixture Magento/CustomerGraphQl /_files/website_store_with_store_view .php
117
115
*/
118
116
public function testCreateCustomerForStoreSendsEmail ()
119
117
{
@@ -141,7 +139,72 @@ public function testCreateCustomerForStoreSendsEmail()
141
139
[],
142
140
'' ,
143
141
[
144
- 'Store ' => 'fixture_second_store '
142
+ 'Store ' => 'test_store_view '
143
+ ]
144
+ );
145
+ $ responseData = $ this ->json ->unserialize ($ response ->getContent ());
146
+
147
+ // Assert the response of the GraphQL request
148
+ $ this ->assertNull ($ responseData ['data ' ]['createCustomer ' ]['customer ' ]['id ' ]);
149
+
150
+ // Verify the customer was created and has the correct data
151
+ $ customer = $ this ->customerRepository ->get ('test@magento.com ' );
152
+ $ this ->assertEquals ('Test ' , $ customer ->getFirstname ());
153
+ $ this ->assertEquals ('Magento ' , $ customer ->getLastname ());
154
+ $ this ->assertEquals ('Test Store View ' , $ customer ->getCreatedIn ());
155
+
156
+ $ store = $ this ->storeRepository ->getById ($ customer ->getStoreId ());
157
+ $ this ->assertEquals ('test_store_view ' , $ store ->getCode ());
158
+
159
+ /** @var TransportBuilderMock $transportBuilderMock */
160
+ $ transportBuilderMock = $ this ->objectManager ->get (TransportBuilderMock::class);
161
+ $ sentMessage = $ transportBuilderMock ->getSentMessage ();
162
+
163
+ // Verify an email was dispatched to the correct user
164
+ $ this ->assertNotNull ($ sentMessage );
165
+ $ this ->assertEquals ('Test Magento ' , $ sentMessage ->getTo ()[0 ]->getName ());
166
+ $ this ->assertEquals ('test@magento.com ' , $ sentMessage ->getTo ()[0 ]->getEmail ());
167
+
168
+ // Assert the email contains the expected content
169
+ $ this ->assertEquals ('Welcome to Test Group ' , $ sentMessage ->getSubject ());
170
+ $ messageRaw = $ sentMessage ->getBody ()->getParts ()[0 ]->getRawContent ();
171
+ $ this ->assertStringContainsString ('Welcome to Test Group. ' , $ messageRaw );
172
+ }
173
+
174
+ /**
175
+ * Test that creating a customer on an alternative store sends an email in the translated language
176
+ *
177
+ * @magentoDataFixture Magento/CustomerGraphQl/_files/website_store_with_store_view.php
178
+ * @magentoConfigFixture test_store_view_store general/locale/code fr_FR
179
+ * @magentoComponentsDir Magento/CustomerGraphQl/_files
180
+ */
181
+ public function testCreateCustomerForStoreSendsTranslatedEmail ()
182
+ {
183
+ $ query
184
+ = <<<QUERY
185
+ mutation createAccount {
186
+ createCustomer(
187
+ input: {
188
+ email: "test@magento.com"
189
+ firstname: "Test"
190
+ lastname: "Magento"
191
+ password: "T3stP4assw0rd"
192
+ is_subscribed: false
193
+ }
194
+ ) {
195
+ customer {
196
+ id
197
+ }
198
+ }
199
+ }
200
+ QUERY ;
201
+
202
+ $ response = $ this ->graphQlRequest ->send (
203
+ $ query ,
204
+ [],
205
+ '' ,
206
+ [
207
+ 'Store ' => 'test_store_view '
145
208
]
146
209
);
147
210
$ responseData = $ this ->json ->unserialize ($ response ->getContent ());
@@ -153,10 +216,10 @@ public function testCreateCustomerForStoreSendsEmail()
153
216
$ customer = $ this ->customerRepository ->get ('test@magento.com ' );
154
217
$ this ->assertEquals ('Test ' , $ customer ->getFirstname ());
155
218
$ this ->assertEquals ('Magento ' , $ customer ->getLastname ());
156
- $ this ->assertEquals ('Fixture Second Store ' , $ customer ->getCreatedIn ());
219
+ $ this ->assertEquals ('Test Store View ' , $ customer ->getCreatedIn ());
157
220
158
221
$ store = $ this ->storeRepository ->getById ($ customer ->getStoreId ());
159
- $ this ->assertEquals ('fixture_second_store ' , $ store ->getCode ());
222
+ $ this ->assertEquals ('test_store_view ' , $ store ->getCode ());
160
223
161
224
/** @var TransportBuilderMock $transportBuilderMock */
162
225
$ transportBuilderMock = $ this ->objectManager ->get (TransportBuilderMock::class);
@@ -168,8 +231,8 @@ public function testCreateCustomerForStoreSendsEmail()
168
231
$ this ->assertEquals ('test@magento.com ' , $ sentMessage ->getTo ()[0 ]->getEmail ());
169
232
170
233
// Assert the email contains the expected content
171
- $ this ->assertEquals ('Welcome to second store group ' , $ sentMessage ->getSubject ());
234
+ $ this ->assertEquals ('Bienvenue sur Test Group. ' , $ sentMessage ->getSubject ());
172
235
$ messageRaw = $ sentMessage ->getBody ()->getParts ()[0 ]->getRawContent ();
173
- $ this ->assertStringContainsString ('Welcome to second store group . ' , $ messageRaw );
236
+ $ this ->assertStringContainsString ('Bienvenue sur Test Group . ' , $ messageRaw );
174
237
}
175
238
}
0 commit comments