blockRepository = Bootstrap::getObjectManager()->get(BlockRepositoryInterface::class); $this->filterEmulate = Bootstrap::getObjectManager()->get(FilterEmulate::class); } /** * Verify the fields of CMS Block selected by identifiers * * @magentoApiDataFixture Magento/Cms/_files/blocks.php */ public function testGetCmsBlock() { $cmsBlock = $this->blockRepository->getById('enabled_block'); $cmsBlockData = $cmsBlock->getData(); $renderedContent = $this->filterEmulate->setUseSessionInUrl(false)->filter($cmsBlock->getContent()); $query = <<graphQlQuery($query); self::assertArrayHasKey('cmsBlocks', $response); self::assertArrayHasKey('items', $response['cmsBlocks']); 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 message when CMS Block is disabled * * @expectedException \Exception * @expectedExceptionMessage The CMS block with the "disabled_block" ID doesn't exist * * @magentoApiDataFixture Magento/Cms/_files/blocks.php */ public function testGetDisabledCmsBlock() { $query = <<graphQlQuery($query); } /** * Verify the message when identifiers were not specified * * @expectedException \Exception * @expectedExceptionMessage "identifiers" of CMS blocks should be specified */ public function testGetCmsBlocksWithoutIdentifiers() { $query = <<graphQlQuery($query); } /** * Verify the message when CMS Block with such identifiers does not exist * * @expectedException \Exception * @expectedExceptionMessage The CMS block with the "nonexistent_id" ID doesn't exist. */ public function testGetCmsBlockByNonExistentIdentifier() { $query = <<graphQlQuery($query); } /** * Verify the fields of CMS Block selected by identifiers * * @magentoApiDataFixture Magento/Cms/_files/blocks.php */ public function testGetEnabledAndDisabledCmsBlockInOneRequest() { $query = <<graphQlQuery($query); self::fail('Response should contains errors.'); } catch (ResponseContainsErrorsException $e) { $responseData = $e->getResponseData(); } self::assertNotEmpty($responseData); self::assertEquals('enabled_block', $responseData['data']['cmsBlocks']['items'][0]['identifier']); self::assertEquals( 'The CMS block with the "disabled_block" ID doesn\'t exist.', $responseData['errors'][0]['message'] ); } }