@@ -13,73 +13,61 @@ class SaveTest extends \PHPUnit_Framework_TestCase
13
13
/**
14
14
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
15
15
*/
16
- protected $ requestMock ;
16
+ private $ requestMock ;
17
17
18
18
/**
19
19
* @var \Magento\Cms\Controller\Adminhtml\Page\PostDataProcessor|\PHPUnit_Framework_MockObject_MockObject
20
20
*/
21
- protected $ dataProcessorMock ;
21
+ private $ dataProcessorMock ;
22
22
23
23
/**
24
24
* @var \Magento\Framework\App\Request\DataPersistorInterface|\PHPUnit_Framework_MockObject_MockObject
25
25
*/
26
- protected $ dataPersistorMock ;
26
+ private $ dataPersistorMock ;
27
27
28
28
/**
29
29
* @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject
30
30
*/
31
- protected $ resultRedirectFactory ;
31
+ private $ resultRedirectFactory ;
32
32
33
33
/**
34
34
* @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject
35
35
*/
36
- protected $ resultRedirect ;
36
+ private $ resultRedirect ;
37
37
38
38
/**
39
- * @var \Magento\Backend\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject
40
- */
41
- protected $ contextMock ;
42
-
43
- /**
44
- * @var \Magento\Framework\ObjectManager\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
45
- */
46
- protected $ objectManagerMock ;
47
-
48
- /**
49
- * @var \Magento\Cms\Model\Page|\PHPUnit_Framework_MockObject_MockObject $pageMock
39
+ * @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
50
40
*/
51
- protected $ pageMock ;
41
+ private $ messageManagerMock ;
52
42
53
43
/**
54
- * @var \Magento\Framework\Message \ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
44
+ * @var \Magento\Framework\Event \ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
55
45
*/
56
- protected $ messageManagerMock ;
46
+ private $ eventManagerMock ;
57
47
58
48
/**
59
- * @var \Magento\Framework\Event\ManagerInterface |\PHPUnit_Framework_MockObject_MockObject
49
+ * @var \Magento\Cms\Model\PageFactory |\PHPUnit_Framework_MockObject_MockObject
60
50
*/
61
- protected $ eventManagerMock ;
51
+ private $ pageFactory ;
62
52
63
53
/**
64
- * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
54
+ * @var \Magento\Cms\Api\PageRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
65
55
*/
66
- protected $ objectManager ;
56
+ private $ pageRepository ;
67
57
68
58
/**
69
59
* @var \Magento\Cms\Controller\Adminhtml\Page\Save
70
60
*/
71
- protected $ saveController ;
61
+ private $ saveController ;
72
62
73
63
/**
74
64
* @var int
75
65
*/
76
- protected $ pageId = 1 ;
66
+ private $ pageId = 1 ;
77
67
78
68
protected function setUp ()
79
69
{
80
- $ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
81
-
82
- $ this ->contextMock = $ this ->getMock (\Magento \Backend \App \Action \Context::class, [], [], '' , false );
70
+ $ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
83
71
84
72
$ this ->resultRedirectFactory = $ this ->getMockBuilder (\Magento \Backend \Model \View \Result \RedirectFactory::class)
85
73
->disableOriginalConstructor ()
@@ -91,69 +79,37 @@ protected function setUp()
91
79
$ this ->resultRedirectFactory ->expects ($ this ->atLeastOnce ())
92
80
->method ('create ' )
93
81
->willReturn ($ this ->resultRedirect );
94
-
95
- $ this ->dataProcessorMock = $ this ->getMock (
96
- \Magento \Cms \Controller \Adminhtml \Page \PostDataProcessor::class,
97
- ['filter ' ],
98
- [],
99
- '' ,
100
- false
101
- );
102
-
82
+ $ this ->dataProcessorMock = $ this ->getMockBuilder (
83
+ \Magento \Cms \Controller \Adminhtml \Page \PostDataProcessor::class
84
+ )->setMethods (['filter ' ])->disableOriginalConstructor ()->getMock ();
103
85
$ this ->dataPersistorMock = $ this ->getMockBuilder (\Magento \Framework \App \Request \DataPersistorInterface::class)
104
86
->getMock ();
105
-
106
- $ this ->requestMock = $ this ->getMockForAbstractClass (
107
- \Magento \Framework \App \RequestInterface::class,
108
- [],
109
- '' ,
110
- false ,
111
- true ,
112
- true ,
113
- ['getParam ' , 'getPostValue ' ]
114
- );
115
-
116
- $ this ->pageMock = $ this ->getMockBuilder (
117
- \Magento \Cms \Model \Page::class
118
- )->disableOriginalConstructor ()->getMock ();
119
-
120
- $ this ->messageManagerMock = $ this ->getMock (
121
- \Magento \Framework \Message \ManagerInterface::class,
122
- [],
123
- [],
124
- '' ,
125
- false
126
- );
127
-
128
- $ this ->eventManagerMock = $ this ->getMockForAbstractClass (
129
- \Magento \Framework \Event \ManagerInterface::class,
130
- [],
131
- '' ,
132
- false ,
133
- true ,
134
- true ,
135
- ['dispatch ' ]
136
- );
137
-
138
- $ this ->objectManagerMock = $ this ->getMockBuilder (\Magento \Framework \ObjectManager \ObjectManager::class)
87
+ $ this ->requestMock = $ this ->getMockBuilder (\Magento \Framework \App \RequestInterface::class)
88
+ ->setMethods (['getParam ' , 'getPostValue ' ])
89
+ ->getMockForAbstractClass ();
90
+ $ this ->messageManagerMock = $ this ->getMockBuilder (\Magento \Framework \Message \ManagerInterface::class)
91
+ ->getMockForAbstractClass ();
92
+ $ this ->eventManagerMock = $ this ->getMockBuilder (\Magento \Framework \Event \ManagerInterface::class)
93
+ ->setMethods (['dispatch ' ])
94
+ ->getMockForAbstractClass ();
95
+ $ this ->pageFactory = $ this ->getMockBuilder (\Magento \Cms \Model \PageFactory::class)
139
96
->disableOriginalConstructor ()
140
- ->setMethods (['get ' , ' create ' ])
97
+ ->setMethods (['create ' ])
141
98
->getMock ();
142
-
143
- $ this ->contextMock ->expects ($ this ->any ())->method ('getRequest ' )->willReturn ($ this ->requestMock );
144
- $ this ->contextMock ->expects ($ this ->any ())->method ('getObjectManager ' )->willReturn ($ this ->objectManagerMock );
145
- $ this ->contextMock ->expects ($ this ->any ())->method ('getMessageManager ' )->willReturn ($ this ->messageManagerMock );
146
- $ this ->contextMock ->expects ($ this ->any ())->method ('getEventManager ' )->willReturn ($ this ->eventManagerMock );
147
- $ this ->contextMock ->expects ($ this ->any ())
148
- ->method ('getResultRedirectFactory ' )
149
- ->willReturn ($ this ->resultRedirectFactory );
150
-
151
- $ this ->saveController = $ this ->objectManager ->getObject (
99
+ $ this ->pageRepository = $ this ->getMockBuilder (\Magento \Cms \Api \PageRepositoryInterface::class)
100
+ ->disableOriginalConstructor ()
101
+ ->getMockForAbstractClass ();
102
+ $ this ->saveController = $ objectManager ->getObject (
152
103
\Magento \Cms \Controller \Adminhtml \Page \Save::class,
153
104
[
154
- 'context ' => $ this ->contextMock ,
105
+ 'request ' => $ this ->requestMock ,
106
+ 'messageManager ' => $ this ->messageManagerMock ,
107
+ 'eventManager ' => $ this ->eventManagerMock ,
108
+ 'resultRedirectFactory ' => $ this ->resultRedirectFactory ,
155
109
'dataProcessor ' => $ this ->dataProcessorMock ,
156
110
'dataPersistor ' => $ this ->dataPersistorMock ,
111
+ 'pageFactory ' => $ this ->pageFactory ,
112
+ 'pageRepository ' => $ this ->pageRepository
157
113
]
158
114
);
159
115
}
@@ -190,20 +146,21 @@ public function testSaveAction()
190
146
['back ' , null , false ],
191
147
]
192
148
);
193
-
194
- $ this ->objectManagerMock ->expects ($ this ->atLeastOnce ())
149
+ $ page = $ this ->getMockBuilder (\Magento \Cms \Model \Page::class)
150
+ ->disableOriginalConstructor ()
151
+ ->getMock ();
152
+ $ this ->pageFactory ->expects ($ this ->atLeastOnce ())
195
153
->method ('create ' )
196
- ->with ($ this ->equalTo (\Magento \Cms \Model \Page::class))
197
- ->willReturn ($ this ->pageMock );
154
+ ->willReturn ($ page );
198
155
199
- $ this -> pageMock ->expects ($ this ->any ())
156
+ $ page ->expects ($ this ->any ())
200
157
->method ('load ' )
201
158
->willReturnSelf ();
202
- $ this -> pageMock ->expects ($ this ->any ())
159
+ $ page ->expects ($ this ->any ())
203
160
->method ('getId ' )
204
161
->willReturn (true );
205
- $ this -> pageMock ->expects ($ this ->once ())->method ('setData ' );
206
- $ this ->pageMock ->expects ($ this ->once ())->method ('save ' );
162
+ $ page ->expects ($ this ->once ())->method ('setData ' );
163
+ $ this ->pageRepository ->expects ($ this ->once ())->method ('save ' )-> with ( $ page );
207
164
208
165
$ this ->dataPersistorMock ->expects ($ this ->any ())
209
166
->method ('clear ' )
@@ -240,20 +197,21 @@ public function testSaveAndContinue()
240
197
$ this ->dataProcessorMock ->expects ($ this ->any ())
241
198
->method ('filter ' )
242
199
->willReturnArgument (0 );
243
-
244
- $ this ->objectManagerMock ->expects ($ this ->atLeastOnce ())
200
+ $ page = $ this ->getMockBuilder (\Magento \Cms \Model \Page::class)
201
+ ->disableOriginalConstructor ()
202
+ ->getMock ();
203
+ $ this ->pageFactory ->expects ($ this ->atLeastOnce ())
245
204
->method ('create ' )
246
- ->with ($ this ->equalTo (\Magento \Cms \Model \Page::class))
247
- ->willReturn ($ this ->pageMock );
205
+ ->willReturn ($ page );
248
206
249
- $ this -> pageMock ->expects ($ this ->any ())
207
+ $ page ->expects ($ this ->any ())
250
208
->method ('load ' )
251
209
->willReturnSelf ();
252
- $ this -> pageMock ->expects ($ this ->any ())
210
+ $ page ->expects ($ this ->any ())
253
211
->method ('getId ' )
254
212
->willReturn (true );
255
- $ this -> pageMock ->expects ($ this ->once ())->method ('setData ' );
256
- $ this ->pageMock ->expects ($ this ->once ())->method ('save ' );
213
+ $ page ->expects ($ this ->once ())->method ('setData ' );
214
+ $ this ->pageRepository ->expects ($ this ->once ())->method ('save ' )-> with ( $ page );
257
215
258
216
$ this ->messageManagerMock ->expects ($ this ->once ())
259
217
->method ('addSuccess ' )
@@ -286,20 +244,22 @@ public function testSaveActionThrowsException()
286
244
$ this ->dataProcessorMock ->expects ($ this ->any ())
287
245
->method ('filter ' )
288
246
->willReturnArgument (0 );
289
-
290
- $ this ->objectManagerMock ->expects ($ this ->atLeastOnce ())
247
+ $ page = $ this ->getMockBuilder (\Magento \Cms \Model \Page::class)
248
+ ->disableOriginalConstructor ()
249
+ ->getMock ();
250
+ $ this ->pageFactory ->expects ($ this ->atLeastOnce ())
291
251
->method ('create ' )
292
- ->with ($ this ->equalTo (\Magento \Cms \Model \Page::class))
293
- ->willReturn ($ this ->pageMock );
252
+ ->willReturn ($ page );
294
253
295
- $ this -> pageMock ->expects ($ this ->any ())
254
+ $ page ->expects ($ this ->any ())
296
255
->method ('load ' )
297
256
->willReturnSelf ();
298
- $ this -> pageMock ->expects ($ this ->any ())
257
+ $ page ->expects ($ this ->any ())
299
258
->method ('getId ' )
300
259
->willReturn (true );
301
- $ this ->pageMock ->expects ($ this ->once ())->method ('setData ' );
302
- $ this ->pageMock ->expects ($ this ->once ())->method ('save ' )->willThrowException (new \Exception ('Error message. ' ));
260
+ $ page ->expects ($ this ->once ())->method ('setData ' );
261
+ $ this ->pageRepository ->expects ($ this ->once ())->method ('save ' )->with ($ page )
262
+ ->willThrowException (new \Exception ('Error message. ' ));
303
263
304
264
$ this ->messageManagerMock ->expects ($ this ->never ())
305
265
->method ('addSuccess ' );
0 commit comments