From ab2f3de4534dd63a55436503e383b2c30553ec55 Mon Sep 17 00:00:00 2001 From: Tobias Westfeld Date: Fri, 28 Jun 2019 12:02:10 +0200 Subject: [PATCH 1/3] #758: Cart applied_taxes of empty cart can be null --- app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php index 48711ec38c4f..22b59b060450 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php @@ -73,7 +73,7 @@ private function getAppliedTaxes(Total $total, string $currency): array $appliedTaxesData = []; $appliedTaxes = $total->getAppliedTaxes(); - if (count($appliedTaxes) === 0) { + if ($appliedTaxes === null || count($appliedTaxes) === 0) { return $appliedTaxesData; } From 0c08e248b5f84f940b084649fc9bc5a187bdeecd Mon Sep 17 00:00:00 2001 From: Tobias Westfeld Date: Sun, 30 Jun 2019 16:15:27 +0200 Subject: [PATCH 2/3] #758: apply suggestion and add test cases --- .../Model/Resolver/CartPrices.php | 2 +- .../GraphQl/Quote/Customer/CartTotalsTest.php | 27 +++++++++++++++++++ .../GraphQl/Quote/Guest/CartTotalsTest.php | 26 ++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) mode change 100644 => 100755 app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php mode change 100644 => 100755 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php mode change 100644 => 100755 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php old mode 100644 new mode 100755 index 22b59b060450..6a57a7662af0 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php @@ -73,7 +73,7 @@ private function getAppliedTaxes(Total $total, string $currency): array $appliedTaxesData = []; $appliedTaxes = $total->getAppliedTaxes(); - if ($appliedTaxes === null || count($appliedTaxes) === 0) { + if (empty($appliedTaxes)) { return $appliedTaxesData; } 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 old mode 100644 new mode 100755 index bb8acfce629f..cb1406e77de2 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php @@ -64,6 +64,33 @@ public function testGetCartTotalsWithTaxApplied() self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']); } + /** + * @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/set_new_shipping_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php + */ + public function testGetCartTotalsWithEmptyCart() + { + $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']; + self::assertEquals(0, $pricesResponse['grand_total']['value']); + self::assertEquals(0, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(0, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(0, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + + $appliedTaxesResponse = $pricesResponse['applied_taxes']; + + self::assertCount(0, $appliedTaxesResponse); + } + /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php 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 old mode 100644 new mode 100755 index 7eb09cf301bf..3691a772a48c --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php @@ -59,6 +59,32 @@ public function testGetCartTotalsWithTaxApplied() self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']); } + /** + * @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/set_new_shipping_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php + */ + public function testGetCartTotalsWithEmptyCart() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); + $response = $this->graphQlQuery($query); + + self::assertArrayHasKey('prices', $response['cart']); + $pricesResponse = $response['cart']['prices']; + self::assertEquals(0, $pricesResponse['grand_total']['value']); + self::assertEquals(0, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(0, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(0, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + + $appliedTaxesResponse = $pricesResponse['applied_taxes']; + + self::assertCount(0, $appliedTaxesResponse); + } + /** * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php From 2f766b115832e0bcb995f0f7feebc201cfc4a5ef Mon Sep 17 00:00:00 2001 From: Tobias Westfeld Date: Sun, 30 Jun 2019 16:47:38 +0200 Subject: [PATCH 3/3] #758: fix code style in tests --- .../GraphQl/Quote/Customer/CartTotalsTest.php | 52 +++++++++---------- .../GraphQl/Quote/Guest/CartTotalsTest.php | 50 +++++++++--------- 2 files changed, 51 insertions(+), 51 deletions(-) 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 cb1406e77de2..f449f6db3c39 100755 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php @@ -64,32 +64,32 @@ public function testGetCartTotalsWithTaxApplied() self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']); } - /** - * @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/set_new_shipping_address.php - * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php - */ - public function testGetCartTotalsWithEmptyCart() - { - $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']; - self::assertEquals(0, $pricesResponse['grand_total']['value']); - self::assertEquals(0, $pricesResponse['subtotal_including_tax']['value']); - self::assertEquals(0, $pricesResponse['subtotal_excluding_tax']['value']); - self::assertEquals(0, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); - - $appliedTaxesResponse = $pricesResponse['applied_taxes']; - - self::assertCount(0, $appliedTaxesResponse); - } + /** + * @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/set_new_shipping_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php + */ + public function testGetCartTotalsWithEmptyCart() + { + $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']; + self::assertEquals(0, $pricesResponse['grand_total']['value']); + self::assertEquals(0, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(0, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(0, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + + $appliedTaxesResponse = $pricesResponse['applied_taxes']; + + self::assertCount(0, $appliedTaxesResponse); + } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php 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 3691a772a48c..3334a98e8feb 100755 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php @@ -59,31 +59,31 @@ public function testGetCartTotalsWithTaxApplied() self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']); } - /** - * @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/set_new_shipping_address.php - * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php - */ - public function testGetCartTotalsWithEmptyCart() - { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); - $query = $this->getQuery($maskedQuoteId); - $response = $this->graphQlQuery($query); - - self::assertArrayHasKey('prices', $response['cart']); - $pricesResponse = $response['cart']['prices']; - self::assertEquals(0, $pricesResponse['grand_total']['value']); - self::assertEquals(0, $pricesResponse['subtotal_including_tax']['value']); - self::assertEquals(0, $pricesResponse['subtotal_excluding_tax']['value']); - self::assertEquals(0, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); - - $appliedTaxesResponse = $pricesResponse['applied_taxes']; - - self::assertCount(0, $appliedTaxesResponse); - } + /** + * @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/set_new_shipping_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php + */ + public function testGetCartTotalsWithEmptyCart() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); + $response = $this->graphQlQuery($query); + + self::assertArrayHasKey('prices', $response['cart']); + $pricesResponse = $response['cart']['prices']; + self::assertEquals(0, $pricesResponse['grand_total']['value']); + self::assertEquals(0, $pricesResponse['subtotal_including_tax']['value']); + self::assertEquals(0, $pricesResponse['subtotal_excluding_tax']['value']); + self::assertEquals(0, $pricesResponse['subtotal_with_discount_excluding_tax']['value']); + + $appliedTaxesResponse = $pricesResponse['applied_taxes']; + + self::assertCount(0, $appliedTaxesResponse); + } /** * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php