21
21
use Magento \Framework \Stdlib \DateTime ;
22
22
use Magento \TestFramework \Bootstrap as TestFrameworkBootstrap ;
23
23
use Magento \TestFramework \Entity ;
24
+ use Magento \TestFramework \Fixture \DataFixture ;
25
+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
26
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
24
27
use Magento \TestFramework \Helper \Bootstrap ;
25
28
use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
26
29
use Magento \User \Model \User as UserModel ;
30
+ use Magento \User \Test \Fixture \User as UserDataFixture ;
27
31
use PHPUnit \Framework \TestCase ;
28
32
29
33
/**
@@ -62,6 +66,11 @@ class UserTest extends TestCase
62
66
*/
63
67
private $ objectManager ;
64
68
69
+ /**
70
+ * @var DataFixtureStorage
71
+ */
72
+ private $ fixtures ;
73
+
65
74
/**
66
75
* @inheritDoc
67
76
*/
@@ -72,6 +81,7 @@ protected function setUp(): void
72
81
$ this ->_dateTime = $ this ->objectManager ->get (DateTime::class);
73
82
$ this ->encryptor = $ this ->objectManager ->get (Encryptor::class);
74
83
$ this ->cache = $ this ->objectManager ->get (CacheInterface::class);
84
+ $ this ->fixtures = DataFixtureStorageManager::getStorage ();
75
85
}
76
86
77
87
/**
@@ -618,6 +628,41 @@ public function testSendNotificationEmailsIfRequired()
618
628
);
619
629
}
620
630
631
+ /**
632
+ * Test admin email notification after password change
633
+ *
634
+ * @throws LocalizedException
635
+ * @return void
636
+ */
637
+ #[
638
+ DataFixture(UserDataFixture::class, ['role_id ' => 1 ], 'user ' )
639
+ ]
640
+ public function testAdminUserEmailNotificationAfterPasswordChange (): void
641
+ {
642
+ // Load admin user
643
+ $ user = $ this ->fixtures ->get ('user ' );
644
+ $ username = $ user ->getDataByKey ('username ' );
645
+ $ adminEmail = $ user ->getDataByKey ('email ' );
646
+
647
+ // Login with old credentials
648
+ $ this ->_model ->login ($ username , TestFrameworkBootstrap::ADMIN_PASSWORD );
649
+
650
+ // Change password
651
+ $ this ->_model ->setPassword ('newPassword123 ' );
652
+ $ this ->_model ->save ();
653
+
654
+ $ this ->_model ->sendNotificationEmailsIfRequired ();
655
+
656
+ /** @var TransportBuilderMock $transportBuilderMock */
657
+ $ transportBuilderMock = $ this ->objectManager ->get (TransportBuilderMock::class);
658
+ $ message = $ transportBuilderMock ->getSentMessage ();
659
+
660
+ // Verify an email was dispatched to the correct user with correct subject
661
+ $ this ->assertNotNull ($ transportBuilderMock ->getSentMessage ());
662
+ $ this ->assertEquals ($ adminEmail , $ message ->getTo ()[0 ]->getEmail ());
663
+ $ this ->assertEquals ($ message ->getSubject (), 'New password for ' .$ username );
664
+ }
665
+
621
666
/**
622
667
* Return email template id by origin template code
623
668
*
0 commit comments