8
8
namespace Magento \GraphQl \Customer ;
9
9
10
10
use Magento \Customer \Api \AccountManagementInterface ;
11
+ use Magento \Customer \Api \CustomerRepositoryInterface ;
11
12
use Magento \Customer \Model \CustomerAuthUpdate ;
12
13
use Magento \Customer \Model \CustomerRegistry ;
13
14
use Magento \Framework \Exception \AuthenticationException ;
@@ -42,12 +43,18 @@ class ChangeCustomerPasswordTest extends GraphQlAbstract
42
43
*/
43
44
private $ customerAuthUpdate ;
44
45
46
+ /**
47
+ * @var CustomerRepositoryInterface
48
+ */
49
+ private $ customerRepository ;
50
+
45
51
protected function setUp ()
46
52
{
47
53
$ this ->customerTokenService = Bootstrap::getObjectManager ()->get (CustomerTokenServiceInterface::class);
48
54
$ this ->accountManagement = Bootstrap::getObjectManager ()->get (AccountManagementInterface::class);
49
55
$ this ->customerRegistry = Bootstrap::getObjectManager ()->get (CustomerRegistry::class);
50
56
$ this ->customerAuthUpdate = Bootstrap::getObjectManager ()->get (CustomerAuthUpdate::class);
57
+ $ this ->customerRepository = Bootstrap::getObjectManager ()->get (CustomerRepositoryInterface::class);
51
58
}
52
59
53
60
/**
@@ -56,19 +63,19 @@ protected function setUp()
56
63
public function testChangePassword ()
57
64
{
58
65
$ customerEmail =
'[email protected] ' ;
59
- $ oldCustomerPassword = 'password ' ;
60
- $ newCustomerPassword = 'anotherPassword1 ' ;
66
+ $ currentPassword = 'password ' ;
67
+ $ newPassword = 'anotherPassword1 ' ;
61
68
62
- $ query = $ this ->getChangePassQuery ( $ oldCustomerPassword , $ newCustomerPassword );
63
- $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ oldCustomerPassword );
69
+ $ query = $ this ->getQuery ( $ currentPassword , $ newPassword );
70
+ $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ currentPassword );
64
71
65
72
$ response = $ this ->graphQlMutation ($ query , [], '' , $ headerMap );
66
- $ this ->assertEquals ($ customerEmail , $ response ['changeCustomerPassword ' ]['email ' ]);
73
+ $ this ->assertEquals ($ customerEmail , $ response ['changePassword ' ]['email ' ]);
67
74
68
75
try {
69
76
// registry contains the old password hash so needs to be reset
70
77
$ this ->customerRegistry ->removeByEmail ($ customerEmail );
71
- $ this ->accountManagement ->authenticate ($ customerEmail , $ newCustomerPassword );
78
+ $ this ->accountManagement ->authenticate ($ customerEmail , $ newPassword );
72
79
} catch (LocalizedException $ e ) {
73
80
$ this ->fail ('Password was not changed: ' . $ e ->getMessage ());
74
81
}
@@ -80,7 +87,7 @@ public function testChangePassword()
80
87
*/
81
88
public function testChangePasswordIfUserIsNotAuthorizedTest ()
82
89
{
83
- $ query = $ this ->getChangePassQuery ('currentpassword ' , 'newpassword ' );
90
+ $ query = $ this ->getQuery ('currentpassword ' , 'newpassword ' );
84
91
$ this ->graphQlMutation ($ query );
85
92
}
86
93
@@ -90,11 +97,11 @@ public function testChangePasswordIfUserIsNotAuthorizedTest()
90
97
public function testChangeWeakPassword ()
91
98
{
92
99
$ customerEmail =
'[email protected] ' ;
93
- $ oldCustomerPassword = 'password ' ;
94
- $ newCustomerPassword = 'weakpass ' ;
100
+ $ currentPassword = 'password ' ;
101
+ $ newPassword = 'weakpass ' ;
95
102
96
- $ query = $ this ->getChangePassQuery ( $ oldCustomerPassword , $ newCustomerPassword );
97
- $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ oldCustomerPassword );
103
+ $ query = $ this ->getQuery ( $ currentPassword , $ newPassword );
104
+ $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ currentPassword );
98
105
99
106
$ this ->expectException (\Exception::class);
100
107
$ this ->expectExceptionMessageRegExp ('/Minimum of different classes of characters in password is.*/ ' );
@@ -110,13 +117,13 @@ public function testChangeWeakPassword()
110
117
public function testChangePasswordIfPasswordIsInvalid ()
111
118
{
112
119
$ customerEmail =
'[email protected] ' ;
113
- $ oldCustomerPassword = 'password ' ;
114
- $ newCustomerPassword = 'anotherPassword1 ' ;
115
- $ incorrectPassword = 'password-incorrect ' ;
120
+ $ currentPassword = 'password ' ;
121
+ $ newPassword = 'anotherPassword1 ' ;
122
+ $ incorrectCurrentPassword = 'password-incorrect ' ;
116
123
117
- $ query = $ this ->getChangePassQuery ( $ incorrectPassword , $ newCustomerPassword );
124
+ $ query = $ this ->getQuery ( $ incorrectCurrentPassword , $ newPassword );
118
125
119
- $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ oldCustomerPassword );
126
+ $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ currentPassword );
120
127
$ this ->graphQlMutation ($ query , [], '' , $ headerMap );
121
128
}
122
129
@@ -128,13 +135,13 @@ public function testChangePasswordIfPasswordIsInvalid()
128
135
public function testChangePasswordIfCurrentPasswordIsEmpty ()
129
136
{
130
137
$ customerEmail =
'[email protected] ' ;
131
- $ oldCustomerPassword = 'password ' ;
132
- $ newCustomerPassword = 'anotherPassword1 ' ;
133
- $ currentCustomerPassword = '' ;
138
+ $ currentPassword = 'password ' ;
139
+ $ newPassword = 'anotherPassword1 ' ;
140
+ $ incorrectCurrentPassword = '' ;
134
141
135
- $ query = $ this ->getChangePassQuery ( $ currentCustomerPassword , $ newCustomerPassword );
142
+ $ query = $ this ->getQuery ( $ incorrectCurrentPassword , $ newPassword );
136
143
137
- $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ oldCustomerPassword );
144
+ $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ currentPassword );
138
145
$ this ->graphQlMutation ($ query , [], '' , $ headerMap );
139
146
}
140
147
@@ -146,29 +153,33 @@ public function testChangePasswordIfCurrentPasswordIsEmpty()
146
153
public function testChangePasswordIfNewPasswordIsEmpty ()
147
154
{
148
155
$ customerEmail =
'[email protected] ' ;
149
- $ currentCustomerPassword = 'password ' ;
150
- $ newCustomerPassword = '' ;
156
+ $ currentPassword = 'password ' ;
157
+ $ incorrectNewPassword = '' ;
151
158
152
- $ query = $ this ->getChangePassQuery ( $ currentCustomerPassword , $ newCustomerPassword );
159
+ $ query = $ this ->getQuery ( $ currentPassword , $ incorrectNewPassword );
153
160
154
- $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ currentCustomerPassword );
161
+ $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ currentPassword );
155
162
$ this ->graphQlMutation ($ query , [], '' , $ headerMap );
156
163
}
157
164
158
165
/**
166
+ * @magentoApiDataFixture Magento/GraphQl/Customer/_files/enable_customer_account_confirmation.php
159
167
* @magentoApiDataFixture Magento/Customer/_files/customer.php
160
168
* @expectedException \Exception
161
- * @expectedExceptionMessage Account is not confirmed.
169
+ * @expectedExceptionMessage This account isn't confirmed. Verify and try again .
162
170
*/
163
- public function testChangeCustomerAddressIfAccountIsNotConfirmed ()
171
+ public function testChangePasswordIfAccountIsNotConfirmed ()
164
172
{
165
173
$ customerEmail =
'[email protected] ' ;
166
- $ currentCustomerPassword = 'password ' ;
167
- $ newCustomerPassword = '' ;
174
+ $ currentPassword = 'password ' ;
175
+ $ newPassword = 'anotherPassword1 ' ;
168
176
169
- $ query = $ this ->getChangePassQuery ($ currentCustomerPassword , $ newCustomerPassword );
177
+ /* get header map before setting the customer unconfirmed */
178
+ $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ currentPassword );
179
+
180
+ $ this ->setCustomerConfirmation (1 );
181
+ $ query = $ this ->getQuery ($ currentPassword , $ newPassword );
170
182
171
- $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ currentCustomerPassword );
172
183
$ this ->graphQlMutation ($ query , [], '' , $ headerMap );
173
184
}
174
185
@@ -180,13 +191,13 @@ public function testChangeCustomerAddressIfAccountIsNotConfirmed()
180
191
public function testChangePasswordIfCustomerIsLocked ()
181
192
{
182
193
$ customerEmail =
'[email protected] ' ;
183
- $ currentCustomerPassword = 'password ' ;
184
- $ newCustomerPassword = 'anotherPassword1 ' ;
194
+ $ currentPassword = 'password ' ;
195
+ $ newPassword = 'anotherPassword1 ' ;
185
196
186
197
$ this ->lockCustomer (1 );
187
- $ query = $ this ->getChangePassQuery ( $ currentCustomerPassword , $ newCustomerPassword );
198
+ $ query = $ this ->getQuery ( $ currentPassword , $ newPassword );
188
199
189
- $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ currentCustomerPassword );
200
+ $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ currentPassword );
190
201
$ this ->graphQlMutation ($ query , [], '' , $ headerMap );
191
202
}
192
203
@@ -203,13 +214,26 @@ private function lockCustomer(int $customerId): void
203
214
$ this ->customerAuthUpdate ->saveAuth ($ customerId );
204
215
}
205
216
217
+ /**
218
+ * @param int $customerId
219
+ *
220
+ * @return void
221
+ * @throws LocalizedException
222
+ */
223
+ private function setCustomerConfirmation (int $ customerId ): void
224
+ {
225
+ $ customer = $ this ->customerRepository ->getById ($ customerId );
226
+ $ customer ->setConfirmation ('d5a21f15bd4cc21bd1b21ef6d9989a38 ' );
227
+ $ this ->customerRepository ->save ($ customer );
228
+ }
229
+
206
230
/**
207
231
* @param $currentPassword
208
232
* @param $newPassword
209
233
*
210
234
* @return string
211
235
*/
212
- private function getChangePassQuery ($ currentPassword , $ newPassword )
236
+ private function getQuery ($ currentPassword , $ newPassword )
213
237
{
214
238
$ query = <<<QUERY
215
239
mutation {
0 commit comments