@@ -178,7 +178,13 @@ protected function setUp()
178
178
);
179
179
}
180
180
181
- public function testApplyCustomLayoutUpdate ()
181
+ /**
182
+ * Apply custom layout update is correct
183
+ *
184
+ * @dataProvider getInvocationData
185
+ * @return void
186
+ */
187
+ public function testApplyCustomLayoutUpdate (array $ expectedData ): void
182
188
{
183
189
$ categoryId = 123 ;
184
190
$ pageLayout = 'page_layout ' ;
@@ -199,11 +205,70 @@ public function testApplyCustomLayoutUpdate()
199
205
\Magento \Framework \DataObject::class,
200
206
['getPageLayout ' , 'getLayoutUpdates ' ]
201
207
);
208
+ $ this ->category ->expects ($ this ->at (1 ))
209
+ ->method ('hasChildren ' )
210
+ ->willReturn (true );
211
+ $ this ->category ->expects ($ this ->at (2 ))
212
+ ->method ('hasChildren ' )
213
+ ->willReturn ($ expectedData [1 ][0 ]['type ' ] === 'default ' ? true : false );
214
+ $ this ->category ->expects ($ this ->once ())
215
+ ->method ('getDisplayMode ' )
216
+ ->willReturn ($ expectedData [2 ][0 ]['displaymode ' ]);
217
+ $ this ->expectationForPageLayoutHandles ($ expectedData );
202
218
$ settings ->expects ($ this ->atLeastOnce ())->method ('getPageLayout ' )->will ($ this ->returnValue ($ pageLayout ));
203
219
$ settings ->expects ($ this ->once ())->method ('getLayoutUpdates ' )->willReturn (['update1 ' , 'update2 ' ]);
204
-
205
220
$ this ->catalogDesign ->expects ($ this ->any ())->method ('getDesignSettings ' )->will ($ this ->returnValue ($ settings ));
206
221
207
222
$ this ->action ->execute ();
208
223
}
224
+
225
+ /**
226
+ * Expected invocation for Layout Handles
227
+ *
228
+ * @param array $data
229
+ * @return void
230
+ */
231
+ private function expectationForPageLayoutHandles ($ data ): void
232
+ {
233
+ $ index = 1 ;
234
+
235
+ foreach ($ data as $ expectedData ) {
236
+ $ this ->page ->expects ($ this ->at ($ index ))
237
+ ->method ('addPageLayoutHandles ' )
238
+ ->with ($ expectedData [0 ], $ expectedData [1 ], $ expectedData [2 ]);
239
+ $ index ++;
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Data provider for execute method.
245
+ *
246
+ * @return array
247
+ */
248
+ public function getInvocationData (): array
249
+ {
250
+ return [
251
+ [
252
+ 'layoutHandles ' => [
253
+ [['type ' => 'default ' ], null , false ],
254
+ [['type ' => 'default_without_children ' ], null , false ],
255
+ [['displaymode ' => 'products ' ], null , false ]
256
+ ]
257
+ ],
258
+ [
259
+ 'layoutHandles ' => [
260
+ [['type ' => 'default ' ], null , false ],
261
+ [['type ' => 'default_without_children ' ], null , false ],
262
+ [['displaymode ' => 'page ' ], null , false ]
263
+ ]
264
+ ],
265
+ [
266
+ 'layoutHandles ' => [
267
+ [['type ' => 'default ' ], null , false ],
268
+ [['type ' => 'default ' ], null , false ],
269
+ [['displaymode ' => 'poducts_and_page ' ], null , false ]
270
+ ]
271
+ ]
272
+ ];
273
+ }
209
274
}
0 commit comments