Skip to content

Commit b21ce3e

Browse files
committed
Merge branch 'graphql-issue-230' of github.com:magento-honey-badgers/magento2ce into graphql-issue-230
2 parents 43500fb + 3ac980d commit b21ce3e

File tree

2 files changed

+136
-6
lines changed

2 files changed

+136
-6
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/PageCache/CacheTagTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
class CacheTagTest extends GraphQlAbstract
1919
{
20-
2120
/**
2221
* @inheritdoc
2322
*/
@@ -87,7 +86,6 @@ public function testCacheTagForCategoriesWithProduct()
8786
$firstProductSku = 'simple333';
8887
$secondProductSku = 'simple444';
8988
$categoryId ='4';
90-
9189
$variables =[
9290
'id' => $categoryId,
9391
'pageSize'=> 10,
@@ -118,22 +116,22 @@ public function testCacheTagForCategoriesWithProduct()
118116
];
119117
$this->assertEquals($expectedCacheTags, $actualCacheTags);
120118

121-
// Cach-debug header should be a MISS for product 1 on first request
119+
// Cache-debug header should be a MISS for product 1 on first request
122120
$responseHeadersFirstProduct = $this->graphQlQueryForHttpHeaders($product1Query);
123121
$this->assertContains('X-Magento-Cache-Debug: MISS', $responseHeadersFirstProduct);
124122

125-
// Cach-debug header should be a MISS for product 2 during first load
123+
// Cache-debug header should be a MISS for product 2 during first load
126124
$responseHeadersSecondProduct = $this->graphQlQueryForHttpHeaders($product2Query);
127125
$this->assertContains('X-Magento-Cache-Debug: MISS', $responseHeadersSecondProduct);
128126

129-
/** cache-debug header value should be MISS after updating product1 and reloading the Category */
127+
/** Cache-debug header value should be MISS after updating product1 and reloading the Category */
130128
$firstProduct->setPrice(20);
131129
$firstProduct->save();
132130
$responseMissHeaders = $this->graphQlQueryForHttpHeaders($categoryQuery, $variables);
133131
preg_match('/X-Magento-Cache-Debug: (.*?)\n/', $responseMissHeaders, $matchesMiss);
134132
$this->assertEquals('MISS', rtrim($matchesMiss[1], "\r"));
135133

136-
/** cache-debug should be a MISS for product 1 after it is updated - cache invalidation */
134+
/** Cache-debug should be a MISS for product 1 after it is updated - cache invalidation */
137135
$responseHeadersFirstProduct = $this->graphQlQueryForHttpHeaders($product1Query);
138136
$this->assertContains('X-Magento-Cache-Debug: MISS', $responseHeadersFirstProduct);
139137

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\PageCache\Quote\Guest;
9+
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use Magento\TestFramework\TestCase\GraphQlAbstract;
12+
13+
/**
14+
* End to end test which creates an empty cart and add product to the cart and load the cart.
15+
* Validates that the cache-debug header is a MISS for any subsequent cart requests
16+
*
17+
* @magentoApiDataFixture Magento/Catalog/_files/products.php
18+
*/
19+
class CartCacheTest extends GraphQlAbstract
20+
{
21+
/** @var string */
22+
private $maskedQuoteId;
23+
24+
protected function setUp()
25+
{
26+
$this->markTestSkipped(
27+
'This test will stay skipped until DEVOPS-4924 is resolved'
28+
);
29+
}
30+
/**
31+
* Tests that X-Magento-Tags are correct
32+
*/
33+
public function testCartIsNotCached()
34+
{
35+
$qty = 2;
36+
$sku = 'simple';
37+
$cartId = $this->createEmptyCart();
38+
$this->addSimpleProductToCart($cartId, $qty, $sku);
39+
$getCartQuery = $this->checkCart($cartId);
40+
$response = $this->graphQlQuery($getCartQuery);
41+
self::assertArrayHasKey('cart', $response);
42+
self::assertArrayHasKey('items', $response['cart']);
43+
44+
$responseMissHeaders = $this->graphQlQueryForHttpHeaders($getCartQuery);
45+
$this->assertContains('X-Magento-Cache-Debug: MISS', $responseMissHeaders);
46+
47+
/** Cache debug header value is still a MISS for any subsequent request */
48+
$responseMissHeadersNext = $this->graphQlQueryForHttpHeaders($getCartQuery);
49+
$this->assertContains('X-Magento-Cache-Debug: MISS', $responseMissHeadersNext);
50+
}
51+
52+
/**
53+
* Create a guest cart which generates a maskedQuoteId
54+
*
55+
* @return mixed
56+
*/
57+
private function createEmptyCart()
58+
{
59+
$query =
60+
<<<QUERY
61+
mutation
62+
{
63+
createEmptyCart
64+
}
65+
QUERY;
66+
67+
$response = $this->graphQlMutation($query);
68+
$this->maskedQuoteId = $response['createEmptyCart'];
69+
return $this->maskedQuoteId;
70+
}
71+
72+
/**
73+
* Add simple product to the cart using the maskedQuoteId
74+
* @param $maskedCartId
75+
* @param $qty
76+
* @param $sku
77+
*/
78+
private function addSimpleProductToCart($maskedCartId, $qty, $sku)
79+
{
80+
$addProductToCartQuery =
81+
<<<QUERY
82+
mutation {
83+
addSimpleProductsToCart(
84+
input: {
85+
cart_id: "{$maskedCartId}"
86+
cartItems: [
87+
{
88+
data: {
89+
qty: $qty
90+
sku: "$sku"
91+
}
92+
}
93+
]
94+
}
95+
) {
96+
cart {
97+
items {
98+
qty
99+
product {
100+
sku
101+
}
102+
}
103+
}
104+
}
105+
}
106+
QUERY;
107+
$response = $this->graphQlMutation($addProductToCartQuery);
108+
self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']);
109+
}
110+
111+
/**
112+
*
113+
* @param string $maskedQuoteId
114+
* @return string
115+
*/
116+
private function checkCart(string $maskedQuoteId): string
117+
{
118+
return <<<QUERY
119+
{
120+
cart(cart_id: "{$maskedQuoteId}") {
121+
items {
122+
id
123+
qty
124+
product {
125+
sku
126+
}
127+
}
128+
}
129+
}
130+
QUERY;
131+
}
132+
}

0 commit comments

Comments
 (0)