Skip to content

Commit 8af9d33

Browse files
authored
Merge pull request #8185 from magento-arcticfoxes/B2B-2530-cache
B2B-2530: Unskip GraphQL cache tests skipped due to DEVOPS-4924 or cr…
2 parents 890f8ac + dc1a4dc commit 8af9d33

File tree

11 files changed

+860
-354
lines changed

11 files changed

+860
-354
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CmsGraphQl\Model\Resolver\Block;
9+
10+
use Magento\Cms\Api\Data\BlockInterface;
11+
use Magento\Cms\Model\Block;
12+
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
13+
14+
class ResolverCacheIdentity implements IdentityInterface
15+
{
16+
/**
17+
* @var string
18+
*/
19+
private $cacheTag = Block::CACHE_TAG;
20+
21+
/**
22+
* Get block identities from resolved data
23+
*
24+
* @param array $resolvedData
25+
* @return string[]
26+
*/
27+
public function getIdentities(array $resolvedData): array
28+
{
29+
$ids = [];
30+
$items = $resolvedData['items'] ?? [];
31+
foreach ($items as $item) {
32+
if (is_array($item) && !empty($item[BlockInterface::BLOCK_ID])) {
33+
$ids[] = sprintf('%s_%s', $this->cacheTag, $item[BlockInterface::BLOCK_ID]);
34+
$ids[] = sprintf('%s_%s', $this->cacheTag, $item[BlockInterface::IDENTIFIER]);
35+
}
36+
}
37+
38+
return $ids;
39+
}
40+
}

app/code/Magento/CmsGraphQl/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<item name="Magento\Cms\Api\Data\PageInterface" xsi:type="string">
1313
Magento\Cms\Api\Data\PageInterface
1414
</item>
15+
<item name="Magento\Cms\Api\Data\BlockInterface" xsi:type="string">
16+
Magento\Cms\Api\Data\BlockInterface
17+
</item>
1518
</argument>
1619
</arguments>
1720
</type>

app/code/Magento/CmsGraphQl/etc/graphql/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
<item name="Magento\CmsGraphQl\Model\Resolver\Page" xsi:type="string">
2525
Magento\CmsGraphQl\Model\Resolver\Page\ResolverCacheIdentity
2626
</item>
27+
<item name="Magento\CmsGraphQl\Model\Resolver\Blocks" xsi:type="string">
28+
Magento\CmsGraphQl\Model\Resolver\Block\ResolverCacheIdentity
29+
</item>
2730
</argument>
2831
</arguments>
2932
</type>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\TestFramework\TestCase\GraphQl;
9+
10+
use Magento\Framework\App\Cache\StateInterface as CacheStateInterface;
11+
use Magento\GraphQlCache\Model\Cache\Query\Resolver\Result\Type as GraphQlResolverCache;
12+
use Magento\TestFramework\TestCase\GraphQlAbstract;
13+
14+
class ResolverCacheAbstract extends GraphQlAbstract
15+
{
16+
/**
17+
* @var GraphQlResolverCache
18+
*/
19+
private $graphQlResolverCache;
20+
21+
/**
22+
* @var CacheStateInterface
23+
*/
24+
private $cacheState;
25+
26+
/**
27+
* @var bool
28+
*/
29+
private $originalCacheStateEnabledStatus;
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
protected function setUp(): void
35+
{
36+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
37+
$this->cacheState = $objectManager->get(CacheStateInterface::class);
38+
$this->originalCacheStateEnabledStatus = $this->cacheState->isEnabled(GraphQlResolverCache::TYPE_IDENTIFIER);
39+
$this->cacheState->setEnabled(GraphQlResolverCache::TYPE_IDENTIFIER, true);
40+
$this->graphQlResolverCache = $objectManager->get(GraphQlResolverCache::class);
41+
42+
parent::setUp();
43+
}
44+
45+
/**
46+
* @inheritDoc
47+
*/
48+
protected function tearDown(): void
49+
{
50+
// clean graphql resolver cache and reset to original enablement status
51+
$this->graphQlResolverCache->clean();
52+
$this->cacheState->setEnabled(
53+
GraphQlResolverCache::TYPE_IDENTIFIER,
54+
$this->originalCacheStateEnabledStatus
55+
);
56+
57+
parent::tearDown();
58+
}
59+
}

0 commit comments

Comments
 (0)