11
11
use Magento \Cms \Api \Data \BlockInterface ;
12
12
use Magento \Cms \Model \Block ;
13
13
use Magento \CmsGraphQl \Model \Resolver \Blocks ;
14
+ use Magento \Framework \Exception \LocalizedException ;
14
15
use Magento \GraphQlResolverCache \Model \Resolver \Result \CacheKey \Calculator \ProviderInterface ;
15
16
use Magento \GraphQlResolverCache \Model \Resolver \Result \Type as GraphQlResolverCache ;
16
17
use 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 ;
17
24
use Magento \TestFramework \ObjectManager ;
18
25
use Magento \TestFramework \TestCase \GraphQl \ResolverCacheAbstract ;
19
26
use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
20
27
use Magento \Widget \Model \Template \FilterEmulate ;
21
28
22
29
/**
23
30
* Test for cms block resolver cache
31
+ *
32
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24
33
*/
25
34
class BlockTest extends ResolverCacheAbstract
26
35
{
@@ -44,24 +53,29 @@ class BlockTest extends ResolverCacheAbstract
44
53
*/
45
54
private $ storeManager ;
46
55
56
+ /**
57
+ * @var DataFixtureStorage
58
+ */
59
+ private $ fixtures ;
60
+
47
61
protected function setUp (): void
48
62
{
49
63
$ objectManager = ObjectManager::getInstance ();
50
64
$ this ->blockRepository = $ objectManager ->get (BlockRepositoryInterface::class);
51
65
$ this ->graphQlResolverCache = $ objectManager ->get (GraphQlResolverCache::class);
52
66
$ this ->widgetFilter = $ objectManager ->get (FilterEmulate::class);
53
67
$ this ->storeManager = $ objectManager ->get (StoreManagerInterface::class);
68
+ $ this ->fixtures = $ objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
54
69
55
70
parent ::setUp ();
56
71
}
57
72
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
+ ]
62
76
public function testCmsSingleBlockResolverCacheAndInvalidationAsGuest ()
63
77
{
64
- $ block = $ this ->blockRepository -> getById ( ' enabled_block ' );
78
+ $ block = $ this ->fixtures -> get ( ' guest_block ' );
65
79
66
80
$ query = $ this ->getQuery ([
67
81
$ block ->getIdentifier (),
@@ -94,15 +108,13 @@ public function testCmsSingleBlockResolverCacheAndInvalidationAsGuest()
94
108
);
95
109
}
96
110
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
+ ]
102
114
public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest ()
103
115
{
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 ' );
106
118
107
119
$ query = $ this ->getQuery ([
108
120
$ block1 ->getIdentifier (),
@@ -139,13 +151,12 @@ public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest()
139
151
);
140
152
}
141
153
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
+ ]
146
157
public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted ()
147
158
{
148
- $ block = $ this ->blockRepository -> getById ( ' fixture_block ' );
159
+ $ block = $ this ->fixtures -> get ( ' deleted_block ' );
149
160
150
161
$ query = $ this ->getQuery ([
151
162
$ block ->getIdentifier (),
@@ -177,13 +188,12 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted()
177
188
);
178
189
}
179
190
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
+ ]
184
194
public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled ()
185
195
{
186
- $ block = $ this ->blockRepository -> getById ('enabled_block ' );
196
+ $ block = $ this ->fixtures -> get ('enabled_block ' );
187
197
188
198
$ query = $ this ->getQuery ([
189
199
$ block ->getIdentifier (),
@@ -217,14 +227,20 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled()
217
227
}
218
228
219
229
/**
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
223
232
*/
233
+ #[
234
+ DataFixture(BlockFixture::class, as: 'block ' ),
235
+ DataFixture(Store::class, as: 'second_store ' ),
236
+ ]
224
237
public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView ()
225
238
{
226
239
/** @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 ' );
228
244
229
245
$ query = $ this ->getQuery ([
230
246
$ block ->getIdentifier (),
@@ -238,17 +254,17 @@ public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView(
238
254
$ cacheEntryDecoded = json_decode ($ cacheEntry , true );
239
255
240
256
$ this ->assertEqualsCanonicalizing (
241
- $ this -> generateExpectedDataFromBlocks ([ $ block ]) ,
242
- $ cacheEntryDecoded
257
+ $ cacheEntryDecoded ,
258
+ $ this -> generateExpectedDataFromBlocks ([ $ block ])
243
259
);
244
260
245
261
$ this ->assertTagsByCacheIdentityAndBlocks (
246
- $ cacheKey ,
262
+ ( string ) $ cacheKey ,
247
263
[$ block ]
248
264
);
249
265
250
266
// assert that cache is invalidated after changing block's store view
251
- $ secondStoreViewId = $ this -> storeManager -> getStore ( ' fixture_second_store ' ) ->getId ();
267
+ $ secondStoreViewId = $ store ->getId ();
252
268
$ block ->setStoreId ($ secondStoreViewId );
253
269
$ this ->blockRepository ->save ($ block );
254
270
@@ -283,15 +299,14 @@ public function testCmsBlockResolverCacheDoesNotSaveNonExistentCmsBlock()
283
299
);
284
300
}
285
301
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
+ ]
291
306
public function testCmsBlockResolverCacheRetainsEntriesThatHaveNotBeenUpdated ()
292
307
{
293
308
// query block1
294
- $ block1 = $ this ->blockRepository -> getById ( ' fixture_block ' );
309
+ $ block1 = $ this ->fixtures -> get ( ' block1 ' );
295
310
296
311
$ queryBlock1 = $ this ->getQuery ([
297
312
$ block1 ->getIdentifier (),
@@ -302,7 +317,7 @@ public function testCmsBlockResolverCacheRetainsEntriesThatHaveNotBeenUpdated()
302
317
$ cacheKeyBlock1 = $ this ->getResolverCacheKeyFromBlocks ([$ block1 ]);
303
318
304
319
// query block2
305
- $ block2 = $ this ->blockRepository -> getById ( ' enabled_block ' );
320
+ $ block2 = $ this ->fixtures -> get ( ' block2 ' );
306
321
307
322
$ queryBlock2 = $ this ->getQuery ([
308
323
$ block2 ->getIdentifier (),
0 commit comments