From 4b89ee0063b69c80e52bbfab9be1830acff60266 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Tue, 5 Mar 2019 16:53:36 +0100 Subject: [PATCH 01/21] Cart totals implementation --- .../QuoteGraphQl/Model/Resolver/CartTaxes.php | 65 +++++++++ .../QuoteGraphQl/Model/Resolver/Totals.php | 74 ++++++++++ .../Magento/QuoteGraphQl/etc/schema.graphqls | 14 ++ .../GraphQl/Quote/Customer/CartTotalsTest.php | 132 ++++++++++++++++++ .../_files/product_simple_with_tax.php | 45 ++++++ .../product_simple_with_tax_rollback.php | 8 ++ .../Checkout/_files/quote_with_tax.php | 67 +++++++++ .../_files/quote_with_tax_rollback.php | 22 +++ .../_files/customer_with_tax_group.php | 10 ++ .../customer_with_tax_group_rollback.php | 7 + 10 files changed, 444 insertions(+) create mode 100644 app/code/Magento/QuoteGraphQl/Model/Resolver/CartTaxes.php create mode 100644 app/code/Magento/QuoteGraphQl/Model/Resolver/Totals.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax.php create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax.php create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group.php create mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group_rollback.php diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartTaxes.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartTaxes.php new file mode 100644 index 000000000000..53782c488fb8 --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartTaxes.php @@ -0,0 +1,65 @@ +totalsCollector = $totalsCollector; + } + + /** + * @inheritdoc + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + if (!isset($value['model'])) { + throw new LocalizedException(__('"model" value should be specified')); + } + + $data = []; + + /** @var Quote $quote */ + $quote = $value['model']; + $appliedTaxes = $this->totalsCollector->collectQuoteTotals($value['model'])->getAppliedTaxes(); + + if (count($appliedTaxes) == 0) { + return []; + } + + $currency = $quote->getQuoteCurrencyCode(); + foreach ($appliedTaxes as $appliedTax) { + $data[] = [ + 'label' => $appliedTax['id'], + 'amount' => ['value' => $appliedTax['amount'], 'currency' => $currency] + ]; + } + + return $data; + } +} diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/Totals.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/Totals.php new file mode 100644 index 000000000000..fd77d7a9d0ef --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/Totals.php @@ -0,0 +1,74 @@ +cartTotalRepository = $cartTotalRepository; + } + + /** + * @inheritdoc + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + if (!isset($value['model'])) { + throw new LocalizedException(__('"model" value should be specified')); + } + + $cartTotals = $this->cartTotalRepository->get($value['model']->getId()); + + $currency = $cartTotals->getQuoteCurrencyCode(); + $data = $this->addCurrencyCode([ + 'grand_total' => ['value' => $cartTotals->getGrandTotal(), ], + 'subtotal_including_tax' => ['value' => $cartTotals->getSubtotalInclTax()], + 'subtotal_excluding_tax' => ['value' => $cartTotals->getSubtotal()], + 'subtotal_with_discount_excluding_tax' => ['value' => $cartTotals->getSubtotalWithDiscount()] + ], $currency); + + $data['model'] = $value['model']; + + return $data; + } + + /** + * Adds currency code to the totals + * + * @param array $totals + * @param string|null $currencyCode + * @return array + */ + private function addCurrencyCode(array $totals, $currencyCode): array + { + foreach ($totals as &$total) { + $total['currency'] = $currencyCode; + } + + return $totals; + } +} diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index e4ced2351572..24694303f4ec 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -120,6 +120,19 @@ input PaymentMethodInput { additional_data: PaymentMethodAdditionalDataInput } +type CartPrices { + grand_total: Money + subtotal_including_tax: Money + subtotal_excluding_tax: Money + subtotal_with_discount_excluding_tax: Money + applied_taxes: [CartTaxItem] @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartTaxes") +} + +type CartTaxItem { + amount: Money! + label: String! +} + input PaymentMethodAdditionalDataInput { } @@ -150,6 +163,7 @@ type Cart { billing_address: CartAddress! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\BillingAddress") available_payment_methods: [AvailablePaymentMethod] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AvailablePaymentMethods") @doc(description: "Available payment methods") selected_payment_method: SelectedPaymentMethod @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SelectedPaymentMethod") + prices: CartPrices @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\Totals") } type CartAddress { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php new file mode 100644 index 000000000000..36da00bdfa79 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php @@ -0,0 +1,132 @@ +quoteResource = $objectManager->create(QuoteResource::class); + $this->quoteFactory = $objectManager->create(QuoteFactory::class); + $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); + $this->customerTokenService = $objectManager->create(CustomerTokenServiceInterface::class); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax.php + */ + public function testGetCartTotalsForCustomerWithTaxApplied() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_tax'); + + $query = <<sendRequestWithToken($query); + + self::assertArrayHasKey('prices', $response['cart']); + $pricesResponse = $response['cart']['prices']; + self::assertEquals(10, $pricesResponse['grand_total']['value']); + self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + + $appliedTaxesResponse = $pricesResponse['applied_taxes']; + + self::assertEquals('US-CA-*-Rate 1', $appliedTaxesResponse[0]['label']); + self::assertEquals(0.83, $appliedTaxesResponse[0]['amount']['value']); + self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']); + } + + /** + * @param string $reversedQuoteId + * @return string + */ + private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } + + /** + * Sends a GraphQL request with using a bearer token + * + * @param string $query + * @return array + * @throws \Magento\Framework\Exception\AuthenticationException + */ + private function sendRequestWithToken(string $query): array + { + + $customerToken = $this->customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; + + return $this->graphQlQuery($query, [], '', $headerMap); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax.php new file mode 100644 index 000000000000..00c2e6673646 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax.php @@ -0,0 +1,45 @@ +create(ProductRepositoryInterface::class); +/** @var ProductFactory $productFactory */ +$productFactory = $objectManager->create(ProductFactory::class); +$product = $productFactory->create(); +$product + ->setTypeId('simple') + ->setId(1) + ->setAttributeSetId(4) + ->setWebsiteIds([1]) + ->setName('Simple Product') + ->setSku('simple') + ->setPrice(10) + ->setMetaTitle('meta title') + ->setMetaKeyword('meta keyword') + ->setMetaDescription('meta description') + ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH) + ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) + ->setStockData(['use_config_manage_stock' => 1, 'qty' => 22, 'is_in_stock' => 1]) + ->setQty(22); + + +/** @var TaxClassCollectionFactory $taxClassCollectionFactory */ +$taxClassCollectionFactory = $objectManager->create(TaxClassCollectionFactory::class); +$taxClassCollection = $taxClassCollectionFactory->create(); + +/** @var TaxClassModel $taxClass */ +$taxClassCollection->addFieldToFilter('class_type', TaxClassModel::TAX_CLASS_TYPE_PRODUCT); +$taxClass = $taxClassCollection->getFirstItem(); + +$product->setCustomAttribute('tax_class_id', $taxClass->getClassId()); +$productRepository->save($product); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax_rollback.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax_rollback.php new file mode 100644 index 000000000000..a7d58fdf7f6f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax_rollback.php @@ -0,0 +1,8 @@ +get(AddressRepositoryInterface::class); +$customerAddress = $addressRepository->getById(1); +$customerAddress->setRegionId(12); // Taxable region +$addressRepository->save($customerAddress); +/** @var CustomerRepositoryInterface $customerRepository */ +$customerRepository = $objectManager->create(CustomerRepositoryInterface::class); +$customer = $customerRepository->get('customer@example.com'); + +/** @var Address $quoteAddress */ +$quoteAddress = $objectManager->create(Address::class); +$quoteAddress->importCustomerAddressData($customerAddress); + +/** @var Quote $quote */ +$quote = $objectManager->create(Quote::class); +$quote->setStoreId( + 1 +)->setIsActive( + true +)->setIsMultiShipping( + false +)->assignCustomer( + $customer +)->setShippingAddress( + $quoteAddress +)->setBillingAddress( + $quoteAddress +)->setCheckoutMethod( + 'customer' +)->setReservedOrderId( + 'test_order_tax' +)->addProduct( + $product +); + +$quote->getShippingAddress()->setRegionId(12); + +$quoteRepository = $objectManager->get( + \Magento\Quote\Api\CartRepositoryInterface::class +); + +$quoteRepository->save($quote); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create(\Magento\Quote\Model\QuoteIdMaskFactory::class) + ->create(); +$quoteIdMask->setQuoteId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_rollback.php new file mode 100644 index 000000000000..1e1eb326d7c8 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_rollback.php @@ -0,0 +1,22 @@ +create(Quote::class); +$quote->load('test_order_tax', 'reserved_order_id')->delete(); + +/** @var QuoteIdMask $quoteIdMask */ +$quoteIdMask = $objectManager->create(QuoteIdMask::class); +$quoteIdMask->delete($quote->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group.php new file mode 100644 index 000000000000..4792df5cdb2f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group.php @@ -0,0 +1,10 @@ +setGroupId(3); // 3 is a predefined retailer group +$customer->save(); diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group_rollback.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group_rollback.php new file mode 100644 index 000000000000..48a09a41c7e0 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group_rollback.php @@ -0,0 +1,7 @@ + Date: Sat, 9 Mar 2019 11:51:55 +0100 Subject: [PATCH 02/21] Added test coverage for guest user --- .../GraphQl/Quote/Customer/CartTotalsTest.php | 2 +- .../GraphQl/Quote/Guest/CartTotalsTest.php | 116 ++++++++++++++++++ ...th_tax.php => quote_with_tax_customer.php} | 0 ...p => quote_with_tax_customer_rollback.php} | 0 .../Checkout/_files/quote_with_tax_guest.php | 64 ++++++++++ .../_files/quote_with_tax_guest_rollback.php | 21 ++++ 6 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php rename dev/tests/integration/testsuite/Magento/Checkout/_files/{quote_with_tax.php => quote_with_tax_customer.php} (100%) rename dev/tests/integration/testsuite/Magento/Checkout/_files/{quote_with_tax_rollback.php => quote_with_tax_customer_rollback.php} (100%) create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest_rollback.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php index 36da00bdfa79..a6ddc7cff20c 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php @@ -49,7 +49,7 @@ protected function setUp() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax_customer.php */ public function testGetCartTotalsForCustomerWithTaxApplied() { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php new file mode 100644 index 000000000000..9396af53e0cc --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php @@ -0,0 +1,116 @@ +quoteResource = $objectManager->create(QuoteResource::class); + $this->quoteFactory = $objectManager->create(QuoteFactory::class); + $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); + $this->customerTokenService = $objectManager->create(CustomerTokenServiceInterface::class); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax_guest.php + */ + public function testGetCartTotalsForCustomerWithTaxApplied() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_tax'); + + $query = <<graphQlQuery($query); + + self::assertArrayHasKey('prices', $response['cart']); + $pricesResponse = $response['cart']['prices']; + self::assertEquals(10, $pricesResponse['grand_total']['value']); + self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + + $appliedTaxesResponse = $pricesResponse['applied_taxes']; + + self::assertEquals('US-CA-*-Rate 1', $appliedTaxesResponse[0]['label']); + self::assertEquals(0.83, $appliedTaxesResponse[0]['amount']['value']); + self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']); + } + + /** + * @param string $reversedQuoteId + * @return string + */ + private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer.php similarity index 100% rename from dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax.php rename to dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer.php diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer_rollback.php similarity index 100% rename from dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_rollback.php rename to dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer_rollback.php diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php new file mode 100644 index 000000000000..75c20e45f11e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php @@ -0,0 +1,64 @@ +create(AddressInterface::class); +$quoteAddress->setData( + [ + 'telephone' => 3468676, + 'postcode' => 75477, + 'country_id' => 'US', + 'city' => 'CityM', + 'company' => 'CompanyName', + 'street' => 'Green str, 67', + 'lastname' => 'Smith', + 'firstname' => 'John', + 'region_id' => 12 + ] +); +//$quoteAddress->save(); + +/** @var Quote $quote */ +$quote = $objectManager->create(Quote::class); +$quote->setStoreId( + 1 +)->setIsActive( + true +)->setIsMultiShipping( + false +)->setShippingAddress( + $quoteAddress +)->setBillingAddress( + $quoteAddress +)->setCheckoutMethod( + 'customer' +)->setReservedOrderId( + 'test_order_tax' +)->addProduct( + $product +); + +$quote->getShippingAddress()->setRegionId(12); + +$quoteRepository = $objectManager->get( + \Magento\Quote\Api\CartRepositoryInterface::class +); + +$quoteRepository->save($quote); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create(\Magento\Quote\Model\QuoteIdMaskFactory::class) + ->create(); +$quoteIdMask->setQuoteId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest_rollback.php new file mode 100644 index 000000000000..6fcbdf7276de --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest_rollback.php @@ -0,0 +1,21 @@ +create(Quote::class); +$quote->load('test_order_tax', 'reserved_order_id')->delete(); + +/** @var QuoteIdMask $quoteIdMask */ +$quoteIdMask = $objectManager->create(QuoteIdMask::class); +$quoteIdMask->delete($quote->getId()); From 8210d824dc4accdb631a03f47f3d311e2ff74ad5 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Sat, 9 Mar 2019 12:40:56 +0100 Subject: [PATCH 03/21] Use a single resolver for totals/taxes for performance improvement --- .../QuoteGraphQl/Model/Resolver/CartTaxes.php | 65 ------------------- .../QuoteGraphQl/Model/Resolver/Totals.php | 62 +++++++++++------- .../Magento/QuoteGraphQl/etc/schema.graphqls | 2 +- .../GraphQl/Quote/Customer/CartTotalsTest.php | 2 +- .../GraphQl/Quote/Guest/CartTotalsTest.php | 2 +- 5 files changed, 40 insertions(+), 93 deletions(-) delete mode 100644 app/code/Magento/QuoteGraphQl/Model/Resolver/CartTaxes.php diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartTaxes.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartTaxes.php deleted file mode 100644 index 53782c488fb8..000000000000 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartTaxes.php +++ /dev/null @@ -1,65 +0,0 @@ -totalsCollector = $totalsCollector; - } - - /** - * @inheritdoc - */ - public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) - { - if (!isset($value['model'])) { - throw new LocalizedException(__('"model" value should be specified')); - } - - $data = []; - - /** @var Quote $quote */ - $quote = $value['model']; - $appliedTaxes = $this->totalsCollector->collectQuoteTotals($value['model'])->getAppliedTaxes(); - - if (count($appliedTaxes) == 0) { - return []; - } - - $currency = $quote->getQuoteCurrencyCode(); - foreach ($appliedTaxes as $appliedTax) { - $data[] = [ - 'label' => $appliedTax['id'], - 'amount' => ['value' => $appliedTax['amount'], 'currency' => $currency] - ]; - } - - return $data; - } -} diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/Totals.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/Totals.php index fd77d7a9d0ef..926f2b2de3cf 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/Totals.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/Totals.php @@ -11,7 +11,8 @@ use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; -use Magento\Quote\Api\CartTotalRepositoryInterface; +use Magento\Quote\Model\Quote\Address\Total; +use Magento\Quote\Model\Quote\TotalsCollector; /** * @inheritdoc @@ -19,17 +20,17 @@ class Totals implements ResolverInterface { /** - * @var CartTotalRepositoryInterface + * @var TotalsCollector */ - private $cartTotalRepository; + private $totalsCollector; /** - * @param CartTotalRepositoryInterface $cartTotalRepository + * @param TotalsCollector $totalsCollector */ public function __construct( - CartTotalRepositoryInterface $cartTotalRepository + TotalsCollector $totalsCollector ) { - $this->cartTotalRepository = $cartTotalRepository; + $this->totalsCollector = $totalsCollector; } /** @@ -41,34 +42,45 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value throw new LocalizedException(__('"model" value should be specified')); } - $cartTotals = $this->cartTotalRepository->get($value['model']->getId()); + /** @var Quote $quote */ + $quote = $value['model']; + $cartTotals = $this->totalsCollector->collectQuoteTotals($quote); + $currency = $quote->getQuoteCurrencyCode(); - $currency = $cartTotals->getQuoteCurrencyCode(); - $data = $this->addCurrencyCode([ - 'grand_total' => ['value' => $cartTotals->getGrandTotal(), ], - 'subtotal_including_tax' => ['value' => $cartTotals->getSubtotalInclTax()], - 'subtotal_excluding_tax' => ['value' => $cartTotals->getSubtotal()], - 'subtotal_with_discount_excluding_tax' => ['value' => $cartTotals->getSubtotalWithDiscount()] - ], $currency); - - $data['model'] = $value['model']; - - return $data; + return [ + 'grand_total' => ['value' => $cartTotals->getGrandTotal(), 'currency' => $currency], + 'subtotal_including_tax' => ['value' => $cartTotals->getSubtotalInclTax(), 'currency' => $currency], + 'subtotal_excluding_tax' => ['value' => $cartTotals->getSubtotal(), 'currency' => $currency], + 'subtotal_with_discount_excluding_tax' => [ + 'value' => $cartTotals->getSubtotalWithDiscount(), 'currency' => $currency + ], + 'applied_taxes' => $this->getAppliedTaxes($cartTotals, $currency), + 'model' => $quote + ]; } /** - * Adds currency code to the totals + * Returns taxes applied to the current quote * - * @param array $totals - * @param string|null $currencyCode + * @param Total $total + * @param string $currency * @return array */ - private function addCurrencyCode(array $totals, $currencyCode): array + private function getAppliedTaxes(Total $total, string $currency): array { - foreach ($totals as &$total) { - $total['currency'] = $currencyCode; + $appliedTaxes = $total->getAppliedTaxes(); + + if (count($appliedTaxes) === 0) { + return []; + } + + foreach ($appliedTaxes as $appliedTax) { + $appliedTaxesData[] = [ + 'label' => $appliedTax['id'], + 'amount' => ['value' => $appliedTax['amount'], 'currency' => $currency] + ]; } - return $totals; + return $appliedTaxesData; } } diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index 24694303f4ec..516da1512d04 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -125,7 +125,7 @@ type CartPrices { subtotal_including_tax: Money subtotal_excluding_tax: Money subtotal_with_discount_excluding_tax: Money - applied_taxes: [CartTaxItem] @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartTaxes") + applied_taxes: [CartTaxItem] } type CartTaxItem { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php index a6ddc7cff20c..f50ebf38aa1e 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php @@ -90,7 +90,7 @@ public function testGetCartTotalsForCustomerWithTaxApplied() self::assertArrayHasKey('prices', $response['cart']); $pricesResponse = $response['cart']['prices']; - self::assertEquals(10, $pricesResponse['grand_total']['value']); + self::assertEquals(10.83, $pricesResponse['grand_total']['value']); self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']); self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php index 9396af53e0cc..b399fea37951 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php @@ -90,7 +90,7 @@ public function testGetCartTotalsForCustomerWithTaxApplied() self::assertArrayHasKey('prices', $response['cart']); $pricesResponse = $response['cart']['prices']; - self::assertEquals(10, $pricesResponse['grand_total']['value']); + self::assertEquals(10.83, $pricesResponse['grand_total']['value']); self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']); self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); From 269730337b2e10b6d4addc85a0cc60fff55e4289 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Sat, 9 Mar 2019 15:30:01 +0100 Subject: [PATCH 04/21] Test coverage for cart with no tax applied --- .../GraphQl/Quote/Customer/CartTotalsTest.php | 68 ++++++++++++------ .../GraphQl/Quote/Guest/CartTotalsTest.php | 72 ++++++++++++------- .../_files/quote_with_address_guest.php | 61 ++++++++++++++++ .../quote_with_address_guest_rollback.php | 21 ++++++ .../Checkout/_files/quote_with_tax_guest.php | 1 - 5 files changed, 176 insertions(+), 47 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest.php create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest_rollback.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php index f50ebf38aa1e..7efbc61be6cd 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php @@ -42,20 +42,62 @@ class CartTotalsTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->quoteResource = $objectManager->create(QuoteResource::class); - $this->quoteFactory = $objectManager->create(QuoteFactory::class); - $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); - $this->customerTokenService = $objectManager->create(CustomerTokenServiceInterface::class); + $this->quoteResource = $objectManager->get(QuoteResource::class); + $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); } /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax_customer.php */ - public function testGetCartTotalsForCustomerWithTaxApplied() + public function testGetCartTotalsWithTaxApplied() { $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_tax'); + $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); + $response = $this->sendRequestWithToken($query); + + self::assertArrayHasKey('prices', $response['cart']); + $pricesResponse = $response['cart']['prices']; + self::assertEquals(10.83, $pricesResponse['grand_total']['value']); + self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + + $appliedTaxesResponse = $pricesResponse['applied_taxes']; + + self::assertEquals('US-CA-*-Rate 1', $appliedTaxesResponse[0]['label']); + self::assertEquals(0.83, $appliedTaxesResponse[0]['amount']['value']); + self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @group last + */ + public function testGetTotalsWithNoTaxApplied() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); + $response = $this->sendRequestWithToken($query); + + $pricesResponse = $response['cart']['prices']; + self::assertEquals(20, $pricesResponse['grand_total']['value']); + self::assertEquals(20, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(20, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(20, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + self::assertEmpty($pricesResponse['applied_taxes']); + } - $query = <<sendRequestWithToken($query); - - self::assertArrayHasKey('prices', $response['cart']); - $pricesResponse = $response['cart']['prices']; - self::assertEquals(10.83, $pricesResponse['grand_total']['value']); - self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); - - $appliedTaxesResponse = $pricesResponse['applied_taxes']; - - self::assertEquals('US-CA-*-Rate 1', $appliedTaxesResponse[0]['label']); - self::assertEquals(0.83, $appliedTaxesResponse[0]['amount']['value']); - self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']); } /** diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php index b399fea37951..d634bd0acbaf 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php @@ -7,7 +7,6 @@ namespace Magento\GraphQl\Quote\Guest; -use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; @@ -19,11 +18,6 @@ */ class CartTotalsTest extends GraphQlAbstract { - /** - * @var CustomerTokenServiceInterface - */ - private $customerTokenService; - /** * @var QuoteResource */ @@ -42,20 +36,60 @@ class CartTotalsTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->quoteResource = $objectManager->create(QuoteResource::class); - $this->quoteFactory = $objectManager->create(QuoteFactory::class); - $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); - $this->customerTokenService = $objectManager->create(CustomerTokenServiceInterface::class); + $this->quoteResource = $objectManager->get(QuoteResource::class); + $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); } /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax_guest.php */ - public function testGetCartTotalsForCustomerWithTaxApplied() + public function testGetCartTotalsWithTaxApplied() { $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_tax'); + $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); + $response = $this->graphQlQuery($query); + + self::assertArrayHasKey('prices', $response['cart']); + $pricesResponse = $response['cart']['prices']; + self::assertEquals(10.83, $pricesResponse['grand_total']['value']); + self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + + $appliedTaxesResponse = $pricesResponse['applied_taxes']; + + self::assertEquals('US-CA-*-Rate 1', $appliedTaxesResponse[0]['label']); + self::assertEquals(0.83, $appliedTaxesResponse[0]['amount']['value']); + self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_guest.php + */ + public function testGetTotalsWithNoTaxApplied() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); + $response = $this->graphQlQuery($query); - $query = <<graphQlQuery($query); - - self::assertArrayHasKey('prices', $response['cart']); - $pricesResponse = $response['cart']['prices']; - self::assertEquals(10.83, $pricesResponse['grand_total']['value']); - self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); - - $appliedTaxesResponse = $pricesResponse['applied_taxes']; - - self::assertEquals('US-CA-*-Rate 1', $appliedTaxesResponse[0]['label']); - self::assertEquals(0.83, $appliedTaxesResponse[0]['amount']['value']); - self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']); } /** diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest.php new file mode 100644 index 000000000000..da496f01ec05 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest.php @@ -0,0 +1,61 @@ +create(AddressInterface::class); +$quoteAddress->setData( + [ + 'telephone' => 3468676, + 'postcode' => 75477, + 'country_id' => 'US', + 'city' => 'CityM', + 'company' => 'CompanyName', + 'street' => 'Green str, 67', + 'lastname' => 'Smith', + 'firstname' => 'John', + 'region_id' => 1 + ] +); + +/** @var Quote $quote */ +$quote = $objectManager->create(Quote::class); +$quote->setStoreId( + 1 +)->setIsActive( + true +)->setIsMultiShipping( + false +)->setShippingAddress( + $quoteAddress +)->setBillingAddress( + $quoteAddress +)->setCheckoutMethod( + 'customer' +)->setReservedOrderId( + 'test_order_1' +)->addProduct( + $product +); + +$quoteRepository = $objectManager->get( + \Magento\Quote\Api\CartRepositoryInterface::class +); + +$quoteRepository->save($quote); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create(\Magento\Quote\Model\QuoteIdMaskFactory::class) + ->create(); +$quoteIdMask->setQuoteId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest_rollback.php new file mode 100644 index 000000000000..3130ca9353e9 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest_rollback.php @@ -0,0 +1,21 @@ +create(Quote::class); +$quote->load('test_order_1', 'reserved_order_id')->delete(); + +/** @var QuoteIdMask $quoteIdMask */ +$quoteIdMask = $objectManager->create(QuoteIdMask::class); +$quoteIdMask->delete($quote->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php index 75c20e45f11e..09d47f3cdca7 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php @@ -25,7 +25,6 @@ 'region_id' => 12 ] ); -//$quoteAddress->save(); /** @var Quote $quote */ $quote = $objectManager->create(Quote::class); From 2aeb8748ce4cf467e81744276c81dd521452a6fe Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Sun, 10 Mar 2019 09:58:15 +0100 Subject: [PATCH 05/21] Test case for getting totals with no quote address set --- .../GraphQl/Quote/Customer/CartTotalsTest.php | 21 +++++++++++++++++- .../GraphQl/Quote/Guest/CartTotalsTest.php | 20 +++++++++++++++++ ...uote_with_customer_no_address_rollback.php | 22 +++++++++++++++++++ .../_files/quote_with_tax_customer.php | 4 ++-- .../Checkout/_files/quote_with_tax_guest.php | 6 ++--- 5 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address_rollback.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php index 7efbc61be6cd..8dc6650b68f9 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php @@ -73,7 +73,6 @@ public function testGetCartTotalsWithTaxApplied() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php - * @group last */ public function testGetTotalsWithNoTaxApplied() { @@ -89,6 +88,26 @@ public function testGetTotalsWithNoTaxApplied() self::assertEmpty($pricesResponse['applied_taxes']); } + /** + * The totals calculation is based on quote address. + * But the totals should be calculated even if no address is set + * + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_customer_no_address.php + */ + public function testGetCartTotalsWithNoAddressSet() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); + $response = $this->sendRequestWithToken($query); + + $pricesResponse = $response['cart']['prices']; + self::assertEquals(10, $pricesResponse['grand_total']['value']); + self::assertEquals(10, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + self::assertEmpty($pricesResponse['applied_taxes']); + } + /** * Generates GraphQl query for retrieving cart totals * diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php index d634bd0acbaf..19ef071b5040 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php @@ -81,6 +81,26 @@ public function testGetTotalsWithNoTaxApplied() self::assertEmpty($pricesResponse['applied_taxes']); } + /** + * The totals calculation is based on quote address. + * But the totals should be calculated even if no address is set + * + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + */ + public function testGetCartTotalsWithNoAddressSet() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); + $response = $this->graphQlQuery($query); + + $pricesResponse = $response['cart']['prices']; + self::assertEquals(10, $pricesResponse['grand_total']['value']); + self::assertEquals(10, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + self::assertEmpty($pricesResponse['applied_taxes']); + } + /** * Generates GraphQl query for retrieving cart totals * diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address_rollback.php new file mode 100644 index 000000000000..83c80d736c16 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address_rollback.php @@ -0,0 +1,22 @@ +create(Quote::class); +$quote->load('test_order_1', 'reserved_order_id')->delete(); + +/** @var QuoteIdMask $quoteIdMask */ +$quoteIdMask = $objectManager->create(QuoteIdMask::class); +$quoteIdMask->delete($quote->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer.php index a8a02f5fe87e..e9cb45b546a4 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer.php @@ -59,8 +59,8 @@ $quoteRepository->save($quote); /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ -$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create(\Magento\Quote\Model\QuoteIdMaskFactory::class) +$quoteIdMask = $objectManager + ->get(\Magento\Quote\Model\QuoteIdMaskFactory::class) ->create(); $quoteIdMask->setQuoteId($quote->getId()); $quoteIdMask->setDataChanges(true); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php index 09d47f3cdca7..78d5b0739d76 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php @@ -39,7 +39,7 @@ )->setBillingAddress( $quoteAddress )->setCheckoutMethod( - 'customer' + 'guest' )->setReservedOrderId( 'test_order_tax' )->addProduct( @@ -55,8 +55,8 @@ $quoteRepository->save($quote); /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ -$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create(\Magento\Quote\Model\QuoteIdMaskFactory::class) +$quoteIdMask = $objectManager + ->get(\Magento\Quote\Model\QuoteIdMaskFactory::class) ->create(); $quoteIdMask->setQuoteId($quote->getId()); $quoteIdMask->setDataChanges(true); From 7cca7811bcc6004c6b9ae826ccdbd22c6be27e1d Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Sun, 10 Mar 2019 09:58:59 +0100 Subject: [PATCH 06/21] Missing fixture --- .../_files/quote_with_customer_no_address.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address.php diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address.php new file mode 100644 index 000000000000..ef030f8bcd92 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address.php @@ -0,0 +1,48 @@ +create(CustomerRepositoryInterface::class); +$customer = $customerRepository->get('customer@example.com'); + +/** @var Quote $quote */ +$quote = $objectManager->create(Quote::class); +$quote->setStoreId( + 1 +)->setIsActive( + true +)->setIsMultiShipping( + false +)->assignCustomer( + $customer +)->setCheckoutMethod( + 'customer' +)->setReservedOrderId( + 'test_order_1' +)->addProduct( + $product +); + +$quoteRepository = $objectManager->get( + \Magento\Quote\Api\CartRepositoryInterface::class +); + +$quoteRepository->save($quote); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = $objectManager + ->get(\Magento\Quote\Model\QuoteIdMaskFactory::class) + ->create(); +$quoteIdMask->setQuoteId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); From 37b48554ede24355e91785c288f3e0a4fb8f94bc Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Wed, 27 Mar 2019 14:08:59 +0200 Subject: [PATCH 07/21] magento/graphql-ce#540: Replace deprecated Magento/Checkout/_files/quote_with_address_saved.php fixture in SetUpsShippingMethodsOnCartTest --- .../GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php index 463f2c4af101..33f0d4c40602 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -62,13 +62,17 @@ protected function setUp() } /** - * @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 * @magentoApiDataFixture Magento/Ups/_files/enable_ups_shipping_method.php */ public function testSetUpsShippingMethod() { $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, 'test_order_1', 'reserved_order_id'); + $this->quoteResource->load($quote, 'test_quote', 'reserved_order_id'); $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId()); $shippingAddressId = (int)$quote->getShippingAddress()->getId(); From 5dd5e3acd8e4d0fc004537effebe6dbd17da5ebb Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Mon, 1 Apr 2019 15:29:04 +0300 Subject: [PATCH 08/21] magento/graphql-ce#540: Replace deprecated Magento/Checkout/_files/quote_with_address_saved.php fixture in SetUpsShippingMethodsOnCartTest --- .../Ups/SetUpsShippingMethodsOnCartTest.php | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php index 33f0d4c40602..9ad47319cac1 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -7,9 +7,9 @@ namespace Magento\GraphQl\Ups; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\Integration\Api\CustomerTokenServiceInterface; -use Magento\Quote\Model\QuoteFactory; -use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; +use Magento\Quote\Model\Quote; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -30,9 +30,9 @@ class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract const CARRIER_METHOD_CODE_GROUND = 'GND'; /** - * @var QuoteFactory + * @var Quote */ - private $quoteFactory; + private $quote; /** * @var CustomerTokenServiceInterface @@ -40,14 +40,9 @@ class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract private $customerTokenService; /** - * @var QuoteResource + * @var GetMaskedQuoteIdByReservedOrderId */ - private $quoteResource; - - /** - * @var QuoteIdToMaskedQuoteIdInterface - */ - private $quoteIdToMaskedId; + private $getMaskedQuoteIdByReservedOrderId; /** * @inheritdoc @@ -55,15 +50,14 @@ class SetUpsShippingMethodsOnCartTest 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->quote = $objectManager->create(Quote::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/Catalog/_files/products.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 @@ -71,9 +65,9 @@ protected function setUp() */ public function testSetUpsShippingMethod() { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, 'test_quote', 'reserved_order_id'); - $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId()); + $quoteReservedId = 'test_quote'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); + $quote = $this->quote->load($quoteReservedId, 'reserved_order_id'); $shippingAddressId = (int)$quote->getShippingAddress()->getId(); $query = $this->getAddUpsShippingMethodQuery( From ba6c5239689f5b7cfc09f03042284742b00499e7 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Tue, 2 Apr 2019 01:52:56 +0300 Subject: [PATCH 09/21] magento/graphql-ce#540: Replace deprecated Magento/Checkout/_files/quote_with_address_saved.php fixture in SetUpsShippingMethodsOnCartTest --- .../Ups/SetUpsShippingMethodsOnCartTest.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php index 9ad47319cac1..32e9cbf99052 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -8,8 +8,8 @@ namespace Magento\GraphQl\Ups; use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; +use Magento\GraphQl\Quote\GetQuoteShippingAddressIdByReservedQuoteId; use Magento\Integration\Api\CustomerTokenServiceInterface; -use Magento\Quote\Model\Quote; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -30,9 +30,9 @@ class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract const CARRIER_METHOD_CODE_GROUND = 'GND'; /** - * @var Quote + * @var GetQuoteShippingAddressIdByReservedQuoteId */ - private $quote; + private $getQuoteShippingAddressIdByReservedQuoteId; /** * @var CustomerTokenServiceInterface @@ -50,9 +50,9 @@ class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->quote = $objectManager->create(Quote::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); + $this->getQuoteShippingAddressIdByReservedQuoteId = $objectManager->get(GetQuoteShippingAddressIdByReservedQuoteId::class); } /** @@ -67,10 +67,9 @@ public function testSetUpsShippingMethod() { $quoteReservedId = 'test_quote'; $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); - $quote = $this->quote->load($quoteReservedId, 'reserved_order_id'); - $shippingAddressId = (int)$quote->getShippingAddress()->getId(); + $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - $query = $this->getAddUpsShippingMethodQuery( + $query = $this->getQuery( $maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, @@ -96,7 +95,7 @@ public function testSetUpsShippingMethod() * @param string $methodCode * @return string */ - private function getAddUpsShippingMethodQuery( + private function getQuery( string $maskedQuoteId, int $shippingAddressId, string $carrierCode, From 844fc58ba48425d6231a2c55e2f6949102421316 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Tue, 2 Apr 2019 11:18:42 +0300 Subject: [PATCH 10/21] magento/graphql-ce#540: Replace deprecated Magento/Checkout/_files/quote_with_address_saved.php fixture in SetUpsShippingMethodsOnCartTest --- .../Ups/SetUpsShippingMethodsOnCartTest.php | 137 ++++++++++++++++-- 1 file changed, 122 insertions(+), 15 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php index 32e9cbf99052..838017b3455d 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -10,7 +10,6 @@ use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\GraphQl\Quote\GetQuoteShippingAddressIdByReservedQuoteId; use Magento\Integration\Api\CustomerTokenServiceInterface; -use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -20,19 +19,14 @@ class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract { /** - * Defines carrier code for "UPS" shipping method - */ - const CARRIER_CODE = 'ups'; - - /** - * Defines method code for the "Ground" UPS shipping + * Defines carrier label for "UPS" shipping method */ - const CARRIER_METHOD_CODE_GROUND = 'GND'; + const CARRIER_LABEL = 'United Parcel Service'; /** - * @var GetQuoteShippingAddressIdByReservedQuoteId + * Defines carrier code for "UPS" shipping method */ - private $getQuoteShippingAddressIdByReservedQuoteId; + const CARRIER_CODE = 'ups'; /** * @var CustomerTokenServiceInterface @@ -44,6 +38,11 @@ class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract */ private $getMaskedQuoteIdByReservedOrderId; + /** + * @var GetQuoteShippingAddressIdByReservedQuoteId + */ + private $getQuoteShippingAddressIdByReservedQuoteId; + /** * @inheritdoc */ @@ -57,13 +56,17 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Catalog/_files/products.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/Ups/_files/enable_ups_shipping_method.php + * + * @param string $carrierMethodCode + * @param string $carrierMethodLabel + * @dataProvider availableForCartShippingMethods */ - public function testSetUpsShippingMethod() + public function testSetAvailableForCartUpsShippingMethod(string $carrierMethodCode, string $carrierMethodLabel) { $quoteReservedId = 'test_quote'; $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); @@ -73,19 +76,123 @@ public function testSetUpsShippingMethod() $maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, - self::CARRIER_METHOD_CODE_GROUND + $carrierMethodCode ); $response = $this->sendRequestWithToken($query); + $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; $expectedResult = [ 'carrier_code' => self::CARRIER_CODE, - 'method_code' => self::CARRIER_METHOD_CODE_GROUND, - 'label' => 'United Parcel Service - Ground', + 'method_code' => $carrierMethodCode, + 'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel, ]; self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); } + /** + * @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/Ups/_files/enable_ups_shipping_method.php + * + * @param string $carrierMethodCode + * @param string $carrierMethodLabel + * @dataProvider notAvailableForCartShippingMethods + */ + public function testSetNotAvailableForCartUpsShippingMethod(string $carrierMethodCode, string $carrierMethodLabel) + { + $quoteReservedId = 'test_quote'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); + $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); + + $query = $this->getQuery( + $maskedQuoteId, + $shippingAddressId, + self::CARRIER_CODE, + $carrierMethodCode + ); + + $this->expectExceptionMessage( + "GraphQL response contains errors: Carrier with such method not found: " . self::CARRIER_CODE . ", " . $carrierMethodCode + ); + + $response = $this->sendRequestWithToken($query); + + $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; + $expectedResult = [ + 'carrier_code' => self::CARRIER_CODE, + 'method_code' => $carrierMethodCode, + 'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel, + ]; + self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); + } + + /** + * @return array + */ + public function availableForCartShippingMethods(): array + { + $shippingMethods = ['1DM', '1DA', '2DA', '3DS', 'GND']; + + return $this->filterShippingMethodsByCodes($shippingMethods); + } + + /** + * @return array + */ + public function notAvailableForCartShippingMethods(): array + { + $shippingMethods = ['1DML', '1DAL', '1DAPI', '1DP', '1DPL', '2DM', '2DML', '2DAL', 'GNDCOM', 'GNDRES', 'STD', 'XPR', 'WXS', 'XPRL', 'XDM', 'XDML', 'XPD']; + + return $this->filterShippingMethodsByCodes($shippingMethods); + } + + /** + * @param array $filter + * @return array + */ + private function filterShippingMethodsByCodes(array $filter):array + { + $result = []; + foreach ($this->getAllUpsShippingMethods() as $shippingMethod) { + if (in_array($shippingMethod[0], $filter)) { + $result[] = $shippingMethod; + } + } + return $result; + } + + private function getAllUpsShippingMethods():array + { + return [ + ['1DM', 'Next Day Air Early AM'], + ['1DML', 'Next Day Air Early AM Letter'], + ['1DA', 'Next Day Air'], + ['1DAL', 'Next Day Air Letter'], + ['1DAPI', 'Next Day Air Intra (Puerto Rico)'], + ['1DP', 'Next Day Air Saver'], + ['1DPL', 'Next Day Air Saver Letter'], + ['2DM', '2nd Day Air AM'], + ['2DML', '2nd Day Air AM Letter'], + ['2DA', '2nd Day Air'], + ['2DAL', '2nd Day Air Letter'], + ['3DS', '3 Day Select'], + ['GND', 'Ground'], + ['GNDCOM', 'Ground Commercial'], + ['GNDRES', 'Ground Residential'], + ['STD', 'Canada Standard'], + ['XPR', 'Worldwide Express'], + ['WXS', 'Worldwide Express Saver'], + ['XPRL', 'Worldwide Express Letter'], + ['XDM', 'Worldwide Express Plus'], + ['XDML', 'Worldwide Express Plus Letter'], + ['XPD', 'Worldwide Expedited'], + ]; + } + /** * Generates query for setting the specified shipping method on cart * From 241450e4e669885ff229ab192a9237498c1b1214 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Mon, 8 Apr 2019 16:41:45 +0200 Subject: [PATCH 11/21] [Checkout Coverage] Place order for guest --- .../Model/Resolver/PlaceOrder.php | 7 + .../GraphQl/Quote/Guest/PlaceOrderTest.php | 134 ++++++++++++++++++ .../Quote/_files/guest/set_guest_email.php | 24 ++++ 3 files changed, 165 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/set_guest_email.php diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/PlaceOrder.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/PlaceOrder.php index 3bd46a664f2a..1672474bb3dd 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/PlaceOrder.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/PlaceOrder.php @@ -65,6 +65,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId()); + if ($context->getUserId() === 0) { + if (!$cart->getCustomerEmail()) { + throw new GraphQlInputException(__("Guest email for cart is missing. Please enter")); + } + $cart->setCheckoutMethod(CartManagementInterface::METHOD_GUEST); + } + try { $orderId = $this->cartManagement->placeOrder($cart->getId()); $order = $this->orderRepository->get($orderId); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php new file mode 100644 index 000000000000..d102a8eb72df --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php @@ -0,0 +1,134 @@ +getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); + $this->orderCollectionFactory = $objectManager->get(CollectionFactory::class); + $this->orderRepository = $objectManager->get(OrderRepositoryInterface::class); + $this->registry = Bootstrap::getObjectManager()->get(Registry::class); + } + + /** + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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_new_billing_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php + */ + public function testPlaceOrder() + { + $reservedOrderId = 'test_quote'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); + + $query = $this->getQuery($maskedQuoteId); + $response = $this->graphQlQuery($query); + + self::assertArrayHasKey('placeOrder', $response); + self::assertArrayHasKey('order_id', $response['placeOrder']['order']); + self::assertEquals($reservedOrderId, $response['placeOrder']['order']['order_id']); + } + + /** + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.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_new_billing_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php + */ + public function testPlaceOrderWithNoEmail() + { + $reservedOrderId = 'test_quote'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); + $query = $this->getQuery($maskedQuoteId); + + self::expectExceptionMessage("Guest email for cart is missing. Please enter"); + $this->graphQlQuery($query); + } + + /** + * @param string $maskedQuoteId + * @return string + */ + private function getQuery(string $maskedQuoteId): string + { + return <<registry->unregister('isSecureArea'); + $this->registry->register('isSecureArea', true); + + $orderCollection = $this->orderCollectionFactory->create(); + foreach ($orderCollection as $order) { + $this->orderRepository->delete($order); + } + $this->registry->unregister('isSecureArea'); + $this->registry->register('isSecureArea', false); + + parent::tearDown(); + } +} diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/set_guest_email.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/set_guest_email.php new file mode 100644 index 000000000000..4e214f431004 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/set_guest_email.php @@ -0,0 +1,24 @@ +get(QuoteFactory::class); +/** @var CartRepositoryInterface $cartRepository */ +$cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class); +/** @var QuoteResource $quoteResource */ +$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class); + +$quote = $quoteFactory->create(); +$quoteResource->load($quote, 'test_quote', 'reserved_order_id'); + +$quote->setCustomerEmail('customer@example.com'); +$cartRepository->save($quote); From 05f345873c3e9567569a5dd63949f490acf0f37a Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Mon, 8 Apr 2019 18:06:26 +0200 Subject: [PATCH 12/21] Additional test cases --- .../GraphQl/Quote/Guest/PlaceOrderTest.php | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php index d102a8eb72df..648b8265ee67 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php @@ -97,6 +97,145 @@ public function testPlaceOrderWithNoEmail() $this->graphQlQuery($query); } + /** + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php + */ + public function testPlaceOrderWithNoItemsInCart() + { + $reservedOrderId = 'test_quote'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); + $query = $this->getQuery($maskedQuoteId); + + self::expectExceptionMessage( + 'Unable to place order: A server error stopped your order from being placed. ' . + 'Please try to place your order again' + ); + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + */ + public function testPlaceOrderWithNoShippingAddress() + { + $reservedOrderId = 'test_quote'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); + $query = $this->getQuery($maskedQuoteId); + + self::expectExceptionMessage( + 'Unable to place order: Some addresses can\'t be used due to the configurations for specific countries' + ); + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + */ + public function testPlaceOrderWithNoShippingMethod() + { + $reservedOrderId = 'test_quote'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); + $query = $this->getQuery($maskedQuoteId); + + self::expectExceptionMessage( + 'Unable to place order: The shipping method is missing. Select the shipping method and try again' + ); + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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 testPlaceOrderWithNoBillingAddress() + { + $reservedOrderId = 'test_quote'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); + $query = $this->getQuery($maskedQuoteId); + + self::expectExceptionMessageRegExp( + '/Unable to place order: Please check the billing address information*/' + ); + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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_new_billing_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php + */ + public function testPlaceOrderWithNoPaymentMethod() + { + $reservedOrderId = 'test_quote'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); + $query = $this->getQuery($maskedQuoteId); + + self::expectExceptionMessage('Unable to place order: Enter a valid payment method and try again'); + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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_new_billing_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php + */ + public function testPlaceOrderWithOutOfStockProduct() + { + $reservedOrderId = 'test_quote'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); + $query = $this->getQuery($maskedQuoteId); + + self::expectExceptionMessage('Unable to place order: Some of the products are out of stock'); + $this->graphQlQuery($query); + } + + /** + * _security + * @magentoApiDataFixture Magento/Customer/_files/three_customers.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.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/set_new_billing_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php + */ + public function testPlaceOrderOfAnotherCustomerCart() + { + $reservedOrderId = 'test_quote'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); + $query = $this->getQuery($maskedQuoteId); + + self::expectExceptionMessageRegExp('/The current user cannot perform operations on cart*/'); + $this->graphQlQuery($query); + } + /** * @param string $maskedQuoteId * @return string From b946dd0eae58d0cc0ccb9bb5e6be6b8aea4b7a77 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Mon, 8 Apr 2019 12:18:28 -0500 Subject: [PATCH 13/21] GraphQL-540: Replace deprecated Magento/Checkout/_files/quote_with_address_saved.php fixture in SetUpsShippingMethodsOnCartTest --- .../Ups/SetUpsShippingMethodsOnCartTest.php | 49 ++++++++++--------- .../Ups/_files/enable_ups_shipping_method.php | 1 + .../enable_ups_shipping_method_rollback.php | 1 + 3 files changed, 29 insertions(+), 22 deletions(-) rename dev/tests/integration/testsuite/Magento/{ => GraphQl}/Ups/_files/enable_ups_shipping_method.php (87%) rename dev/tests/integration/testsuite/Magento/{ => GraphQl}/Ups/_files/enable_ups_shipping_method_rollback.php (84%) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php index 838017b3455d..a46cf6f0e16b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -55,39 +55,44 @@ protected function setUp() } /** - * @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/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php + * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php * - * @param string $carrierMethodCode - * @param string $carrierMethodLabel + * @param string $methodCode + * @param string $methodLabel * @dataProvider availableForCartShippingMethods */ - public function testSetAvailableForCartUpsShippingMethod(string $carrierMethodCode, string $carrierMethodLabel) + public function testSetAvailableUpsShippingMethodOnCart(string $methodCode, string $methodLabel) { $quoteReservedId = 'test_quote'; $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - $query = $this->getQuery( - $maskedQuoteId, - $shippingAddressId, - self::CARRIER_CODE, - $carrierMethodCode - ); + $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); + $response = $this->graphQlQuery($query); - $response = $this->sendRequestWithToken($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']); - $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; - $expectedResult = [ - 'carrier_code' => self::CARRIER_CODE, - 'method_code' => $carrierMethodCode, - 'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel, - ]; - self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); + $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingAddress); + + self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); + self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); + + self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); + + self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); + self::assertEquals( + self::CARRIER_LABEL . ' - ' . $methodLabel, + $shippingAddress['selected_shipping_method']['label'] + ); } /** @@ -96,7 +101,7 @@ public function testSetAvailableForCartUpsShippingMethod(string $carrierMethodCo * @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/Ups/_files/enable_ups_shipping_method.php + * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php * * @param string $carrierMethodCode * @param string $carrierMethodLabel diff --git a/dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method.php b/dev/tests/integration/testsuite/Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php similarity index 87% rename from dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method.php rename to dev/tests/integration/testsuite/Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php index 5c6c60866faf..ffdc215d50a6 100644 --- a/dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method.php +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Ups/_files/enable_ups_shipping_method.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/Ups/_files/enable_ups_shipping_method_rollback.php b/dev/tests/integration/testsuite/Magento/GraphQl/Ups/_files/enable_ups_shipping_method_rollback.php similarity index 84% rename from dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method_rollback.php rename to dev/tests/integration/testsuite/Magento/GraphQl/Ups/_files/enable_ups_shipping_method_rollback.php index 6d7894879f97..243ec0217a0b 100644 --- a/dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method_rollback.php +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Ups/_files/enable_ups_shipping_method_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; From 9e8519de2367581ff26dc76432e88a7ccbf987d8 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Thu, 11 Apr 2019 12:24:00 +0200 Subject: [PATCH 14/21] Tests refactoring based on new fixtures principle --- .../GraphQl/Quote/Customer/CartTotalsTest.php | 47 ++++++++----- .../GraphQl/Quote/Guest/CartTotalsTest.php | 53 +++++++++------ .../_files/product_simple_with_tax.php | 45 ------------- .../product_simple_with_tax_rollback.php | 8 --- .../_files/quote_with_address_guest.php | 61 ----------------- .../quote_with_address_guest_rollback.php | 21 ------ .../_files/quote_with_customer_no_address.php | 48 ------------- ...uote_with_customer_no_address_rollback.php | 22 ------ .../_files/quote_with_tax_customer.php | 67 ------------------- .../quote_with_tax_customer_rollback.php | 22 ------ .../Checkout/_files/quote_with_tax_guest.php | 63 ----------------- .../_files/quote_with_tax_guest_rollback.php | 21 ------ .../_files/customer_with_tax_group.php | 10 --- .../customer_with_tax_group_rollback.php | 7 -- .../_files/apply_tax_for_simple_product.php | 26 +++++++ .../Tax/_files/tax_rule_for_region_1.php | 53 +++++++++++++++ .../_files/tax_rule_for_region_1_rollback.php | 38 +++++++++++ 17 files changed, 181 insertions(+), 431 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax.php delete mode 100644 dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax_rollback.php delete mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest.php delete mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest_rollback.php delete mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address.php delete mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address_rollback.php delete mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer.php delete mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer_rollback.php delete mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php delete mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest_rollback.php delete mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group.php delete mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Catalog/_files/apply_tax_for_simple_product.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Tax/_files/tax_rule_for_region_1_rollback.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php index 8dc6650b68f9..4a25e9331d86 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php @@ -49,34 +49,46 @@ protected function setUp() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax_customer.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/apply_tax_for_simple_product.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/set_new_billing_address.php */ public function testGetCartTotalsWithTaxApplied() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_tax'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_quote'); $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); $response = $this->sendRequestWithToken($query); self::assertArrayHasKey('prices', $response['cart']); $pricesResponse = $response['cart']['prices']; - self::assertEquals(10.83, $pricesResponse['grand_total']['value']); - self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + self::assertEquals(21.5, $pricesResponse['grand_total']['value']); + self::assertEquals(21.5, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(20, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(20, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); $appliedTaxesResponse = $pricesResponse['applied_taxes']; - self::assertEquals('US-CA-*-Rate 1', $appliedTaxesResponse[0]['label']); - self::assertEquals(0.83, $appliedTaxesResponse[0]['amount']['value']); + self::assertEquals('US-TEST-*-Rate-1', $appliedTaxesResponse[0]['label']); + self::assertEquals(1.5, $appliedTaxesResponse[0]['amount']['value']); self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/set_new_billing_address.php */ public function testGetTotalsWithNoTaxApplied() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_quote'); $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); $response = $this->sendRequestWithToken($query); @@ -92,19 +104,22 @@ public function testGetTotalsWithNoTaxApplied() * The totals calculation is based on quote address. * But the totals should be calculated even if no address is set * - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_customer_no_address.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ public function testGetCartTotalsWithNoAddressSet() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_quote'); $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); $response = $this->sendRequestWithToken($query); $pricesResponse = $response['cart']['prices']; - self::assertEquals(10, $pricesResponse['grand_total']['value']); - self::assertEquals(10, $pricesResponse['subtotal_including_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + self::assertEquals(20, $pricesResponse['grand_total']['value']); + self::assertEquals(20, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(20, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(20, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); self::assertEmpty($pricesResponse['applied_taxes']); } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php index 19ef071b5040..9fec6fdfd269 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php @@ -42,42 +42,52 @@ protected function setUp() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax_guest.php + * @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/apply_tax_for_simple_product.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_new_billing_address.php */ public function testGetCartTotalsWithTaxApplied() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_tax'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_quote'); $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); $response = $this->graphQlQuery($query); self::assertArrayHasKey('prices', $response['cart']); $pricesResponse = $response['cart']['prices']; - self::assertEquals(10.83, $pricesResponse['grand_total']['value']); - self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + self::assertEquals(21.5, $pricesResponse['grand_total']['value']); + self::assertEquals(21.5, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(20, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(20, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); $appliedTaxesResponse = $pricesResponse['applied_taxes']; - self::assertEquals('US-CA-*-Rate 1', $appliedTaxesResponse[0]['label']); - self::assertEquals(0.83, $appliedTaxesResponse[0]['amount']['value']); + self::assertEquals('US-TEST-*-Rate-1', $appliedTaxesResponse[0]['label']); + self::assertEquals(1.5, $appliedTaxesResponse[0]['amount']['value']); self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_guest.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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_new_billing_address.php */ public function testGetTotalsWithNoTaxApplied() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_quote'); $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); $response = $this->graphQlQuery($query); $pricesResponse = $response['cart']['prices']; - self::assertEquals(10, $pricesResponse['grand_total']['value']); - self::assertEquals(10, $pricesResponse['subtotal_including_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + self::assertEquals(20, $pricesResponse['grand_total']['value']); + self::assertEquals(20, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(20, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(20, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); self::assertEmpty($pricesResponse['applied_taxes']); } @@ -85,19 +95,22 @@ public function testGetTotalsWithNoTaxApplied() * The totals calculation is based on quote address. * But the totals should be calculated even if no address is set * - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @group recent */ public function testGetCartTotalsWithNoAddressSet() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_quote'); $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); $response = $this->graphQlQuery($query); $pricesResponse = $response['cart']['prices']; - self::assertEquals(10, $pricesResponse['grand_total']['value']); - self::assertEquals(10, $pricesResponse['subtotal_including_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']); - self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + self::assertEquals(20, $pricesResponse['grand_total']['value']); + self::assertEquals(20, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(20, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(20, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); self::assertEmpty($pricesResponse['applied_taxes']); } diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax.php deleted file mode 100644 index 00c2e6673646..000000000000 --- a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax.php +++ /dev/null @@ -1,45 +0,0 @@ -create(ProductRepositoryInterface::class); -/** @var ProductFactory $productFactory */ -$productFactory = $objectManager->create(ProductFactory::class); -$product = $productFactory->create(); -$product - ->setTypeId('simple') - ->setId(1) - ->setAttributeSetId(4) - ->setWebsiteIds([1]) - ->setName('Simple Product') - ->setSku('simple') - ->setPrice(10) - ->setMetaTitle('meta title') - ->setMetaKeyword('meta keyword') - ->setMetaDescription('meta description') - ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH) - ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) - ->setStockData(['use_config_manage_stock' => 1, 'qty' => 22, 'is_in_stock' => 1]) - ->setQty(22); - - -/** @var TaxClassCollectionFactory $taxClassCollectionFactory */ -$taxClassCollectionFactory = $objectManager->create(TaxClassCollectionFactory::class); -$taxClassCollection = $taxClassCollectionFactory->create(); - -/** @var TaxClassModel $taxClass */ -$taxClassCollection->addFieldToFilter('class_type', TaxClassModel::TAX_CLASS_TYPE_PRODUCT); -$taxClass = $taxClassCollection->getFirstItem(); - -$product->setCustomAttribute('tax_class_id', $taxClass->getClassId()); -$productRepository->save($product); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax_rollback.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax_rollback.php deleted file mode 100644 index a7d58fdf7f6f..000000000000 --- a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_tax_rollback.php +++ /dev/null @@ -1,8 +0,0 @@ -create(AddressInterface::class); -$quoteAddress->setData( - [ - 'telephone' => 3468676, - 'postcode' => 75477, - 'country_id' => 'US', - 'city' => 'CityM', - 'company' => 'CompanyName', - 'street' => 'Green str, 67', - 'lastname' => 'Smith', - 'firstname' => 'John', - 'region_id' => 1 - ] -); - -/** @var Quote $quote */ -$quote = $objectManager->create(Quote::class); -$quote->setStoreId( - 1 -)->setIsActive( - true -)->setIsMultiShipping( - false -)->setShippingAddress( - $quoteAddress -)->setBillingAddress( - $quoteAddress -)->setCheckoutMethod( - 'customer' -)->setReservedOrderId( - 'test_order_1' -)->addProduct( - $product -); - -$quoteRepository = $objectManager->get( - \Magento\Quote\Api\CartRepositoryInterface::class -); - -$quoteRepository->save($quote); - -/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ -$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create(\Magento\Quote\Model\QuoteIdMaskFactory::class) - ->create(); -$quoteIdMask->setQuoteId($quote->getId()); -$quoteIdMask->setDataChanges(true); -$quoteIdMask->save(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest_rollback.php deleted file mode 100644 index 3130ca9353e9..000000000000 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_guest_rollback.php +++ /dev/null @@ -1,21 +0,0 @@ -create(Quote::class); -$quote->load('test_order_1', 'reserved_order_id')->delete(); - -/** @var QuoteIdMask $quoteIdMask */ -$quoteIdMask = $objectManager->create(QuoteIdMask::class); -$quoteIdMask->delete($quote->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address.php deleted file mode 100644 index ef030f8bcd92..000000000000 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address.php +++ /dev/null @@ -1,48 +0,0 @@ -create(CustomerRepositoryInterface::class); -$customer = $customerRepository->get('customer@example.com'); - -/** @var Quote $quote */ -$quote = $objectManager->create(Quote::class); -$quote->setStoreId( - 1 -)->setIsActive( - true -)->setIsMultiShipping( - false -)->assignCustomer( - $customer -)->setCheckoutMethod( - 'customer' -)->setReservedOrderId( - 'test_order_1' -)->addProduct( - $product -); - -$quoteRepository = $objectManager->get( - \Magento\Quote\Api\CartRepositoryInterface::class -); - -$quoteRepository->save($quote); - -/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ -$quoteIdMask = $objectManager - ->get(\Magento\Quote\Model\QuoteIdMaskFactory::class) - ->create(); -$quoteIdMask->setQuoteId($quote->getId()); -$quoteIdMask->setDataChanges(true); -$quoteIdMask->save(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address_rollback.php deleted file mode 100644 index 83c80d736c16..000000000000 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_customer_no_address_rollback.php +++ /dev/null @@ -1,22 +0,0 @@ -create(Quote::class); -$quote->load('test_order_1', 'reserved_order_id')->delete(); - -/** @var QuoteIdMask $quoteIdMask */ -$quoteIdMask = $objectManager->create(QuoteIdMask::class); -$quoteIdMask->delete($quote->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer.php deleted file mode 100644 index e9cb45b546a4..000000000000 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer.php +++ /dev/null @@ -1,67 +0,0 @@ -get(AddressRepositoryInterface::class); -$customerAddress = $addressRepository->getById(1); -$customerAddress->setRegionId(12); // Taxable region -$addressRepository->save($customerAddress); -/** @var CustomerRepositoryInterface $customerRepository */ -$customerRepository = $objectManager->create(CustomerRepositoryInterface::class); -$customer = $customerRepository->get('customer@example.com'); - -/** @var Address $quoteAddress */ -$quoteAddress = $objectManager->create(Address::class); -$quoteAddress->importCustomerAddressData($customerAddress); - -/** @var Quote $quote */ -$quote = $objectManager->create(Quote::class); -$quote->setStoreId( - 1 -)->setIsActive( - true -)->setIsMultiShipping( - false -)->assignCustomer( - $customer -)->setShippingAddress( - $quoteAddress -)->setBillingAddress( - $quoteAddress -)->setCheckoutMethod( - 'customer' -)->setReservedOrderId( - 'test_order_tax' -)->addProduct( - $product -); - -$quote->getShippingAddress()->setRegionId(12); - -$quoteRepository = $objectManager->get( - \Magento\Quote\Api\CartRepositoryInterface::class -); - -$quoteRepository->save($quote); - -/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ -$quoteIdMask = $objectManager - ->get(\Magento\Quote\Model\QuoteIdMaskFactory::class) - ->create(); -$quoteIdMask->setQuoteId($quote->getId()); -$quoteIdMask->setDataChanges(true); -$quoteIdMask->save(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer_rollback.php deleted file mode 100644 index 1e1eb326d7c8..000000000000 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer_rollback.php +++ /dev/null @@ -1,22 +0,0 @@ -create(Quote::class); -$quote->load('test_order_tax', 'reserved_order_id')->delete(); - -/** @var QuoteIdMask $quoteIdMask */ -$quoteIdMask = $objectManager->create(QuoteIdMask::class); -$quoteIdMask->delete($quote->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php deleted file mode 100644 index 78d5b0739d76..000000000000 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php +++ /dev/null @@ -1,63 +0,0 @@ -create(AddressInterface::class); -$quoteAddress->setData( - [ - 'telephone' => 3468676, - 'postcode' => 75477, - 'country_id' => 'US', - 'city' => 'CityM', - 'company' => 'CompanyName', - 'street' => 'Green str, 67', - 'lastname' => 'Smith', - 'firstname' => 'John', - 'region_id' => 12 - ] -); - -/** @var Quote $quote */ -$quote = $objectManager->create(Quote::class); -$quote->setStoreId( - 1 -)->setIsActive( - true -)->setIsMultiShipping( - false -)->setShippingAddress( - $quoteAddress -)->setBillingAddress( - $quoteAddress -)->setCheckoutMethod( - 'guest' -)->setReservedOrderId( - 'test_order_tax' -)->addProduct( - $product -); - -$quote->getShippingAddress()->setRegionId(12); - -$quoteRepository = $objectManager->get( - \Magento\Quote\Api\CartRepositoryInterface::class -); - -$quoteRepository->save($quote); - -/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ -$quoteIdMask = $objectManager - ->get(\Magento\Quote\Model\QuoteIdMaskFactory::class) - ->create(); -$quoteIdMask->setQuoteId($quote->getId()); -$quoteIdMask->setDataChanges(true); -$quoteIdMask->save(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest_rollback.php deleted file mode 100644 index 6fcbdf7276de..000000000000 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest_rollback.php +++ /dev/null @@ -1,21 +0,0 @@ -create(Quote::class); -$quote->load('test_order_tax', 'reserved_order_id')->delete(); - -/** @var QuoteIdMask $quoteIdMask */ -$quoteIdMask = $objectManager->create(QuoteIdMask::class); -$quoteIdMask->delete($quote->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group.php deleted file mode 100644 index 4792df5cdb2f..000000000000 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group.php +++ /dev/null @@ -1,10 +0,0 @@ -setGroupId(3); // 3 is a predefined retailer group -$customer->save(); diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group_rollback.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group_rollback.php deleted file mode 100644 index 48a09a41c7e0..000000000000 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_with_tax_group_rollback.php +++ /dev/null @@ -1,7 +0,0 @@ -get(ProductRepositoryInterface::class); +$product = $productRepository->get('simple_product'); + +/** @var TaxClassCollectionFactory $taxClassCollectionFactory */ +$taxClassCollectionFactory = $objectManager->get(TaxClassCollectionFactory::class); +$taxClassCollection = $taxClassCollectionFactory->create(); + +/** @var TaxClassModel $taxClass */ +$taxClassCollection->addFieldToFilter('class_type', TaxClassModel::TAX_CLASS_TYPE_PRODUCT); +$taxClass = $taxClassCollection->getFirstItem(); + +$product->setCustomAttribute('tax_class_id', $taxClass->getClassId()); +$productRepository->save($product); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php b/dev/tests/integration/testsuite/Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php new file mode 100644 index 000000000000..aca55bd8414f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php @@ -0,0 +1,53 @@ +get(DataObjectHelper::class); +/** @var RateFactory $rateFactory */ +$rateFactory = $objectManager->get(RateFactory::class); +/** @var RuleFactory $ruleFactory */ +$ruleFactory = $objectManager->get(RuleFactory::class); +/** @var RateRepository $rateRepository */ +$rateRepository = $objectManager->get(TaxRateRepositoryInterface::class); +/** @var TaxRuleRepository $ruleRepository */ +$ruleRepository = $objectManager->get(TaxRuleRepositoryInterface::class); +/** @var Rate $rate */ +$rate = $rateFactory->create(); +$rateData = [ + Rate::KEY_COUNTRY_ID => 'US', + Rate::KEY_REGION_ID => '1', + Rate::KEY_POSTCODE => '*', + Rate::KEY_CODE => 'US-TEST-*-Rate-1', + Rate::KEY_PERCENTAGE_RATE => '7.5', +]; +$dataObjectHelper->populateWithArray($rate, $rateData, TaxRateInterface::class); +$rateRepository->save($rate); + +$rule = $ruleFactory->create(); +$ruleData = [ + Rule::KEY_CODE=> 'GraphQl Test Rule', + Rule::KEY_PRIORITY => '0', + Rule::KEY_POSITION => '0', + Rule::KEY_CUSTOMER_TAX_CLASS_IDS => [3], + Rule::KEY_PRODUCT_TAX_CLASS_IDS => [2], + Rule::KEY_TAX_RATE_IDS => [$rate->getId()], +]; +$dataObjectHelper->populateWithArray($rule, $ruleData, TaxRuleInterface::class); +$ruleRepository->save($rule); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Tax/_files/tax_rule_for_region_1_rollback.php b/dev/tests/integration/testsuite/Magento/GraphQl/Tax/_files/tax_rule_for_region_1_rollback.php new file mode 100644 index 000000000000..aba1960624ed --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Tax/_files/tax_rule_for_region_1_rollback.php @@ -0,0 +1,38 @@ +get(RateFactory::class); +/** @var RuleFactory $ruleFactory */ +$ruleFactory = $objectManager->get(RuleFactory::class); +/** @var RateRepository $rateRepository */ +$rateRepository = $objectManager->get(TaxRateRepositoryInterface::class); +/** @var TaxRuleRepository $ruleRepository */ +$ruleRepository = $objectManager->get(TaxRuleRepositoryInterface::class); +/** @var RateResource $rateResource */ +$rateResource = $objectManager->get(RateResource::class); +/** @var RuleResource $ruleResource */ +$ruleResource = $objectManager->get(RuleResource::class); + +$rate = $rateFactory->create(); +$rateResource->load($rate, 'US-TEST-*-Rate-1', Rate::KEY_CODE); +$rule = $ruleFactory->create(); +$ruleResource->load($rule, 'GraphQl Test Rule', Rule::KEY_CODE); +$ruleRepository->delete($rule); +$rateRepository->delete($rate); From 87312d4b58e57f70962ebc7078dd87cf2a29ac6c Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Fri, 12 Apr 2019 11:36:08 -0500 Subject: [PATCH 15/21] GraphQL-564: [Checkout coverage] setGuestEmailOnCart mutation --- .../testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php index 648b8265ee67..31f60afc1331 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php @@ -226,7 +226,7 @@ public function testPlaceOrderWithOutOfStockProduct() * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php */ - public function testPlaceOrderOfAnotherCustomerCart() + public function testPlaceOrderOfCustomerCart() { $reservedOrderId = 'test_quote'; $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); From 78f02fa51cd4322bd89785c95805ca4b7359443a Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Sat, 13 Apr 2019 09:27:02 +0300 Subject: [PATCH 16/21] magento/graphql-ce#540: Replace deprecated fixture --- .../Ups/SetUpsShippingMethodsOnCartTest.php | 160 ++++++++++++++---- 1 file changed, 124 insertions(+), 36 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php index d4e6448eb5fb..3e2d6d23f6c2 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -55,20 +55,21 @@ protected function setUp() } /** + * Set "Next Day Air Early AM" UPS shipping method + * * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php - * - * @param string $carrierMethodCode - * @param string $carrierMethodLabel - * @dataProvider availableForCartShippingMethods */ - public function testSetAvailableForCartUpsShippingMethod(string $carrierMethodCode, string $carrierMethodLabel) + public function testSetNextDayAirEarlyAmUpsShippingMethod() { $quoteReservedId = 'test_quote'; + $carrierMethodCode = '1DM'; + $carrierMethodLabel = 'Next Day Air Early AM'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); @@ -91,20 +92,21 @@ public function testSetAvailableForCartUpsShippingMethod(string $carrierMethodCo } /** + * Set "Next Day Air" UPS shipping method + * * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php - * - * @param string $carrierMethodCode - * @param string $carrierMethodLabel - * @dataProvider notAvailableForCartShippingMethods */ - public function testSetNotAvailableForCartUpsShippingMethod(string $carrierMethodCode, string $carrierMethodLabel) + public function testSetNextDayAirUpsShippingMethod() { $quoteReservedId = 'test_quote'; + $carrierMethodCode = '1DA'; + $carrierMethodLabel = 'Next Day Air'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); @@ -115,8 +117,41 @@ public function testSetNotAvailableForCartUpsShippingMethod(string $carrierMetho $carrierMethodCode ); - $this->expectExceptionMessage( - "GraphQL response contains errors: Carrier with such method not found: " . self::CARRIER_CODE . ", " . $carrierMethodCode + $response = $this->sendRequestWithToken($query); + + $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; + $expectedResult = [ + 'carrier_code' => self::CARRIER_CODE, + 'method_code' => $carrierMethodCode, + 'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel, + ]; + self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); + } + + /** + * Set "2nd Day Air" UPS shipping method + * + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php + */ + public function testSet2ndDayAirUpsShippingMethod() + { + $quoteReservedId = 'test_quote'; + $carrierMethodCode = '2DA'; + $carrierMethodLabel = '2nd Day Air'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); + $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); + + $query = $this->getQuery( + $maskedQuoteId, + $shippingAddressId, + self::CARRIER_CODE, + $carrierMethodCode ); $response = $this->sendRequestWithToken($query); @@ -131,56 +166,109 @@ public function testSetNotAvailableForCartUpsShippingMethod(string $carrierMetho } /** - * @return array + * Set "3 Day Select" UPS shipping method + * + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php */ - public function availableForCartShippingMethods(): array + public function testSet3DaySelectUpsShippingMethod() { - $shippingMethods = ['1DM', '1DA', '2DA', '3DS', 'GND']; + $quoteReservedId = 'test_quote'; + $carrierMethodCode = '3DS'; + $carrierMethodLabel = '3 Day Select'; - return $this->filterShippingMethodsByCodes($shippingMethods); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); + $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); + + $query = $this->getQuery( + $maskedQuoteId, + $shippingAddressId, + self::CARRIER_CODE, + $carrierMethodCode + ); + + $response = $this->sendRequestWithToken($query); + + $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; + $expectedResult = [ + 'carrier_code' => self::CARRIER_CODE, + 'method_code' => $carrierMethodCode, + 'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel, + ]; + self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); } /** - * @return array + * Set "Ground" UPS shipping method + * + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php */ - public function notAvailableForCartShippingMethods(): array + public function testSetGroundUpsShippingMethod() { - $shippingMethods = ['1DML', '1DAL', '1DAPI', '1DP', '1DPL', '2DM', '2DML', '2DAL', 'GNDCOM', 'GNDRES', 'STD', 'XPR', 'WXS', 'XPRL', 'XDM', 'XDML', 'XPD']; + $quoteReservedId = 'test_quote'; + $carrierMethodCode = 'GND'; + $carrierMethodLabel = 'Ground'; - return $this->filterShippingMethodsByCodes($shippingMethods); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); + $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); + + $query = $this->getQuery( + $maskedQuoteId, + $shippingAddressId, + self::CARRIER_CODE, + $carrierMethodCode + ); + + $response = $this->sendRequestWithToken($query); + + $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; + $expectedResult = [ + 'carrier_code' => self::CARRIER_CODE, + 'method_code' => $carrierMethodCode, + 'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel, + ]; + self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); } + + + + /** - * @param array $filter * @return array */ - private function filterShippingMethodsByCodes(array $filter):array + public function notAvailableForCartShippingMethods(): array { - $result = []; - foreach ($this->getAllUpsShippingMethods() as $shippingMethod) { - if (in_array($shippingMethod[0], $filter)) { - $result[] = $shippingMethod; - } - } - return $result; + $shippingMethods = ['1DML', '1DAL', '1DAPI', '1DP', '1DPL', '2DM', '2DML', '2DAL', 'GNDCOM', 'GNDRES', 'STD', 'XPR', 'WXS', 'XPRL', 'XDM', 'XDML', 'XPD']; + + return $this->filterShippingMethodsByCodes($shippingMethods); } private function getAllUpsShippingMethods():array { return [ - ['1DM', 'Next Day Air Early AM'], + ['1DM', 'Next Day Air Early AM'], // ['1DML', 'Next Day Air Early AM Letter'], - ['1DA', 'Next Day Air'], + ['1DA', 'Next Day Air'], // ['1DAL', 'Next Day Air Letter'], ['1DAPI', 'Next Day Air Intra (Puerto Rico)'], ['1DP', 'Next Day Air Saver'], ['1DPL', 'Next Day Air Saver Letter'], ['2DM', '2nd Day Air AM'], ['2DML', '2nd Day Air AM Letter'], - ['2DA', '2nd Day Air'], + ['2DA', '2nd Day Air'], // ['2DAL', '2nd Day Air Letter'], - ['3DS', '3 Day Select'], - ['GND', 'Ground'], + ['3DS', '3 Day Select'], // + ['GND', 'Ground'], // ['GNDCOM', 'Ground Commercial'], ['GNDRES', 'Ground Residential'], ['STD', 'Canada Standard'], From 8f0c2332e712c174cb8ff946553f87995d9bf4ea Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Sat, 13 Apr 2019 18:35:54 +0300 Subject: [PATCH 17/21] magento/graphql-ce#540: Replace deprecated fixture --- .../Ups/SetUpsShippingMethodsOnCartTest.php | 479 +++++++++++------- .../Quote/_files/set_new_shipping_address.php | 2 +- .../set_new_shipping_canada_address.php | 43 ++ 3 files changed, 349 insertions(+), 175 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_canada_address.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php index de05a860f6b0..ccb925770184 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -14,7 +14,37 @@ use Magento\TestFramework\TestCase\GraphQlAbstract; /** - * Test for setting "UPS" shipping method on cart + * Test for setting "UPS" shipping method on cart. Current class covers the next UPS shipping methods: + * + * | Code | Label + * -------------------------------------- + * | 1DM | Next Day Air Early AM + * | 1DA | Next Day Air + * | 2DA | 2nd Day Air + * | 3DS | 3 Day Select + * | GND | Ground + * | STD | Canada Standard + * | XPR | Worldwide Express + * | WXS | Worldwide Express Saver + * | XDM | Worldwide Express Plus + * | XPD | Worldwide Expedited + * + * Current class does not cover these UPS shipping methods (depends on sandbox settings) + * + * | Code | Label + * -------------------------------------- + * | 1DML | Next Day Air Early AM Letter + * | 1DAL | Next Day Air Letter + * | 1DAPI | Next Day Air Intra (Puerto Rico) + * | 1DP | Next Day Air Saver + * | 1DPL | Next Day Air Saver Letter + * | 2DM | 2nd Day Air AM + * | 2DML | 2nd Day Air AM Letter + * | 2DAL | 2nd Day Air Letter + * | GNDCOM | Ground Commercial + * | GNDRES | Ground Residential + * | XPRL | Worldwide Express Letter + * | XDML | Worldwide Express Plus Letter */ class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract { @@ -55,24 +85,26 @@ protected function setUp() } /** + * Set "Next Day Air Early AM" UPS shipping method + * + * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php - * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.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/Ups/_files/enable_ups_shipping_method.php - * - * @param string $methodCode - * @param string $methodLabel - * @dataProvider availableForCartShippingMethods */ - public function testSetAvailableUpsShippingMethodOnCart(string $methodCode, string $methodLabel) + public function testSetNextDayAirEarlyAmUpsShippingMethod() { $quoteReservedId = 'test_quote'; + $methodCode = '1DM'; + $methodLabel = 'Next Day Air Early AM'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); - $response = $this->graphQlQuery($query); + $response = $this->sendRequestWithToken($query); self::assertArrayHasKey('setShippingMethodsOnCart', $response); self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); @@ -96,291 +128,390 @@ public function testSetAvailableUpsShippingMethodOnCart(string $methodCode, stri } /** - * Set "Next Day Air Early AM" UPS shipping method + * Set "Next Day Air" UPS shipping method * * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php + * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php */ - public function testSetNextDayAirEarlyAmUpsShippingMethod() + public function testSetNextDayAirUpsShippingMethod() { $quoteReservedId = 'test_quote'; - $carrierMethodCode = '1DM'; - $carrierMethodLabel = 'Next Day Air Early AM'; + $methodCode = '1DA'; + $methodLabel = 'Next Day Air'; $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - $query = $this->getQuery( - $maskedQuoteId, - $shippingAddressId, - self::CARRIER_CODE, - $carrierMethodCode - ); - + $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); $response = $this->sendRequestWithToken($query); - $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; - $expectedResult = [ - 'carrier_code' => self::CARRIER_CODE, - 'method_code' => $carrierMethodCode, - 'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel, - ]; - self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); + self::assertArrayHasKey('setShippingMethodsOnCart', $response); + self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); + self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); + self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + + $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingAddress); + + self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); + self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); + + self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); + + self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); + self::assertEquals( + self::CARRIER_LABEL . ' - ' . $methodLabel, + $shippingAddress['selected_shipping_method']['label'] + ); } /** - * Set "Next Day Air" UPS shipping method + * Set "2nd Day Air" UPS shipping method * * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php + * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php */ - public function testSetNextDayAirUpsShippingMethod() + public function testSet2ndDayAirUpsShippingMethod() { $quoteReservedId = 'test_quote'; - $carrierMethodCode = '1DA'; - $carrierMethodLabel = 'Next Day Air'; + $methodCode = '2DA'; + $methodLabel = '2nd Day Air'; $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - $query = $this->getQuery( - $maskedQuoteId, - $shippingAddressId, - self::CARRIER_CODE, - $carrierMethodCode - ); - + $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); $response = $this->sendRequestWithToken($query); - $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; - $expectedResult = [ - 'carrier_code' => self::CARRIER_CODE, - 'method_code' => $carrierMethodCode, - 'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel, - ]; - self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); + self::assertArrayHasKey('setShippingMethodsOnCart', $response); + self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); + self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); + self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + + $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingAddress); + + self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); + self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); + + self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); + + self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); + self::assertEquals( + self::CARRIER_LABEL . ' - ' . $methodLabel, + $shippingAddress['selected_shipping_method']['label'] + ); } /** - * Set "2nd Day Air" UPS shipping method + * Set "3 Day Select" UPS shipping method * * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php + * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php */ - public function testSet2ndDayAirUpsShippingMethod() + public function testSet3DaySelectUpsShippingMethod() { $quoteReservedId = 'test_quote'; - $carrierMethodCode = '2DA'; - $carrierMethodLabel = '2nd Day Air'; + $methodCode = '3DS'; + $methodLabel = '3 Day Select'; $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - $query = $this->getQuery( - $maskedQuoteId, - $shippingAddressId, - self::CARRIER_CODE, - $carrierMethodCode - ); - + $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); $response = $this->sendRequestWithToken($query); - $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; - $expectedResult = [ - 'carrier_code' => self::CARRIER_CODE, - 'method_code' => $carrierMethodCode, - 'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel, - ]; - self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); + self::assertArrayHasKey('setShippingMethodsOnCart', $response); + self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); + self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); + self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + + $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingAddress); + + self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); + self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); + + self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); + + self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); + self::assertEquals( + self::CARRIER_LABEL . ' - ' . $methodLabel, + $shippingAddress['selected_shipping_method']['label'] + ); } /** - * Set "3 Day Select" UPS shipping method + * Set "Ground" UPS shipping method * * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php + * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php */ - public function testSet3DaySelectUpsShippingMethod() + public function testSetGroundUpsShippingMethod() { $quoteReservedId = 'test_quote'; - $carrierMethodCode = '3DS'; - $carrierMethodLabel = '3 Day Select'; + $methodCode = 'GND'; + $methodLabel = 'Ground'; $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - $query = $this->getQuery( - $maskedQuoteId, - $shippingAddressId, - self::CARRIER_CODE, - $carrierMethodCode - ); - + $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); $response = $this->sendRequestWithToken($query); - $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; - $expectedResult = [ - 'carrier_code' => self::CARRIER_CODE, - 'method_code' => $carrierMethodCode, - 'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel, - ]; - self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); + self::assertArrayHasKey('setShippingMethodsOnCart', $response); + self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); + self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); + self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + + $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingAddress); + + self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); + self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); + + self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); + + self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); + self::assertEquals( + self::CARRIER_LABEL . ' - ' . $methodLabel, + $shippingAddress['selected_shipping_method']['label'] + ); } /** - * Set "Ground" UPS shipping method + * Set "Canada Standard" UPS shipping method * * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_canada_address.php + * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php */ - public function testSetGroundUpsShippingMethod() + public function testSetCanadaStandardUpsShippingMethod() { $quoteReservedId = 'test_quote'; - $carrierMethodCode = 'GND'; - $carrierMethodLabel = 'Ground'; + $methodCode = 'STD'; + $methodLabel = 'Canada Standard'; $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - $query = $this->getQuery( - $maskedQuoteId, - $shippingAddressId, - self::CARRIER_CODE, - $carrierMethodCode - ); - + $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); $response = $this->sendRequestWithToken($query); - $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; - $expectedResult = [ - 'carrier_code' => self::CARRIER_CODE, - 'method_code' => $carrierMethodCode, - 'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel, - ]; - self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); + self::assertArrayHasKey('setShippingMethodsOnCart', $response); + self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); + self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); + self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + + $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingAddress); + + self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); + self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); + + self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); + + self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); + self::assertEquals( + self::CARRIER_LABEL . ' - ' . $methodLabel, + $shippingAddress['selected_shipping_method']['label'] + ); } /** + * Set "Worldwide Express" UPS shipping method + * * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php - * - * @param string $carrierMethodCode - * @param string $carrierMethodLabel - * @dataProvider notAvailableForCartShippingMethods + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_canada_address.php + * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php */ - public function testSetNotAvailableForCartUpsShippingMethod(string $carrierMethodCode, string $carrierMethodLabel) + public function testSetWorldwideExpressUpsShippingMethod() { $quoteReservedId = 'test_quote'; + $methodCode = 'XPR'; + $methodLabel = 'Worldwide Express'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - $query = $this->getQuery( - $maskedQuoteId, - $shippingAddressId, - self::CARRIER_CODE, - $carrierMethodCode - ); + $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); + $response = $this->sendRequestWithToken($query); - $this->expectExceptionMessage( - "GraphQL response contains errors: Carrier with such method not found: " . self::CARRIER_CODE . ", " . $carrierMethodCode - ); + self::assertArrayHasKey('setShippingMethodsOnCart', $response); + self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); + self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); + self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - $response = $this->sendRequestWithToken($query); + $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingAddress); + + self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); + self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); - $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; - $expectedResult = [ - 'carrier_code' => self::CARRIER_CODE, - 'method_code' => $carrierMethodCode, - 'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel, - ]; - self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); + self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); + + self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); + self::assertEquals( + self::CARRIER_LABEL . ' - ' . $methodLabel, + $shippingAddress['selected_shipping_method']['label'] + ); } /** - * @return array + * Set "Worldwide Express Saver" UPS shipping method + * + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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_canada_address.php + * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php */ - public function availableForCartShippingMethods(): array + public function testSetWorldwideExpressSaverUpsShippingMethod() { - $shippingMethods = ['1DM', '1DA', '2DA', '3DS', 'GND']; + $quoteReservedId = 'test_quote'; + $methodCode = 'WXS'; + $methodLabel = 'Worldwide Express Saver'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); + $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); + + $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); + $response = $this->sendRequestWithToken($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']); + + $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingAddress); - return $this->filterShippingMethodsByCodes($shippingMethods); + self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); + self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); + + self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); + + self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); + self::assertEquals( + self::CARRIER_LABEL . ' - ' . $methodLabel, + $shippingAddress['selected_shipping_method']['label'] + ); } /** - * @return array + * Set "Worldwide Express Plus" UPS shipping method + * + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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_canada_address.php + * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php */ - public function notAvailableForCartShippingMethods(): array + public function testSetWorldwideExpressPlusUpsShippingMethod() { - $shippingMethods = ['1DML', '1DAL', '1DAPI', '1DP', '1DPL', '2DM', '2DML', '2DAL', 'GNDCOM', 'GNDRES', 'STD', 'XPR', 'WXS', 'XPRL', 'XDM', 'XDML', 'XPD']; + $quoteReservedId = 'test_quote'; + $methodCode = 'XDM'; + $methodLabel = 'Worldwide Express Plus'; + + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); + $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); + + $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); + $response = $this->sendRequestWithToken($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']); - return $this->filterShippingMethodsByCodes($shippingMethods); + $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingAddress); + + self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); + self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); + + self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); + + self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); + self::assertEquals( + self::CARRIER_LABEL . ' - ' . $methodLabel, + $shippingAddress['selected_shipping_method']['label'] + ); } /** - * @param array $filter - * @return array + * Set "Worldwide Expedited" UPS shipping method + * + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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_canada_address.php + * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php */ - private function filterShippingMethodsByCodes(array $filter):array + public function testSetWorldwideExpeditedUpsShippingMethod() { - $result = []; - foreach ($this->getAllUpsShippingMethods() as $shippingMethod) { - if (in_array($shippingMethod[0], $filter)) { - $result[] = $shippingMethod; - } - } - return $result; - } + $quoteReservedId = 'test_quote'; + $methodCode = 'XPD'; + $methodLabel = 'Worldwide Expedited'; - private function getAllUpsShippingMethods():array - { - return [ - ['1DM', 'Next Day Air Early AM'], // - ['1DML', 'Next Day Air Early AM Letter'], - ['1DA', 'Next Day Air'], // - ['1DAL', 'Next Day Air Letter'], - ['1DAPI', 'Next Day Air Intra (Puerto Rico)'], - ['1DP', 'Next Day Air Saver'], - ['1DPL', 'Next Day Air Saver Letter'], - ['2DM', '2nd Day Air AM'], - ['2DML', '2nd Day Air AM Letter'], - ['2DA', '2nd Day Air'], // - ['2DAL', '2nd Day Air Letter'], - ['3DS', '3 Day Select'], // - ['GND', 'Ground'], // - ['GNDCOM', 'Ground Commercial'], - ['GNDRES', 'Ground Residential'], - ['STD', 'Canada Standard'], - ['XPR', 'Worldwide Express'], - ['WXS', 'Worldwide Express Saver'], - ['XPRL', 'Worldwide Express Letter'], - ['XDM', 'Worldwide Express Plus'], - ['XDML', 'Worldwide Express Plus Letter'], - ['XPD', 'Worldwide Expedited'], - ]; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); + $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); + + $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); + $response = $this->sendRequestWithToken($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']); + + $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); + self::assertArrayHasKey('selected_shipping_method', $shippingAddress); + + self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); + self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); + + self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); + self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); + + self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); + self::assertEquals( + self::CARRIER_LABEL . ' - ' . $methodLabel, + $shippingAddress['selected_shipping_method']['label'] + ); } /** diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_address.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_address.php index e17b9e61f82d..54f4d8d0c6e7 100644 --- a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_address.php +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_address.php @@ -26,7 +26,7 @@ $quoteAddressData = [ AddressInterface::KEY_TELEPHONE => 3468676, - AddressInterface::KEY_POSTCODE => 75477, + AddressInterface::KEY_POSTCODE => '75477', AddressInterface::KEY_COUNTRY_ID => 'US', AddressInterface::KEY_CITY => 'CityM', AddressInterface::KEY_COMPANY => 'CompanyName', diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_canada_address.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_canada_address.php new file mode 100644 index 000000000000..8e60dc904bd4 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_canada_address.php @@ -0,0 +1,43 @@ +get(QuoteFactory::class); +/** @var QuoteResource $quoteResource */ +$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::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); + +$quoteAddressData = [ + AddressInterface::KEY_TELEPHONE => 3468676, + AddressInterface::KEY_POSTCODE => 'M4L 1V3', + AddressInterface::KEY_COUNTRY_ID => 'CA', + AddressInterface::KEY_CITY => 'Toronto', + AddressInterface::KEY_COMPANY => 'CompanyName', + AddressInterface::KEY_STREET => '500 Kingston Rd', + AddressInterface::KEY_LASTNAME => 'Smith', + AddressInterface::KEY_FIRSTNAME => 'John', + AddressInterface::KEY_REGION_CODE => 'ON', +]; +$quoteAddress = $quoteAddressFactory->create(); +$dataObjectHelper->populateWithArray($quoteAddress, $quoteAddressData, AddressInterfaceFactory::class); + +$quote = $quoteFactory->create(); +$quoteResource->load($quote, 'test_quote', 'reserved_order_id'); +$shippingAddressManagement->assign($quote->getId(), $quoteAddress); From 9d475b828a323d072619c3332fb3408ead9d7ca5 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Sat, 13 Apr 2019 18:49:38 +0300 Subject: [PATCH 18/21] magento/graphql-ce#540: Replace deprecated fixture 1. Use POST for mutation query instead of GET --- .../Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php index ccb925770184..b41c7d0898f7 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -567,6 +567,6 @@ private function sendRequestWithToken(string $query): array $customerToken = $this->customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; - return $this->graphQlQuery($query, [], '', $headerMap); + return $this->graphQlMutation($query, [], '', $headerMap); } } From 265d82e51adadf3d1c8ede0166c0aa82eac856f6 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Mon, 15 Apr 2019 12:31:55 -0500 Subject: [PATCH 19/21] GraphQL-425: [Place order] Cart grand total --- .../Resolver/{Totals.php => CartPrices.php} | 7 +- .../Magento/QuoteGraphQl/etc/schema.graphqls | 2 +- .../GraphQl/Quote/Customer/CartTotalsTest.php | 112 ++++++++++-------- .../GraphQl/Quote/Guest/CartTotalsTest.php | 69 ++++++----- 4 files changed, 102 insertions(+), 88 deletions(-) rename app/code/Magento/QuoteGraphQl/Model/Resolver/{Totals.php => CartPrices.php} (94%) diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/Totals.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php similarity index 94% rename from app/code/Magento/QuoteGraphQl/Model/Resolver/Totals.php rename to app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php index 926f2b2de3cf..7a9bdd926764 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/Totals.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php @@ -11,13 +11,14 @@ use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; +use Magento\Quote\Model\Quote; use Magento\Quote\Model\Quote\Address\Total; use Magento\Quote\Model\Quote\TotalsCollector; /** * @inheritdoc */ -class Totals implements ResolverInterface +class CartPrices implements ResolverInterface { /** * @var TotalsCollector @@ -68,10 +69,11 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value */ private function getAppliedTaxes(Total $total, string $currency): array { + $appliedTaxesData = []; $appliedTaxes = $total->getAppliedTaxes(); if (count($appliedTaxes) === 0) { - return []; + return $appliedTaxesData; } foreach ($appliedTaxes as $appliedTax) { @@ -80,7 +82,6 @@ private function getAppliedTaxes(Total $total, string $currency): array 'amount' => ['value' => $appliedTax['amount'], 'currency' => $currency] ]; } - return $appliedTaxesData; } } diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index 85a0703a137e..70690b102306 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -173,7 +173,7 @@ type Cart { billing_address: CartAddress! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\BillingAddress") available_payment_methods: [AvailablePaymentMethod] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AvailablePaymentMethods") @doc(description: "Available payment methods") selected_payment_method: SelectedPaymentMethod @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SelectedPaymentMethod") - prices: CartPrices @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\Totals") + prices: CartPrices @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartPrices") } type CartAddress { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php index 4a25e9331d86..bb8acfce629f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.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,26 +23,14 @@ class CartTotalsTest extends GraphQlAbstract private $customerTokenService; /** - * @var QuoteResource + * @var GetMaskedQuoteIdByReservedOrderId */ - private $quoteResource; - - /** - * @var QuoteFactory - */ - private $quoteFactory; - - /** - * @var QuoteIdToMaskedQuoteIdInterface - */ - private $quoteIdToMaskedId; + private $getMaskedQuoteIdByReservedOrderId; 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->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); } @@ -60,9 +46,9 @@ protected function setUp() */ public function testGetCartTotalsWithTaxApplied() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_quote'); - $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); - $response = $this->sendRequestWithToken($query); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); self::assertArrayHasKey('prices', $response['cart']); $pricesResponse = $response['cart']['prices']; @@ -88,9 +74,9 @@ public function testGetCartTotalsWithTaxApplied() */ public function testGetTotalsWithNoTaxApplied() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_quote'); - $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); - $response = $this->sendRequestWithToken($query); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); $pricesResponse = $response['cart']['prices']; self::assertEquals(20, $pricesResponse['grand_total']['value']); @@ -111,9 +97,9 @@ public function testGetTotalsWithNoTaxApplied() */ public function testGetCartTotalsWithNoAddressSet() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_quote'); - $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); - $response = $this->sendRequestWithToken($query); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); $pricesResponse = $response['cart']['prices']; self::assertEquals(20, $pricesResponse['grand_total']['value']); @@ -123,13 +109,57 @@ public function testGetCartTotalsWithNoAddressSet() self::assertEmpty($pricesResponse['applied_taxes']); } + /** + * _security + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/apply_tax_for_simple_product.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_new_billing_address.php + */ + public function testGetTotalsFromGuestCart() + { + $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()); + } + + /** + * _security + * @magentoApiDataFixture Magento/Customer/_files/three_customers.php + * @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/apply_tax_for_simple_product.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/set_new_billing_address.php + */ + public function testGetTotalsFromAnotherCustomerCart() + { + $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('customer3@search.example.com')); + } + /** * Generates GraphQl query for retrieving cart totals * * @param string $maskedQuoteId * @return string */ - private function getCartTotalsGraphqlQuery(string $maskedQuoteId): string + private function getQuery(string $maskedQuoteId): string { return <<quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } - - /** - * Sends a GraphQL request with using a bearer token - * - * @param string $query + * @param string $username + * @param string $password * @return array - * @throws \Magento\Framework\Exception\AuthenticationException */ - private function sendRequestWithToken(string $query): array + private function getHeaderMap(string $username = 'customer@example.com', string $password = 'password'): array { - - $customerToken = $this->customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + $customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password); $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; - - return $this->graphQlQuery($query, [], '', $headerMap); + return $headerMap; } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php index 9fec6fdfd269..ee2d6a2b31de 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.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,26 +17,17 @@ class CartTotalsTest extends GraphQlAbstract { /** - * @var QuoteResource + * @var GetMaskedQuoteIdByReservedOrderId */ - private $quoteResource; + private $getMaskedQuoteIdByReservedOrderId; /** - * @var QuoteFactory + * @inheritdoc */ - private $quoteFactory; - - /** - * @var QuoteIdToMaskedQuoteIdInterface - */ - private $quoteIdToMaskedId; - 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->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); } /** @@ -52,8 +41,8 @@ protected function setUp() */ public function testGetCartTotalsWithTaxApplied() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_quote'); - $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query); self::assertArrayHasKey('prices', $response['cart']); @@ -79,8 +68,8 @@ public function testGetCartTotalsWithTaxApplied() */ public function testGetTotalsWithNoTaxApplied() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_quote'); - $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query); $pricesResponse = $response['cart']['prices']; @@ -102,8 +91,8 @@ public function testGetTotalsWithNoTaxApplied() */ public function testGetCartTotalsWithNoAddressSet() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_quote'); - $query = $this->getCartTotalsGraphqlQuery($maskedQuoteId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query); $pricesResponse = $response['cart']['prices']; @@ -114,13 +103,35 @@ public function testGetCartTotalsWithNoAddressSet() self::assertEmpty($pricesResponse['applied_taxes']); } + /** + * _security + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/apply_tax_for_simple_product.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/set_new_billing_address.php + */ + public function testGetSelectedShippingMethodFromCustomerCart() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); + + $this->expectExceptionMessage( + "The current user cannot perform operations on cart \"$maskedQuoteId\"" + ); + $this->graphQlQuery($query); + } + /** * Generates GraphQl query for retrieving cart totals * * @param string $maskedQuoteId * @return string */ - private function getCartTotalsGraphqlQuery(string $maskedQuoteId): string + private function getQuery(string $maskedQuoteId): string { return <<quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } From 259ee45bcfc4f0db2b74d42518f62f4583d5a41b Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Mon, 15 Apr 2019 14:49:14 -0500 Subject: [PATCH 20/21] GraphQL-281: [Shipping methods] Support of UPS shipping method --- .../Ups/SetUpsShippingMethodsOnCartTest.php | 373 ++---------------- 1 file changed, 28 insertions(+), 345 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php index b41c7d0898f7..cfaf53e690c6 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -29,7 +29,7 @@ * | XDM | Worldwide Express Plus * | XPD | Worldwide Expedited * - * Current class does not cover these UPS shipping methods (depends on sandbox settings) + * Current class does not cover these UPS shipping methods (depends on address and sandbox settings) * * | Code | Label * -------------------------------------- @@ -81,197 +81,26 @@ protected function setUp() $objectManager = Bootstrap::getObjectManager(); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); - $this->getQuoteShippingAddressIdByReservedQuoteId = $objectManager->get(GetQuoteShippingAddressIdByReservedQuoteId::class); - } - - /** - * Set "Next Day Air Early AM" UPS shipping method - * - * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php - */ - public function testSetNextDayAirEarlyAmUpsShippingMethod() - { - $quoteReservedId = 'test_quote'; - $methodCode = '1DM'; - $methodLabel = 'Next Day Air Early AM'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); - $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - - $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); - $response = $this->sendRequestWithToken($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']); - - $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $shippingAddress); - - self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); - self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); - - self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); - self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); - - self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); - self::assertEquals( - self::CARRIER_LABEL . ' - ' . $methodLabel, - $shippingAddress['selected_shipping_method']['label'] - ); - } - - /** - * Set "Next Day Air" UPS shipping method - * - * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php - */ - public function testSetNextDayAirUpsShippingMethod() - { - $quoteReservedId = 'test_quote'; - $methodCode = '1DA'; - $methodLabel = 'Next Day Air'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); - $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - - $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); - $response = $this->sendRequestWithToken($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']); - - $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $shippingAddress); - - self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); - self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); - - self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); - self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); - - self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); - self::assertEquals( - self::CARRIER_LABEL . ' - ' . $methodLabel, - $shippingAddress['selected_shipping_method']['label'] + $this->getQuoteShippingAddressIdByReservedQuoteId = $objectManager->get( + GetQuoteShippingAddressIdByReservedQuoteId::class ); } /** - * Set "2nd Day Air" UPS shipping method - * * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php - */ - public function testSet2ndDayAirUpsShippingMethod() - { - $quoteReservedId = 'test_quote'; - $methodCode = '2DA'; - $methodLabel = '2nd Day Air'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); - $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - - $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); - $response = $this->sendRequestWithToken($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']); - - $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $shippingAddress); - - self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); - self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); - - self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); - self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); - - self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); - self::assertEquals( - self::CARRIER_LABEL . ' - ' . $methodLabel, - $shippingAddress['selected_shipping_method']['label'] - ); - } - - /** - * Set "3 Day Select" UPS shipping method * - * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php - */ - public function testSet3DaySelectUpsShippingMethod() - { - $quoteReservedId = 'test_quote'; - $methodCode = '3DS'; - $methodLabel = '3 Day Select'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); - $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - - $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); - $response = $this->sendRequestWithToken($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']); - - $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $shippingAddress); - - self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); - self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); - - self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); - self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); - - self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); - self::assertEquals( - self::CARRIER_LABEL . ' - ' . $methodLabel, - $shippingAddress['selected_shipping_method']['label'] - ); - } - - /** - * Set "Ground" UPS shipping method - * - * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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/Ups/_files/enable_ups_shipping_method.php + * @dataProvider dataProviderShippingMethods + * @param string $methodCode + * @param string $methodLabel */ - public function testSetGroundUpsShippingMethod() + public function testSetUpsShippingMethod(string $methodCode, string $methodLabel) { $quoteReservedId = 'test_quote'; - $methodCode = 'GND'; - $methodLabel = 'Ground'; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); @@ -300,150 +129,34 @@ public function testSetGroundUpsShippingMethod() } /** - * Set "Canada Standard" UPS shipping method - * - * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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_canada_address.php - * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php + * @return array */ - public function testSetCanadaStandardUpsShippingMethod() + public function dataProviderShippingMethods(): array { - $quoteReservedId = 'test_quote'; - $methodCode = 'STD'; - $methodLabel = 'Canada Standard'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); - $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - - $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); - $response = $this->sendRequestWithToken($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']); - - $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $shippingAddress); - - self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); - self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); - - self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); - self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); - - self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); - self::assertEquals( - self::CARRIER_LABEL . ' - ' . $methodLabel, - $shippingAddress['selected_shipping_method']['label'] - ); + return [ + 'Next Day Air Early AM' => ['1DM', 'Next Day Air Early AM'], + 'Next Day Air' => ['1DA', 'Next Day Air'], + '2nd Day Air' => ['2DA', '2nd Day Air'], + '3 Day Select' => ['3DS', '3 Day Select'], + 'Ground' => ['GND', 'Ground'], + ]; } /** - * Set "Worldwide Express" UPS shipping method - * * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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_canada_address.php * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php - */ - public function testSetWorldwideExpressUpsShippingMethod() - { - $quoteReservedId = 'test_quote'; - $methodCode = 'XPR'; - $methodLabel = 'Worldwide Express'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); - $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - - $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); - $response = $this->sendRequestWithToken($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']); - - $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $shippingAddress); - - self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); - self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); - - self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); - self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); - - self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); - self::assertEquals( - self::CARRIER_LABEL . ' - ' . $methodLabel, - $shippingAddress['selected_shipping_method']['label'] - ); - } - - /** - * Set "Worldwide Express Saver" UPS shipping method * - * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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_canada_address.php - * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php - */ - public function testSetWorldwideExpressSaverUpsShippingMethod() - { - $quoteReservedId = 'test_quote'; - $methodCode = 'WXS'; - $methodLabel = 'Worldwide Express Saver'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); - $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - - $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); - $response = $this->sendRequestWithToken($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']); - - $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $shippingAddress); - - self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); - self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); - - self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); - self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); - - self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); - self::assertEquals( - self::CARRIER_LABEL . ' - ' . $methodLabel, - $shippingAddress['selected_shipping_method']['label'] - ); - } - - /** - * Set "Worldwide Express Plus" UPS shipping method - * - * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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_canada_address.php - * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php + * @dataProvider dataProviderShippingMethodsBasedOnCanadaAddress + * @param string $methodCode + * @param string $methodLabel */ - public function testSetWorldwideExpressPlusUpsShippingMethod() + public function testSetUpsShippingMethodBasedOnCanadaAddress(string $methodCode, string $methodLabel) { $quoteReservedId = 'test_quote'; - $methodCode = 'XDM'; - $methodLabel = 'Worldwide Express Plus'; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); @@ -472,46 +185,16 @@ public function testSetWorldwideExpressPlusUpsShippingMethod() } /** - * Set "Worldwide Expedited" UPS shipping method - * - * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.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_canada_address.php - * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php + * @return array */ - public function testSetWorldwideExpeditedUpsShippingMethod() + public function dataProviderShippingMethodsBasedOnCanadaAddress(): array { - $quoteReservedId = 'test_quote'; - $methodCode = 'XPD'; - $methodLabel = 'Worldwide Expedited'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId); - $shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId); - - $query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode); - $response = $this->sendRequestWithToken($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']); - - $shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $shippingAddress); - - self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']); - self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']); - - self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']); - self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']); - - self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']); - self::assertEquals( - self::CARRIER_LABEL . ' - ' . $methodLabel, - $shippingAddress['selected_shipping_method']['label'] - ); + return [ + 'Canada Standard' => ['STD', 'Canada Standard'], + 'Worldwide Express' => ['XPR', 'Worldwide Express'], + 'Worldwide Express Saver' => ['WXS', 'Worldwide Express Saver'], + 'Worldwide Express Plus' => ['XDM', 'Worldwide Express Plus'], + ]; } /** From c81353d878168776e4bec5b164e9bdaab1e899c8 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Mon, 15 Apr 2019 16:21:33 -0500 Subject: [PATCH 21/21] GraphQL-564: [Checkout coverage] setGuestEmailOnCart mutation --- .../GraphQl/Quote/Guest/PlaceOrderTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php index 31f60afc1331..30ad69eada29 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php @@ -69,7 +69,7 @@ public function testPlaceOrder() $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); $query = $this->getQuery($maskedQuoteId); - $response = $this->graphQlQuery($query); + $response = $this->graphQlMutation($query); self::assertArrayHasKey('placeOrder', $response); self::assertArrayHasKey('order_id', $response['placeOrder']['order']); @@ -94,7 +94,7 @@ public function testPlaceOrderWithNoEmail() $query = $this->getQuery($maskedQuoteId); self::expectExceptionMessage("Guest email for cart is missing. Please enter"); - $this->graphQlQuery($query); + $this->graphQlMutation($query); } /** @@ -111,7 +111,7 @@ public function testPlaceOrderWithNoItemsInCart() 'Unable to place order: A server error stopped your order from being placed. ' . 'Please try to place your order again' ); - $this->graphQlQuery($query); + $this->graphQlMutation($query); } /** @@ -129,7 +129,7 @@ public function testPlaceOrderWithNoShippingAddress() self::expectExceptionMessage( 'Unable to place order: Some addresses can\'t be used due to the configurations for specific countries' ); - $this->graphQlQuery($query); + $this->graphQlMutation($query); } /** @@ -148,7 +148,7 @@ public function testPlaceOrderWithNoShippingMethod() self::expectExceptionMessage( 'Unable to place order: The shipping method is missing. Select the shipping method and try again' ); - $this->graphQlQuery($query); + $this->graphQlMutation($query); } /** @@ -169,7 +169,7 @@ public function testPlaceOrderWithNoBillingAddress() self::expectExceptionMessageRegExp( '/Unable to place order: Please check the billing address information*/' ); - $this->graphQlQuery($query); + $this->graphQlMutation($query); } /** @@ -189,7 +189,7 @@ public function testPlaceOrderWithNoPaymentMethod() $query = $this->getQuery($maskedQuoteId); self::expectExceptionMessage('Unable to place order: Enter a valid payment method and try again'); - $this->graphQlQuery($query); + $this->graphQlMutation($query); } /** @@ -210,7 +210,7 @@ public function testPlaceOrderWithOutOfStockProduct() $query = $this->getQuery($maskedQuoteId); self::expectExceptionMessage('Unable to place order: Some of the products are out of stock'); - $this->graphQlQuery($query); + $this->graphQlMutation($query); } /** @@ -233,7 +233,7 @@ public function testPlaceOrderOfCustomerCart() $query = $this->getQuery($maskedQuoteId); self::expectExceptionMessageRegExp('/The current user cannot perform operations on cart*/'); - $this->graphQlQuery($query); + $this->graphQlMutation($query); } /**