3
3
* Copyright © 2015 Magento. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
- namespace Magento \Cms \Test \Unit \Controller \Page ;
6
+ namespace Magento \Cms \Test \Unit \Controller \Adminhtml \ Page ;
7
7
8
8
use Magento \Cms \Controller \Adminhtml \Page \InlineEdit ;
9
9
@@ -49,38 +49,11 @@ public function setUp()
49
49
{
50
50
$ helper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
51
51
52
- $ this ->request = $ this ->getMockForAbstractClass (
53
- 'Magento\Framework\App\RequestInterface ' ,
54
- [],
55
- '' ,
56
- false
57
- );
58
- $ this ->messageManager = $ this ->getMockForAbstractClass (
59
- 'Magento\Framework\Message\ManagerInterface ' ,
60
- [],
61
- '' ,
62
- false
63
- );
64
- $ this ->messageCollection = $ this ->getMock (
65
- 'Magento\Framework\Message\Collection ' ,
66
- [],
67
- [],
68
- '' ,
69
- false
70
- );
71
- $ this ->message = $ this ->getMockForAbstractClass (
72
- 'Magento\Framework\Message\MessageInterface ' ,
73
- [],
74
- '' ,
75
- false
76
- );
77
- $ this ->cmsPage = $ this ->getMock (
78
- 'Magento\Cms\Model\Page ' ,
79
- [],
80
- [],
81
- '' ,
82
- false
83
- );
52
+ $ this ->request = $ this ->getMockForAbstractClass ('Magento\Framework\App\RequestInterface ' );
53
+ $ this ->messageManager = $ this ->getMockForAbstractClass ('Magento\Framework\Message\ManagerInterface ' );
54
+ $ this ->messageCollection = $ this ->getMock ('Magento\Framework\Message\Collection ' , [], [], '' , false );
55
+ $ this ->message = $ this ->getMockForAbstractClass ('Magento\Framework\Message\MessageInterface ' );
56
+ $ this ->cmsPage = $ this ->getMock ('Magento\Cms\Model\Page ' , [], [], '' , false );
84
57
$ this ->context = $ helper ->getObject (
85
58
'Magento\Backend\App\Action\Context ' ,
86
59
[
@@ -95,12 +68,7 @@ public function setUp()
95
68
'' ,
96
69
false
97
70
);
98
- $ this ->pageRepository = $ this ->getMockForAbstractClass (
99
- 'Magento\Cms\Api\PageRepositoryInterface ' ,
100
- [],
101
- '' ,
102
- false
103
- );
71
+ $ this ->pageRepository = $ this ->getMockForAbstractClass ('Magento\Cms\Api\PageRepositoryInterface ' );
104
72
$ this ->resultJson = $ this ->getMock ('Magento\Framework\Controller\Result\Json ' , [], [], '' , false );
105
73
$ this ->jsonFactory = $ this ->getMock (
106
74
'Magento\Framework\Controller\Result\JsonFactory ' ,
@@ -125,15 +93,14 @@ public function prepareMocksForTestExecute()
125
93
'identifier ' => 'no-route '
126
94
]
127
95
];
128
-
129
- $ this ->request ->expects ($ this ->at (1 ))
130
- ->method ('getParam ' )
131
- ->with ('isAjax ' )
132
- ->willReturn (true );
133
- $ this ->request ->expects ($ this ->at (0 ))
96
+ $ this ->request ->expects ($ this ->any ())
134
97
->method ('getParam ' )
135
- ->with ('items ' , [])
136
- ->willReturn ($ postData );
98
+ ->willReturnMap (
99
+ [
100
+ ['isAjax ' , null , true ],
101
+ ['items ' , [], $ postData ]
102
+ ]
103
+ );
137
104
$ this ->pageRepository ->expects ($ this ->once ())
138
105
->method ('getById ' )
139
106
->with (1 )
@@ -160,7 +127,7 @@ public function prepareMocksForTestExecute()
160
127
$ this ->cmsPage ->expects ($ this ->atLeastOnce ())
161
128
->method ('getId ' )
162
129
->willReturn ('1 ' );
163
- $ this ->cmsPage ->expects ($ this ->once ())
130
+ $ this ->cmsPage ->expects ($ this ->atLeastOnce ())
164
131
->method ('getData ' )
165
132
->willReturn ([
166
133
'layout ' => '1column ' ,
@@ -196,7 +163,7 @@ public function testExecuteWithLocalizedException()
196
163
])
197
164
->willReturnSelf ();
198
165
199
- $ this ->controller ->execute ();
166
+ $ this ->assertSame ( $ this -> resultJson , $ this -> controller ->execute () );
200
167
}
201
168
202
169
public function testExecuteWithRuntimeException ()
@@ -217,7 +184,7 @@ public function testExecuteWithRuntimeException()
217
184
])
218
185
->willReturnSelf ();
219
186
220
- $ this ->controller ->execute ();
187
+ $ this ->assertSame ( $ this -> resultJson , $ this -> controller ->execute () );
221
188
}
222
189
223
190
public function testExecuteWithException ()
@@ -238,22 +205,22 @@ public function testExecuteWithException()
238
205
])
239
206
->willReturnSelf ();
240
207
241
- $ this ->controller ->execute ();
208
+ $ this ->assertSame ( $ this -> resultJson , $ this -> controller ->execute () );
242
209
}
243
210
244
211
public function testExecuteWithoutData ()
245
212
{
246
213
$ this ->jsonFactory ->expects ($ this ->once ())
247
214
->method ('create ' )
248
215
->willReturn ($ this ->resultJson );
249
- $ this ->request ->expects ($ this ->at ( 0 ))
216
+ $ this ->request ->expects ($ this ->any ( ))
250
217
->method ('getParam ' )
251
- ->with ( ' items ' , [])
252
- -> willReturn ([]);
253
- $ this -> request -> expects ( $ this -> at ( 1 ))
254
- -> method ( ' getParam ' )
255
- -> with ( ' isAjax ' , null )
256
- -> willReturn ( true );
218
+ ->willReturnMap (
219
+ [
220
+ [ ' items ' , [], []],
221
+ [ ' isAjax ' , null , true ]
222
+ ]
223
+ );
257
224
$ this ->resultJson ->expects ($ this ->once ())
258
225
->method ('setData ' )
259
226
->with ([
@@ -264,6 +231,71 @@ public function testExecuteWithoutData()
264
231
])
265
232
->willReturnSelf ();
266
233
267
- $ this ->controller ->execute ();
234
+ $ this ->assertSame ($ this ->resultJson , $ this ->controller ->execute ());
235
+ }
236
+
237
+ public function testSetCmsPageData ()
238
+ {
239
+ $ extendedPageData = [
240
+ 'page_id ' => '2 ' ,
241
+ 'title ' => 'Home Page ' ,
242
+ 'page_layout ' => '1column ' ,
243
+ 'identifier ' => 'home ' ,
244
+ 'content_heading ' => 'Home Page ' ,
245
+ 'content ' => 'CMS homepage content goes here. ' ,
246
+ 'is_active ' => '1 ' ,
247
+ 'sort_order ' => '1 ' ,
248
+ 'custom_theme ' => '3 ' ,
249
+ 'website_root ' => '1 ' ,
250
+ 'under_version_control ' => '0 ' ,
251
+ 'store_id ' => ['0 ' ]
252
+ ];
253
+ $ pageData = [
254
+ 'page_id ' => '2 ' ,
255
+ 'title ' => 'Home Page ' ,
256
+ 'page_layout ' => '1column ' ,
257
+ 'identifier ' => 'home ' ,
258
+ 'is_active ' => '1 ' ,
259
+ 'custom_theme ' => '3 ' ,
260
+ 'under_version_control ' => '0 ' ,
261
+ ];
262
+ $ getData = [
263
+ 'page_id ' => '2 ' ,
264
+ 'title ' => 'Home Page ' ,
265
+ 'page_layout ' => '1column ' ,
266
+ 'identifier ' => 'home ' ,
267
+ 'content_heading ' => 'Home Page ' ,
268
+ 'content ' => 'CMS homepage content goes here. ' ,
269
+ 'is_active ' => '1 ' ,
270
+ 'sort_order ' => '1 ' ,
271
+ 'custom_theme ' => '3 ' ,
272
+ 'custom_root_template ' => '1column ' ,
273
+ 'published_revision_id ' => '0 ' ,
274
+ 'website_root ' => '1 ' ,
275
+ 'under_version_control ' => '0 ' ,
276
+ 'store_id ' => ['0 ' ]
277
+ ];
278
+ $ mergedData = [
279
+ 'page_id ' => '2 ' ,
280
+ 'title ' => 'Home Page ' ,
281
+ 'page_layout ' => '1column ' ,
282
+ 'identifier ' => 'home ' ,
283
+ 'content_heading ' => 'Home Page ' ,
284
+ 'content ' => 'CMS homepage content goes here. ' ,
285
+ 'is_active ' => '1 ' ,
286
+ 'sort_order ' => '1 ' ,
287
+ 'custom_theme ' => '3 ' ,
288
+ 'custom_root_template ' => '1column ' ,
289
+ 'published_revision_id ' => '0 ' ,
290
+ 'website_root ' => '1 ' ,
291
+ 'under_version_control ' => '0 ' ,
292
+ 'store_id ' => ['0 ' ]
293
+ ];
294
+ $ this ->cmsPage ->expects ($ this ->once ())->method ('getData ' )->willReturn ($ getData );
295
+ $ this ->cmsPage ->expects ($ this ->once ())->method ('setData ' )->with ($ mergedData )->willReturnSelf ();
296
+ $ this ->assertSame (
297
+ $ this ->controller ,
298
+ $ this ->controller ->setCmsPageData ($ this ->cmsPage , $ extendedPageData , $ pageData )
299
+ );
268
300
}
269
301
}
0 commit comments