From 95f2c640402c7cec553c9563272a11633fa97524 Mon Sep 17 00:00:00 2001 From: Tomash Khamlai Date: Tue, 8 Oct 2019 15:17:22 +0300 Subject: [PATCH 1/4] Cover GraphQlAuthenticationException "This account isn't confirmed. Verify and try again." Ignore coverage for functionality that is related to the DB constraint violations. Reformat lines for LiveCodeTest Signed-off-by: Tomash Khamlai --- .../Model/Customer/GetCustomer.php | 4 ++ .../GraphQl/Customer/GetCustomerTest.php | 44 ++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Customer/GetCustomer.php b/app/code/Magento/CustomerGraphQl/Model/Customer/GetCustomer.php index 63f42ea1825a..812b3fd28352 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Customer/GetCustomer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Customer/GetCustomer.php @@ -70,6 +70,7 @@ public function execute(ContextInterface $context): CustomerInterface try { $customer = $this->customerRepository->getById($currentUserId); + // @codeCoverageIgnoreStart } catch (NoSuchEntityException $e) { throw new GraphQlNoSuchEntityException( __('Customer with id "%customer_id" does not exist.', ['customer_id' => $currentUserId]), @@ -77,6 +78,7 @@ public function execute(ContextInterface $context): CustomerInterface ); } catch (LocalizedException $e) { throw new GraphQlInputException(__($e->getMessage())); + // @codeCoverageIgnoreEnd } if (true === $this->authentication->isLocked($currentUserId)) { @@ -85,8 +87,10 @@ public function execute(ContextInterface $context): CustomerInterface try { $confirmationStatus = $this->accountManagement->getConfirmationStatus($currentUserId); + // @codeCoverageIgnoreStart } catch (LocalizedException $e) { throw new GraphQlInputException(__($e->getMessage())); + // @codeCoverageIgnoreEnd } if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php index b15a799ae752..b549d370466c 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php @@ -7,6 +7,8 @@ namespace Magento\GraphQl\Customer; +use Magento\Customer\Api\AccountManagementInterface; +use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Model\CustomerAuthUpdate; use Magento\Customer\Model\CustomerRegistry; use Magento\Integration\Api\CustomerTokenServiceInterface; @@ -30,13 +32,25 @@ class GetCustomerTest extends GraphQlAbstract */ private $customerAuthUpdate; + /** + * @var AccountManagementInterface + */ + private $accountManagement; + + /** + * @var CustomerRepositoryInterface + */ + private $customerRepository; + protected function setUp() { parent::setUp(); $this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class); + $this->accountManagement = Bootstrap::getObjectManager()->get(AccountManagementInterface::class); $this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class); $this->customerAuthUpdate = Bootstrap::getObjectManager()->get(CustomerAuthUpdate::class); + $this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class); } /** @@ -57,7 +71,12 @@ public function testGetCustomer() } } QUERY; - $response = $this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword)); + $response = $this->graphQlQuery( + $query, + [], + '', + $this->getCustomerAuthHeaders($currentEmail, $currentPassword) + ); $this->assertEquals(null, $response['customer']['id']); $this->assertEquals('John', $response['customer']['firstname']); @@ -104,7 +123,28 @@ public function testGetCustomerIfAccountIsLocked() } } QUERY; - $this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword)); + $this->graphQlQuery( + $query, + [], + '', + $this->getCustomerAuthHeaders($currentEmail, $currentPassword) + ); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @expectedException \Exception + * @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily + */ + public function testAccountIsNotConfirmed() + { + $confirmation_required = $this->accountManagement::ACCOUNT_CONFIRMATION_REQUIRED; + $customerEmail = 'customer@example.com'; + $currentPassword = 'password'; + $customer = $this->customerRepository->getById(1)->setConfirmation($confirmation_required); + $this->customerRepository->save($customer); + $this->getCustomerAuthHeaders($customerEmail, $currentPassword); } /** From b52c14e601dedc4ece9512d64ad6741c3f3089cc Mon Sep 17 00:00:00 2001 From: Tomash Khamlai Date: Wed, 9 Oct 2019 13:10:26 +0300 Subject: [PATCH 2/4] Corrections after mistake. Signed-off-by: Tomash Khamlai --- .../GraphQl/Customer/GetCustomerTest.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php index b549d370466c..c6540bb1676b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php @@ -135,16 +135,31 @@ public function testGetCustomerIfAccountIsLocked() * @magentoApiDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php * @magentoApiDataFixture Magento/Customer/_files/customer.php * @expectedException \Exception - * @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily + * @expectedExceptionMessage This account isn't confirmed. Verify and try again. */ public function testAccountIsNotConfirmed() { $confirmation_required = $this->accountManagement::ACCOUNT_CONFIRMATION_REQUIRED; $customerEmail = 'customer@example.com'; $currentPassword = 'password'; + $headersMap = $this->getCustomerAuthHeaders($customerEmail, $currentPassword); $customer = $this->customerRepository->getById(1)->setConfirmation($confirmation_required); $this->customerRepository->save($customer); - $this->getCustomerAuthHeaders($customerEmail, $currentPassword); + $query = <<graphQlQuery( + $query, + [], + '', + $headersMap + ); } /** From 6da7a67a2ccc9c763b288e42bfa4767cc44ccbbb Mon Sep 17 00:00:00 2001 From: Tomash Khamlai Date: Fri, 11 Oct 2019 16:04:13 +0300 Subject: [PATCH 3/4] Optimize code. Optimize imports. Signed-off-by: Tomash Khamlai --- .../Magento/GraphQl/Customer/GetCustomerTest.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php index c6540bb1676b..5ed559b88311 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php @@ -32,11 +32,6 @@ class GetCustomerTest extends GraphQlAbstract */ private $customerAuthUpdate; - /** - * @var AccountManagementInterface - */ - private $accountManagement; - /** * @var CustomerRepositoryInterface */ @@ -47,7 +42,6 @@ protected function setUp() parent::setUp(); $this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class); - $this->accountManagement = Bootstrap::getObjectManager()->get(AccountManagementInterface::class); $this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class); $this->customerAuthUpdate = Bootstrap::getObjectManager()->get(CustomerAuthUpdate::class); $this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class); @@ -139,11 +133,12 @@ public function testGetCustomerIfAccountIsLocked() */ public function testAccountIsNotConfirmed() { - $confirmation_required = $this->accountManagement::ACCOUNT_CONFIRMATION_REQUIRED; $customerEmail = 'customer@example.com'; $currentPassword = 'password'; $headersMap = $this->getCustomerAuthHeaders($customerEmail, $currentPassword); - $customer = $this->customerRepository->getById(1)->setConfirmation($confirmation_required); + $customer = $this->customerRepository->getById(1)->setConfirmation( + AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED + ); $this->customerRepository->save($customer); $query = << Date: Fri, 11 Oct 2019 16:13:27 +0300 Subject: [PATCH 4/4] Join comma-separated values into a single line Signed-off-by: Tomash Khamlai --- .../Magento/GraphQl/Customer/GetCustomerTest.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php index 5ed559b88311..8ced4e479e00 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php @@ -7,7 +7,6 @@ namespace Magento\GraphQl\Customer; -use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Model\CustomerAuthUpdate; use Magento\Customer\Model\CustomerRegistry; @@ -137,7 +136,7 @@ public function testAccountIsNotConfirmed() $currentPassword = 'password'; $headersMap = $this->getCustomerAuthHeaders($customerEmail, $currentPassword); $customer = $this->customerRepository->getById(1)->setConfirmation( - AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED + \Magento\Customer\Api\AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED ); $this->customerRepository->save($customer); $query = <<graphQlQuery( - $query, - [], - '', - $headersMap - ); + $this->graphQlQuery($query, [], '', $headersMap); } /**