From 4f19d038cf47cca7664cf9664ee667573200e2da Mon Sep 17 00:00:00 2001 From: Yogesh Suhagiya Date: Tue, 12 Mar 2019 18:39:04 +0530 Subject: [PATCH 1/7] Corrected Mutation Query for SetShippingMethodsOnCartTest --- .../Quote/Guest/SetShippingMethodsOnCartTest.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php index f159cb6f6151e..b452c2cd9d6d2 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php @@ -113,7 +113,7 @@ public function testSetMultipleShippingMethods() * @param string $maskedQuoteId * @param string $shippingMethodCode * @param string $shippingCarrierCode - * @param string $shippingAddressId + * @param int $shippingAddressId * @return string * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ @@ -121,21 +121,20 @@ private function prepareMutationQuery( string $maskedQuoteId, string $shippingMethodCode, string $shippingCarrierCode, - string $shippingAddressId + int $shippingAddressId ) : string { return << Date: Wed, 13 Mar 2019 17:14:51 +0530 Subject: [PATCH 2/7] Covered all the cases of SetShippingMethod for Guest --- .../Guest/SetShippingMethodsOnCartTest.php | 400 +++++++++++++++++- ...ote_with_simple_product_saved_rollback.php | 2 + ...h_virtual_product_and_address_rollback.php | 4 + ...te_with_virtual_product_saved_rollback.php | 2 + .../_files/simple_product_rollback.php | 24 ++ 5 files changed, 419 insertions(+), 13 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/simple_product_rollback.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php index b452c2cd9d6d2..e76974b5290e5 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php @@ -12,6 +12,7 @@ use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; +use Magento\Quote\Model\Quote\Address as QuoteAddress; /** * Test for setting shipping methods on cart for guest @@ -33,6 +34,11 @@ class SetShippingMethodsOnCartTest extends GraphQlAbstract */ private $quoteIdToMaskedId; + /** + * @var QuoteAddress + */ + private $quoteAddress; + /** * @inheritdoc */ @@ -42,71 +48,409 @@ protected function setUp() $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + $this->quoteAddress = $objectManager->get(QuoteAddress::class); } + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php + */ public function testShippingMethodWithVirtualProduct() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = 'flatrate'; + $carrierCode = 'flatrate'; + $reservedOrderId = 'test_order_with_virtual_product_without_address'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + $quoteAddressId = $this->getQuoteAddressIdByReversedQuoteId($reservedOrderId); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode, + $carrierCode, + $quoteAddressId + ); + + self::expectException(\Exception::class); + self::expectExceptionMessage('Carrier with such method not found: ' . $methodCode . ', ' . $methodCode . ''); + $this->graphQlQuery($query); } + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + */ public function testShippingMethodWithSimpleProduct() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = 'flatrate'; + $carrierCode = 'flatrate'; + $reservedOrderId = 'test_order_with_simple_product_without_address'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + $quoteAddressId = $this->getQuoteAddressIdByReversedQuoteId($reservedOrderId); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode, + $carrierCode, + $quoteAddressId + ); + + $response = $this->graphQlQuery($query); + + self::assertArrayHasKey('setShippingMethodsOnCart', $response); + self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); + self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); + + $selectedShippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $selectedShippingMethod); + self::assertEquals($carrierCode, $selectedShippingMethod['selected_shipping_method']['carrier_code']); + self::assertEquals($methodCode, $selectedShippingMethod['selected_shipping_method']['method_code']); } + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @expectedException \Exception + * @expectedExceptionMessage Required parameter "cart_address_id" is missing. + */ public function testShippingMethodWithSimpleProductWithoutAddress() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = 'flatrate'; + $carrierCode = 'flatrate'; + $reservedOrderId = 'test_order_with_simple_product_without_address'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + $quoteAddressId = 0; + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode, + $carrierCode, + $quoteAddressId + ); + + $this->graphQlQuery($query); } + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @expectedException \Exception + * @expectedExceptionMessage Required parameter "method_code" is missing. + */ public function testSetShippingMethodWithMissedRequiredParameters() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = ''; + $carrierCode = 'flatrate'; + $reservedOrderId = 'test_order_with_simple_product_without_address'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + $quoteAddressId = $this->getQuoteAddressIdByReversedQuoteId($reservedOrderId); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode, + $carrierCode, + $quoteAddressId + ); + + $this->graphQlQuery($query); } + /** + * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + */ public function testSetNonExistentShippingMethod() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = 'non-existed-method-code'; + $carrierCode = 'non-carrier-method-code'; + $reservedOrderId = 'guest_quote'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + + /** @var Quote $quote */ + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, 'guest_quote', 'reserved_order_id'); + $quoteAddressId = (int) $quote->getShippingAddress()->getId(); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode, + $carrierCode, + $quoteAddressId + ); + + self::expectException(\Exception::class); + self::expectExceptionMessage('Carrier with such method not found: ' . $carrierCode . ', ' . $methodCode . ''); + $this->graphQlQuery($query); } + /** + * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + */ public function testSetShippingMethodIfAddressIsNotBelongToCart() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = 'flatrate'; + $carrierCode = 'flatrate'; + $reservedOrderId = 'guest_quote'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + + /** @var Quote $quote */ + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, 'test_order_with_virtual_product', 'reserved_order_id'); + $quoteAddressId = (int) $quote->getShippingAddress()->getId(); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode, + $carrierCode, + $quoteAddressId + ); + + self::expectException(\Exception::class); + self::expectExceptionMessage('The current user cannot use cart address with ID "' . $quoteAddressId . '"'); + $this->graphQlQuery($query); } + /** + * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage No such entity with cartId = 0 + */ public function testSetShippingMethodToNonExistentCart() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = 'flatrate'; + $carrierCode = 'flatrate'; + $reservedOrderId = 'non_existent_cart_reversed_quote_id'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + $quoteAddressId = 1; + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode, + $carrierCode, + $quoteAddressId + ); + + $this->graphQlQuery($query); } + /** + * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + */ public function testSetShippingMethodToGuestCart() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = 'flatrate'; + $carrierCode = 'flatrate'; + $reservedOrderId = 'guest_quote'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + + /** @var Quote $quote */ + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); + $quoteAddressId = (int) $quote->getShippingAddress()->getId(); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode, + $carrierCode, + $quoteAddressId + ); + + $response = $this->graphQlQuery($query); + + self::assertArrayHasKey('setShippingMethodsOnCart', $response); + self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); + self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); + + $selectedShippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $selectedShippingMethod); + self::assertEquals($carrierCode, $selectedShippingMethod['selected_shipping_method']['carrier_code']); + self::assertEquals($methodCode, $selectedShippingMethod['selected_shipping_method']['method_code']); } + /** + * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + */ public function testSetShippingMethodToAnotherCustomerCart() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = 'flatrate'; + $carrierCode = 'flatrate'; + $reservedOrderId = 'guest_quote'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_virtual_product'); + + /** @var Quote $quote */ + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); + $quoteAddressId = (int) $quote->getShippingAddress()->getId(); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode, + $carrierCode, + $quoteAddressId + ); + + self::expectException(\Exception::class); + self::expectExceptionMessage( + 'The current user cannot perform operations on cart "' . $maskedQuoteId . '"' + ); + $this->graphQlQuery($query); } + /** + * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + */ public function testSetShippingMethodToNonExistentCartAddress() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = 'flatrate'; + $carrierCode = 'flatrate'; + $reservedOrderId = 'guest_quote'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + + /** @var Quote $quote */ + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); + $quoteAddressId = 1963425585; + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode, + $carrierCode, + $quoteAddressId + ); + + self::expectException(\Exception::class); + self::expectExceptionMessage( + 'Could not find a cart address with ID "' . $quoteAddressId . '"' + ); + $this->graphQlQuery($query); } + /** + * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + */ public function testSetShippingMethodToGuestCartAddress() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = 'flatrate'; + $carrierCode = 'flatrate'; + $reservedOrderId = 'guest_quote'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + + /** @var Quote $quote */ + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); + $quoteAddressId = (int) $quote->getShippingAddress()->getId(); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode, + $carrierCode, + $quoteAddressId + ); + + $response = $this->graphQlQuery($query); + + self::assertArrayHasKey('setShippingMethodsOnCart', $response); + self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); + self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); + + $selectedShippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $selectedShippingMethod); + self::assertEquals($carrierCode, $selectedShippingMethod['selected_shipping_method']['carrier_code']); + self::assertEquals($methodCode, $selectedShippingMethod['selected_shipping_method']['method_code']); } + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ public function testSetShippingMethodToAnotherCustomerCartAddress() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = 'flatrate'; + $carrierCode = 'flatrate'; + $reservedOrderId = 'test_order_1'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + + /** @var Quote $quote */ + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); + $quoteAddressId = (int) $quote->getShippingAddress()->getId(); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode, + $carrierCode, + $quoteAddressId + ); + + self::expectException(\Exception::class); + self::expectExceptionMessage( + 'The current user cannot perform operations on cart "' . $maskedQuoteId . '"' + ); + $this->graphQlQuery($query); } + /** + * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + * @magentoApiDataFixture Magento/Checkout/_files/enable_all_shipping_methods.php + * @expectedException \Exception + * @expectedExceptionMessage You cannot specify multiple shipping methods. + */ public function testSetMultipleShippingMethods() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/422'); + $methodCode = 'flatrate'; + $carrierCode = 'flatrate'; + $reservedOrderId = 'guest_quote'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + + /** @var Quote $quote */ + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); + $shippingAddressId = (int) $quote->getShippingAddress()->getId(); + + $query = <<graphQlQuery($query); } /** @@ -163,4 +507,34 @@ private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): str return $this->quoteIdToMaskedId->execute((int)$quote->getId()); } + + /** + * @param string $reversedQuoteId + * @return int + */ + private function getQuoteAddressIdByReversedQuoteId(string $reversedQuoteId): int + { + $guestAddress = $this->quoteAddress->setData([ + 'firstname'=> 'John', + 'lastname'=> 'Smith', + 'company'=> 'Company Name', + 'street'=> 'Green str, 67', + 'city'=> 'CityM', + 'region' => 'AL', + 'postcode'=> 75477, + 'telephone'=> 3468676, + 'country_id'=> 'US', + 'region_id' => 1 + ]); + + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + + $quote->setBillingAddress($guestAddress); + $quote->setShippingAddress($guestAddress); + $quote->collectTotals(); + $this->quoteResource->save($quote); + + return (int) $quote->getShippingAddress()->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 105a981ccfc84..39b758447221c 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 @@ -14,3 +14,5 @@ /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ $quoteIdMask = $objectManager->create(\Magento\Quote\Model\QuoteIdMask::class); $quoteIdMask->delete($quote->getId()); + +require 'simple_product_rollback.php'; diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address_rollback.php index 2b906bdc022f5..52ce4b4006db8 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address_rollback.php @@ -13,3 +13,7 @@ /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ $quoteIdMask = $objectManager->create(\Magento\Quote\Model\QuoteIdMask::class); $quoteIdMask->delete($quote->getId()); + +require __DIR__ . '/../../Customer/_files/customer_rollback.php'; +require __DIR__ . '/../../Customer/_files/customer_address_rollback.php'; +require __DIR__ . '/../../../Magento/Catalog/_files/product_virtual_rollback.php'; diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved_rollback.php index b3224bb527442..afcb7f56f8d1b 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved_rollback.php @@ -14,3 +14,5 @@ /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ $quoteIdMask = $objectManager->create(\Magento\Quote\Model\QuoteIdMask::class); $quoteIdMask->delete($quote->getId()); + +require __DIR__ . '/../../../Magento/Catalog/_files/product_virtual_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..f03784519f371 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/simple_product_rollback.php @@ -0,0 +1,24 @@ +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 4bdc30ed09f7093c772d359daecd7980e9555e46 Mon Sep 17 00:00:00 2001 From: Yogesh Suhagiya Date: Wed, 13 Mar 2019 17:32:33 +0530 Subject: [PATCH 3/7] Fixed issue of undefined variable: objectManager --- .../Magento/Checkout/_files/simple_product_rollback.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 f03784519f371..43beafe822043 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 @@ -3,9 +3,11 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +/** @var \Magento\Framework\ObjectManagerInterface $objectManager */ +$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var \Magento\Framework\Registry $registry */ -$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class); +$registry = $objectManager->get(\Magento\Framework\Registry::class); $registry->unregister('isSecureArea'); $registry->register('isSecureArea', true); From f9ecace0ff70df87cf8c08de17ee5cf557f8d339 Mon Sep 17 00:00:00 2001 From: Yogesh Suhagiya Date: Wed, 13 Mar 2019 18:52:02 +0530 Subject: [PATCH 4/7] Renamed variable and keep name length under 20. --- .../Guest/SetShippingMethodsOnCartTest.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php index e76974b5290e5..f6444027d0ca3 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php @@ -100,10 +100,10 @@ public function testShippingMethodWithSimpleProduct() self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); - $selectedShippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $selectedShippingMethod); - self::assertEquals($carrierCode, $selectedShippingMethod['selected_shipping_method']['carrier_code']); - self::assertEquals($methodCode, $selectedShippingMethod['selected_shipping_method']['method_code']); + $shippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingMethod); + self::assertEquals($carrierCode, $shippingMethod['selected_shipping_method']['carrier_code']); + self::assertEquals($methodCode, $shippingMethod['selected_shipping_method']['method_code']); } /** @@ -264,10 +264,10 @@ public function testSetShippingMethodToGuestCart() self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); - $selectedShippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $selectedShippingMethod); - self::assertEquals($carrierCode, $selectedShippingMethod['selected_shipping_method']['carrier_code']); - self::assertEquals($methodCode, $selectedShippingMethod['selected_shipping_method']['method_code']); + $shippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingMethod); + self::assertEquals($carrierCode, $shippingMethod['selected_shipping_method']['carrier_code']); + self::assertEquals($methodCode, $shippingMethod['selected_shipping_method']['method_code']); } /** @@ -360,10 +360,10 @@ public function testSetShippingMethodToGuestCartAddress() self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); - $selectedShippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $selectedShippingMethod); - self::assertEquals($carrierCode, $selectedShippingMethod['selected_shipping_method']['carrier_code']); - self::assertEquals($methodCode, $selectedShippingMethod['selected_shipping_method']['method_code']); + $shippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingMethod); + self::assertEquals($carrierCode, $shippingMethod['selected_shipping_method']['carrier_code']); + self::assertEquals($methodCode, $shippingMethod['selected_shipping_method']['method_code']); } /** From 16ce0467b88b7ded25b9d1e25bd1393784a615c2 Mon Sep 17 00:00:00 2001 From: Yogesh Suhagiya Date: Tue, 26 Mar 2019 12:16:55 +0530 Subject: [PATCH 5/7] Removed duplicate case & applied logic fixes --- .../Guest/SetShippingMethodsOnCartTest.php | 75 +++++++------------ 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php index f6444027d0ca3..eadc131ee464a 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php @@ -71,21 +71,25 @@ public function testShippingMethodWithVirtualProduct() ); self::expectException(\Exception::class); - self::expectExceptionMessage('Carrier with such method not found: ' . $methodCode . ', ' . $methodCode . ''); + self::expectExceptionMessage('You can\'t set shipping methods for virtual products'); $this->graphQlQuery($query); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php */ public function testShippingMethodWithSimpleProduct() { $methodCode = 'flatrate'; $carrierCode = 'flatrate'; - $reservedOrderId = 'test_order_with_simple_product_without_address'; + $reservedOrderId = 'guest_quote'; $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - $quoteAddressId = $this->getQuoteAddressIdByReversedQuoteId($reservedOrderId); + + /** @var Quote $quote */ + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); + $quoteAddressId = (int) $quote->getShippingAddress()->getId(); $query = $this->prepareMutationQuery( $maskedQuoteId, @@ -109,27 +113,38 @@ public function testShippingMethodWithSimpleProduct() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @expectedException \Exception - * @expectedExceptionMessage Required parameter "cart_address_id" is missing. */ - public function testShippingMethodWithSimpleProductWithoutAddress() + public function testShippingMethodWithSimpleProductWithoutAddress(int $addressId, string $message) { $methodCode = 'flatrate'; $carrierCode = 'flatrate'; $reservedOrderId = 'test_order_with_simple_product_without_address'; $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - $quoteAddressId = 0; - $query = $this->prepareMutationQuery( $maskedQuoteId, $methodCode, $carrierCode, - $quoteAddressId + $addressId ); + $this->expectExceptionMessage($message); $this->graphQlQuery($query); } + /** + * @return array + */ + public function dataProviderWithMissedRequiredParameters() + { + return [ + 'shipping_methods' => [ + 0, + 'Required parameter "cart_address_id" is missing.', + ] + ]; + } + /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @expectedException \Exception @@ -213,16 +228,15 @@ public function testSetShippingMethodIfAddressIsNotBelongToCart() /** * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage No such entity with cartId = 0 + * @expectedException \Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException + * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" */ public function testSetShippingMethodToNonExistentCart() { $methodCode = 'flatrate'; $carrierCode = 'flatrate'; - $reservedOrderId = 'non_existent_cart_reversed_quote_id'; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + $maskedQuoteId = 'non_existent_masked_id'; $quoteAddressId = 1; $query = $this->prepareMutationQuery( @@ -235,41 +249,6 @@ public function testSetShippingMethodToNonExistentCart() $this->graphQlQuery($query); } - /** - * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php - */ - public function testSetShippingMethodToGuestCart() - { - $methodCode = 'flatrate'; - $carrierCode = 'flatrate'; - $reservedOrderId = 'guest_quote'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - - /** @var Quote $quote */ - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); - $quoteAddressId = (int) $quote->getShippingAddress()->getId(); - - $query = $this->prepareMutationQuery( - $maskedQuoteId, - $methodCode, - $carrierCode, - $quoteAddressId - ); - - $response = $this->graphQlQuery($query); - - self::assertArrayHasKey('setShippingMethodsOnCart', $response); - self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); - self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); - - $shippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $shippingMethod); - self::assertEquals($carrierCode, $shippingMethod['selected_shipping_method']['carrier_code']); - self::assertEquals($methodCode, $shippingMethod['selected_shipping_method']['method_code']); - } - /** * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php From c2f15b388db0ba654920289f32a3e3e0def072e2 Mon Sep 17 00:00:00 2001 From: Yogesh Suhagiya Date: Tue, 26 Mar 2019 12:53:33 +0530 Subject: [PATCH 6/7] Added data Provider --- .../GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php index eadc131ee464a..2fc919fd86689 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php @@ -112,6 +112,9 @@ public function testShippingMethodWithSimpleProduct() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @dataProvider dataProviderWithMissedRequiredParameters + * @param int $addressId + * @param string $message * @expectedException \Exception */ public function testShippingMethodWithSimpleProductWithoutAddress(int $addressId, string $message) From 829a39b3578f2236e8fe5645822a57afe42a5666 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Fri, 29 Mar 2019 11:25:43 -0500 Subject: [PATCH 7/7] GraphQL-422: Test coverage: SetShippingMethodsOnCartTest for Guest --- .../Model/Cart/GetQuoteAddress.php | 21 +- .../Model/Cart/SetShippingMethodsOnCart.php | 3 +- .../Customer/SetBillingAddressOnCartTest.php | 18 +- .../Customer/SetPaymentMethodOnCartTest.php | 12 +- .../GetMaskedQuoteIdByReservedOrderId.php | 3 +- ...uoteShippingAddressIdByReservedQuoteId.php | 53 ++ .../Guest/SetBillingAddressOnCartTest.php | 29 +- .../Guest/SetPaymentMethodOnCartTest.php | 12 +- .../Guest/SetShippingMethodsOnCartTest.php | 610 +++++++----------- ...h_virtual_product_and_address_rollback.php | 2 +- .../_files/simple_product_rollback.php | 2 +- .../Quote/_files/guest/quote_with_address.php | 49 ++ .../guest/quote_with_address_rollback.php | 28 + .../_files/set_flatrate_shipping_method.php | 36 ++ 14 files changed, 474 insertions(+), 404 deletions(-) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetQuoteShippingAddressIdByReservedQuoteId.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/quote_with_address.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/quote_with_address_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/GetQuoteAddress.php b/app/code/Magento/QuoteGraphQl/Model/Cart/GetQuoteAddress.php index 1fb737d964139..89124c594dd87 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/GetQuoteAddress.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/GetQuoteAddress.php @@ -8,10 +8,10 @@ namespace Magento\QuoteGraphQl\Model\Cart; use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; -use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Quote\Api\Data\AddressInterface; use Magento\Quote\Api\Data\AddressInterfaceFactory; +use Magento\Quote\Api\Data\CartInterface; use Magento\Quote\Model\ResourceModel\Quote\Address as AddressResource; /** @@ -44,14 +44,14 @@ public function __construct( /** * Get quote address * + * @param CartInterface $cart * @param int $quoteAddressId * @param int|null $customerId * @return AddressInterface - * @throws GraphQlInputException - * @throws GraphQlNoSuchEntityException * @throws GraphQlAuthorizationException + * @throws GraphQlNoSuchEntityException */ - public function execute(int $quoteAddressId, ?int $customerId): AddressInterface + public function execute(CartInterface $cart, int $quoteAddressId, ?int $customerId): AddressInterface { $quoteAddress = $this->quoteAddressFactory->create(); @@ -62,14 +62,15 @@ public function execute(int $quoteAddressId, ?int $customerId): AddressInterface ); } - $quoteAddressCustomerId = (int)$quoteAddress->getCustomerId(); - - /* Guest cart, allow operations */ - if (!$quoteAddressCustomerId && null === $customerId) { - return $quoteAddress; + // TODO: GetQuoteAddress::execute should depend only on AddressInterface contract + // https://github.com/magento/graphql-ce/issues/550 + if ($quoteAddress->getQuoteId() !== $cart->getId()) { + throw new GraphQlNoSuchEntityException( + __('Cart does not contain address with ID "%cart_address_id"', ['cart_address_id' => $quoteAddressId]) + ); } - if ($quoteAddressCustomerId !== $customerId) { + if ((int)$quoteAddress->getCustomerId() !== (int)$customerId) { throw new GraphQlAuthorizationException( __( 'The current user cannot use cart address with ID "%cart_address_id"', diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/SetShippingMethodsOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/SetShippingMethodsOnCart.php index 37e0118423745..4104e179160d9 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/SetShippingMethodsOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/SetShippingMethodsOnCart.php @@ -69,8 +69,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s } $methodCode = $shippingMethodInput['method_code']; - $quoteAddress = $this->getQuoteAddress->execute($cartAddressId, $context->getUserId()); - + $quoteAddress = $this->getQuoteAddress->execute($cart, $cartAddressId, $context->getUserId()); $this->assignShippingMethodToCart->execute($cart, $quoteAddress, $carrierCode, $methodCode); } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index 129375debe068..88e7b93dd1d08 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -429,6 +429,7 @@ public function testSetBillingAddressIfCustomerIsNotOwnerOfAddress() /** * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @expectedException \Exception * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" */ @@ -436,10 +437,19 @@ public function testSetBillingAddressOnNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; $query = <<getQuery($maskedQuoteId, $methodCode); $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php index c5a4e8af02a58..eab362c3a0a6f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php @@ -7,6 +7,7 @@ namespace Magento\GraphQl\Quote; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\QuoteFactory; @@ -51,7 +52,7 @@ public function __construct( * * @param string $reversedOrderId * @return string - * @throws \Magento\Framework\Exception\NoSuchEntityException + * @throws NoSuchEntityException */ public function execute(string $reversedOrderId): string { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetQuoteShippingAddressIdByReservedQuoteId.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetQuoteShippingAddressIdByReservedQuoteId.php new file mode 100644 index 0000000000000..fa42ad4d71fb2 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetQuoteShippingAddressIdByReservedQuoteId.php @@ -0,0 +1,53 @@ +quoteFactory = $quoteFactory; + $this->quoteResource = $quoteResource; + } + + /** + * Get quote shipping address id by reserved order id + * + * @param string $reversedOrderId + * @return int + */ + public function execute(string $reversedOrderId): int + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); + + return (int)$quote->getShippingAddress()->getId(); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php index 3808ce38b9d7b..ae0a1a0e822ac 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php @@ -248,10 +248,30 @@ public function testSetBillingAddressOnNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; $query = <<expectExceptionMessage($message); $this->graphQlQuery($query); } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php index 8f37f00c3db7f..c9078fd84f6bc 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php @@ -113,15 +113,9 @@ public function testSetNonExistentPaymentMethod() public function testSetPaymentOnNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; - $query = <<getQuery($maskedQuoteId, $methodCode); $this->graphQlQuery($query); } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php index 07ccfc7bf727e..6289d88de6ee4 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php @@ -7,12 +7,10 @@ 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\GraphQl\Quote\GetQuoteShippingAddressIdByReservedQuoteId; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; -use Magento\Quote\Model\Quote\Address as QuoteAddress; /** * Test for setting shipping methods on cart for guest @@ -20,24 +18,14 @@ class SetShippingMethodsOnCartTest extends GraphQlAbstract { /** - * @var QuoteResource + * @var GetMaskedQuoteIdByReservedOrderId */ - private $quoteResource; + private $getMaskedQuoteIdByReservedOrderId; /** - * @var QuoteFactory + * @var GetQuoteShippingAddressIdByReservedQuoteId */ - private $quoteFactory; - - /** - * @var QuoteIdToMaskedQuoteIdInterface - */ - private $quoteIdToMaskedId; - - /** - * @var QuoteAddress - */ - private $quoteAddress; + private $getQuoteShippingAddressIdByReservedQuoteId; /** * @inheritdoc @@ -45,410 +33,355 @@ class SetShippingMethodsOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->quoteResource = $objectManager->get(QuoteResource::class); - $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); - $this->quoteAddress = $objectManager->get(QuoteAddress::class); - } - - /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php - */ - public function testShippingMethodWithVirtualProduct() - { - $methodCode = 'flatrate'; - $carrierCode = 'flatrate'; - $reservedOrderId = 'test_order_with_virtual_product_without_address'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - $quoteAddressId = $this->getQuoteAddressIdByReversedQuoteId($reservedOrderId); - - $query = $this->prepareMutationQuery( - $maskedQuoteId, - $methodCode, - $carrierCode, - $quoteAddressId + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); + $this->getQuoteShippingAddressIdByReservedQuoteId = $objectManager->get( + GetQuoteShippingAddressIdByReservedQuoteId::class ); - - self::expectException(\Exception::class); - self::expectExceptionMessage('You can\'t set shipping methods for virtual products'); - $this->graphQlQuery($query); } /** - * @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 testShippingMethodWithSimpleProduct() + public function testSetShippingMethodOnCartWithSimpleProduct() { - $methodCode = 'flatrate'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $carrierCode = 'flatrate'; - $reservedOrderId = 'guest_quote'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - - /** @var Quote $quote */ - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); - $quoteAddressId = (int) $quote->getShippingAddress()->getId(); + $methodCode = 'flatrate'; + $quoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('test_quote'); - $query = $this->prepareMutationQuery( + $query = $this->getQuery( $maskedQuoteId, $methodCode, $carrierCode, $quoteAddressId ); - $response = $this->graphQlQuery($query); self::assertArrayHasKey('setShippingMethodsOnCart', $response); self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); + self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - $shippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $shippingMethod); - self::assertEquals($carrierCode, $shippingMethod['selected_shipping_method']['carrier_code']); - self::assertEquals($methodCode, $shippingMethod['selected_shipping_method']['method_code']); - } - - /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php - * @dataProvider dataProviderWithMissedRequiredParameters - * @param int $addressId - * @param string $message - * @expectedException \Exception - */ - public function testShippingMethodWithSimpleProductWithoutAddress(int $addressId, string $message) - { - $methodCode = 'flatrate'; - $carrierCode = 'flatrate'; - $reservedOrderId = 'test_order_with_simple_product_without_address'; + $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingAddress); - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - $query = $this->prepareMutationQuery( - $maskedQuoteId, - $methodCode, - $carrierCode, - $addressId - ); + self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($carrierCode, $shippingAddress['selected_shipping_method']['carrier_code']); - $this->expectExceptionMessage($message); - $this->graphQlQuery($query); + self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); } /** - * @return array - */ - public function dataProviderWithMissedRequiredParameters() - { - return [ - 'shipping_methods' => [ - 0, - 'Required parameter "cart_address_id" is missing.', - ] - ]; - } - - /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.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 + * * @expectedException \Exception - * @expectedExceptionMessage Required parameter "method_code" is missing. + * @expectedExceptionMessage The shipping address is missing. Set the address and try again. */ - public function testSetShippingMethodWithMissedRequiredParameters() + public function testSetShippingMethodOnCartWithSimpleProductAndWithoutAddress() { - $methodCode = ''; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $carrierCode = 'flatrate'; - $reservedOrderId = 'test_order_with_simple_product_without_address'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - $quoteAddressId = $this->getQuoteAddressIdByReversedQuoteId($reservedOrderId); + $methodCode = 'flatrate'; + $quoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('test_quote'); - $query = $this->prepareMutationQuery( + $query = $this->getQuery( $maskedQuoteId, $methodCode, $carrierCode, $quoteAddressId ); - $this->graphQlQuery($query); } /** - * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_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/set_flatrate_shipping_method.php */ - public function testSetNonExistentShippingMethod() + public function testReSetShippingMethod() { - $methodCode = 'non-existed-method-code'; - $carrierCode = 'non-carrier-method-code'; - $reservedOrderId = 'guest_quote'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - - /** @var Quote $quote */ - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, 'guest_quote', 'reserved_order_id'); - $quoteAddressId = (int) $quote->getShippingAddress()->getId(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $carrierCode = 'freeshipping'; + $methodCode = 'freeshipping'; + $quoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('test_quote'); - $query = $this->prepareMutationQuery( + $query = $this->getQuery( $maskedQuoteId, $methodCode, $carrierCode, $quoteAddressId ); + $response = $this->graphQlQuery($query); - self::expectException(\Exception::class); - self::expectExceptionMessage('Carrier with such method not found: ' . $carrierCode . ', ' . $methodCode . ''); - $this->graphQlQuery($query); - } - - /** - * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php - */ - public function testSetShippingMethodIfAddressIsNotBelongToCart() - { - $methodCode = 'flatrate'; - $carrierCode = 'flatrate'; - $reservedOrderId = 'guest_quote'; + self::assertArrayHasKey('setShippingMethodsOnCart', $response); + self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); + self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); + self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingAddress); - /** @var Quote $quote */ - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, 'test_order_with_virtual_product', 'reserved_order_id'); - $quoteAddressId = (int) $quote->getShippingAddress()->getId(); + self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($carrierCode, $shippingAddress['selected_shipping_method']['carrier_code']); - $query = $this->prepareMutationQuery( - $maskedQuoteId, - $methodCode, - $carrierCode, - $quoteAddressId - ); - - self::expectException(\Exception::class); - self::expectExceptionMessage('The current user cannot use cart address with ID "' . $quoteAddressId . '"'); - $this->graphQlQuery($query); + self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); } /** - * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php - * @expectedException \Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException - * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" + * @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 + * + * @param string $input + * @param string $message + * @dataProvider dataProviderSetShippingMethodWithWrongParameters + * @throws \Exception */ - public function testSetShippingMethodToNonExistentCart() + public function testSetShippingMethodWithWrongParameters(string $input, string $message) { - $methodCode = 'flatrate'; - $carrierCode = 'flatrate'; - - $maskedQuoteId = 'non_existent_masked_id'; - $quoteAddressId = 1; - - $query = $this->prepareMutationQuery( - $maskedQuoteId, - $methodCode, - $carrierCode, - $quoteAddressId - ); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $quoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('test_quote'); + $input = str_replace(['cart_id_value', 'cart_address_id_value'], [$maskedQuoteId, $quoteAddressId], $input); + $query = <<expectExceptionMessage($message); $this->graphQlQuery($query); } /** - * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + * @return array + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testSetShippingMethodToAnotherCustomerCart() + public function dataProviderSetShippingMethodWithWrongParameters(): array { - $methodCode = 'flatrate'; - $carrierCode = 'flatrate'; - $reservedOrderId = 'guest_quote'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_virtual_product'); - - /** @var Quote $quote */ - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); - $quoteAddressId = (int) $quote->getShippingAddress()->getId(); - - $query = $this->prepareMutationQuery( - $maskedQuoteId, - $methodCode, - $carrierCode, - $quoteAddressId - ); - - self::expectException(\Exception::class); - self::expectExceptionMessage( - 'The current user cannot perform operations on cart "' . $maskedQuoteId . '"' - ); - $this->graphQlQuery($query); + return [ + 'missed_cart_id' => [ + 'shipping_methods: [{ + cart_address_id: cart_address_id_value + carrier_code: "flatrate" + method_code: "flatrate" + }]', + 'Required parameter "cart_id" is missing' + ], + 'missed_shipping_methods' => [ + 'cart_id: "cart_id_value"', + 'Required parameter "shipping_methods" is missing' + ], + 'shipping_methods_are_empty' => [ + 'cart_id: "cart_id_value" shipping_methods: []', + 'Required parameter "shipping_methods" is missing' + ], + 'missed_cart_address_id' => [ + 'cart_id: "cart_id_value", shipping_methods: [{ + carrier_code: "flatrate" + method_code: "flatrate" + }]', + 'Required parameter "cart_address_id" is missing.' + ], + 'non_existent_cart_address_id' => [ + 'cart_id: "cart_id_value", shipping_methods: [{ + cart_address_id: -1 + carrier_code: "flatrate" + method_code: "flatrate" + }]', + 'Could not find a cart address with ID "-1"' + ], + 'missed_carrier_code' => [ + 'cart_id: "cart_id_value", shipping_methods: [{ + cart_address_id: cart_address_id_value + method_code: "flatrate" + }]', + 'Field ShippingMethodInput.carrier_code of required type String! was not provided.' + ], + 'empty_carrier_code' => [ + 'cart_id: "cart_id_value", shipping_methods: [{ + cart_address_id: cart_address_id_value + carrier_code: "" + method_code: "flatrate" + }]', + 'Required parameter "carrier_code" is missing.' + ], + 'non_existent_carrier_code' => [ + 'cart_id: "cart_id_value", shipping_methods: [{ + cart_address_id: cart_address_id_value + carrier_code: "wrong-carrier-code" + method_code: "flatrate" + }]', + 'Carrier with such method not found: wrong-carrier-code, flatrate' + ], + 'missed_method_code' => [ + 'cart_id: "cart_id_value", shipping_methods: [{ + cart_address_id: cart_address_id_value + carrier_code: "flatrate" + }]', + 'Required parameter "method_code" is missing.' + ], + 'empty_method_code' => [ + 'cart_id: "cart_id_value", shipping_methods: [{ + cart_address_id: cart_address_id_value + carrier_code: "flatrate" + method_code: "" + }]', + 'Required parameter "method_code" is missing.' + ], + 'non_existent_method_code' => [ + 'cart_id: "cart_id_value", shipping_methods: [{ + cart_address_id: cart_address_id_value + carrier_code: "flatrate" + method_code: "wrong-carrier-code" + }]', + 'Carrier with such method not found: flatrate, wrong-carrier-code' + ], + 'non_existent_shopping_cart' => [ + 'cart_id: "non_existent_masked_id", shipping_methods: [{ + cart_address_id: cart_address_id_value + carrier_code: "flatrate" + method_code: "flatrate" + }]', + 'Could not find a cart with ID "non_existent_masked_id"' + ], + ]; } /** - * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_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 + * @expectedException \Exception + * @expectedExceptionMessage You cannot specify multiple shipping methods. */ - public function testSetShippingMethodToNonExistentCartAddress() + public function testSetMultipleShippingMethods() { - $methodCode = 'flatrate'; - $carrierCode = 'flatrate'; - $reservedOrderId = 'guest_quote'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $quoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('test_quote'); - /** @var Quote $quote */ - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); - $quoteAddressId = 1963425585; - - $query = $this->prepareMutationQuery( - $maskedQuoteId, - $methodCode, - $carrierCode, - $quoteAddressId - ); - - self::expectException(\Exception::class); - self::expectExceptionMessage( - 'Could not find a cart address with ID "' . $quoteAddressId . '"' - ); + $query = <<graphQlQuery($query); } /** - * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.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 + * + * @expectedException \Exception */ - public function testSetShippingMethodToGuestCartAddress() + public function testSetShippingMethodToCustomerCart() { - $methodCode = 'flatrate'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $carrierCode = 'flatrate'; - $reservedOrderId = 'guest_quote'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - - /** @var Quote $quote */ - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); - $quoteAddressId = (int) $quote->getShippingAddress()->getId(); - - $query = $this->prepareMutationQuery( + $methodCode = 'flatrate'; + $quoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('test_quote'); + $query = $this->getQuery( $maskedQuoteId, $methodCode, $carrierCode, $quoteAddressId ); - $response = $this->graphQlQuery($query); - - self::assertArrayHasKey('setShippingMethodsOnCart', $response); - self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); - self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); - - $shippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $shippingMethod); - self::assertEquals($carrierCode, $shippingMethod['selected_shipping_method']['carrier_code']); - self::assertEquals($methodCode, $shippingMethod['selected_shipping_method']['method_code']); + $this->expectExceptionMessage( + "The current user cannot perform operations on cart \"$maskedQuoteId\"" + ); + $this->graphQlQuery($query); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * _security + * + * @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/guest/quote_with_address.php */ - public function testSetShippingMethodToAnotherCustomerCartAddress() + public function testSetShippingMethodIfGuestIsNotOwnerOfAddress() { - $methodCode = 'flatrate'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $carrierCode = 'flatrate'; - $reservedOrderId = 'test_order_1'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - - /** @var Quote $quote */ - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); - $quoteAddressId = (int) $quote->getShippingAddress()->getId(); - - $query = $this->prepareMutationQuery( + $methodCode = 'flatrate'; + $anotherQuoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('guest_quote_with_address'); + $query = $this->getQuery( $maskedQuoteId, $methodCode, $carrierCode, - $quoteAddressId + $anotherQuoteAddressId ); - self::expectException(\Exception::class); - self::expectExceptionMessage( - 'The current user cannot perform operations on cart "' . $maskedQuoteId . '"' + $this->expectExceptionMessage( + "Cart does not contain address with ID \"{$anotherQuoteAddressId}\"" ); $this->graphQlQuery($query); } - /** - * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php - * @magentoApiDataFixture Magento/Checkout/_files/enable_all_shipping_methods.php - * @expectedException \Exception - * @expectedExceptionMessage You cannot specify multiple shipping methods. - */ - public function testSetMultipleShippingMethods() - { - $methodCode = 'flatrate'; - $carrierCode = 'flatrate'; - $reservedOrderId = 'guest_quote'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - - /** @var Quote $quote */ - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); - $shippingAddressId = (int) $quote->getShippingAddress()->getId(); - - $query = <<graphQlQuery($query); - } - /** * @param string $maskedQuoteId * @param string $shippingMethodCode * @param string $shippingCarrierCode * @param int $shippingAddressId * @return string - * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function prepareMutationQuery( + private function getQuery( string $maskedQuoteId, string $shippingMethodCode, string $shippingCarrierCode, int $shippingAddressId - ) : string { + ): string { return <<quoteFactory->create(); - $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } - - /** - * @param string $reversedQuoteId - * @return int - */ - private function getQuoteAddressIdByReversedQuoteId(string $reversedQuoteId): int - { - $guestAddress = $this->quoteAddress->setData([ - 'firstname'=> 'John', - 'lastname'=> 'Smith', - 'company'=> 'Company Name', - 'street'=> 'Green str, 67', - 'city'=> 'CityM', - 'region' => 'AL', - 'postcode'=> 75477, - 'telephone'=> 3468676, - 'country_id'=> 'US', - 'region_id' => 1 - ]); - - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - $quote->setBillingAddress($guestAddress); - $quote->setShippingAddress($guestAddress); - $quote->collectTotals(); - $this->quoteResource->save($quote); - - return (int) $quote->getShippingAddress()->getId(); - } } diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address_rollback.php index 52ce4b4006db8..402ad030ed857 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address_rollback.php @@ -16,4 +16,4 @@ require __DIR__ . '/../../Customer/_files/customer_rollback.php'; require __DIR__ . '/../../Customer/_files/customer_address_rollback.php'; -require __DIR__ . '/../../../Magento/Catalog/_files/product_virtual_rollback.php'; +require __DIR__ . '/../../Catalog/_files/product_virtual_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 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/GraphQl/Quote/_files/guest/quote_with_address.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/quote_with_address.php new file mode 100644 index 0000000000000..60d2f1c49d240 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/quote_with_address.php @@ -0,0 +1,49 @@ +get(GuestCartManagementInterface::class); +/** @var CartRepositoryInterface $cartRepository */ +$cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class); +/** @var MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId */ +$maskedQuoteIdToQuoteId = Bootstrap::getObjectManager()->get(MaskedQuoteIdToQuoteIdInterface::class); +/** @var AddressInterfaceFactory $quoteAddressFactory */ +$quoteAddressFactory = Bootstrap::getObjectManager()->get(AddressInterfaceFactory::class); +/** @var DataObjectHelper $dataObjectHelper */ +$dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class); +/** @var ShippingAddressManagementInterface $shippingAddressManagement */ +$shippingAddressManagement = Bootstrap::getObjectManager()->get(ShippingAddressManagementInterface::class); + +$cartHash = $guestCartManagement->createEmptyCart(); +$cartId = $maskedQuoteIdToQuoteId->execute($cartHash); +$cart = $cartRepository->get($cartId); +$cart->setReservedOrderId('guest_quote_with_address'); +$cartRepository->save($cart); + +$quoteAddressData = [ + AddressInterface::KEY_TELEPHONE => 4435555, + AddressInterface::KEY_POSTCODE => 78717, + AddressInterface::KEY_COUNTRY_ID => 'US', + AddressInterface::KEY_CITY => 'CityA', + AddressInterface::KEY_COMPANY => 'CompanyName', + AddressInterface::KEY_STREET => 'Andora str, 121', + AddressInterface::KEY_LASTNAME => 'Smith', + AddressInterface::KEY_FIRSTNAME => 'John', + AddressInterface::KEY_REGION_ID => 1, +]; +$quoteAddress = $quoteAddressFactory->create(); +$dataObjectHelper->populateWithArray($quoteAddress, $quoteAddressData, AddressInterfaceFactory::class); +$shippingAddressManagement->assign($cartId, $quoteAddress); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/quote_with_address_rollback.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/quote_with_address_rollback.php new file mode 100644 index 0000000000000..d9f894abf45b4 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/quote_with_address_rollback.php @@ -0,0 +1,28 @@ +get(QuoteFactory::class); +/** @var QuoteResource $quoteResource */ +$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class); +/** @var QuoteIdMaskFactory $quoteIdMaskFactory */ +$quoteIdMaskFactory = Bootstrap::getObjectManager()->get(QuoteIdMaskFactory::class); + +$quote = $quoteFactory->create(); +$quoteResource->load($quote, 'guest_quote_with_address', 'reserved_order_id'); +$quoteResource->delete($quote); + +/** @var QuoteIdMask $quoteIdMask */ +$quoteIdMask = $quoteIdMaskFactory->create(); +$quoteIdMask->setQuoteId($quote->getId()) + ->delete(); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php new file mode 100644 index 0000000000000..1e7c10d251be0 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php @@ -0,0 +1,36 @@ +get(QuoteFactory::class); +/** @var QuoteResource $quoteResource */ +$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class); +/** @var ShippingInformationInterfaceFactory $shippingInformationFactory */ +$shippingInformationFactory = Bootstrap::getObjectManager()->get(ShippingInformationInterfaceFactory::class); +/** @var ShippingInformationManagementInterface $shippingInformationManagement */ +$shippingInformationManagement = Bootstrap::getObjectManager()->get(ShippingInformationManagementInterface::class); + +$quote = $quoteFactory->create(); +$quoteResource->load($quote, 'test_quote', 'reserved_order_id'); +$quoteAddress = $quote->getShippingAddress(); + +/** @var ShippingInformationInterface $shippingInformation */ +$shippingInformation = $shippingInformationFactory->create([ + 'data' => [ + ShippingInformationInterface::SHIPPING_ADDRESS => $quoteAddress, + ShippingInformationInterface::SHIPPING_CARRIER_CODE => 'flatrate', + ShippingInformationInterface::SHIPPING_METHOD_CODE => 'flatrate', + ], +]); +$shippingInformationManagement->saveAddressInformation($quote->getId(), $shippingInformation);