@@ -153,12 +153,7 @@ public function testSaveAction()
153
153
->method ('create ' )
154
154
->willReturn ($ page );
155
155
156
- $ page ->expects ($ this ->any ())
157
- ->method ('load ' )
158
- ->willReturnSelf ();
159
- $ page ->expects ($ this ->any ())
160
- ->method ('getId ' )
161
- ->willReturn (true );
156
+ $ this ->pageRepository ->expects ($ this ->once ())->method ('getById ' )->with ($ this ->pageId )->willReturn ($ page );
162
157
$ page ->expects ($ this ->once ())->method ('setData ' );
163
158
$ this ->pageRepository ->expects ($ this ->once ())->method ('save ' )->with ($ page );
164
159
@@ -182,6 +177,36 @@ public function testSaveActionWithoutData()
182
177
$ this ->assertSame ($ this ->resultRedirect , $ this ->saveController ->execute ());
183
178
}
184
179
180
+ public function testSaveActionNoId ()
181
+ {
182
+ $ this ->requestMock ->expects ($ this ->any ())->method ('getPostValue ' )->willReturn (['page_id ' => 1 ]);
183
+ $ this ->requestMock ->expects ($ this ->atLeastOnce ())
184
+ ->method ('getParam ' )
185
+ ->willReturnMap (
186
+ [
187
+ ['page_id ' , null , 1 ],
188
+ ['back ' , null , false ],
189
+ ]
190
+ );
191
+
192
+ $ page = $ this ->getMockBuilder (\Magento \Cms \Model \Page::class)
193
+ ->disableOriginalConstructor ()
194
+ ->getMock ();
195
+
196
+ $ this ->pageFactory ->expects ($ this ->atLeastOnce ())
197
+ ->method ('create ' )
198
+ ->willReturn ($ page );
199
+ $ this ->pageRepository ->expects ($ this ->once ())
200
+ ->method ('getById ' )
201
+ ->with ($ this ->pageId )
202
+ ->willThrowException (new \Magento \Framework \Exception \NoSuchEntityException (__ ('Error message ' )));
203
+ $ this ->messageManagerMock ->expects ($ this ->once ())
204
+ ->method ('addErrorMessage ' )
205
+ ->with (__ ('This page no longer exists. ' ));
206
+ $ this ->resultRedirect ->expects ($ this ->atLeastOnce ())->method ('setPath ' )->with ('*/*/ ' ) ->willReturnSelf ();
207
+ $ this ->assertSame ($ this ->resultRedirect , $ this ->saveController ->execute ());
208
+ }
209
+
185
210
public function testSaveAndContinue ()
186
211
{
187
212
$ this ->requestMock ->expects ($ this ->any ())->method ('getPostValue ' )->willReturn (['page_id ' => $ this ->pageId ]);
@@ -204,12 +229,7 @@ public function testSaveAndContinue()
204
229
->method ('create ' )
205
230
->willReturn ($ page );
206
231
207
- $ page ->expects ($ this ->any ())
208
- ->method ('load ' )
209
- ->willReturnSelf ();
210
- $ page ->expects ($ this ->any ())
211
- ->method ('getId ' )
212
- ->willReturn (true );
232
+ $ this ->pageRepository ->expects ($ this ->once ())->method ('getById ' )->with ($ this ->pageId )->willReturn ($ page );
213
233
$ page ->expects ($ this ->once ())->method ('setData ' );
214
234
$ this ->pageRepository ->expects ($ this ->once ())->method ('save ' )->with ($ page );
215
235
@@ -251,12 +271,7 @@ public function testSaveActionThrowsException()
251
271
->method ('create ' )
252
272
->willReturn ($ page );
253
273
254
- $ page ->expects ($ this ->any ())
255
- ->method ('load ' )
256
- ->willReturnSelf ();
257
- $ page ->expects ($ this ->any ())
258
- ->method ('getId ' )
259
- ->willReturn (true );
274
+ $ this ->pageRepository ->expects ($ this ->once ())->method ('getById ' )->with ($ this ->pageId )->willReturn ($ page );
260
275
$ page ->expects ($ this ->once ())->method ('setData ' );
261
276
$ this ->pageRepository ->expects ($ this ->once ())->method ('save ' )->with ($ page )
262
277
->willThrowException (new \Exception ('Error message. ' ));
0 commit comments