CmsPageTest.php 3.3 KB

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