Skip to content

Commit 6c88644

Browse files
committed
GraphQL-672: Change customer password > Check if customer is locked
1 parent 89e61e9 commit 6c88644

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/ChangeCustomerPasswordTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
namespace Magento\GraphQl\Customer;
99

1010
use Magento\Customer\Api\AccountManagementInterface;
11+
use Magento\Customer\Model\CustomerAuthUpdate;
1112
use Magento\Customer\Model\CustomerRegistry;
1213
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\Exception\NoSuchEntityException;
1315
use Magento\Integration\Api\CustomerTokenServiceInterface;
1416
use Magento\TestFramework\Helper\Bootstrap;
1517
use Magento\TestFramework\TestCase\GraphQlAbstract;
@@ -34,11 +36,17 @@ class ChangeCustomerPasswordTest extends GraphQlAbstract
3436
*/
3537
private $customerRegistry;
3638

39+
/**
40+
* @var CustomerAuthUpdate
41+
*/
42+
private $customerAuthUpdate;
43+
3744
protected function setUp()
3845
{
3946
$this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class);
4047
$this->accountManagement = Bootstrap::getObjectManager()->get(AccountManagementInterface::class);
4148
$this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class);
49+
$this->customerAuthUpdate = Bootstrap::getObjectManager()->get(CustomerAuthUpdate::class);
4250
}
4351

4452
/**
@@ -146,6 +154,54 @@ public function testChangePasswordIfNewPasswordIsEmpty()
146154
$this->graphQlMutation($query, [], '', $headerMap);
147155
}
148156

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+
149205
private function getChangePassQuery($currentPassword, $newPassword)
150206
{
151207
$query = <<<QUERY

0 commit comments

Comments
 (0)