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..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 @@ -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, @@ -108,28 +112,42 @@ public function testShippingMethodWithSimpleProduct() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @dataProvider dataProviderWithMissedRequiredParameters + * @param int $addressId + * @param string $message * @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 +231,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 +252,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