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,13 @@ 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: 'block ' , count: 2 )
113+ ]
102114 public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest ()
103115 {
104- $ block1 = $ this ->blockRepository -> getById ( ' enabled_block ' );
105- $ block2 = $ this ->blockRepository -> getById ( ' fixture_block ' );
116+ $ block1 = $ this ->fixtures -> get ( ' block1 ' );
117+ $ block2 = $ this ->fixtures -> get ( ' block2 ' );
106118
107119 $ query = $ this ->getQuery ([
108120 $ block1 ->getIdentifier (),
@@ -139,13 +151,12 @@ public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest()
139151 );
140152 }
141153
142- /**
143- * @magentoConfigFixture default_store web/seo/use_rewrites 1
144- * @magentoDataFixture Magento/Cms/_files/block.php
145- */
154+ #[
155+ DataFixture(BlockFixture::class, as: 'deleted_block ' )
156+ ]
146157 public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted ()
147158 {
148- $ block = $ this ->blockRepository -> getById ( ' fixture_block ' );
159+ $ block = $ this ->fixtures -> get ( ' deleted_block ' );
149160
150161 $ query = $ this ->getQuery ([
151162 $ block ->getIdentifier (),
@@ -177,13 +188,12 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted()
177188 );
178189 }
179190
180- /**
181- * @magentoConfigFixture default_store web/seo/use_rewrites 1
182- * @magentoDataFixture Magento/Cms/_files/blocks.php
183- */
191+ #[
192+ DataFixture(BlockFixture::class, as: 'enabled_block ' )
193+ ]
184194 public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled ()
185195 {
186- $ block = $ this ->blockRepository -> getById ('enabled_block ' );
196+ $ block = $ this ->fixtures -> get ('enabled_block ' );
187197
188198 $ query = $ this ->getQuery ([
189199 $ block ->getIdentifier (),
@@ -217,14 +227,20 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled()
217227 }
218228
219229 /**
220- * @magentoConfigFixture default_store web/seo/use_rewrites 1
221- * @magentoDataFixture Magento/Cms/_files/block.php
222- * @magentoDataFixture Magento/Store/_files/second_store.php
230+ * @throws LocalizedException
231+ * @throws \Zend_Cache_Exception
223232 */
233+ #[
234+ DataFixture(BlockFixture::class, as: 'block ' ),
235+ DataFixture(Store::class, as: 'second_store ' ),
236+ ]
224237 public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView ()
225238 {
226239 /** @var Block $block */
227- $ block = $ this ->blockRepository ->getById ('fixture_block ' );
240+ $ block = $ this ->fixtures ->get ('block ' );
241+
242+ /** @var \Magento\Store\Model\Store $store */
243+ $ store = $ this ->fixtures ->get ('second_store ' );
228244
229245 $ query = $ this ->getQuery ([
230246 $ block ->getIdentifier (),
@@ -238,17 +254,17 @@ public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView(
238254 $ cacheEntryDecoded = json_decode ($ cacheEntry , true );
239255
240256 $ this ->assertEqualsCanonicalizing (
241- $ this -> generateExpectedDataFromBlocks ([ $ block ]) ,
242- $ cacheEntryDecoded
257+ $ cacheEntryDecoded ,
258+ $ this -> generateExpectedDataFromBlocks ([ $ block ])
243259 );
244260
245261 $ this ->assertTagsByCacheIdentityAndBlocks (
246- $ cacheKey ,
262+ ( string ) $ cacheKey ,
247263 [$ block ]
248264 );
249265
250266 // assert that cache is invalidated after changing block's store view
251- $ secondStoreViewId = $ this -> storeManager -> getStore ( ' fixture_second_store ' ) ->getId ();
267+ $ secondStoreViewId = $ store ->getId ();
252268 $ block ->setStoreId ($ secondStoreViewId );
253269 $ this ->blockRepository ->save ($ block );
254270
@@ -283,15 +299,14 @@ public function testCmsBlockResolverCacheDoesNotSaveNonExistentCmsBlock()
283299 );
284300 }
285301
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- */
302+ #[
303+ Config('system/full_page_cache/caching_application ' , '2 ' ),
304+ DataFixture(BlockFixture::class, as: 'block ' , count: 2 )
305+ ]
291306 public function testCmsBlockResolverCacheRetainsEntriesThatHaveNotBeenUpdated ()
292307 {
293308 // query block1
294- $ block1 = $ this ->blockRepository -> getById ( ' fixture_block ' );
309+ $ block1 = $ this ->fixtures -> get ( ' block1 ' );
295310
296311 $ queryBlock1 = $ this ->getQuery ([
297312 $ block1 ->getIdentifier (),
@@ -302,7 +317,7 @@ public function testCmsBlockResolverCacheRetainsEntriesThatHaveNotBeenUpdated()
302317 $ cacheKeyBlock1 = $ this ->getResolverCacheKeyFromBlocks ([$ block1 ]);
303318
304319 // query block2
305- $ block2 = $ this ->blockRepository -> getById ( ' enabled_block ' );
320+ $ block2 = $ this ->fixtures -> get ( ' block2 ' );
306321
307322 $ queryBlock2 = $ this ->getQuery ([
308323 $ block2 ->getIdentifier (),
0 commit comments