objectManager = Bootstrap::getObjectManager(); $this->accountManagement = $this->objectManager->get(AccountManagementInterface::class); $this->customerRegistry = $this->objectManager->get(CustomerRegistry::class); $this->lockCustomer = Bootstrap::getObjectManager()->get(LockCustomer::class); parent::setUp(); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * * @return void * @throws NoSuchEntityException * @throws Exception * * @throws LocalizedException */ public function testResetCustomerAccountPasswordSuccessfully(): void { $query = <<getCustomerEmail()}" resetPasswordToken: "{$this->getResetPasswordToken()}" newPassword: "{$this->getNewPassword()}" ) } QUERY; $response = $this->graphQlMutation($query); self::assertArrayHasKey('resetPassword', $response); self::assertTrue($response['resetPassword']); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * * @throws NoSuchEntityException * @throws Exception * @throws LocalizedException */ public function testEmailAvailableEmptyValue() { $this->expectException(\Exception::class); $this->expectExceptionMessage('You must specify an email address.'); $query = <<getResetPasswordToken()}" newPassword: "{$this->getNewPassword()}" ) } QUERY; $this->graphQlMutation($query); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * * @throws NoSuchEntityException * @throws Exception * @throws LocalizedException */ public function testEmailInvalidValue() { $this->expectException(\Exception::class); $this->expectExceptionMessage('The email address has an invalid format.'); $query = <<getResetPasswordToken()}" newPassword: "{$this->getNewPassword()}" ) } QUERY; $this->graphQlMutation($query); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * * @throws NoSuchEntityException * @throws Exception * @throws LocalizedException */ public function testResetPasswordTokenEmptyValue() { $this->expectException(\Exception::class); $this->expectExceptionMessage('resetPasswordToken must be specified'); $query = <<getCustomerEmail()}" resetPasswordToken: "" newPassword: "{$this->getNewPassword()}" ) } QUERY; $this->graphQlMutation($query); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * * @throws NoSuchEntityException * @throws Exception * @throws LocalizedException */ public function testResetPasswordTokenMismatched() { $this->expectException(\Exception::class); $this->expectExceptionMessage('The password token is mismatched. Reset and try again'); $query = <<getCustomerEmail()}" resetPasswordToken: "1234567890XYZ" newPassword: "{$this->getNewPassword()}" ) } QUERY; $this->graphQlMutation($query); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * * @throws NoSuchEntityException * @throws Exception * @throws LocalizedException */ public function testNewPasswordEmptyValue() { $this->expectException(\Exception::class); $this->expectExceptionMessage('newPassword must be specified'); $query = <<getCustomerEmail()}" resetPasswordToken: "{$this->getResetPasswordToken()}" newPassword: "" ) } QUERY; $this->graphQlMutation($query); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * * @throws NoSuchEntityException * @throws Exception * @throws LocalizedException */ public function testNewPasswordCheckMinLength() { $this->expectException(\Exception::class); $this->expectExceptionMessage('The password needs at least 8 characters. Create a new password and try again'); $query = <<getCustomerEmail()}" resetPasswordToken: "{$this->getResetPasswordToken()}" newPassword: "new_" ) } QUERY; $this->graphQlMutation($query); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * * @throws NoSuchEntityException * @throws Exception * @throws LocalizedException */ public function testNewPasswordCheckCharactersStrength() { $this->expectException(\Exception::class); $this->expectExceptionMessage( 'Minimum of different classes of characters in password is 3. ' . 'Classes of characters: Lower Case, Upper Case, Digits, Special Characters.' ); $query = <<getCustomerEmail()}" resetPasswordToken: "{$this->getResetPasswordToken()}" newPassword: "new_password" ) } QUERY; $this->graphQlMutation($query); } /** * Check password reset for lock customer * * @magentoApiDataFixture Magento/Customer/_files/customer.php * * @throws LocalizedException * @throws NoSuchEntityException */ public function testPasswordResetForLockCustomer() { $this->expectException(\Exception::class); $this->expectExceptionMessage('The account is locked'); $this->lockCustomer->execute(1); $query = <<getCustomerEmail()}" resetPasswordToken: "{$this->getResetPasswordToken()}" newPassword: "{$this->getNewPassword()}" ) } QUERY; $this->graphQlMutation($query); } /** * Get reset password token * * @return string * * @throws LocalizedException * @throws NoSuchEntityException */ private function getResetPasswordToken() { $this->accountManagement->initiatePasswordReset( $this->getCustomerEmail(), AccountManagement::EMAIL_RESET, 1 ); $customerSecure = $this->customerRegistry->retrieveSecureData(1); return $customerSecure->getRpToken(); } /** * Get customer email * * @return string */ private function getCustomerEmail() { return self::CUSTOMER_EMAIL; } /** * Get new password for customer account * * @return string */ private function getNewPassword() { return self::CUSTOMER_NEW_PASSWORD; } }