33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
7+
68namespace Magento \Cms \Test \Unit \Controller \Page ;
79
8- class ViewTest extends \PHPUnit \Framework \TestCase
10+ use Magento \Cms \Controller \Page \View ;
11+ use Magento \Cms \Helper \Page as PageHelper ;
12+ use Magento \Framework \App \RequestInterface ;
13+ use Magento \Framework \Controller \Result \Forward ;
14+ use Magento \Framework \Controller \Result \ForwardFactory ;
15+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
16+ use Magento \Framework \View \Result \Page ;
17+ use PHPUnit \Framework \MockObject \MockObject ;
18+ use PHPUnit \Framework \TestCase ;
19+
20+ class ViewTest extends TestCase
921{
22+ private const STUB_PAGE_ID = 2 ;
23+
1024 /**
11- * @var \Magento\Cms\Controller\Page\ View
25+ * @var View
1226 */
1327 protected $ controller ;
1428
1529 /**
16- * @var \PHPUnit_Framework_MockObject_MockObject
30+ * @var MockObject
1731 */
18- protected $ cmsHelperMock ;
32+ protected $ pageHelperMock ;
1933
2034 /**
21- * @var \PHPUnit_Framework_MockObject_MockObject
35+ * @var MockObject|RequestInterface
2236 */
2337 protected $ requestMock ;
2438
2539 /**
26- * @var \Magento\Framework\Controller\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject
40+ * @var MockObject|ForwardFactory
2741 */
2842 protected $ forwardFactoryMock ;
2943
3044 /**
31- * @var \Magento\Framework\Controller\Result\Forward|\PHPUnit_Framework_MockObject_MockObject
45+ * @var MockObject|Forward
3246 */
3347 protected $ forwardMock ;
3448
3549 /**
36- * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject
50+ * @var MockObject|Page
3751 */
3852 protected $ resultPageMock ;
3953
40- /**
41- * @var string
42- */
43- protected $ pageId = '2 ' ;
44-
4554 protected function setUp ()
4655 {
47- $ helper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
48- $ objectManagerMock = $ this ->createMock (\Magento \Framework \ObjectManagerInterface::class);
49- $ responseMock = $ this ->createMock (\Magento \Framework \App \Response \Http::class);
50- $ this ->resultPageMock = $ this ->getMockBuilder (\Magento \Framework \View \Result \Page::class)
56+ $ objectManager = new ObjectManagerHelper ($ this );
57+
58+ $ this ->resultPageMock = $ this ->getMockBuilder (Page::class)
5159 ->disableOriginalConstructor ()
5260 ->getMock ();
53- $ this ->forwardFactoryMock = $ this ->getMockBuilder (\ Magento \ Framework \ Controller \ Result \ ForwardFactory::class)
61+ $ this ->forwardFactoryMock = $ this ->getMockBuilder (ForwardFactory::class)
5462 ->setMethods (['create ' ])
5563 ->disableOriginalConstructor ()
5664 ->getMock ();
57- $ this ->forwardMock = $ this ->getMockBuilder (\ Magento \ Framework \ Controller \ Result \ Forward::class)
65+ $ this ->forwardMock = $ this ->getMockBuilder (Forward::class)
5866 ->disableOriginalConstructor ()
5967 ->getMock ();
6068 $ this ->forwardFactoryMock ->expects ($ this ->any ())
6169 ->method ('create ' )
6270 ->willReturn ($ this ->forwardMock );
6371
64- $ this ->requestMock = $ this ->createMock (\ Magento \ Framework \ App \ Request \Http ::class);
65- $ this ->cmsHelperMock = $ this ->createMock (\ Magento \ Cms \ Helper \Page ::class);
66- $ objectManagerMock -> expects ( $ this -> once ())-> method ( ' get ' )-> willReturn ( $ this -> cmsHelperMock );
67- $ this ->controller = $ helper ->getObject (
68- \ Magento \ Cms \ Controller \ Page \ View::class,
72+ $ this ->requestMock = $ this ->createMock (RequestInterface ::class);
73+ $ this ->pageHelperMock = $ this ->createMock (PageHelper ::class);
74+
75+ $ this ->controller = $ objectManager ->getObject (
76+ View::class,
6977 [
70- 'response ' => $ responseMock ,
71- 'objectManager ' => $ objectManagerMock ,
7278 'request ' => $ this ->requestMock ,
79+ 'pageHelper ' => $ this ->pageHelperMock ,
7380 'resultForwardFactory ' => $ this ->forwardFactoryMock
7481 ]
7582 );
@@ -81,13 +88,13 @@ public function testExecuteResultPage()
8188 ->method ('getParam ' )
8289 ->willReturnMap (
8390 [
84- ['page_id ' , $ this -> pageId , $ this -> pageId ],
85- ['id ' , false , $ this -> pageId ]
91+ ['page_id ' , null , self :: STUB_PAGE_ID ],
92+ ['id ' , null , self :: STUB_PAGE_ID ]
8693 ]
8794 );
88- $ this ->cmsHelperMock ->expects ($ this ->once ())
95+ $ this ->pageHelperMock ->expects ($ this ->once ())
8996 ->method ('prepareResultPage ' )
90- ->with ($ this ->controller , $ this -> pageId )
97+ ->with ($ this ->controller , self :: STUB_PAGE_ID )
9198 ->willReturn ($ this ->resultPageMock );
9299 $ this ->assertSame ($ this ->resultPageMock , $ this ->controller ->execute ());
93100 }
@@ -98,8 +105,8 @@ public function testExecuteResultForward()
98105 ->method ('getParam ' )
99106 ->willReturnMap (
100107 [
101- ['page_id ' , $ this -> pageId , $ this -> pageId ],
102- ['id ' , false , $ this -> pageId ]
108+ ['page_id ' , null , self :: STUB_PAGE_ID ],
109+ ['id ' , null , self :: STUB_PAGE_ID ]
103110 ]
104111 );
105112 $ this ->forwardMock ->expects ($ this ->once ())
0 commit comments