Skip to content

Commit

Permalink
magento/graphql-ce#387: Test coverage of getting IDs of CMS page/bloc…
Browse files Browse the repository at this point in the history
…ks by GraphQL API
  • Loading branch information
atwixfirster committed Apr 10, 2019
1 parent 7a90599 commit 8a5b3b7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function getData(string $blockIdentifier): array
$renderedContent = $this->widgetFilter->filter($block->getContent());

$blockData = [
BlockInterface::BLOCK_ID => $block->getId(),
BlockInterface::IDENTIFIER => $block->getIdentifier(),
BlockInterface::TITLE => $block->getTitle(),
BlockInterface::CONTENT => $renderedContent,
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/CmsGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type CmsBlocks @doc(description: "CMS blocks information") {
}

type CmsBlock @doc(description: "CMS block defines all CMS block information") {
block_id: Int @doc(description: "Entity ID of CMS block")
identifier: String @doc(description: "CMS block identifier")
title: String @doc(description: "CMS block title")
content: String @doc(description: "CMS block content")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function testGetCmsBlock()
{
cmsBlocks(identifiers: "enabled_block") {
items {
block_id
identifier
title
content
Expand All @@ -59,6 +60,43 @@ public function testGetCmsBlock()
self::assertArrayHasKey('cmsBlocks', $response);
self::assertArrayHasKey('items', $response['cmsBlocks']);

self::assertEquals($cmsBlockData['block_id'], $response['cmsBlocks']['items'][0]['block_id']);
self::assertEquals($cmsBlockData['identifier'], $response['cmsBlocks']['items'][0]['identifier']);
self::assertEquals($cmsBlockData['title'], $response['cmsBlocks']['items'][0]['title']);
self::assertEquals($renderedContent, $response['cmsBlocks']['items'][0]['content']);
}

/**
* Verify the fields of CMS Block selected by block_id
*
* @magentoApiDataFixture Magento/Cms/_files/blocks.php
*/
public function testGetCmsBlockByBlockId()
{
$cmsBlock = $this->blockRepository->getById('enabled_block');
$cmsBlockData = $cmsBlock->getData();
$blockId = $cmsBlockData['block_id'];
$renderedContent = $this->filterEmulate->setUseSessionInUrl(false)->filter($cmsBlock->getContent());

$query =
<<<QUERY
{
cmsBlocks(identifiers: "$blockId") {
items {
block_id
identifier
title
content
}
}
}
QUERY;
$response = $this->graphQlQuery($query);

self::assertArrayHasKey('cmsBlocks', $response);
self::assertArrayHasKey('items', $response['cmsBlocks']);

self::assertEquals($blockId, $response['cmsBlocks']['items'][0]['block_id']);
self::assertEquals($cmsBlockData['identifier'], $response['cmsBlocks']['items'][0]['identifier']);
self::assertEquals($cmsBlockData['title'], $response['cmsBlocks']['items'][0]['title']);
self::assertEquals($renderedContent, $response['cmsBlocks']['items'][0]['content']);
Expand Down

0 comments on commit 8a5b3b7

Please sign in to comment.