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