1111use Magento \Cms \Api \Data \BlockInterface ;
1212use Magento \Cms \Model \Block ;
1313use Magento \CmsGraphQl \Model \Resolver \Blocks ;
14+ use Magento \Framework \Exception \LocalizedException ;
1415use Magento \GraphQlResolverCache \Model \Resolver \Result \CacheKey \Calculator \ProviderInterface ;
1516use Magento \GraphQlResolverCache \Model \Resolver \Result \Type as GraphQlResolverCache ;
1617use Magento \Store \Model \StoreManagerInterface ;
18+ use Magento \Store \Test \Fixture \Store ;
19+ use Magento \Cms \Test \Fixture \Block as BlockFixture ;
20+ use Magento \TestFramework \Fixture \Config ;
21+ use Magento \TestFramework \Fixture \DataFixture ;
22+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
23+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
1724use Magento \TestFramework \ObjectManager ;
1825use Magento \TestFramework \TestCase \GraphQl \ResolverCacheAbstract ;
1926use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
2027use Magento \Widget \Model \Template \FilterEmulate ;
2128
2229/**
2330 * Test for cms block resolver cache
31+ *
32+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2433 */
2534class BlockTest extends ResolverCacheAbstract
2635{
@@ -44,24 +53,29 @@ class BlockTest extends ResolverCacheAbstract
4453 */
4554 private $ storeManager ;
4655
56+ /**
57+ * @var DataFixtureStorage
58+ */
59+ private $ fixtures ;
60+
4761 protected function setUp (): void
4862 {
4963 $ objectManager = ObjectManager::getInstance ();
5064 $ this ->blockRepository = $ objectManager ->get (BlockRepositoryInterface::class);
5165 $ this ->graphQlResolverCache = $ objectManager ->get (GraphQlResolverCache::class);
5266 $ this ->widgetFilter = $ objectManager ->get (FilterEmulate::class);
5367 $ this ->storeManager = $ objectManager ->get (StoreManagerInterface::class);
68+ $ this ->fixtures = $ objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
5469
5570 parent ::setUp ();
5671 }
5772
58- /**
59- * @magentoConfigFixture default_store web/seo/use_rewrites 1
60- * @magentoDataFixture Magento/Cms/_files/blocks.php
61- */
73+ #[
74+ DataFixture(BlockFixture::class, as: 'guest_block ' )
75+ ]
6276 public function testCmsSingleBlockResolverCacheAndInvalidationAsGuest ()
6377 {
64- $ block = $ this ->blockRepository -> getById ( ' enabled_block ' );
78+ $ block = $ this ->fixtures -> get ( ' guest_block ' );
6579
6680 $ query = $ this ->getQuery ([
6781 $ block ->getIdentifier (),
@@ -94,15 +108,14 @@ public function testCmsSingleBlockResolverCacheAndInvalidationAsGuest()
94108 );
95109 }
96110
97- /**
98- * @magentoConfigFixture default_store web/seo/use_rewrites 1
99- * @magentoDataFixture Magento/Cms/_files/block.php
100- * @magentoDataFixture Magento/Cms/_files/blocks.php
101- */
111+ #[
112+ DataFixture(BlockFixture::class, as: 'block1 ' ),
113+ DataFixture(BlockFixture::class, as: 'block2 ' )
114+ ]
102115 public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest ()
103116 {
104- $ block1 = $ this ->blockRepository -> getById ( ' enabled_block ' );
105- $ block2 = $ this ->blockRepository -> getById ( ' fixture_block ' );
117+ $ block1 = $ this ->fixtures -> get ( ' block1 ' );
118+ $ block2 = $ this ->fixtures -> get ( ' block2 ' );
106119
107120 $ query = $ this ->getQuery ([
108121 $ block1 ->getIdentifier (),
@@ -139,13 +152,12 @@ public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest()
139152 );
140153 }
141154
142- /**
143- * @magentoConfigFixture default_store web/seo/use_rewrites 1
144- * @magentoDataFixture Magento/Cms/_files/block.php
145- */
155+ #[
156+ DataFixture(BlockFixture::class, as: 'deleted_block ' )
157+ ]
146158 public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted ()
147159 {
148- $ block = $ this ->blockRepository -> getById ( ' fixture_block ' );
160+ $ block = $ this ->fixtures -> get ( ' deleted_block ' );
149161
150162 $ query = $ this ->getQuery ([
151163 $ block ->getIdentifier (),
@@ -177,13 +189,12 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted()
177189 );
178190 }
179191
180- /**
181- * @magentoConfigFixture default_store web/seo/use_rewrites 1
182- * @magentoDataFixture Magento/Cms/_files/blocks.php
183- */
192+ #[
193+ DataFixture(BlockFixture::class, as: 'disabled_block ' )
194+ ]
184195 public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled ()
185196 {
186- $ block = $ this ->blockRepository -> getById ( ' enabled_block ' );
197+ $ block = $ this ->fixtures -> get ( ' disabled_block ' );
187198
188199 $ query = $ this ->getQuery ([
189200 $ block ->getIdentifier (),
@@ -217,14 +228,20 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled()
217228 }
218229
219230 /**
220- * @magentoConfigFixture default_store web/seo/use_rewrites 1
221- * @magentoDataFixture Magento/Cms/_files/block.php
222- * @magentoDataFixture Magento/Store/_files/second_store.php
231+ * @throws LocalizedException
232+ * @throws \Zend_Cache_Exception
223233 */
234+ #[
235+ DataFixture(BlockFixture::class, as: 'block ' ),
236+ DataFixture(Store::class, as: 'second_store ' ),
237+ ]
224238 public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView ()
225239 {
226240 /** @var Block $block */
227- $ block = $ this ->blockRepository ->getById ('fixture_block ' );
241+ $ block = $ this ->fixtures ->get ('block ' );
242+
243+ /** @var \Magento\Store\Model\Store $store */
244+ $ store = $ this ->fixtures ->get ('second_store ' );
228245
229246 $ query = $ this ->getQuery ([
230247 $ block ->getIdentifier (),
@@ -238,17 +255,17 @@ public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView(
238255 $ cacheEntryDecoded = json_decode ($ cacheEntry , true );
239256
240257 $ this ->assertEqualsCanonicalizing (
241- $ this -> generateExpectedDataFromBlocks ([ $ block ]) ,
242- $ cacheEntryDecoded
258+ $ cacheEntryDecoded ,
259+ $ this -> generateExpectedDataFromBlocks ([ $ block ])
243260 );
244261
245262 $ this ->assertTagsByCacheIdentityAndBlocks (
246- $ cacheKey ,
263+ ( string ) $ cacheKey ,
247264 [$ block ]
248265 );
249266
250267 // assert that cache is invalidated after changing block's store view
251- $ secondStoreViewId = $ this -> storeManager -> getStore ( ' fixture_second_store ' ) ->getId ();
268+ $ secondStoreViewId = $ store ->getId ();
252269 $ block ->setStoreId ($ secondStoreViewId );
253270 $ this ->blockRepository ->save ($ block );
254271
@@ -283,15 +300,15 @@ public function testCmsBlockResolverCacheDoesNotSaveNonExistentCmsBlock()
283300 );
284301 }
285302
286- /**
287- * @magentoConfigFixture default/ system/full_page_cache/caching_application 2
288- * @magentoDataFixture Magento/Cms/_files/block.php
289- * @magentoDataFixture Magento/Cms/_files/blocks.php
290- */
303+ #[
304+ Config( ' system/full_page_cache/caching_application ' , ' 2 ' , ' store ' , ' default ' ),
305+ DataFixture(BlockFixture::class, as: ' block1 ' ),
306+ DataFixture(BlockFixture::class, as: ' block2 ' )
307+ ]
291308 public function testCmsBlockResolverCacheRetainsEntriesThatHaveNotBeenUpdated ()
292309 {
293310 // query block1
294- $ block1 = $ this ->blockRepository -> getById ( ' fixture_block ' );
311+ $ block1 = $ this ->fixtures -> get ( ' block1 ' );
295312
296313 $ queryBlock1 = $ this ->getQuery ([
297314 $ block1 ->getIdentifier (),
@@ -302,7 +319,7 @@ public function testCmsBlockResolverCacheRetainsEntriesThatHaveNotBeenUpdated()
302319 $ cacheKeyBlock1 = $ this ->getResolverCacheKeyFromBlocks ([$ block1 ]);
303320
304321 // query block2
305- $ block2 = $ this ->blockRepository -> getById ( ' enabled_block ' );
322+ $ block2 = $ this ->fixtures -> get ( ' block2 ' );
306323
307324 $ queryBlock2 = $ this ->getQuery ([
308325 $ block2 ->getIdentifier (),
0 commit comments