From 36a59815ee8fcbb7f78ab1b360afd3f250df4d67 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Wed, 13 Mar 2019 17:03:04 +0200 Subject: [PATCH 01/10] 428 - Test coverage: GetAvailableShippingMethodsTest --- .../GetAvailableShippingMethodsTest.php | 184 ++++++++++++++++++ .../Quote/GetAvailableShippingMethodsTest.php | 121 ------------ .../Guest/GetAvailableShippingMethodsTest.php | 162 +++++++++++++++ .../disable_all_active_shipping_methods.php | 39 ++++ ...e_all_active_shipping_methods_rollback.php | 33 ++++ 5 files changed, 418 insertions(+), 121 deletions(-) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php delete mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetAvailableShippingMethodsTest.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods.php create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods_rollback.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php new file mode 100644 index 0000000000000..9a8b3a254c435 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php @@ -0,0 +1,184 @@ +quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteResource = $objectManager->create(QuoteResource::class); + $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); + $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); + } + + /** + * Test case: get available shipping methods from current customer quote + * + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetAvailableShippingMethods() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); + $response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap()); + + self::assertArrayHasKey('cart', $response); + self::assertArrayHasKey('shipping_addresses', $response['cart']); + self::assertCount(1, $response['cart']['shipping_addresses']); + self::assertArrayHasKey('available_shipping_methods', $response['cart']['shipping_addresses'][0]); + self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']); + + $expectedAddressData = [ + 'amount' => 10, + 'base_amount' => 10, + 'carrier_code' => 'flatrate', + 'carrier_title' => 'Flat Rate', + 'error_message' => '', + 'method_code' => 'flatrate', + 'method_title' => 'Fixed', + 'price_incl_tax' => 10, + 'price_excl_tax' => 10, + ]; + self::assertEquals( + $expectedAddressData, + $response['cart']['shipping_addresses'][0]['available_shipping_methods'][0] + ); + } + + /** + * Test case: get available shipping methods from quote of another customer + * + * @magentoApiDataFixture Magento/Customer/_files/three_customers.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetAvailableShippingMethodsFromAnotherCustomerCart() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); + + $this->expectExceptionMessage( + "The current user cannot perform operations on cart \"$maskedQuoteId\"" + ); + + $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap('customer2@search.example.com')); + } + + /** + * Test case: get available shipping methods when all shipping methods are disabled + * + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Checkout/_files/disable_all_active_shipping_methods.php + */ + public function testGetAvailableShippingMethodsIfShippingsAreNotSet() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); + $response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap()); + + self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods'])); + } + + /** + * Test case: get available shipping methods from non-existent cart + * + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @expectedException \Exception + * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" + */ + public function testGetAvailableShippingMethodsOfNonExistentCart() + { + $maskedQuoteId = 'non_existent_masked_id'; + $query = $this->getQuery($maskedQuoteId); + + $this->graphQlQuery($query, [], '', $this->getHeaderMap()); + } + + /** + * @param string $maskedQuoteId + * @return string + */ + private function getQuery( + string $maskedQuoteId + ): string { + return <<customerTokenService->createCustomerAccessToken($username, $password); + $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; + return $headerMap; + } + + /** + * @param string $reservedOrderId + * @return string + */ + private function getMaskedQuoteIdByReservedOrderId(string $reservedOrderId): string + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetAvailableShippingMethodsTest.php deleted file mode 100644 index 1a0ccbd198c37..0000000000000 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetAvailableShippingMethodsTest.php +++ /dev/null @@ -1,121 +0,0 @@ -customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); - $this->quoteResource = $objectManager->create(QuoteResource::class); - $this->quote = $objectManager->create(Quote::class); - $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); - } - - /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php - */ - public function testGetAvailableShippingMethods() - { - $this->quoteResource->load( - $this->quote, - 'test_order_1', - 'reserved_order_id' - ); - $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); - - $query = <<graphQlQuery( - $query, - [], - '', - $this->getCustomerAuthHeaders('customer@example.com', 'password') - ); - self::assertArrayHasKey('cart', $response); - self::assertArrayHasKey('shipping_addresses', $response['cart']); - self::assertCount(1, $response['cart']['shipping_addresses']); - self::assertArrayHasKey('available_shipping_methods', $response['cart']['shipping_addresses'][0]); - self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']); - - $expectedAddressData = [ - 'amount' => 10, - 'base_amount' => 10, - 'carrier_code' => 'flatrate', - 'carrier_title' => 'Flat Rate', - 'error_message' => '', - 'method_code' => 'flatrate', - 'method_title' => 'Fixed', - 'price_incl_tax' => 10, - 'price_excl_tax' => 10, - ]; - self::assertEquals( - $expectedAddressData, - $response['cart']['shipping_addresses'][0]['available_shipping_methods'][0] - ); - } - - /** - * @param string $email - * @param string $password - * @return array - */ - private function getCustomerAuthHeaders(string $email, string $password): array - { - $customerToken = $this->customerTokenService->createCustomerAccessToken($email, $password); - return ['Authorization' => 'Bearer ' . $customerToken]; - } -} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php new file mode 100644 index 0000000000000..8834fd5bfccc5 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php @@ -0,0 +1,162 @@ +quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteResource = $objectManager->create(QuoteResource::class); + $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); + } + + /** + * Test case: get available shipping methods from current customer quote + * + * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + */ + public function testGetAvailableShippingMethodsFromGuestCart() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('guest_quote'); + $response = $this->graphQlQuery($this->getQuery($maskedQuoteId)); + + self::assertArrayHasKey('cart', $response); + self::assertArrayHasKey('shipping_addresses', $response['cart']); + self::assertCount(1, $response['cart']['shipping_addresses']); + self::assertArrayHasKey('available_shipping_methods', $response['cart']['shipping_addresses'][0]); + self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']); + + $expectedAddressData = [ + 'amount' => 5, + 'base_amount' => 5, + 'carrier_code' => 'flatrate', + 'carrier_title' => 'Flat Rate', + 'error_message' => '', + 'method_code' => 'flatrate', + 'method_title' => 'Fixed', + 'price_incl_tax' => 5, + 'price_excl_tax' => 5, + ]; + self::assertEquals( + $expectedAddressData, + $response['cart']['shipping_addresses'][0]['available_shipping_methods'][0] + ); + } + + /** + * Test case: get available shipping methods from customer's quote + * + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetAvailableShippingMethodsFromAnotherCustomerCart() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); + + $this->expectExceptionMessage( + "The current user cannot perform operations on cart \"$maskedQuoteId\"" + ); + + $this->graphQlQuery($this->getQuery($maskedQuoteId)); + } + + /** + * Test case: get available shipping methods when all shipping methods are disabled + * + * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + * @magentoApiDataFixture Magento/Checkout/_files/disable_all_active_shipping_methods.php + */ + public function testGetAvailableShippingMethodsIfShippingsAreNotSet() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('guest_quote'); + $response = $this->graphQlQuery($this->getQuery($maskedQuoteId)); + + self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods'])); + } + + /** + * Test case: get available shipping methods from non-existent cart + * + * @expectedException \Exception + * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" + */ + public function testGetAvailableShippingMethodsOfNonExistentCart() + { + $maskedQuoteId = 'non_existent_masked_id'; + + $this->graphQlQuery($this->getQuery($maskedQuoteId)); + } + + /** + * @param string $maskedQuoteId + * @return string + */ + private function getQuery( + string $maskedQuoteId + ): string { + return <<quoteFactory->create(); + $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods.php new file mode 100644 index 0000000000000..925a3bd6503aa --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods.php @@ -0,0 +1,39 @@ +get(Magento\Shipping\Model\Config::class); +$rollbackConfigKey = 'test/carriers/disabled_shipment_methods'; +$configData = []; +$disabledShipmentMethods = []; + +// Get all active Shipping Methods +foreach ($shippingConfig->getAllCarriers() as $carrierCode => $carrierModel) { + if (!$carrierModel->isActive()) { + continue; + } + + $carrierConfigKey = sprintf('carriers/%s/active', $carrierCode); + $configData[$carrierConfigKey] = 0; + $disabledShipmentMethods[] = $carrierCode; +} + +// Remember all manually disabled Shipping Methods for rollback +$configData[$rollbackConfigKey] = implode(',', $disabledShipmentMethods); + +/** @var Config $defConfig */ +$defConfig = $objectManager->create(Config::class); +$defConfig->setScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT); + +foreach ($configData as $key => $value) { + $defConfig->setDataByPath($key, $value); + $defConfig->save(); +} diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods_rollback.php new file mode 100644 index 0000000000000..a6d7a30e091b1 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods_rollback.php @@ -0,0 +1,33 @@ +create(WriterInterface::class); +$rollbackConfigValue = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class) + ->getStore(\Magento\Store\Model\Store::DEFAULT_STORE_ID) + ->getConfig($rollbackConfigKey); + +$disabledShipmentMethods = []; +if (!empty($rollbackConfigValue)) { + $disabledShipmentMethods = explode(',', $rollbackConfigValue); +} + +if (count($disabledShipmentMethods)) { + foreach ($disabledShipmentMethods as $keyToRemove) { + $configWriter->delete(sprintf('carriers/%s/active', $keyToRemove)); + } +} +$configWriter->delete($rollbackConfigKey); + +$scopeConfig = $objectManager->get(ScopeConfigInterface::class); +$scopeConfig->clean(); From 10a220200eccec74bdb92a85d1dcea8d4d573031 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Wed, 13 Mar 2019 18:51:48 +0200 Subject: [PATCH 02/10] 428 - Test coverage: GetAvailableShippingMethodsTest Fix for PHP Fatal error: Uncaught Exception: Exception occurred when running the "\/home\/travis\/build\/magento\/graphql-ce\/dev\/tests\/integration\/testsuite\/Magento\/Sales\/_files\/guest_quote_with_addresses.php" fixture: URL key for specified store already exists. in /home/travis/build/magento/graphql-ce/dev/tests/api-functional/framework/Magento/TestFramework/Annotation/ApiDataFixture.php:114 --- .../GetAvailableShippingMethodsTest.php | 37 ++++++++++--------- .../Guest/GetAvailableShippingMethodsTest.php | 37 ++++++++++--------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php index 9a8b3a254c435..336eaf4a0b3a6 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -declare(strict_types=1); +declare(strict_types = 1); namespace Magento\GraphQl\Quote\Customer; @@ -44,11 +44,11 @@ class GetAvailableShippingMethodsTest extends GraphQlAbstract */ protected function setUp() { - $objectManager = Bootstrap::getObjectManager(); - $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteResource = $objectManager->create(QuoteResource::class); + $objectManager = Bootstrap::getObjectManager(); + $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteResource = $objectManager->create(QuoteResource::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); - $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); + $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); } /** @@ -59,7 +59,7 @@ protected function setUp() public function testGetAvailableShippingMethods() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); - $response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap()); + $response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId), [], '', $this->getHeaderMap()); self::assertArrayHasKey('cart', $response); self::assertArrayHasKey('shipping_addresses', $response['cart']); @@ -68,13 +68,13 @@ public function testGetAvailableShippingMethods() self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']); $expectedAddressData = [ - 'amount' => 10, - 'base_amount' => 10, - 'carrier_code' => 'flatrate', - 'carrier_title' => 'Flat Rate', - 'error_message' => '', - 'method_code' => 'flatrate', - 'method_title' => 'Fixed', + 'amount' => 10, + 'base_amount' => 10, + 'carrier_code' => 'flatrate', + 'carrier_title' => 'Flat Rate', + 'error_message' => '', + 'method_code' => 'flatrate', + 'method_title' => 'Fixed', 'price_incl_tax' => 10, 'price_excl_tax' => 10, ]; @@ -98,7 +98,7 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart() "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); - $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap('customer2@search.example.com')); + $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId), [], '', $this->getHeaderMap('customer2@search.example.com')); } /** @@ -110,7 +110,7 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart() public function testGetAvailableShippingMethodsIfShippingsAreNotSet() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); - $response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap()); + $response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId), [], '', $this->getHeaderMap()); self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods'])); } @@ -125,7 +125,7 @@ public function testGetAvailableShippingMethodsIfShippingsAreNotSet() public function testGetAvailableShippingMethodsOfNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; - $query = $this->getQuery($maskedQuoteId); + $query = $this->getAvailableShippingMethodsQuery($maskedQuoteId); $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } @@ -134,9 +134,10 @@ public function testGetAvailableShippingMethodsOfNonExistentCart() * @param string $maskedQuoteId * @return string */ - private function getQuery( + private function getAvailableShippingMethodsQuery( string $maskedQuoteId - ): string { + ): string + { return <<quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteResource = $objectManager->create(QuoteResource::class); - $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); + $objectManager = Bootstrap::getObjectManager(); + $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteResource = $objectManager->create(QuoteResource::class); + $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); } /** @@ -52,7 +52,7 @@ protected function setUp() public function testGetAvailableShippingMethodsFromGuestCart() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('guest_quote'); - $response = $this->graphQlQuery($this->getQuery($maskedQuoteId)); + $response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId)); self::assertArrayHasKey('cart', $response); self::assertArrayHasKey('shipping_addresses', $response['cart']); @@ -61,13 +61,13 @@ public function testGetAvailableShippingMethodsFromGuestCart() self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']); $expectedAddressData = [ - 'amount' => 5, - 'base_amount' => 5, - 'carrier_code' => 'flatrate', - 'carrier_title' => 'Flat Rate', - 'error_message' => '', - 'method_code' => 'flatrate', - 'method_title' => 'Fixed', + 'amount' => 5, + 'base_amount' => 5, + 'carrier_code' => 'flatrate', + 'carrier_title' => 'Flat Rate', + 'error_message' => '', + 'method_code' => 'flatrate', + 'method_title' => 'Fixed', 'price_incl_tax' => 5, 'price_excl_tax' => 5, ]; @@ -90,7 +90,7 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart() "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); - $this->graphQlQuery($this->getQuery($maskedQuoteId)); + $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId)); } /** @@ -102,7 +102,7 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart() public function testGetAvailableShippingMethodsIfShippingsAreNotSet() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('guest_quote'); - $response = $this->graphQlQuery($this->getQuery($maskedQuoteId)); + $response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId)); self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods'])); } @@ -117,16 +117,17 @@ public function testGetAvailableShippingMethodsOfNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; - $this->graphQlQuery($this->getQuery($maskedQuoteId)); + $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId)); } /** * @param string $maskedQuoteId * @return string */ - private function getQuery( + private function getAvailableShippingMethodsQuery( string $maskedQuoteId - ): string { + ): string + { return << Date: Thu, 14 Mar 2019 17:30:23 +0200 Subject: [PATCH 03/10] 428 - Test coverage: GetAvailableShippingMethodsTest --- .../GetAvailableShippingMethodsTest.php | 10 ++--- .../Guest/GetAvailableShippingMethodsTest.php | 2 +- .../disable_all_active_shipping_methods.php | 39 ------------------- ...e_all_active_shipping_methods_rollback.php | 33 ---------------- .../disable_offline_shipping_methods.php | 22 +++++++++++ ...able_offline_shipping_methods_rollback.php | 18 +++++++++ .../_files/guest_quote_with_addresses.php | 2 +- 7 files changed, 47 insertions(+), 79 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods.php delete mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods.php create mode 100644 dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods_rollback.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php index 336eaf4a0b3a6..c81d2d99f3514 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php @@ -68,15 +68,15 @@ public function testGetAvailableShippingMethods() self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']); $expectedAddressData = [ - 'amount' => 10, - 'base_amount' => 10, + 'amount' => 0, + 'base_amount' => 0, 'carrier_code' => 'flatrate', 'carrier_title' => 'Flat Rate', 'error_message' => '', 'method_code' => 'flatrate', 'method_title' => 'Fixed', - 'price_incl_tax' => 10, - 'price_excl_tax' => 10, + 'price_incl_tax' => 0, + 'price_excl_tax' => 0, ]; self::assertEquals( $expectedAddressData, @@ -105,7 +105,7 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart() * Test case: get available shipping methods when all shipping methods are disabled * * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php - * @magentoApiDataFixture Magento/Checkout/_files/disable_all_active_shipping_methods.php + * @magentoApiDataFixture Magento/OfflineShipping/_files/disable_offline_shipping_methods.php */ public function testGetAvailableShippingMethodsIfShippingsAreNotSet() { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php index 21ba48ee8a5ec..3b955fb53f6b1 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php @@ -97,7 +97,7 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart() * Test case: get available shipping methods when all shipping methods are disabled * * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php - * @magentoApiDataFixture Magento/Checkout/_files/disable_all_active_shipping_methods.php + * @magentoApiDataFixture Magento/OfflineShipping/_files/disable_offline_shipping_methods.php */ public function testGetAvailableShippingMethodsIfShippingsAreNotSet() { diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods.php deleted file mode 100644 index 925a3bd6503aa..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods.php +++ /dev/null @@ -1,39 +0,0 @@ -get(Magento\Shipping\Model\Config::class); -$rollbackConfigKey = 'test/carriers/disabled_shipment_methods'; -$configData = []; -$disabledShipmentMethods = []; - -// Get all active Shipping Methods -foreach ($shippingConfig->getAllCarriers() as $carrierCode => $carrierModel) { - if (!$carrierModel->isActive()) { - continue; - } - - $carrierConfigKey = sprintf('carriers/%s/active', $carrierCode); - $configData[$carrierConfigKey] = 0; - $disabledShipmentMethods[] = $carrierCode; -} - -// Remember all manually disabled Shipping Methods for rollback -$configData[$rollbackConfigKey] = implode(',', $disabledShipmentMethods); - -/** @var Config $defConfig */ -$defConfig = $objectManager->create(Config::class); -$defConfig->setScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT); - -foreach ($configData as $key => $value) { - $defConfig->setDataByPath($key, $value); - $defConfig->save(); -} diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods_rollback.php deleted file mode 100644 index a6d7a30e091b1..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/disable_all_active_shipping_methods_rollback.php +++ /dev/null @@ -1,33 +0,0 @@ -create(WriterInterface::class); -$rollbackConfigValue = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class) - ->getStore(\Magento\Store\Model\Store::DEFAULT_STORE_ID) - ->getConfig($rollbackConfigKey); - -$disabledShipmentMethods = []; -if (!empty($rollbackConfigValue)) { - $disabledShipmentMethods = explode(',', $rollbackConfigValue); -} - -if (count($disabledShipmentMethods)) { - foreach ($disabledShipmentMethods as $keyToRemove) { - $configWriter->delete(sprintf('carriers/%s/active', $keyToRemove)); - } -} -$configWriter->delete($rollbackConfigKey); - -$scopeConfig = $objectManager->get(ScopeConfigInterface::class); -$scopeConfig->clean(); diff --git a/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods.php b/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods.php new file mode 100644 index 0000000000000..30c64ab7a42a2 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods.php @@ -0,0 +1,22 @@ +get(WriterInterface::class); + +$configWriter->save('carriers/flatrate/active', 0); +$configWriter->save('carriers/tablerate/active', 0); +$configWriter->save('carriers/freeshipping/active', 0); + +$scopeConfig = $objectManager->get(ScopeConfigInterface::class); +$scopeConfig->clean(); diff --git a/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods_rollback.php b/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods_rollback.php new file mode 100644 index 0000000000000..31a16f42adfce --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods_rollback.php @@ -0,0 +1,18 @@ +create(WriterInterface::class); + +$configWriter->delete('carriers/flatrate/active'); +$configWriter->delete('carriers/tablerate/active'); +$configWriter->delete('carriers/freeshipping/active'); diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/guest_quote_with_addresses.php b/dev/tests/integration/testsuite/Magento/Sales/_files/guest_quote_with_addresses.php index b8f2ca38e2489..f25cf8e927ca3 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/guest_quote_with_addresses.php +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/guest_quote_with_addresses.php @@ -14,7 +14,7 @@ $product = $objectManager->create(\Magento\Catalog\Model\Product::class); $product->setTypeId('simple') ->setAttributeSetId($product->getDefaultAttributeSetId()) - ->setName('Simple Product') + ->setName('Simple Product For Guest Quote') ->setSku('simple-product-guest-quote') ->setPrice(10) ->setTaxClassId(0) From d2a7142d4dc2ce27fbd451c6c43dcf951f0d7f2d Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Fri, 15 Mar 2019 13:43:26 +0200 Subject: [PATCH 04/10] 428 - Test coverage: GetAvailableShippingMethodsTest Fix 1) Magento\GraphQl\Quote\Customer\GetAvailableShippingMethodsTest::testGetAvailableShippingMethods Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( - 'amount' => 0 - 'base_amount' => 0 + 'amount' => 10 + 'base_amount' => 10 'carrier_code' => 'flatrate' 'carrier_title' => 'Flat Rate' 'error_message' => '' 'method_code' => 'flatrate' 'method_title' => 'Fixed' - 'price_incl_tax' => 0 - 'price_excl_tax' => 0 + 'price_incl_tax' => 10 + 'price_excl_tax' => 10 --- .../Quote/Customer/GetAvailableShippingMethodsTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php index c81d2d99f3514..da5801cb9a06e 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php @@ -68,15 +68,15 @@ public function testGetAvailableShippingMethods() self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']); $expectedAddressData = [ - 'amount' => 0, - 'base_amount' => 0, + 'amount' => 10, + 'base_amount' => 10, 'carrier_code' => 'flatrate', 'carrier_title' => 'Flat Rate', 'error_message' => '', 'method_code' => 'flatrate', 'method_title' => 'Fixed', - 'price_incl_tax' => 0, - 'price_excl_tax' => 0, + 'price_incl_tax' => 10, + 'price_excl_tax' => 10, ]; self::assertEquals( $expectedAddressData, From 99134c0a1ee7161177ca65889e85b62d2b5f24f8 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Mon, 25 Mar 2019 12:16:58 -0500 Subject: [PATCH 05/10] GraphQL-428: Test coverage: GetAvailableShippingMethodsTest --- .../GetAvailablePaymentMethodsTest.php | 10 ++++----- .../GetAvailableShippingMethodsTest.php | 21 ++++++++++++------- .../Guest/GetAvailablePaymentMethodsTest.php | 8 +++---- .../Guest/GetAvailableShippingMethodsTest.php | 20 +++++++++--------- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php index a7287ada093b8..00627cb893103 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php @@ -54,7 +54,7 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php */ - public function testGetCartWithPaymentMethods() + public function testGetAvailablePaymentMethods() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items'); $query = $this->getQuery($maskedQuoteId); @@ -74,7 +74,7 @@ public function testGetCartWithPaymentMethods() * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php */ - public function testGetPaymentMethodsFromGuestCart() + public function testGetAvailablePaymentMethodsFromGuestCart() { $guestQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId( 'test_order_with_virtual_product_without_address' @@ -91,7 +91,7 @@ public function testGetPaymentMethodsFromGuestCart() * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php */ - public function testGetPaymentMethodsFromAnotherCustomerCart() + public function testGetAvailablePaymentMethodsFromAnotherCustomerCart() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items'); $query = $this->getQuery($maskedQuoteId); @@ -106,7 +106,7 @@ public function testGetPaymentMethodsFromAnotherCustomerCart() * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php * @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php */ - public function testGetPaymentMethodsIfPaymentsAreNotSet() + public function testGetAvailablePaymentMethodsIfAllPaymentsAreDisabled() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items'); $query = $this->getQuery($maskedQuoteId); @@ -120,7 +120,7 @@ public function testGetPaymentMethodsIfPaymentsAreNotSet() * @expectedException \Exception * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" */ - public function testGetPaymentMethodsOfNonExistentCart() + public function testGetAvailablePaymentMethodsOfNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; $query = $this->getQuery($maskedQuoteId); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php index da5801cb9a06e..6f5a9b5d99cbf 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php @@ -46,9 +46,9 @@ protected function setUp() { $objectManager = Bootstrap::getObjectManager(); $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteResource = $objectManager->create(QuoteResource::class); + $this->quoteResource = $objectManager->get(QuoteResource::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); - $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); } /** @@ -59,7 +59,7 @@ protected function setUp() public function testGetAvailableShippingMethods() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); - $response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId), [], '', $this->getHeaderMap()); + $response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap()); self::assertArrayHasKey('cart', $response); self::assertArrayHasKey('shipping_addresses', $response['cart']); @@ -98,7 +98,12 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart() "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); - $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId), [], '', $this->getHeaderMap('customer2@search.example.com')); + $this->graphQlQuery( + $this->getQuery($maskedQuoteId), + [], + '', + $this->getHeaderMap('customer2@search.example.com') + ); } /** @@ -107,10 +112,10 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart() * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php * @magentoApiDataFixture Magento/OfflineShipping/_files/disable_offline_shipping_methods.php */ - public function testGetAvailableShippingMethodsIfShippingsAreNotSet() + public function testGetAvailableShippingMethodsIfAllShippingsAreDisabled() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); - $response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId), [], '', $this->getHeaderMap()); + $response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap()); self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods'])); } @@ -125,7 +130,7 @@ public function testGetAvailableShippingMethodsIfShippingsAreNotSet() public function testGetAvailableShippingMethodsOfNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; - $query = $this->getAvailableShippingMethodsQuery($maskedQuoteId); + $query = $this->getQuery($maskedQuoteId); $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } @@ -134,7 +139,7 @@ public function testGetAvailableShippingMethodsOfNonExistentCart() * @param string $maskedQuoteId * @return string */ - private function getAvailableShippingMethodsQuery( + private function getQuery( string $maskedQuoteId ): string { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php index c4dd9af490c99..d083e8a859e9f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php @@ -47,7 +47,7 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php */ - public function testGetCartWithPaymentMethods() + public function testGetAvailablePaymentMethods() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_with_simple_product_without_address'); $query = $this->getQuery($maskedQuoteId); @@ -73,7 +73,7 @@ public function testGetCartWithPaymentMethods() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php */ - public function testGetPaymentMethodsFromCustomerCart() + public function testGetAvailablePaymentMethodsFromCustomerCart() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); $query = $this->getQuery($maskedQuoteId); @@ -88,7 +88,7 @@ public function testGetPaymentMethodsFromCustomerCart() * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php */ - public function testGetPaymentMethodsIfPaymentsAreNotSet() + public function testGetPaymentMethodsIfPaymentsAreDisabled() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_with_simple_product_without_address'); $query = $this->getQuery($maskedQuoteId); @@ -101,7 +101,7 @@ public function testGetPaymentMethodsIfPaymentsAreNotSet() * @expectedException \Exception * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" */ - public function testGetPaymentMethodsOfNonExistentCart() + public function testGetAvailablePaymentMethodsOfNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; $query = $this->getQuery($maskedQuoteId); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php index 3b955fb53f6b1..c9f8f37669e5d 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php @@ -40,8 +40,8 @@ protected function setUp() { $objectManager = Bootstrap::getObjectManager(); $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteResource = $objectManager->create(QuoteResource::class); - $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); + $this->quoteResource = $objectManager->get(QuoteResource::class); + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); } /** @@ -49,10 +49,10 @@ protected function setUp() * * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php */ - public function testGetAvailableShippingMethodsFromGuestCart() + public function testGetAvailableShippingMethods() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('guest_quote'); - $response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId)); + $response = $this->graphQlQuery($this->getQuery($maskedQuoteId)); self::assertArrayHasKey('cart', $response); self::assertArrayHasKey('shipping_addresses', $response['cart']); @@ -82,7 +82,7 @@ public function testGetAvailableShippingMethodsFromGuestCart() * * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php */ - public function testGetAvailableShippingMethodsFromAnotherCustomerCart() + public function testGetAvailableShippingMethodsFromCustomerCart() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); @@ -90,7 +90,7 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart() "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); - $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId)); + $this->graphQlQuery($this->getQuery($maskedQuoteId)); } /** @@ -99,10 +99,10 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart() * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php * @magentoApiDataFixture Magento/OfflineShipping/_files/disable_offline_shipping_methods.php */ - public function testGetAvailableShippingMethodsIfShippingsAreNotSet() + public function testGetAvailableShippingMethodsIfShippingsAreDisabled() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('guest_quote'); - $response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId)); + $response = $this->graphQlQuery($this->getQuery($maskedQuoteId)); self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods'])); } @@ -117,14 +117,14 @@ public function testGetAvailableShippingMethodsOfNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; - $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId)); + $this->graphQlQuery($this->getQuery($maskedQuoteId)); } /** * @param string $maskedQuoteId * @return string */ - private function getAvailableShippingMethodsQuery( + private function getQuery( string $maskedQuoteId ): string { From 8136c3816dfa47b1f15d7ae61b8f75b9074fb02e Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Mon, 25 Mar 2019 20:30:19 +0200 Subject: [PATCH 06/10] 428 - Test coverage: GetAvailableShippingMethodsTest 1. Rollback fixture changes --- .../Magento/Sales/_files/guest_quote_with_addresses.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/guest_quote_with_addresses.php b/dev/tests/integration/testsuite/Magento/Sales/_files/guest_quote_with_addresses.php index f25cf8e927ca3..b8f2ca38e2489 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/guest_quote_with_addresses.php +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/guest_quote_with_addresses.php @@ -14,7 +14,7 @@ $product = $objectManager->create(\Magento\Catalog\Model\Product::class); $product->setTypeId('simple') ->setAttributeSetId($product->getDefaultAttributeSetId()) - ->setName('Simple Product For Guest Quote') + ->setName('Simple Product') ->setSku('simple-product-guest-quote') ->setPrice(10) ->setTaxClassId(0) From 0b8bebc0698d8433d62e620b8d4ee111ec21797a Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Mon, 25 Mar 2019 15:47:31 -0500 Subject: [PATCH 07/10] GraphQL-428: Test coverage: GetAvailableShippingMethodsTest --- .../Quote/Customer/GetAvailableShippingMethodsTest.php | 4 +--- .../GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php index 6f5a9b5d99cbf..5ca3307371d2f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php @@ -139,9 +139,7 @@ public function testGetAvailableShippingMethodsOfNonExistentCart() * @param string $maskedQuoteId * @return string */ - private function getQuery( - string $maskedQuoteId - ): string + private function getQuery(string $maskedQuoteId): string { return << Date: Tue, 26 Mar 2019 09:36:47 +0200 Subject: [PATCH 08/10] 428 - Test coverage: GetAvailableShippingMethodsTest 1. Fix for "URL key for specified store already exists" --- .../_files/quote_with_simple_product_saved_rollback.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php index 105a981ccfc84..2e333bbcb3049 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php @@ -1,11 +1,13 @@ create(\Magento\Quote\Model\Quote::class); From 18e41ba22fcd5126c7d1731781538f65ce997ab6 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Tue, 26 Mar 2019 12:07:27 +0200 Subject: [PATCH 09/10] 428 - Test coverage: GetAvailableShippingMethodsTest --- .../_files/simple_product_rollback.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/simple_product_rollback.php diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/simple_product_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/simple_product_rollback.php new file mode 100644 index 0000000000000..43beafe822043 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/simple_product_rollback.php @@ -0,0 +1,26 @@ +get(\Magento\Framework\Registry::class); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ +$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); + +try { + $product = $productRepository->get('simple', false, null, true); + $productRepository->delete($product); +} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) { + //Product already removed +} + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); From b64170a5782be475c6ad3a7df74facd13a78a1ed Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Fri, 29 Mar 2019 12:25:58 -0500 Subject: [PATCH 10/10] GraphQL-428: Test coverage: GetAvailableShippingMethodsTest --- .../GetAvailableShippingMethodsTest.php | 92 +++++++++---------- .../Guest/GetAvailableShippingMethodsTest.php | 77 ++++++---------- ...ote_with_simple_product_saved_rollback.php | 4 +- .../_files/simple_product_rollback.php | 2 +- .../disable_offline_shipping_methods.php | 1 + ...able_offline_shipping_methods_rollback.php | 1 + 6 files changed, 80 insertions(+), 97 deletions(-) rename dev/tests/integration/testsuite/Magento/{OfflineShipping => GraphQl/Quote}/_files/disable_offline_shipping_methods.php (89%) rename dev/tests/integration/testsuite/Magento/{OfflineShipping => GraphQl/Quote}/_files/disable_offline_shipping_methods_rollback.php (86%) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php index 5ca3307371d2f..71cf0201951a3 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php @@ -7,10 +7,8 @@ namespace Magento\GraphQl\Quote\Customer; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\Integration\Api\CustomerTokenServiceInterface; -use Magento\Quote\Model\QuoteFactory; -use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; -use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -25,19 +23,9 @@ class GetAvailableShippingMethodsTest extends GraphQlAbstract private $customerTokenService; /** - * @var QuoteIdToMaskedQuoteIdInterface + * @var GetMaskedQuoteIdByReservedOrderId */ - private $quoteIdToMaskedId; - - /** - * @var QuoteFactory - */ - private $quoteFactory; - - /** - * @var QuoteResource - */ - private $quoteResource; + private $getMaskedQuoteIdByReservedOrderId; /** * @inheritdoc @@ -45,20 +33,22 @@ class GetAvailableShippingMethodsTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteResource = $objectManager->get(QuoteResource::class); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); - $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); } /** * Test case: get available shipping methods from current customer quote * - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ public function testGetAvailableShippingMethods() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap()); self::assertArrayHasKey('cart', $response); @@ -84,40 +74,62 @@ public function testGetAvailableShippingMethods() ); } + /** + * _security + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + */ + public function testGetAvailableShippingMethodsFromGuestCart() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); + + $this->expectExceptionMessage( + "The current user cannot perform operations on cart \"$maskedQuoteId\"" + ); + $this->graphQlQuery($query, [], '', $this->getHeaderMap()); + } + /** * Test case: get available shipping methods from quote of another customer * + * _security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ public function testGetAvailableShippingMethodsFromAnotherCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); $this->expectExceptionMessage( "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); - - $this->graphQlQuery( - $this->getQuery($maskedQuoteId), - [], - '', - $this->getHeaderMap('customer2@search.example.com') - ); + $this->graphQlQuery($query, [], '', $this->getHeaderMap('customer3@search.example.com')); } /** * Test case: get available shipping methods when all shipping methods are disabled * - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php - * @magentoApiDataFixture Magento/OfflineShipping/_files/disable_offline_shipping_methods.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/disable_offline_shipping_methods.php */ - public function testGetAvailableShippingMethodsIfAllShippingsAreDisabled() + public function testGetAvailableShippingMethodsIfShippingMethodsAreNotPresent() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap()); - self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods'])); + self::assertEmpty($response['cart']['shipping_addresses'][0]['available_shipping_methods']); } /** @@ -173,16 +185,4 @@ private function getHeaderMap(string $username = 'customer@example.com', string $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; return $headerMap; } - - /** - * @param string $reservedOrderId - * @return string - */ - private function getMaskedQuoteIdByReservedOrderId(string $reservedOrderId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php index 9522d65991cd2..38fda50ba5836 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php @@ -7,9 +7,7 @@ namespace Magento\GraphQl\Quote\Guest; -use Magento\Quote\Model\QuoteFactory; -use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; -use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -19,19 +17,9 @@ class GetAvailableShippingMethodsTest extends GraphQlAbstract { /** - * @var QuoteIdToMaskedQuoteIdInterface + * @var GetMaskedQuoteIdByReservedOrderId */ - private $quoteIdToMaskedId; - - /** - * @var QuoteFactory - */ - private $quoteFactory; - - /** - * @var QuoteResource - */ - private $quoteResource; + private $getMaskedQuoteIdByReservedOrderId; /** * @inheritdoc @@ -39,19 +27,20 @@ class GetAvailableShippingMethodsTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteResource = $objectManager->get(QuoteResource::class); - $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); } /** * Test case: get available shipping methods from current customer quote * - * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ public function testGetAvailableShippingMethods() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('guest_quote'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $response = $this->graphQlQuery($this->getQuery($maskedQuoteId)); self::assertArrayHasKey('cart', $response); @@ -61,15 +50,15 @@ public function testGetAvailableShippingMethods() self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']); $expectedAddressData = [ - 'amount' => 5, - 'base_amount' => 5, + 'amount' => 10, + 'base_amount' => 10, 'carrier_code' => 'flatrate', 'carrier_title' => 'Flat Rate', 'error_message' => '', 'method_code' => 'flatrate', 'method_title' => 'Fixed', - 'price_incl_tax' => 5, - 'price_excl_tax' => 5, + 'price_incl_tax' => 10, + 'price_excl_tax' => 10, ]; self::assertEquals( $expectedAddressData, @@ -78,33 +67,38 @@ public function testGetAvailableShippingMethods() } /** - * Test case: get available shipping methods from customer's quote - * - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * _security + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ public function testGetAvailableShippingMethodsFromCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $this->expectExceptionMessage( "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); - $this->graphQlQuery($this->getQuery($maskedQuoteId)); } /** * Test case: get available shipping methods when all shipping methods are disabled * - * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php - * @magentoApiDataFixture Magento/OfflineShipping/_files/disable_offline_shipping_methods.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/disable_offline_shipping_methods.php */ - public function testGetAvailableShippingMethodsIfShippingsAreDisabled() + public function testGetAvailableShippingMethodsIfShippingMethodsAreNotPresent() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('guest_quote'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $response = $this->graphQlQuery($this->getQuery($maskedQuoteId)); - self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods'])); + self::assertEmpty($response['cart']['shipping_addresses'][0]['available_shipping_methods']); } /** @@ -116,8 +110,9 @@ public function testGetAvailableShippingMethodsIfShippingsAreDisabled() public function testGetAvailableShippingMethodsOfNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; + $query = $this->getQuery($maskedQuoteId); - $this->graphQlQuery($this->getQuery($maskedQuoteId)); + $this->graphQlQuery($query); } /** @@ -146,16 +141,4 @@ private function getQuery(string $maskedQuoteId): string } QUERY; } - - /** - * @param string $reservedOrderId - * @return string - */ - private function getMaskedQuoteIdByReservedOrderId(string $reservedOrderId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php index 2e333bbcb3049..105a981ccfc84 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php @@ -1,13 +1,11 @@ create(\Magento\Quote\Model\Quote::class); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/simple_product_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/simple_product_rollback.php index 43beafe822043..d8744873af00c 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/simple_product_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/simple_product_rollback.php @@ -13,7 +13,7 @@ $registry->register('isSecureArea', true); /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ -$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); +$productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class); try { $product = $productRepository->get('simple', false, null, true); diff --git a/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/disable_offline_shipping_methods.php similarity index 89% rename from dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods.php rename to dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/disable_offline_shipping_methods.php index 30c64ab7a42a2..c5d0468dbfacb 100644 --- a/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods.php +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/disable_offline_shipping_methods.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167 declare(strict_types=1); use Magento\Framework\App\Config\Storage\Writer; diff --git a/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods_rollback.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/disable_offline_shipping_methods_rollback.php similarity index 86% rename from dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods_rollback.php rename to dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/disable_offline_shipping_methods_rollback.php index 31a16f42adfce..384ffbdf51f3c 100644 --- a/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/disable_offline_shipping_methods_rollback.php +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/disable_offline_shipping_methods_rollback.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167 declare(strict_types=1); use Magento\Framework\App\Config\Storage\Writer;