PageTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test class for \Magento\Cms\Controller\Page.
  8. */
  9. namespace Magento\Cms\Controller;
  10. class PageTest extends \Magento\TestFramework\TestCase\AbstractController
  11. {
  12. public function testViewAction()
  13. {
  14. $this->dispatch('/enable-cookies');
  15. $this->assertContains('What are Cookies?', $this->getResponse()->getBody());
  16. }
  17. public function testViewRedirectWithTrailingSlash()
  18. {
  19. $this->dispatch('/enable-cookies/');
  20. $code = $this->getResponse()->getStatusCode();
  21. $location = $this->getResponse()->getHeader('Location')->getFieldValue();
  22. $this->assertEquals(301, $code, 'Invalid response code');
  23. $this->assertStringEndsWith('/enable-cookies', $location, 'Invalid location header');
  24. }
  25. /**
  26. * Test \Magento\Cms\Block\Page::_addBreadcrumbs
  27. */
  28. public function testAddBreadcrumbs()
  29. {
  30. $this->dispatch('/enable-cookies');
  31. $layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  32. \Magento\Framework\View\LayoutInterface::class
  33. );
  34. $breadcrumbsBlock = $layout->getBlock('breadcrumbs');
  35. $this->assertContains($breadcrumbsBlock->toHtml(), $this->getResponse()->getBody());
  36. }
  37. /**
  38. * @magentoDataFixture cmsPageWithSystemRouteFixture
  39. */
  40. public function testCreatePageWithSameModuleName()
  41. {
  42. $this->dispatch('/shipping');
  43. $content = $this->getResponse()->getBody();
  44. $this->assertContains('Shipping Test Page', $content);
  45. }
  46. public static function cmsPageWithSystemRouteFixture()
  47. {
  48. /** @var $page \Magento\Cms\Model\Page */
  49. $page = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Cms\Model\Page::class);
  50. $page->setTitle('Test title')
  51. ->setIdentifier('shipping')
  52. ->setStores([0])
  53. ->setIsActive(1)
  54. ->setContent('<h1>Shipping Test Page</h1>')
  55. ->setPageLayout('1column')
  56. ->save();
  57. }
  58. }