|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\GraphQl\Cms; |
| 9 | + |
| 10 | +use Magento\Cms\Model\GetPageByIdentifier; |
| 11 | +use Magento\TestFramework\ObjectManager; |
| 12 | +use Magento\TestFramework\TestCase\GraphQlAbstract; |
| 13 | + |
| 14 | + |
| 15 | +class CmsPageTest extends GraphQlAbstract |
| 16 | +{ |
| 17 | + /** |
| 18 | + * Verify the fields of CMS Page selected by page_id |
| 19 | + * |
| 20 | + * @magentoApiDataFixture Magento/Cms/_files/pages.php |
| 21 | + */ |
| 22 | + public function testGetCmsPageById() |
| 23 | + { |
| 24 | + $cmsPage = ObjectManager::getInstance()->get(GetPageByIdentifier::class)->execute('page100', 0); |
| 25 | + $pageId = $cmsPage->getPageId(); |
| 26 | + $cmsPageData = $cmsPage->getData(); |
| 27 | + $query = |
| 28 | + <<<QUERY |
| 29 | +{ |
| 30 | + cmsPage(id: $pageId) { |
| 31 | + url_key |
| 32 | + title |
| 33 | + content |
| 34 | + content_heading |
| 35 | + page_layout |
| 36 | + meta_title |
| 37 | + meta_description |
| 38 | + meta_keywords |
| 39 | + } |
| 40 | +} |
| 41 | +QUERY; |
| 42 | + |
| 43 | + $response = $this->graphQlQuery($query); |
| 44 | + $this->assertEquals($cmsPageData['identifier'], $response['cmsPage']['url_key']); |
| 45 | + $this->assertEquals($cmsPageData['title'], $response['cmsPage']['title']); |
| 46 | + $this->assertEquals($cmsPageData['content'], $response['cmsPage']['content']); |
| 47 | + $this->assertEquals($cmsPageData['content_heading'], $response['cmsPage']['content_heading']); |
| 48 | + $this->assertEquals($cmsPageData['page_layout'], $response['cmsPage']['page_layout']); |
| 49 | + $this->assertEquals($cmsPageData['meta_title'], $response['cmsPage']['meta_title']); |
| 50 | + $this->assertEquals($cmsPageData['meta_description'], $response['cmsPage']['meta_description']); |
| 51 | + $this->assertEquals($cmsPageData['meta_keywords'], $response['cmsPage']['meta_keywords']); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Verify the message when page_id is not specified. |
| 56 | + */ |
| 57 | + public function testGetCmsPageWithoutId() |
| 58 | + { |
| 59 | + $query = |
| 60 | + <<<QUERY |
| 61 | +{ |
| 62 | + cmsPage { |
| 63 | + url_key |
| 64 | + title |
| 65 | + content |
| 66 | + content_heading |
| 67 | + page_layout |
| 68 | + meta_title |
| 69 | + meta_description |
| 70 | + meta_keywords |
| 71 | + } |
| 72 | +} |
| 73 | +QUERY; |
| 74 | + |
| 75 | + $this->expectException(\Exception::class); |
| 76 | + $this->expectExceptionMessage('Page id should be specified'); |
| 77 | + $this->graphQlQuery($query); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Verify the message when page_id does not exist. |
| 82 | + */ |
| 83 | + public function testGetCmsPageByNonExistentId() |
| 84 | + { |
| 85 | + $query = |
| 86 | + <<<QUERY |
| 87 | +{ |
| 88 | + cmsPage(id: 0) { |
| 89 | + url_key |
| 90 | + title |
| 91 | + content |
| 92 | + content_heading |
| 93 | + page_layout |
| 94 | + meta_title |
| 95 | + meta_description |
| 96 | + meta_keywords |
| 97 | + } |
| 98 | +} |
| 99 | +QUERY; |
| 100 | + |
| 101 | + $this->expectException(\Exception::class); |
| 102 | + $this->expectExceptionMessage('The CMS page with the "0" ID doesn\'t exist.'); |
| 103 | + $this->graphQlQuery($query); |
| 104 | + |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Verify the message when CMS Page selected by page_id is disabled |
| 109 | + * |
| 110 | + * @magentoApiDataFixture Magento/Cms/_files/noroute.php |
| 111 | + */ |
| 112 | + public function testGetDisabledCmsPageById() |
| 113 | + { |
| 114 | + $cmsPageId = ObjectManager::getInstance()->get(GetPageByIdentifier::class)->execute('no-route', 0)->getPageId(); |
| 115 | + $query = |
| 116 | + <<<QUERY |
| 117 | +{ |
| 118 | + cmsPage(id: $cmsPageId) { |
| 119 | + url_key |
| 120 | + title |
| 121 | + content |
| 122 | + content_heading |
| 123 | + page_layout |
| 124 | + meta_title |
| 125 | + meta_description |
| 126 | + meta_keywords |
| 127 | + } |
| 128 | +} |
| 129 | +QUERY; |
| 130 | + |
| 131 | + $this->expectException(\Exception::class); |
| 132 | + $this->expectExceptionMessage('No such entity.'); |
| 133 | + $this->graphQlQuery($query); |
| 134 | + } |
| 135 | + |
| 136 | +} |
0 commit comments