12
12
use Magento \Catalog \Controller \Category \View ;
13
13
use Magento \Catalog \Helper \Category ;
14
14
use Magento \Catalog \Model \Design ;
15
+ use Magento \Catalog \Model \Product \ProductList \Toolbar ;
16
+ use Magento \Catalog \Model \Product \ProductList \ToolbarMemorizer ;
15
17
use Magento \Framework \App \Action \Action ;
16
18
use Magento \Framework \App \RequestInterface ;
17
19
use Magento \Framework \App \ResponseInterface ;
20
+ use Magento \Framework \App \Response \RedirectInterface ;
18
21
use Magento \Framework \App \ViewInterface ;
19
22
use Magento \Framework \Controller \ResultFactory ;
20
23
use Magento \Framework \DataObject ;
@@ -127,13 +130,21 @@ class ViewTest extends TestCase
127
130
*/
128
131
protected $ pageConfig ;
129
132
133
+ /**
134
+ * @var ToolbarMemorizer|MockObject
135
+ */
136
+ protected ToolbarMemorizer $ toolbarMemorizer ;
137
+
130
138
/**
131
139
* @inheritDoc
132
140
*/
133
141
protected function setUp (): void
134
142
{
135
143
$ this ->request = $ this ->getMockForAbstractClass (RequestInterface::class);
136
- $ this ->response = $ this ->getMockForAbstractClass (ResponseInterface::class);
144
+ $ this ->response = $ this ->getMockBuilder (ResponseInterface::class)
145
+ ->addMethods (['setRedirect ' , 'isRedirect ' ])
146
+ ->onlyMethods (['sendResponse ' ])
147
+ ->getMock ();
137
148
138
149
$ this ->categoryHelper = $ this ->createMock (Category::class);
139
150
$ this ->objectManager = $ this ->getMockForAbstractClass (ObjectManagerInterface::class);
@@ -180,6 +191,8 @@ protected function setUp(): void
180
191
$ this ->context ->expects ($ this ->any ())->method ('getView ' )->willReturn ($ this ->view );
181
192
$ this ->context ->expects ($ this ->any ())->method ('getResultFactory ' )
182
193
->willReturn ($ this ->resultFactory );
194
+ $ this ->context ->expects ($ this ->once ())->method ('getRedirect ' )
195
+ ->willReturn ($ this ->createMock (RedirectInterface::class));
183
196
184
197
$ this ->category = $ this ->createMock (\Magento \Catalog \Model \Category::class);
185
198
$ this ->categoryRepository = $ this ->getMockForAbstractClass (CategoryRepositoryInterface::class);
@@ -198,6 +211,8 @@ protected function setUp(): void
198
211
->method ('create ' )
199
212
->willReturn ($ this ->page );
200
213
214
+ $ this ->toolbarMemorizer = $ this ->createMock (ToolbarMemorizer::class);
215
+
201
216
$ this ->action = (new ObjectManager ($ this ))->getObject (
202
217
View::class,
203
218
[
@@ -206,9 +221,46 @@ protected function setUp(): void
206
221
'categoryRepository ' => $ this ->categoryRepository ,
207
222
'storeManager ' => $ this ->storeManager ,
208
223
'resultPageFactory ' => $ resultPageFactory ,
209
- 'categoryHelper ' => $ this ->categoryHelper
224
+ 'categoryHelper ' => $ this ->categoryHelper ,
225
+ 'toolbarMemorizer ' => $ this ->toolbarMemorizer
226
+ ]
227
+ );
228
+ }
229
+
230
+ public function testRedirectOnToolbarAction ()
231
+ {
232
+ $ categoryId = 123 ;
233
+ $ this ->request ->expects ($ this ->any ())
234
+ ->method ('getParams ' )
235
+ ->willReturn ([Toolbar::LIMIT_PARAM_NAME => 12 ]);
236
+ $ this ->request ->expects ($ this ->any ())->method ('getParam ' )->willReturnMap (
237
+ [
238
+ [Action::PARAM_NAME_URL_ENCODED ],
239
+ ['id ' , false , $ categoryId ]
210
240
]
211
241
);
242
+ $ this ->categoryRepository ->expects ($ this ->any ())->method ('get ' )->with ($ categoryId )
243
+ ->willReturn ($ this ->category );
244
+ $ this ->categoryHelper ->expects ($ this ->once ())->method ('canShow ' )->with ($ this ->category )->willReturn (true );
245
+ $ this ->toolbarMemorizer ->expects ($ this ->once ())->method ('memorizeParams ' );
246
+ $ this ->toolbarMemorizer ->expects ($ this ->once ())->method ('isMemorizingAllowed ' )->willReturn (true );
247
+ $ this ->response ->expects ($ this ->once ())->method ('setRedirect ' );
248
+ $ settings = $ this ->getMockBuilder (DataObject::class)
249
+ ->addMethods (['getPageLayout ' , 'getLayoutUpdates ' ])
250
+ ->disableOriginalConstructor ()
251
+ ->getMock ();
252
+ $ this ->category
253
+ ->method ('hasChildren ' )
254
+ ->willReturnOnConsecutiveCalls (true );
255
+ $ this ->category ->expects ($ this ->any ())
256
+ ->method ('getDisplayMode ' )
257
+ ->willReturn ('products ' );
258
+
259
+ $ settings ->expects ($ this ->atLeastOnce ())->method ('getPageLayout ' )->willReturn ('page_layout ' );
260
+ $ settings ->expects ($ this ->once ())->method ('getLayoutUpdates ' )->willReturn (['update1 ' , 'update2 ' ]);
261
+ $ this ->catalogDesign ->expects ($ this ->any ())->method ('getDesignSettings ' )->willReturn ($ settings );
262
+
263
+ $ this ->action ->execute ();
212
264
}
213
265
214
266
/**
@@ -230,6 +282,9 @@ public function testApplyCustomLayoutUpdate(array $expectedData): void
230
282
['id ' , false , $ categoryId ]
231
283
]
232
284
);
285
+ $ this ->request ->expects ($ this ->any ())
286
+ ->method ('getParams ' )
287
+ ->willReturn ([]);
233
288
234
289
$ this ->categoryRepository ->expects ($ this ->any ())->method ('get ' )->with ($ categoryId )
235
290
->willReturn ($ this ->category );
0 commit comments