Skip to content

Commit

Permalink
Merge pull request #8185 from magento-arcticfoxes/B2B-2530-cache
Browse files Browse the repository at this point in the history
B2B-2530: Unskip GraphQL cache tests skipped due to DEVOPS-4924 or cr…
  • Loading branch information
dhaecker authored May 4, 2023
2 parents 890f8ac + dc1a4dc commit 8af9d33
Show file tree
Hide file tree
Showing 11 changed files with 860 additions and 354 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CmsGraphQl\Model\Resolver\Block;

use Magento\Cms\Api\Data\BlockInterface;
use Magento\Cms\Model\Block;
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;

class ResolverCacheIdentity implements IdentityInterface
{
/**
* @var string
*/
private $cacheTag = Block::CACHE_TAG;

/**
* Get block identities from resolved data
*
* @param array $resolvedData
* @return string[]
*/
public function getIdentities(array $resolvedData): array
{
$ids = [];
$items = $resolvedData['items'] ?? [];
foreach ($items as $item) {
if (is_array($item) && !empty($item[BlockInterface::BLOCK_ID])) {
$ids[] = sprintf('%s_%s', $this->cacheTag, $item[BlockInterface::BLOCK_ID]);
$ids[] = sprintf('%s_%s', $this->cacheTag, $item[BlockInterface::IDENTIFIER]);
}
}

return $ids;
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/CmsGraphQl/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<item name="Magento\Cms\Api\Data\PageInterface" xsi:type="string">
Magento\Cms\Api\Data\PageInterface
</item>
<item name="Magento\Cms\Api\Data\BlockInterface" xsi:type="string">
Magento\Cms\Api\Data\BlockInterface
</item>
</argument>
</arguments>
</type>
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/CmsGraphQl/etc/graphql/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<item name="Magento\CmsGraphQl\Model\Resolver\Page" xsi:type="string">
Magento\CmsGraphQl\Model\Resolver\Page\ResolverCacheIdentity
</item>
<item name="Magento\CmsGraphQl\Model\Resolver\Blocks" xsi:type="string">
Magento\CmsGraphQl\Model\Resolver\Block\ResolverCacheIdentity
</item>
</argument>
</arguments>
</type>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\TestFramework\TestCase\GraphQl;

use Magento\Framework\App\Cache\StateInterface as CacheStateInterface;
use Magento\GraphQlCache\Model\Cache\Query\Resolver\Result\Type as GraphQlResolverCache;
use Magento\TestFramework\TestCase\GraphQlAbstract;

class ResolverCacheAbstract extends GraphQlAbstract
{
/**
* @var GraphQlResolverCache
*/
private $graphQlResolverCache;

/**
* @var CacheStateInterface
*/
private $cacheState;

/**
* @var bool
*/
private $originalCacheStateEnabledStatus;

/**
* @inheritDoc
*/
protected function setUp(): void
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->cacheState = $objectManager->get(CacheStateInterface::class);
$this->originalCacheStateEnabledStatus = $this->cacheState->isEnabled(GraphQlResolverCache::TYPE_IDENTIFIER);
$this->cacheState->setEnabled(GraphQlResolverCache::TYPE_IDENTIFIER, true);
$this->graphQlResolverCache = $objectManager->get(GraphQlResolverCache::class);

parent::setUp();
}

/**
* @inheritDoc
*/
protected function tearDown(): void
{
// clean graphql resolver cache and reset to original enablement status
$this->graphQlResolverCache->clean();
$this->cacheState->setEnabled(
GraphQlResolverCache::TYPE_IDENTIFIER,
$this->originalCacheStateEnabledStatus
);

parent::tearDown();
}
}
Loading

0 comments on commit 8af9d33

Please sign in to comment.