2121use Magento \Framework \Stdlib \DateTime ;
2222use Magento \TestFramework \Bootstrap as TestFrameworkBootstrap ;
2323use Magento \TestFramework \Entity ;
24+ use Magento \TestFramework \Fixture \DataFixture ;
25+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
26+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
2427use Magento \TestFramework \Helper \Bootstrap ;
2528use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
2629use Magento \User \Model \User as UserModel ;
30+ use Magento \User \Test \Fixture \User as UserDataFixture ;
2731use PHPUnit \Framework \TestCase ;
2832
2933/**
@@ -62,6 +66,11 @@ class UserTest extends TestCase
6266 */
6367 private $ objectManager ;
6468
69+ /**
70+ * @var DataFixtureStorage
71+ */
72+ private $ fixtures ;
73+
6574 /**
6675 * @inheritDoc
6776 */
@@ -72,6 +81,7 @@ protected function setUp(): void
7281 $ this ->_dateTime = $ this ->objectManager ->get (DateTime::class);
7382 $ this ->encryptor = $ this ->objectManager ->get (Encryptor::class);
7483 $ this ->cache = $ this ->objectManager ->get (CacheInterface::class);
84+ $ this ->fixtures = DataFixtureStorageManager::getStorage ();
7585 }
7686
7787 /**
@@ -618,6 +628,41 @@ public function testSendNotificationEmailsIfRequired()
618628 );
619629 }
620630
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+
621666 /**
622667 * Return email template id by origin template code
623668 *
0 commit comments