3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Cms \Test \Unit \Controller \Page ;
7
9
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
9
21
{
22
+ private const STUB_PAGE_ID = 2 ;
23
+
10
24
/**
11
- * @var \Magento\Cms\Controller\Page\ View
25
+ * @var View
12
26
*/
13
27
protected $ controller ;
14
28
15
29
/**
16
- * @var \PHPUnit_Framework_MockObject_MockObject
30
+ * @var MockObject
17
31
*/
18
- protected $ cmsHelperMock ;
32
+ protected $ pageHelperMock ;
19
33
20
34
/**
21
- * @var \PHPUnit_Framework_MockObject_MockObject
35
+ * @var MockObject|RequestInterface
22
36
*/
23
37
protected $ requestMock ;
24
38
25
39
/**
26
- * @var \Magento\Framework\Controller\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject
40
+ * @var MockObject|ForwardFactory
27
41
*/
28
42
protected $ forwardFactoryMock ;
29
43
30
44
/**
31
- * @var \Magento\Framework\Controller\Result\Forward|\PHPUnit_Framework_MockObject_MockObject
45
+ * @var MockObject|Forward
32
46
*/
33
47
protected $ forwardMock ;
34
48
35
49
/**
36
- * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject
50
+ * @var MockObject|Page
37
51
*/
38
52
protected $ resultPageMock ;
39
53
40
- /**
41
- * @var string
42
- */
43
- protected $ pageId = '2 ' ;
44
-
45
54
protected function setUp ()
46
55
{
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)
51
59
->disableOriginalConstructor ()
52
60
->getMock ();
53
- $ this ->forwardFactoryMock = $ this ->getMockBuilder (\ Magento \ Framework \ Controller \ Result \ ForwardFactory::class)
61
+ $ this ->forwardFactoryMock = $ this ->getMockBuilder (ForwardFactory::class)
54
62
->setMethods (['create ' ])
55
63
->disableOriginalConstructor ()
56
64
->getMock ();
57
- $ this ->forwardMock = $ this ->getMockBuilder (\ Magento \ Framework \ Controller \ Result \ Forward::class)
65
+ $ this ->forwardMock = $ this ->getMockBuilder (Forward::class)
58
66
->disableOriginalConstructor ()
59
67
->getMock ();
60
68
$ this ->forwardFactoryMock ->expects ($ this ->any ())
61
69
->method ('create ' )
62
70
->willReturn ($ this ->forwardMock );
63
71
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,
69
77
[
70
- 'response ' => $ responseMock ,
71
- 'objectManager ' => $ objectManagerMock ,
72
78
'request ' => $ this ->requestMock ,
79
+ 'pageHelper ' => $ this ->pageHelperMock ,
73
80
'resultForwardFactory ' => $ this ->forwardFactoryMock
74
81
]
75
82
);
@@ -81,13 +88,13 @@ public function testExecuteResultPage()
81
88
->method ('getParam ' )
82
89
->willReturnMap (
83
90
[
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 ]
86
93
]
87
94
);
88
- $ this ->cmsHelperMock ->expects ($ this ->once ())
95
+ $ this ->pageHelperMock ->expects ($ this ->once ())
89
96
->method ('prepareResultPage ' )
90
- ->with ($ this ->controller , $ this -> pageId )
97
+ ->with ($ this ->controller , self :: STUB_PAGE_ID )
91
98
->willReturn ($ this ->resultPageMock );
92
99
$ this ->assertSame ($ this ->resultPageMock , $ this ->controller ->execute ());
93
100
}
@@ -98,8 +105,8 @@ public function testExecuteResultForward()
98
105
->method ('getParam ' )
99
106
->willReturnMap (
100
107
[
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 ]
103
110
]
104
111
);
105
112
$ this ->forwardMock ->expects ($ this ->once ())
0 commit comments