44 * See COPYING.txt for license details.
55 */
66
7- /**
8- * Test class for \Magento\Cms\Controller\Page.
9- */
107namespace Magento \Cms \Controller ;
118
129use Magento \Cms \Api \GetPageByIdentifierInterface ;
10+ use Magento \Cms \Model \Page \CustomLayoutManagerInterface ;
1311use Magento \Framework \View \LayoutInterface ;
14- use Magento \TestFramework \Helper \Bootstrap ;
12+ use Magento \TestFramework \Cms \Model \CustomLayoutManager ;
13+ use Magento \TestFramework \TestCase \AbstractController ;
1514
16- class PageTest extends \Magento \TestFramework \TestCase \AbstractController
15+ /**
16+ * Test for \Magento\Cms\Controller\Page\View class.
17+ */
18+ class PageTest extends AbstractController
1719{
20+ /**
21+ * @var GetPageByIdentifierInterface
22+ */
23+ private $ pageRetriever ;
24+
1825 /**
1926 * @inheritDoc
2027 */
2128 protected function setUp (): void
2229 {
23- Bootstrap::getObjectManager ()->configure ([
30+ parent ::setUp ();
31+ $ this ->_objectManager ->configure ([
2432 'preferences ' => [
25- \Magento \Cms \Model \Page \CustomLayoutManagerInterface::class =>
26- \Magento \TestFramework \Cms \Model \CustomLayoutManager::class
33+ CustomLayoutManagerInterface::class => CustomLayoutManager::class,
2734 ]
2835 ]);
29- parent :: setUp ( );
36+ $ this -> pageRetriever = $ this -> _objectManager -> get (GetPageByIdentifierInterface::class );
3037 }
3138
3239 public function testViewAction ()
@@ -51,9 +58,7 @@ public function testViewRedirectWithTrailingSlash()
5158 public function testAddBreadcrumbs ()
5259 {
5360 $ this ->dispatch ('/enable-cookies ' );
54- $ layout = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
55- \Magento \Framework \View \LayoutInterface::class
56- );
61+ $ layout = $ this ->_objectManager ->get (LayoutInterface::class);
5762 $ breadcrumbsBlock = $ layout ->getBlock ('breadcrumbs ' );
5863 $ this ->assertStringContainsString ($ breadcrumbsBlock ->toHtml (), $ this ->getResponse ()->getBody ());
5964 }
@@ -90,12 +95,10 @@ public static function cmsPageWithSystemRouteFixture()
9095 */
9196 public function testCustomHandles (): void
9297 {
93- /** @var GetPageByIdentifierInterface $pageFinder */
94- $ pageFinder = Bootstrap::getObjectManager ()->get (GetPageByIdentifierInterface::class);
95- $ page = $ pageFinder ->execute ('test_custom_layout_page_3 ' , 0 );
96- $ this ->dispatch ('/cms/page/view/page_id/ ' .$ page ->getId ());
98+ $ page = $ this ->pageRetriever ->execute ('test_custom_layout_page_3 ' , 0 );
99+ $ this ->dispatch ('/cms/page/view/page_id/ ' . $ page ->getId ());
97100 /** @var LayoutInterface $layout */
98- $ layout = Bootstrap:: getObjectManager () ->get (LayoutInterface::class);
101+ $ layout = $ this -> _objectManager ->get (LayoutInterface::class);
99102 $ handles = $ layout ->getUpdate ()->getHandles ();
100103 $ this ->assertContains ('cms_page_view_selectable_test_custom_layout_page_3_test_selected ' , $ handles );
101104 }
@@ -111,8 +114,37 @@ public function testHomePageCustomHandles(): void
111114 {
112115 $ this ->dispatch ('/ ' );
113116 /** @var LayoutInterface $layout */
114- $ layout = Bootstrap:: getObjectManager () ->get (LayoutInterface::class);
117+ $ layout = $ this -> _objectManager ->get (LayoutInterface::class);
115118 $ handles = $ layout ->getUpdate ()->getHandles ();
116119 $ this ->assertContains ('cms_page_view_selectable_home_page_custom_layout ' , $ handles );
117120 }
121+
122+ /**
123+ * Tests page renders even with unavailable custom page layout.
124+ *
125+ * @magentoDataFixture Magento/Cms/Fixtures/page_list.php
126+ * @dataProvider pageLayoutDataProvider
127+ * @param string $pageIdentifier
128+ * @return void
129+ */
130+ public function testPageWithCustomLayout (string $ pageIdentifier ): void
131+ {
132+ $ page = $ this ->pageRetriever ->execute ($ pageIdentifier , 0 );
133+ $ this ->dispatch ('/cms/page/view/page_id/ ' . $ page ->getId ());
134+ $ this ->assertStringContainsString (
135+ '<main id="maincontent" class="page-main"> ' ,
136+ $ this ->getResponse ()->getBody ()
137+ );
138+ }
139+
140+ /**
141+ * @return array
142+ */
143+ public function pageLayoutDataProvider (): array
144+ {
145+ return [
146+ 'Page with 1column layout ' => ['page-with-1column-layout ' ],
147+ 'Page with unavailable layout ' => ['page-with-unavailable-layout ' ]
148+ ];
149+ }
118150}
0 commit comments