From 8a5b3b7bf87959c6ed9118fcd213cdc34c563ed7 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Wed, 10 Apr 2019 15:11:08 +0300 Subject: [PATCH] magento/graphql-ce#387: Test coverage of getting IDs of CMS page/blocks by GraphQL API --- .../Model/Resolver/DataProvider/Block.php | 1 + .../Magento/CmsGraphQl/etc/schema.graphqls | 1 + .../Magento/GraphQl/Cms/CmsBlockTest.php | 38 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider/Block.php b/app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider/Block.php index 47a2439c4fad0..fa4944381b858 100644 --- a/app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider/Block.php +++ b/app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider/Block.php @@ -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, diff --git a/app/code/Magento/CmsGraphQl/etc/schema.graphqls b/app/code/Magento/CmsGraphQl/etc/schema.graphqls index 765e58849fc96..5504c42b339f9 100644 --- a/app/code/Magento/CmsGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CmsGraphQl/etc/schema.graphqls @@ -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") diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php index 57f526b1cb2f7..6e07f8cd7876a 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php @@ -47,6 +47,7 @@ public function testGetCmsBlock() { cmsBlocks(identifiers: "enabled_block") { items { + block_id identifier title content @@ -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 = + <<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']);