Skip to content

Commit 52c0afb

Browse files
committed
Merge remote-tracking branch 'origin/AC-11729-v1' into spartans_pr_05082024
2 parents 341d1ac + 2ace5c4 commit 52c0afb

File tree

3 files changed

+123
-10
lines changed

3 files changed

+123
-10
lines changed

app/code/Magento/GraphQlCache/Controller/Plugin/GraphQl.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ public function beforeDispatch(
9898
): void {
9999
try {
100100
$this->requestProcessor->validateRequest($request);
101+
/** @var \Magento\Framework\App\Request\Http $request */
102+
$this->requestProcessor->processHeaders($request);
103+
$this->request = $request;
101104
} catch (\Exception $error) {
102105
$this->logger->critical($error->getMessage());
103106
}
104-
/** @var \Magento\Framework\App\Request\Http $request */
105-
$this->requestProcessor->processHeaders($request);
106-
$this->request = $request;
107107
}
108108

109109
/**

dev/tests/api-functional/testsuite/Magento/GraphQl/GraphQlCache/GraphQlTest.php

+113
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,96 @@
88
namespace Magento\GraphQl\GraphQlCache;
99

1010
use Magento\Customer\Test\Fixture\Customer;
11+
use Magento\Framework\Registry;
1112
use Magento\TestFramework\Fixture\DataFixture;
1213
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
1314
use Magento\TestFramework\TestCase\GraphQlAbstract;
15+
use Magento\Framework\App\FrontControllerInterface;
16+
use Magento\Framework\App\Request\Http;
17+
use Magento\Framework\App\Response\Http as ResponseHttp;
18+
use Magento\GraphQl\Controller\HttpRequestProcessor;
19+
use Magento\GraphQlCache\Controller\Plugin\GraphQl;
20+
use Magento\GraphQlCache\Model\CacheableQuery;
21+
use Magento\GraphQlCache\Model\CacheId\CacheIdCalculator;
22+
use Magento\PageCache\Model\Config;
23+
use PHPUnit\Framework\MockObject\MockObject;
24+
use Psr\Log\LoggerInterface;
1425

1526
class GraphQlTest extends GraphQlAbstract
1627
{
28+
/**
29+
* @var GraphQl
30+
*/
31+
private $graphql;
32+
33+
/**
34+
* @var CacheableQuery|MockObject
35+
*/
36+
private $cacheableQueryMock;
37+
38+
/**
39+
* @var Config|MockObject
40+
*/
41+
private $configMock;
42+
43+
/**
44+
* @var HttpRequestProcessor|MockObject
45+
*/
46+
private $requestProcessorMock;
47+
48+
/**
49+
* @var CacheIdCalculator|MockObject
50+
*/
51+
private $cacheIdCalculatorMock;
52+
53+
/**
54+
* @var LoggerInterface|MockObject
55+
*/
56+
private $loggerMock;
57+
58+
/**
59+
* @var FrontControllerInterface|MockObject
60+
*/
61+
private $subjectMock;
62+
63+
/**
64+
* @var Http|MockObject
65+
*/
66+
private $requestMock;
67+
68+
/**
69+
* @var Registry
70+
*/
71+
private $registryMock;
72+
73+
protected function setUp(): void
74+
{
75+
$this->cacheableQueryMock = $this->createMock(CacheableQuery::class);
76+
$this->cacheIdCalculatorMock = $this->createMock(CacheIdCalculator::class);
77+
$this->configMock = $this->createMock(Config::class);
78+
$this->loggerMock = $this->getMockBuilder(LoggerInterface::class)
79+
->onlyMethods(['critical'])
80+
->disableOriginalConstructor()
81+
->getMockForAbstractClass();
82+
$this->requestProcessorMock = $this->getMockBuilder(HttpRequestProcessor::class)
83+
->onlyMethods(['validateRequest','processHeaders'])
84+
->disableOriginalConstructor()
85+
->getMockForAbstractClass();
86+
$this->registryMock = $this->createMock(Registry::class);
87+
$this->subjectMock = $this->createMock(FrontControllerInterface::class);
88+
$this->requestMock = $this
89+
->getMockBuilder(Http::class)
90+
->disableOriginalConstructor()
91+
->getMockForAbstractClass();
92+
$this->graphql = new GraphQl(
93+
$this->cacheableQueryMock,
94+
$this->cacheIdCalculatorMock,
95+
$this->configMock,
96+
$this->loggerMock,
97+
$this->requestProcessorMock,
98+
$this->registryMock
99+
);
100+
}
17101
#[
18102
DataFixture(Customer::class, as: 'customer'),
19103
]
@@ -40,4 +124,33 @@ public function testMutation(): void
40124
$tokenResponse['headers']['Cache-Control']
41125
);
42126
}
127+
128+
public function testBeforeDispatch(): void
129+
{
130+
$this->requestProcessorMock
131+
->expects($this->once())
132+
->method('validateRequest');
133+
$this->requestProcessorMock
134+
->expects($this->once())
135+
->method('processHeaders');
136+
$this->loggerMock
137+
->expects($this->never())
138+
->method('critical');
139+
$this->assertNull($this->graphql->beforeDispatch($this->subjectMock, $this->requestMock));
140+
}
141+
142+
public function testBeforeDispatchForException(): void
143+
{
144+
$this->requestProcessorMock
145+
->expects($this->once())
146+
->method('validateRequest')
147+
->willThrowException(new \Exception('Invalid Headers'));
148+
$this->requestProcessorMock
149+
->expects($this->never())
150+
->method('processHeaders');
151+
$this->loggerMock
152+
->expects($this->once())
153+
->method('critical');
154+
$this->assertNull($this->graphql->beforeDispatch($this->subjectMock, $this->requestMock));
155+
}
43156
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
219219
$productNameInFixtureStore = 'Product\'s Name in Fixture Store';
220220
$product->setName($productNameInFixtureStore)->setStoreId($storeId)->save();
221221

222+
// test cached response store + currency header with non existing currency, and no valid response, no cache
223+
$headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'SOMECURRENCY'];
224+
$this->expectExceptionMessage(
225+
'GraphQL response contains errors: Please correct the target currency'
226+
);
227+
$this->graphQlQuery($query, [], '', $headerMap);
228+
222229
// test store header only, query is cached at this point in EUR
223230
$headerMap = ['Store' => $storeCodeFromFixture];
224231
$response = $this->graphQlQuery($query, [], '', $headerMap);
@@ -302,12 +309,5 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
302309
$response['products']['items'][0]['price']['minimalPrice']['amount']['currency'],
303310
'Currency code USD in fixture store default is unexpected'
304311
);
305-
306-
// test cached response store + currency header with non existing currency, and no valid response, no cache
307-
$headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'SOMECURRENCY'];
308-
$this->expectExceptionMessage(
309-
'GraphQL response contains errors: Please correct the target currency'
310-
);
311-
$this->graphQlQuery($query, [], '', $headerMap);
312312
}
313313
}

0 commit comments

Comments
 (0)