4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
- /**
8
- * Test class for \Magento\Cms\Controller\Page.
9
- */
10
7
namespace Magento \Cms \Controller ;
11
8
12
9
use Magento \Cms \Api \GetPageByIdentifierInterface ;
10
+ use Magento \Cms \Model \Page \CustomLayoutManagerInterface ;
13
11
use Magento \Framework \View \LayoutInterface ;
14
- use Magento \TestFramework \Helper \Bootstrap ;
12
+ use Magento \TestFramework \Cms \Model \CustomLayoutManager ;
13
+ use Magento \TestFramework \TestCase \AbstractController ;
15
14
16
- class PageTest extends \Magento \TestFramework \TestCase \AbstractController
15
+ /**
16
+ * Test for \Magento\Cms\Controller\Page\View class.
17
+ */
18
+ class PageTest extends AbstractController
17
19
{
20
+ /**
21
+ * @var GetPageByIdentifierInterface
22
+ */
23
+ private $ pageRetriever ;
24
+
18
25
/**
19
26
* @inheritDoc
20
27
*/
21
28
protected function setUp (): void
22
29
{
23
- Bootstrap::getObjectManager ()->configure ([
30
+ parent ::setUp ();
31
+ $ this ->_objectManager ->configure ([
24
32
'preferences ' => [
25
- \Magento \Cms \Model \Page \CustomLayoutManagerInterface::class =>
26
- \Magento \TestFramework \Cms \Model \CustomLayoutManager::class
33
+ CustomLayoutManagerInterface::class => CustomLayoutManager::class,
27
34
]
28
35
]);
29
- parent :: setUp ( );
36
+ $ this -> pageRetriever = $ this -> _objectManager -> get (GetPageByIdentifierInterface::class );
30
37
}
31
38
32
39
public function testViewAction ()
@@ -51,9 +58,7 @@ public function testViewRedirectWithTrailingSlash()
51
58
public function testAddBreadcrumbs ()
52
59
{
53
60
$ 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);
57
62
$ breadcrumbsBlock = $ layout ->getBlock ('breadcrumbs ' );
58
63
$ this ->assertStringContainsString ($ breadcrumbsBlock ->toHtml (), $ this ->getResponse ()->getBody ());
59
64
}
@@ -90,12 +95,10 @@ public static function cmsPageWithSystemRouteFixture()
90
95
*/
91
96
public function testCustomHandles (): void
92
97
{
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 ());
97
100
/** @var LayoutInterface $layout */
98
- $ layout = Bootstrap:: getObjectManager () ->get (LayoutInterface::class);
101
+ $ layout = $ this -> _objectManager ->get (LayoutInterface::class);
99
102
$ handles = $ layout ->getUpdate ()->getHandles ();
100
103
$ this ->assertContains ('cms_page_view_selectable_test_custom_layout_page_3_test_selected ' , $ handles );
101
104
}
@@ -111,8 +114,37 @@ public function testHomePageCustomHandles(): void
111
114
{
112
115
$ this ->dispatch ('/ ' );
113
116
/** @var LayoutInterface $layout */
114
- $ layout = Bootstrap:: getObjectManager () ->get (LayoutInterface::class);
117
+ $ layout = $ this -> _objectManager ->get (LayoutInterface::class);
115
118
$ handles = $ layout ->getUpdate ()->getHandles ();
116
119
$ this ->assertContains ('cms_page_view_selectable_home_page_custom_layout ' , $ handles );
117
120
}
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
+ }
118
150
}
0 commit comments