Skip to content

Commit 64ca4a2

Browse files
committed
ACP2E-3125: Password reset template issue with Admin user
1 parent de4dfb8 commit 64ca4a2

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

app/code/Magento/User/view/adminhtml/email/user_notification.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
* See COPYING.txt for license details.
55
*/
66
-->
7-
<!--@subject {{trans "New %changes for %user_name" changes=$changes user_name=$user.name}} @-->
7+
<!--@subject {{trans "New %changes for %user_name" changes=$changes user_name=$user.username}} @-->
88
<!--@vars {
99
"var store.frontend_name":"Store Name",
1010
"var store_name":"Store Name",
1111
"var store_email":"Store Email",
1212
"var store_phone":"Store Phone",
1313
"var changes":"Changes",
14-
"var user.name":"User Name"
14+
"var user.username":"User Name"
1515
} @-->
1616

1717
{{trans "Hello,"}}

dev/tests/integration/testsuite/Magento/User/Model/UserTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
use Magento\Framework\Stdlib\DateTime;
2222
use Magento\TestFramework\Bootstrap as TestFrameworkBootstrap;
2323
use Magento\TestFramework\Entity;
24+
use Magento\TestFramework\Fixture\DataFixture;
25+
use Magento\TestFramework\Fixture\DataFixtureStorage;
26+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
2427
use Magento\TestFramework\Helper\Bootstrap;
2528
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
2629
use Magento\User\Model\User as UserModel;
30+
use Magento\User\Test\Fixture\User as UserDataFixture;
2731
use 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

Comments
 (0)