3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
declare (strict_types=1 );
7
8
8
9
namespace Magento \Customer \Test \Unit \Model ;
17
18
use Magento \Store \Model \Store ;
18
19
use Magento \Customer \Model \Data \CustomerSecure ;
19
20
use Magento \Store \Model \Website ;
21
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
20
22
21
23
/**
22
- * Class EmailNotificationTest
24
+ * Unit test for \Magento\Customer\Model\EmailNotification
23
25
*
24
26
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25
27
*/
@@ -80,7 +82,7 @@ class EmailNotificationTest extends TestCase
80
82
private $ storeMock ;
81
83
82
84
/**
83
- * @var \Magento\Customer\Model\ EmailNotification
85
+ * @var EmailNotification
84
86
*/
85
87
private $ model ;
86
88
@@ -124,7 +126,7 @@ public function setUp(): void
124
126
->disableOriginalConstructor ()
125
127
->getMockForAbstractClass ();
126
128
127
- $ objectManager = new \ Magento \ Framework \ TestFramework \ Unit \ Helper \ ObjectManager ($ this );
129
+ $ objectManager = new ObjectManagerHelper ($ this );
128
130
129
131
$ this ->model = $ objectManager ->getObject (
130
132
EmailNotification::class,
@@ -142,7 +144,7 @@ public function setUp(): void
142
144
143
145
/**
144
146
* Test email notify when credentials changed
145
- *
147
+ *
146
148
* @param int $testNumber
147
149
* @param string $oldEmail
148
150
* @param string $newEmail
@@ -164,7 +166,7 @@ public function testEmailNotifyWhenCredentialsChanged($testNumber, $oldEmail, $n
164
166
$ expects = $ this ->once ();
165
167
break ;
166
168
case 2 :
167
- $ xmlPathTemplate = \ Magento \ Customer \ Model \ EmailNotification::XML_PATH_CHANGE_EMAIL_TEMPLATE ;
169
+ $ xmlPathTemplate = EmailNotification::XML_PATH_CHANGE_EMAIL_TEMPLATE ;
168
170
$ expects = $ this ->exactly (2 );
169
171
break ;
170
172
case 3 :
@@ -249,20 +251,32 @@ public function testEmailNotifyWhenCredentialsChanged($testNumber, $oldEmail, $n
249
251
$ this ->scopeConfigMock ->expects ($ this ->any ())
250
252
->method ('getValue ' )
251
253
->withConsecutive (
252
- [$ xmlPathTemplate , ScopeInterface::SCOPE_STORE , self ::STUB_CUSTOMER_STORE_ID ],
253
254
[
254
- \Magento \Customer \Model \EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY ,
255
+ $ xmlPathTemplate ,
256
+ ScopeInterface::SCOPE_STORE ,
257
+ self ::STUB_CUSTOMER_STORE_ID
258
+ ],
259
+ [
260
+ EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY ,
261
+ ScopeInterface::SCOPE_STORE ,
262
+ self ::STUB_CUSTOMER_STORE_ID
263
+ ],
264
+ [
265
+ $ xmlPathTemplate ,
255
266
ScopeInterface::SCOPE_STORE ,
256
267
self ::STUB_CUSTOMER_STORE_ID
257
268
],
258
- [$ xmlPathTemplate , ScopeInterface::SCOPE_STORE , self ::STUB_CUSTOMER_STORE_ID ],
259
269
[
260
- \ Magento \ Customer \ Model \ EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY ,
270
+ EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY ,
261
271
ScopeInterface::SCOPE_STORE ,
262
272
self ::STUB_CUSTOMER_STORE_ID
263
273
]
264
- )
265
- ->willReturnOnConsecutiveCalls (self ::STUB_EMAIL_IDENTIFIER , self ::STUB_SENDER , self ::STUB_EMAIL_IDENTIFIER , self ::STUB_SENDER );
274
+ )->willReturnOnConsecutiveCalls (
275
+ self ::STUB_EMAIL_IDENTIFIER ,
276
+ self ::STUB_SENDER ,
277
+ self ::STUB_EMAIL_IDENTIFIER ,
278
+ self ::STUB_SENDER
279
+ );
266
280
267
281
$ this ->transportBuilderMock ->expects (clone $ expects )
268
282
->method ('setTemplateIdentifier ' )
@@ -300,7 +314,7 @@ public function testEmailNotifyWhenCredentialsChanged($testNumber, $oldEmail, $n
300
314
301
315
/**
302
316
* Provides Emails Data Provider
303
- *
317
+ *
304
318
* @param void
305
319
* @return array
306
320
*/
@@ -329,6 +343,8 @@ public function sendNotificationEmailsDataProvider(): array
329
343
}
330
344
331
345
/**
346
+ * Test Password Reminder Email Notify
347
+ *
332
348
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
333
349
*/
334
350
public function testPasswordReminder (): void
@@ -366,7 +382,7 @@ public function testPasswordReminder(): void
366
382
->method ('getStore ' )
367
383
->willReturn ($ this ->storeMock );
368
384
369
- $ websiteMock = $ this ->createPartialMock (\ Magento \ Store \ Model \ Website::class, ['getStoreIds ' ]);
385
+ $ websiteMock = $ this ->createPartialMock (Website::class, ['getStoreIds ' ]);
370
386
$ websiteMock ->expects ($ this ->any ())
371
387
->method ('getStoreIds ' )
372
388
->willReturn ($ storeIds );
@@ -402,12 +418,18 @@ public function testPasswordReminder(): void
402
418
403
419
$ this ->scopeConfigMock ->expects ($ this ->at (0 ))
404
420
->method ('getValue ' )
405
- ->with (EmailNotification::XML_PATH_REMIND_EMAIL_TEMPLATE , ScopeInterface::SCOPE_STORE , self ::STUB_CUSTOMER_STORE_ID )
406
- ->willReturn (self ::STUB_EMAIL_IDENTIFIER );
421
+ ->with (
422
+ EmailNotification::XML_PATH_REMIND_EMAIL_TEMPLATE ,
423
+ ScopeInterface::SCOPE_STORE ,
424
+ self ::STUB_CUSTOMER_STORE_ID
425
+ )->willReturn (self ::STUB_EMAIL_IDENTIFIER );
407
426
$ this ->scopeConfigMock ->expects ($ this ->at (1 ))
408
427
->method ('getValue ' )
409
- ->with (EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY , ScopeInterface::SCOPE_STORE , self ::STUB_CUSTOMER_STORE_ID )
410
- ->willReturn (self ::STUB_SENDER );
428
+ ->with (
429
+ EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY ,
430
+ ScopeInterface::SCOPE_STORE ,
431
+ self ::STUB_CUSTOMER_STORE_ID
432
+ )->willReturn (self ::STUB_SENDER );
411
433
412
434
$ this ->mockDefaultTransportBuilder (
413
435
self ::STUB_EMAIL_IDENTIFIER ,
@@ -423,7 +445,7 @@ public function testPasswordReminder(): void
423
445
424
446
/**
425
447
* Test password reminder customer withouer store id info
426
- *
448
+ *
427
449
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
428
450
*/
429
451
public function testPasswordReminderCustomerWithoutStoreId (): void
@@ -462,7 +484,7 @@ public function testPasswordReminderCustomerWithoutStoreId(): void
462
484
->method ('getStore ' )
463
485
->with ($ defaultStoreId )
464
486
->willReturn ($ this ->storeMock );
465
- $ websiteMock = $ this ->createPartialMock (\ Magento \ Store \ Model \ Website::class, ['getStoreIds ' ]);
487
+ $ websiteMock = $ this ->createPartialMock (Website::class, ['getStoreIds ' ]);
466
488
$ websiteMock ->expects ($ this ->any ())
467
489
->method ('getStoreIds ' )
468
490
->willReturn ($ storeIds );
@@ -493,12 +515,18 @@ public function testPasswordReminderCustomerWithoutStoreId(): void
493
515
->willReturnSelf ();
494
516
$ this ->scopeConfigMock ->expects ($ this ->at (0 ))
495
517
->method ('getValue ' )
496
- ->with (EmailNotification::XML_PATH_REMIND_EMAIL_TEMPLATE , ScopeInterface::SCOPE_STORE , $ defaultStoreId )
497
- ->willReturn (self ::STUB_EMAIL_IDENTIFIER );
518
+ ->with (
519
+ EmailNotification::XML_PATH_REMIND_EMAIL_TEMPLATE ,
520
+ ScopeInterface::SCOPE_STORE ,
521
+ $ defaultStoreId
522
+ )->willReturn (self ::STUB_EMAIL_IDENTIFIER );
498
523
$ this ->scopeConfigMock ->expects ($ this ->at (1 ))
499
524
->method ('getValue ' )
500
- ->with (EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY , ScopeInterface::SCOPE_STORE , $ defaultStoreId )
501
- ->willReturn (self ::STUB_SENDER );
525
+ ->with (
526
+ EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY ,
527
+ ScopeInterface::SCOPE_STORE ,
528
+ $ defaultStoreId
529
+ )->willReturn (self ::STUB_SENDER );
502
530
$ this ->mockDefaultTransportBuilder (
503
531
self ::STUB_EMAIL_IDENTIFIER ,
504
532
$ defaultStoreId ,
@@ -512,7 +540,7 @@ public function testPasswordReminderCustomerWithoutStoreId(): void
512
540
513
541
/**
514
542
* Test email notify for password reset confirm
515
- *
543
+ *
516
544
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
517
545
*/
518
546
public function testPasswordResetConfirmation (): void
@@ -572,12 +600,18 @@ public function testPasswordResetConfirmation(): void
572
600
573
601
$ this ->scopeConfigMock ->expects ($ this ->at (0 ))
574
602
->method ('getValue ' )
575
- ->with (EmailNotification::XML_PATH_FORGOT_EMAIL_TEMPLATE , ScopeInterface::SCOPE_STORE , self ::STUB_CUSTOMER_STORE_ID )
576
- ->willReturn (self ::STUB_EMAIL_IDENTIFIER );
603
+ ->with (
604
+ EmailNotification::XML_PATH_FORGOT_EMAIL_TEMPLATE ,
605
+ ScopeInterface::SCOPE_STORE ,
606
+ self ::STUB_CUSTOMER_STORE_ID
607
+ )->willReturn (self ::STUB_EMAIL_IDENTIFIER );
577
608
$ this ->scopeConfigMock ->expects ($ this ->at (1 ))
578
609
->method ('getValue ' )
579
- ->with (EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY , ScopeInterface::SCOPE_STORE , self ::STUB_CUSTOMER_STORE_ID )
580
- ->willReturn (self ::STUB_SENDER );
610
+ ->with (
611
+ EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY ,
612
+ ScopeInterface::SCOPE_STORE ,
613
+ self ::STUB_CUSTOMER_STORE_ID
614
+ )->willReturn (self ::STUB_SENDER );
581
615
582
616
$ this ->mockDefaultTransportBuilder (
583
617
self ::STUB_EMAIL_IDENTIFIER ,
@@ -593,7 +627,7 @@ public function testPasswordResetConfirmation(): void
593
627
594
628
/**
595
629
* Test email notify with new account
596
- *
630
+ *
597
631
* @param void
598
632
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
599
633
*/
@@ -655,12 +689,18 @@ public function testNewAccount(): void
655
689
656
690
$ this ->scopeConfigMock ->expects ($ this ->at (0 ))
657
691
->method ('getValue ' )
658
- ->with (EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE , ScopeInterface::SCOPE_STORE , self ::STUB_CUSTOMER_STORE_ID )
659
- ->willReturn (self ::STUB_EMAIL_IDENTIFIER );
692
+ ->with (
693
+ EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE ,
694
+ ScopeInterface::SCOPE_STORE ,
695
+ self ::STUB_CUSTOMER_STORE_ID
696
+ )->willReturn (self ::STUB_EMAIL_IDENTIFIER );
660
697
$ this ->scopeConfigMock ->expects ($ this ->at (1 ))
661
698
->method ('getValue ' )
662
- ->with (EmailNotification::XML_PATH_REGISTER_EMAIL_IDENTITY , ScopeInterface::SCOPE_STORE , self ::STUB_CUSTOMER_STORE_ID )
663
- ->willReturn (self ::STUB_SENDER );
699
+ ->with (
700
+ EmailNotification::XML_PATH_REGISTER_EMAIL_IDENTITY ,
701
+ ScopeInterface::SCOPE_STORE ,
702
+ self ::STUB_CUSTOMER_STORE_ID
703
+ )->willReturn (self ::STUB_SENDER );
664
704
665
705
$ this ->mockDefaultTransportBuilder (
666
706
self ::STUB_EMAIL_IDENTIFIER ,
@@ -671,7 +711,12 @@ public function testNewAccount(): void
671
711
['customer ' => $ this ->customerSecureMock , 'back_url ' => '' , 'store ' => $ this ->storeMock ]
672
712
);
673
713
674
- $ this ->model ->newAccount ($ customer , EmailNotification::NEW_ACCOUNT_EMAIL_REGISTERED , '' , self ::STUB_CUSTOMER_STORE_ID );
714
+ $ this ->model ->newAccount (
715
+ $ customer ,
716
+ EmailNotification::NEW_ACCOUNT_EMAIL_REGISTERED ,
717
+ '' ,
718
+ self ::STUB_CUSTOMER_STORE_ID
719
+ );
675
720
}
676
721
677
722
/**
0 commit comments