Skip to content

Commit 4712830

Browse files
akaashakaash
authored andcommitted
ACQE-4975 | PR Feedback
1 parent e0b50b4 commit 4712830

File tree

1 file changed

+57
-14
lines changed

1 file changed

+57
-14
lines changed

dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
namespace Magento\User\Controller\Adminhtml;
99

10-
use Magento\Framework\App\Config\Storage\WriterInterface;
10+
use Magento\Framework\App\Area;
11+
use Magento\Framework\App\Config\ReinitableConfigInterface;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
1113
use Magento\Framework\Exception\LocalizedException;
1214
use Magento\Framework\Mail\EmailMessage;
1315
use Magento\Framework\Message\MessageInterface;
1416
use Magento\Store\Model\Store;
17+
use Magento\TestFramework\Fixture\AppArea;
1518
use Magento\TestFramework\Fixture\Config as Config;
1619
use Magento\TestFramework\Fixture\DataFixture;
1720
use Magento\TestFramework\Fixture\DataFixtureStorage;
@@ -24,6 +27,7 @@
2427
use Magento\User\Model\UserFactory;
2528
use Magento\User\Test\Fixture\User as UserDataFixture;
2629
use Magento\Framework\App\ResourceConnection;
30+
use Magento\Config\Model\ResourceModel\Config as CoreConfig;
2731

2832
/**
2933
* Test class for user reset password email
@@ -48,14 +52,19 @@ class UserResetPasswordEmailTest extends AbstractBackendController
4852
private $userFactory;
4953

5054
/**
51-
* @var WriterInterface
55+
* @var ResourceConnection
5256
*/
53-
private $configWriter;
57+
private $resourceConnection;
5458

5559
/**
56-
* @var ResourceConnection
60+
* @var ReinitableConfigInterface
5761
*/
58-
private $resourceConnection;
62+
private $reinitableConfig;
63+
64+
/**
65+
* @var CoreConfig
66+
*/
67+
protected $resourceConfig;
5968

6069
/**
6170
* @throws LocalizedException
@@ -66,8 +75,9 @@ protected function setUp(): void
6675
$this->fixtures = DataFixtureStorageManager::getStorage();
6776
$this->userModel = $this->_objectManager->create(UserModel::class);
6877
$this->userFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(UserFactory::class);
69-
$this->configWriter = $this->_objectManager->get(WriterInterface::class);
7078
$this->resourceConnection = $this->_objectManager->get(ResourceConnection::class);
79+
$this->reinitableConfig = $this->_objectManager->get(ReinitableConfigInterface::class);
80+
$this->resourceConfig = $this->_objectManager->get(CoreConfig::class);
7181
}
7282

7383
#[
@@ -104,6 +114,7 @@ private function getResetPasswordUri(EmailMessage $message): string
104114
* @throws LocalizedException
105115
*/
106116
#[
117+
AppArea('adminhtml'),
107118
DbIsolation(false),
108119
DataFixture(UserDataFixture::class, ['role_id' => 1], 'user')
109120
]
@@ -118,14 +129,30 @@ public function testLimitNumberOfResetRequestPerHourByEmail(): void
118129
$adminUser = $this->userFactory->create();
119130
$adminUser->login($username, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD);
120131

121-
// Setting Password Reset Protection Type to By Email
122-
$this->configWriter->save('admin/security/password_reset_protection_type', 3);
132+
// Setting Password Reset Protection Type By Email
133+
$this->resourceConfig->saveConfig(
134+
'admin/security/password_reset_protection_type',
135+
3,
136+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
137+
0
138+
);
123139

124140
// Setting Max Number of Password Reset Requests 0
125-
$this->configWriter->save('admin/security/max_number_password_reset_requests', 0);
141+
$this->resourceConfig->saveConfig(
142+
'admin/security/max_number_password_reset_requests',
143+
0,
144+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
145+
0
146+
);
126147

127148
// Setting Min Time Between Password Reset Requests 0
128-
$this->configWriter->save('admin/security/min_time_between_password_reset_requests', 0);
149+
$this->resourceConfig->saveConfig(
150+
'admin/security/min_time_between_password_reset_requests',
151+
0,
152+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
153+
0
154+
);
155+
$this->reinitableConfig->reinit();
129156

130157
// Resetting Password
131158
$this->getRequest()->setPostValue('email', $adminEmail);
@@ -148,10 +175,24 @@ public function testLimitNumberOfResetRequestPerHourByEmail(): void
148175
);
149176

150177
// Setting Max Number of Password Reset Requests greater than 0
151-
$this->configWriter->save('admin/security/max_number_password_reset_requests', 3);
178+
$this->resourceConfig->saveConfig(
179+
'admin/security/max_number_password_reset_requests',
180+
2,
181+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
182+
0
183+
);
184+
$this->reinitableConfig->reinit();
185+
186+
$this->getRequest()->setPostValue('email', $adminEmail);
187+
$this->dispatch('backend/admin/auth/forgotpassword');
188+
189+
$this->assertSessionMessages(
190+
$this->equalTo([]),
191+
MessageInterface::TYPE_ERROR
192+
);
152193

153194
// Resetting password multiple times
154-
for ($i = 0; $i < 1; $i++) {
195+
for ($i = 0; $i < 2; $i++) {
155196
$this->getRequest()->setPostValue('email', $adminEmail);
156197
$this->dispatch('backend/admin/auth/forgotpassword');
157198

@@ -164,15 +205,17 @@ public function testLimitNumberOfResetRequestPerHourByEmail(): void
164205
);
165206
}
166207

208+
// Clearing the table password_reset_request_event
167209
$connection = $this->resourceConnection->getConnection();
168210
$tableName = $this->resourceConnection->getTableName('password_reset_request_event');
169-
170211
$connection->truncateTable($tableName);
171212

172213
$this->assertEquals(0, $connection->fetchOne("SELECT COUNT(*) FROM $tableName"));
173214

174-
$sendMessage = $transportMock->getSentMessage()->getBody()->getParts()[0]->getRawContent();
215+
$this->getRequest()->setPostValue('email', $adminEmail);
216+
$this->dispatch('backend/admin/auth/forgotpassword');
175217

218+
$sendMessage = $transportMock->getSentMessage()->getBody()->getParts()[0]->getRawContent();
176219
$this->assertStringContainsString(
177220
'There was recently a request to change the password for your account',
178221
$sendMessage

0 commit comments

Comments
 (0)