8
8
namespace Magento \GraphQl \Customer ;
9
9
10
10
use Magento \Customer \Api \AccountManagementInterface ;
11
+ use Magento \Customer \Model \CustomerAuthUpdate ;
11
12
use Magento \Customer \Model \CustomerRegistry ;
12
13
use Magento \Framework \Exception \LocalizedException ;
14
+ use Magento \Framework \Exception \NoSuchEntityException ;
13
15
use Magento \Integration \Api \CustomerTokenServiceInterface ;
14
16
use Magento \TestFramework \Helper \Bootstrap ;
15
17
use Magento \TestFramework \TestCase \GraphQlAbstract ;
@@ -34,11 +36,17 @@ class ChangeCustomerPasswordTest extends GraphQlAbstract
34
36
*/
35
37
private $ customerRegistry ;
36
38
39
+ /**
40
+ * @var CustomerAuthUpdate
41
+ */
42
+ private $ customerAuthUpdate ;
43
+
37
44
protected function setUp ()
38
45
{
39
46
$ this ->customerTokenService = Bootstrap::getObjectManager ()->get (CustomerTokenServiceInterface::class);
40
47
$ this ->accountManagement = Bootstrap::getObjectManager ()->get (AccountManagementInterface::class);
41
48
$ this ->customerRegistry = Bootstrap::getObjectManager ()->get (CustomerRegistry::class);
49
+ $ this ->customerAuthUpdate = Bootstrap::getObjectManager ()->get (CustomerAuthUpdate::class);
42
50
}
43
51
44
52
/**
@@ -146,6 +154,54 @@ public function testChangePasswordIfNewPasswordIsEmpty()
146
154
$ this ->graphQlMutation ($ query , [], '' , $ headerMap );
147
155
}
148
156
157
+ /**
158
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
159
+ * @expectedException \Exception
160
+ * @expectedExceptionMessage Account is not confirmed.
161
+ */
162
+ public function testChangeCustomerAddressIfAccountIsNotConfirmed ()
163
+ {
164
+ $ customerEmail =
'[email protected] ' ;
165
+ $ currentCustomerPassword = 'password ' ;
166
+ $ newCustomerPassword = '' ;
167
+
168
+ $ query = $ this ->getChangePassQuery ($ currentCustomerPassword , $ newCustomerPassword );
169
+
170
+ $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ currentCustomerPassword );
171
+ $ this ->graphQlMutation ($ query , [], '' , $ headerMap );
172
+ }
173
+
174
+ /**
175
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
176
+ * @expectedException \Exception
177
+ * @expectedExceptionMessage The account is locked.
178
+ */
179
+ public function testChangePasswordIfCustomerIsLocked ()
180
+ {
181
+ $ customerEmail =
'[email protected] ' ;
182
+ $ currentCustomerPassword = 'password ' ;
183
+ $ newCustomerPassword = 'anotherPassword1 ' ;
184
+
185
+ $ this ->lockCustomer (1 );
186
+ $ query = $ this ->getChangePassQuery ($ currentCustomerPassword , $ newCustomerPassword );
187
+
188
+ $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ currentCustomerPassword );
189
+ $ this ->graphQlMutation ($ query , [], '' , $ headerMap );
190
+ }
191
+
192
+ /**
193
+ * @param int $customerId
194
+ *
195
+ * @return void
196
+ * @throws NoSuchEntityException
197
+ */
198
+ private function lockCustomer (int $ customerId ): void
199
+ {
200
+ $ customerSecure = $ this ->customerRegistry ->retrieveSecureData ($ customerId );
201
+ $ customerSecure ->setLockExpires ('2030-12-31 00:00:00 ' );
202
+ $ this ->customerAuthUpdate ->saveAuth ($ customerId );
203
+ }
204
+
149
205
private function getChangePassQuery ($ currentPassword , $ newPassword )
150
206
{
151
207
$ query = <<<QUERY
0 commit comments