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,14 @@ 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: 'block1 ' ),
113
+ DataFixture(BlockFixture::class, as: 'block2 ' )
114
+ ]
102
115
public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest ()
103
116
{
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 ' );
106
119
107
120
$ query = $ this ->getQuery ([
108
121
$ block1 ->getIdentifier (),
@@ -139,13 +152,12 @@ public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest()
139
152
);
140
153
}
141
154
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
+ ]
146
158
public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted ()
147
159
{
148
- $ block = $ this ->blockRepository -> getById ( ' fixture_block ' );
160
+ $ block = $ this ->fixtures -> get ( ' deleted_block ' );
149
161
150
162
$ query = $ this ->getQuery ([
151
163
$ block ->getIdentifier (),
@@ -177,13 +189,12 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted()
177
189
);
178
190
}
179
191
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
+ ]
184
195
public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled ()
185
196
{
186
- $ block = $ this ->blockRepository -> getById ( ' enabled_block ' );
197
+ $ block = $ this ->fixtures -> get ( ' disabled_block ' );
187
198
188
199
$ query = $ this ->getQuery ([
189
200
$ block ->getIdentifier (),
@@ -217,14 +228,20 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled()
217
228
}
218
229
219
230
/**
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
223
233
*/
234
+ #[
235
+ DataFixture(BlockFixture::class, as: 'block ' ),
236
+ DataFixture(Store::class, as: 'second_store ' ),
237
+ ]
224
238
public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView ()
225
239
{
226
240
/** @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 ' );
228
245
229
246
$ query = $ this ->getQuery ([
230
247
$ block ->getIdentifier (),
@@ -238,17 +255,17 @@ public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView(
238
255
$ cacheEntryDecoded = json_decode ($ cacheEntry , true );
239
256
240
257
$ this ->assertEqualsCanonicalizing (
241
- $ this -> generateExpectedDataFromBlocks ([ $ block ]) ,
242
- $ cacheEntryDecoded
258
+ $ cacheEntryDecoded ,
259
+ $ this -> generateExpectedDataFromBlocks ([ $ block ])
243
260
);
244
261
245
262
$ this ->assertTagsByCacheIdentityAndBlocks (
246
- $ cacheKey ,
263
+ ( string ) $ cacheKey ,
247
264
[$ block ]
248
265
);
249
266
250
267
// assert that cache is invalidated after changing block's store view
251
- $ secondStoreViewId = $ this -> storeManager -> getStore ( ' fixture_second_store ' ) ->getId ();
268
+ $ secondStoreViewId = $ store ->getId ();
252
269
$ block ->setStoreId ($ secondStoreViewId );
253
270
$ this ->blockRepository ->save ($ block );
254
271
@@ -283,15 +300,15 @@ public function testCmsBlockResolverCacheDoesNotSaveNonExistentCmsBlock()
283
300
);
284
301
}
285
302
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
+ ]
291
308
public function testCmsBlockResolverCacheRetainsEntriesThatHaveNotBeenUpdated ()
292
309
{
293
310
// query block1
294
- $ block1 = $ this ->blockRepository -> getById ( ' fixture_block ' );
311
+ $ block1 = $ this ->fixtures -> get ( ' block1 ' );
295
312
296
313
$ queryBlock1 = $ this ->getQuery ([
297
314
$ block1 ->getIdentifier (),
@@ -302,7 +319,7 @@ public function testCmsBlockResolverCacheRetainsEntriesThatHaveNotBeenUpdated()
302
319
$ cacheKeyBlock1 = $ this ->getResolverCacheKeyFromBlocks ([$ block1 ]);
303
320
304
321
// query block2
305
- $ block2 = $ this ->blockRepository -> getById ( ' enabled_block ' );
322
+ $ block2 = $ this ->fixtures -> get ( ' block2 ' );
306
323
307
324
$ queryBlock2 = $ this ->getQuery ([
308
325
$ block2 ->getIdentifier (),
0 commit comments