7
7
8
8
namespace Magento \GraphQl \Customer ;
9
9
10
+ use Exception ;
10
11
use Magento \Customer \Model \CustomerAuthUpdate ;
11
- use Magento \Customer \ Model \ CustomerRegistry ;
12
+ use Magento \Framework \ Exception \ AuthenticationException ;
12
13
use Magento \Integration \Api \CustomerTokenServiceInterface ;
13
14
use Magento \TestFramework \Helper \Bootstrap ;
14
15
use Magento \TestFramework \TestCase \GraphQlAbstract ;
@@ -113,7 +114,7 @@ public function testUpdateCustomer()
113
114
*/
114
115
public function testUpdateCustomerIfInputDataIsEmpty ()
115
116
{
116
- $ this ->expectException (\ Exception::class);
117
+ $ this ->expectException (Exception::class);
117
118
$ this ->expectExceptionMessage ('"input" value should be specified ' );
118
119
119
120
$ currentEmail = 'customer@example.com ' ;
@@ -139,7 +140,7 @@ public function testUpdateCustomerIfInputDataIsEmpty()
139
140
*/
140
141
public function testUpdateCustomerIfUserIsNotAuthorized ()
141
142
{
142
- $ this ->expectException (\ Exception::class);
143
+ $ this ->expectException (Exception::class);
143
144
$ this ->expectExceptionMessage ('The current customer isn \'t authorized. ' );
144
145
145
146
$ newFirstname = 'Richard ' ;
@@ -165,7 +166,7 @@ public function testUpdateCustomerIfUserIsNotAuthorized()
165
166
*/
166
167
public function testUpdateCustomerIfAccountIsLocked ()
167
168
{
168
- $ this ->expectException (\ Exception::class);
169
+ $ this ->expectException (Exception::class);
169
170
$ this ->expectExceptionMessage ('The account is locked. ' );
170
171
171
172
$ this ->lockCustomer ->execute (1 );
@@ -195,7 +196,7 @@ public function testUpdateCustomerIfAccountIsLocked()
195
196
*/
196
197
public function testUpdateEmailIfPasswordIsMissed ()
197
198
{
198
- $ this ->expectException (\ Exception::class);
199
+ $ this ->expectException (Exception::class);
199
200
$ this ->expectExceptionMessage ('Provide the current "password" to change "email". ' );
200
201
201
202
$ currentEmail = 'customer@example.com ' ;
@@ -223,7 +224,7 @@ public function testUpdateEmailIfPasswordIsMissed()
223
224
*/
224
225
public function testUpdateEmailIfPasswordIsInvalid ()
225
226
{
226
- $ this ->expectException (\ Exception::class);
227
+ $ this ->expectException (Exception::class);
227
228
$ this ->expectExceptionMessage ('Invalid login or password. ' );
228
229
229
230
$ currentEmail = 'customer@example.com ' ;
@@ -253,8 +254,10 @@ public function testUpdateEmailIfPasswordIsInvalid()
253
254
*/
254
255
public function testUpdateEmailIfEmailAlreadyExists ()
255
256
{
256
- $ this ->expectException (\Exception::class);
257
- $ this ->expectExceptionMessage ('A customer with the same email address already exists in an associated website. ' );
257
+ $ this ->expectException (Exception::class);
258
+ $ this ->expectExceptionMessage (
259
+ 'A customer with the same email address already exists in an associated website. '
260
+ );
258
261
259
262
$ currentEmail = 'customer@example.com ' ;
260
263
$ currentPassword = 'password ' ;
@@ -281,12 +284,42 @@ public function testUpdateEmailIfEmailAlreadyExists()
281
284
$ this ->graphQlMutation ($ query , [], '' , $ this ->getCustomerAuthHeaders ($ currentEmail , $ currentPassword ));
282
285
}
283
286
287
+ /**
288
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
289
+ */
290
+ public function testUpdateEmailIfEmailIsInvalid ()
291
+ {
292
+ $ currentEmail = 'customer@example.com ' ;
293
+ $ currentPassword = 'password ' ;
294
+ $ invalidEmail = 'customer.example.com ' ;
295
+
296
+ $ query = <<<QUERY
297
+ mutation {
298
+ updateCustomer(
299
+ input: {
300
+ email: " {$ invalidEmail }"
301
+ password: " {$ currentPassword }"
302
+ }
303
+ ) {
304
+ customer {
305
+ email
306
+ }
307
+ }
308
+ }
309
+ QUERY ;
310
+
311
+ $ this ->expectException (Exception::class);
312
+ $ this ->expectExceptionMessage ('" ' . $ invalidEmail . '" is not a valid email address. ' );
313
+
314
+ $ this ->graphQlMutation ($ query , [], '' , $ this ->getCustomerAuthHeaders ($ currentEmail , $ currentPassword ));
315
+ }
316
+
284
317
/**
285
318
* @magentoApiDataFixture Magento/Customer/_files/customer.php
286
319
*/
287
320
public function testEmptyCustomerName ()
288
321
{
289
- $ this ->expectException (\ Exception::class);
322
+ $ this ->expectException (Exception::class);
290
323
$ this ->expectExceptionMessage ('Required parameters are missing: First Name ' );
291
324
292
325
$ currentEmail = 'customer@example.com ' ;
@@ -310,10 +343,63 @@ public function testEmptyCustomerName()
310
343
$ this ->graphQlMutation ($ query , [], '' , $ this ->getCustomerAuthHeaders ($ currentEmail , $ currentPassword ));
311
344
}
312
345
346
+ /**
347
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
348
+ */
349
+ public function testEmptyCustomerLastName ()
350
+ {
351
+ $ query = <<<QUERY
352
+ mutation {
353
+ updateCustomer(
354
+ input: {
355
+ lastname: ""
356
+ }
357
+ ) {
358
+ customer {
359
+ lastname
360
+ }
361
+ }
362
+ }
363
+ QUERY ;
364
+
365
+ $ this ->expectException (Exception::class);
366
+ $ this ->expectExceptionMessage ('Required parameters are missing: Last Name ' );
367
+
368
+ $ this ->graphQlMutation ($ query , [], '' , $ this ->getCustomerAuthHeaders ('customer@example.com ' , 'password ' ));
369
+ }
370
+
371
+ /**
372
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
373
+ */
374
+ public function testUpdateCustomerIfDobIsInvalid ()
375
+ {
376
+ $ invalidDob = 'bla-bla-bla ' ;
377
+
378
+ $ query = <<<QUERY
379
+ mutation {
380
+ updateCustomer(
381
+ input: {
382
+ date_of_birth: " {$ invalidDob }"
383
+ }
384
+ ) {
385
+ customer {
386
+ date_of_birth
387
+ }
388
+ }
389
+ }
390
+ QUERY ;
391
+
392
+ $ this ->expectException (Exception::class);
393
+ $ this ->expectExceptionMessage ('Invalid date ' );
394
+
395
+ $ this ->graphQlMutation ($ query , [], '' , $ this ->getCustomerAuthHeaders ('customer@example.com ' , 'password ' ));
396
+ }
397
+
313
398
/**
314
399
* @param string $email
315
400
* @param string $password
316
401
* @return array
402
+ * @throws AuthenticationException
317
403
*/
318
404
private function getCustomerAuthHeaders (string $ email , string $ password ): array
319
405
{
0 commit comments