File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed
app/code/Magento/CmsGraphQl/Test/Integration/Model/Resolver
dev/tests/api-functional/testsuite/Magento/CmsGraphQl/Model/Resolver Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -185,6 +185,44 @@ public function testNeitherSaveNorLoadAreCalledWhenResolverCacheIsDisabled()
185185 $ this ->graphQlRequest ->send ($ query );
186186 }
187187
188+ public function testSaveIsNeverCalledWhenMissingRequiredArgumentInQuery ()
189+ {
190+ $ objectManager = $ this ->objectManager ;
191+
192+ $ frontendPool = $ objectManager ->get (FrontendPool::class);
193+
194+ $ cacheProxy = $ this ->getMockBuilder (GraphQlResolverCache::class)
195+ ->enableProxyingToOriginalMethods ()
196+ ->setConstructorArgs ([
197+ $ frontendPool
198+ ])
199+ ->getMock ();
200+
201+ // assert cache proxy never calls save
202+ $ cacheProxy
203+ ->expects ($ this ->never ())
204+ ->method ('save ' );
205+
206+ $ resolverPluginWithCacheProxy = $ objectManager ->create (ResolverResultCachePlugin::class, [
207+ 'graphQlResolverCache ' => $ cacheProxy ,
208+ ]);
209+
210+ // override resolver plugin with plugin instance containing cache proxy class
211+ $ objectManager ->addSharedInstance ($ resolverPluginWithCacheProxy , ResolverResultCachePlugin::class);
212+
213+ $ query = <<<QUERY
214+ {
215+ cmsPage {
216+ title
217+ }
218+ }
219+ QUERY ;
220+
221+ // send request multiple times and assert save is never called
222+ $ this ->graphQlRequest ->send ($ query );
223+ $ this ->graphQlRequest ->send ($ query );
224+ }
225+
188226 private function getQuery (string $ identifier , array $ fields = ['title ' ]): string
189227 {
190228 $ fields = implode (PHP_EOL , $ fields );
Original file line number Diff line number Diff line change 1717use Magento \GraphQlCache \Model \CacheId \CacheIdCalculator ;
1818use Magento \Integration \Api \CustomerTokenServiceInterface ;
1919use Magento \TestFramework \ObjectManager ;
20+ use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
2021use Magento \TestFramework \TestCase \GraphQlAbstract ;
2122
2223/**
@@ -366,6 +367,34 @@ public function testCmsPageResolverCacheInvalidatesWhenPageGetsDisabled()
366367 );
367368 }
368369
370+ /**
371+ * @magentoConfigFixture default/system/full_page_cache/caching_application 2
372+ * @magentoDataFixture Magento/Cms/Fixtures/page_list.php
373+ * @return void
374+ */
375+ public function testCmsPageResolverCacheDoesNotSaveNonExistentCmsPage ()
376+ {
377+ $ nonExistentPage = ObjectManager::getInstance ()->create (PageInterface::class);
378+ $ nonExistentPage ->setIdentifier ('non-existent-page ' );
379+
380+ $ query = $ this ->getQuery ($ nonExistentPage ->getIdentifier ());
381+
382+ try {
383+ $ response = $ this ->graphQlQueryWithResponseHeaders ($ query );
384+ $ this ->fail ('Expected exception was not thrown ' );
385+ } catch (ResponseContainsErrorsException $ e ) {
386+ // expected exception
387+ }
388+
389+ $ response ['headers ' ] = $ e ->getResponseHeaders ();
390+
391+ $ cacheIdentityString = $ this ->getResolverCacheKeyFromResponseAndPage ($ response , $ nonExistentPage );
392+
393+ $ this ->assertFalse (
394+ $ this ->graphqlCache ->load ($ cacheIdentityString )
395+ );
396+ }
397+
369398 private function generateExpectedDataFromPage (PageInterface $ page ): array
370399 {
371400 return [
You can’t perform that action at this time.
0 commit comments