From 6e78ca6a12330c37c6ea1596dba08614260f985a Mon Sep 17 00:00:00 2001 From: Tomash Khamlai Date: Tue, 21 Aug 2018 19:06:55 +0300 Subject: [PATCH] Test coverage for CMS block --- .../Magento/GraphQl/Cms/CmsBlockTest.php | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php new file mode 100644 index 0000000000000..9ca1ba381d94c --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php @@ -0,0 +1,138 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + /** + * Verify the fields of CMS Block selected by identifiers + * + * @magentoApiDataFixture Magento/Cms/_files/block.php + */ + public function testGetCmsBlocksByIdentifiers() + { + /** @var StoreManagerInterface $storeManager */ + $storeManager = $this->objectManager->get(StoreManagerInterface::class); + $storeId = (int)$storeManager->getStore()->getId(); + $cmsBlock = $this->objectManager->get(GetBlockByIdentifier::class)->execute("fixture_block", $storeId); + $cmsBlockData = $cmsBlock->getData(); + /** @var FilterEmulate $widgetFilter */ + $widgetFilter = $this->objectManager->get(FilterEmulate::class); + $renderedContent = $widgetFilter->setUseSessionInUrl(false)->filter($cmsBlock->getContent()); + $query = + <<graphQlQuery($query); + $this->assertArrayHasKey('cmsBlocks', $response); + $this->assertArrayHasKey('items', $response['cmsBlocks']); + $this->assertArrayHasKey('content', $response['cmsBlocks']['items'][0]); + $this->assertEquals($cmsBlockData['identifier'], $response['cmsBlocks']['items'][0]['identifier']); + $this->assertEquals($cmsBlockData['title'], $response['cmsBlocks']['items'][0]['title']); + $this->assertEquals($renderedContent, $response['cmsBlocks']['items'][0]['content']); + } + + /** + * Verify the message when CMS Block is disabled + */ + public function testGetDisabledCmsBlockByIdentifiers() + { + /** @var StoreManagerInterface $storeManager */ + $storeManager = $this->objectManager->get(StoreManagerInterface::class); + $storeId = (int)$storeManager->getStore()->getId(); + $cmsBlockId = $this->objectManager->get(GetBlockByIdentifier::class)->execute("fixture_block", $storeId)->getId(); + $this->objectManager->get(Block::class)->load($cmsBlockId)->setIsActive(0)->save(); + $query = + <<expectException(\Exception::class); + $this->expectExceptionMessage('No such entity.'); + $this->graphQlQuery($query); + } + + /** + * Verify the message when identifiers were not specified + */ + public function testGetCmsBlockBypassingIdentifiers() + { + $query = + <<expectException(\Exception::class); + $this->expectExceptionMessage('"identifiers" of CMS blocks should be specified'); + $this->graphQlQuery($query); + } + + /** + * Verify the message when CMS Block with such identifiers does not exist + */ + public function testGetCmsBlockByNonExistentIdentifier() + { + $query = + <<expectException(\Exception::class); + $this->expectExceptionMessage('The CMS block with the "0" ID doesn\'t exist.'); + $this->graphQlQuery($query); + } +}