7
7
8
8
namespace Magento \User \Controller \Adminhtml ;
9
9
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 ;
11
13
use Magento \Framework \Exception \LocalizedException ;
12
14
use Magento \Framework \Mail \EmailMessage ;
13
15
use Magento \Framework \Message \MessageInterface ;
14
16
use Magento \Store \Model \Store ;
17
+ use Magento \TestFramework \Fixture \AppArea ;
15
18
use Magento \TestFramework \Fixture \Config as Config ;
16
19
use Magento \TestFramework \Fixture \DataFixture ;
17
20
use Magento \TestFramework \Fixture \DataFixtureStorage ;
24
27
use Magento \User \Model \UserFactory ;
25
28
use Magento \User \Test \Fixture \User as UserDataFixture ;
26
29
use Magento \Framework \App \ResourceConnection ;
30
+ use Magento \Config \Model \ResourceModel \Config as CoreConfig ;
27
31
28
32
/**
29
33
* Test class for user reset password email
@@ -48,14 +52,19 @@ class UserResetPasswordEmailTest extends AbstractBackendController
48
52
private $ userFactory ;
49
53
50
54
/**
51
- * @var WriterInterface
55
+ * @var ResourceConnection
52
56
*/
53
- private $ configWriter ;
57
+ private $ resourceConnection ;
54
58
55
59
/**
56
- * @var ResourceConnection
60
+ * @var ReinitableConfigInterface
57
61
*/
58
- private $ resourceConnection ;
62
+ private $ reinitableConfig ;
63
+
64
+ /**
65
+ * @var CoreConfig
66
+ */
67
+ protected $ resourceConfig ;
59
68
60
69
/**
61
70
* @throws LocalizedException
@@ -66,8 +75,9 @@ protected function setUp(): void
66
75
$ this ->fixtures = DataFixtureStorageManager::getStorage ();
67
76
$ this ->userModel = $ this ->_objectManager ->create (UserModel::class);
68
77
$ this ->userFactory = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (UserFactory::class);
69
- $ this ->configWriter = $ this ->_objectManager ->get (WriterInterface::class);
70
78
$ this ->resourceConnection = $ this ->_objectManager ->get (ResourceConnection::class);
79
+ $ this ->reinitableConfig = $ this ->_objectManager ->get (ReinitableConfigInterface::class);
80
+ $ this ->resourceConfig = $ this ->_objectManager ->get (CoreConfig::class);
71
81
}
72
82
73
83
#[
@@ -104,6 +114,7 @@ private function getResetPasswordUri(EmailMessage $message): string
104
114
* @throws LocalizedException
105
115
*/
106
116
#[
117
+ AppArea('adminhtml ' ),
107
118
DbIsolation(false ),
108
119
DataFixture(UserDataFixture::class, ['role_id ' => 1 ], 'user ' )
109
120
]
@@ -118,14 +129,30 @@ public function testLimitNumberOfResetRequestPerHourByEmail(): void
118
129
$ adminUser = $ this ->userFactory ->create ();
119
130
$ adminUser ->login ($ username , \Magento \TestFramework \Bootstrap::ADMIN_PASSWORD );
120
131
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
+ );
123
139
124
140
// 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
+ );
126
147
127
148
// 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 ();
129
156
130
157
// Resetting Password
131
158
$ this ->getRequest ()->setPostValue ('email ' , $ adminEmail );
@@ -148,10 +175,24 @@ public function testLimitNumberOfResetRequestPerHourByEmail(): void
148
175
);
149
176
150
177
// 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
+ );
152
193
153
194
// Resetting password multiple times
154
- for ($ i = 0 ; $ i < 1 ; $ i ++) {
195
+ for ($ i = 0 ; $ i < 2 ; $ i ++) {
155
196
$ this ->getRequest ()->setPostValue ('email ' , $ adminEmail );
156
197
$ this ->dispatch ('backend/admin/auth/forgotpassword ' );
157
198
@@ -164,15 +205,17 @@ public function testLimitNumberOfResetRequestPerHourByEmail(): void
164
205
);
165
206
}
166
207
208
+ // Clearing the table password_reset_request_event
167
209
$ connection = $ this ->resourceConnection ->getConnection ();
168
210
$ tableName = $ this ->resourceConnection ->getTableName ('password_reset_request_event ' );
169
-
170
211
$ connection ->truncateTable ($ tableName );
171
212
172
213
$ this ->assertEquals (0 , $ connection ->fetchOne ("SELECT COUNT(*) FROM $ tableName " ));
173
214
174
- $ sendMessage = $ transportMock ->getSentMessage ()->getBody ()->getParts ()[0 ]->getRawContent ();
215
+ $ this ->getRequest ()->setPostValue ('email ' , $ adminEmail );
216
+ $ this ->dispatch ('backend/admin/auth/forgotpassword ' );
175
217
218
+ $ sendMessage = $ transportMock ->getSentMessage ()->getBody ()->getParts ()[0 ]->getRawContent ();
176
219
$ this ->assertStringContainsString (
177
220
'There was recently a request to change the password for your account ' ,
178
221
$ sendMessage
0 commit comments