Skip to content

Commit

Permalink
ENGCOM-5436: #758: applied_taxes of empty cart causes 'Internal serve…
Browse files Browse the repository at this point in the history
…r error' message on PHP 7.2 #759

 - Merge Pull Request magento/graphql-ce#759 from therealtbs/graphql-ce:758-cart-applied_taxes-null
 - Merged commits:
   1. ab2f3de
   2. 0c08e24
   3. 2f766b1
  • Loading branch information
magento-engcom-team committed Jul 15, 2019
2 parents fb58417 + 2f766b1 commit 276e37a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function getAppliedTaxes(Total $total, string $currency): array
$appliedTaxesData = [];
$appliedTaxes = $total->getAppliedTaxes();

if (count($appliedTaxes) === 0) {
if (empty($appliedTaxes)) {
return $appliedTaxesData;
}

Expand Down
27 changes: 27 additions & 0 deletions dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 276e37a

Please sign in to comment.