@@ -178,7 +178,13 @@ protected function setUp()
178178 );
179179 }
180180
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
182188 {
183189 $ categoryId = 123 ;
184190 $ pageLayout = 'page_layout ' ;
@@ -199,11 +205,70 @@ public function testApplyCustomLayoutUpdate()
199205 \Magento \Framework \DataObject::class,
200206 ['getPageLayout ' , 'getLayoutUpdates ' ]
201207 );
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 );
202218 $ settings ->expects ($ this ->atLeastOnce ())->method ('getPageLayout ' )->will ($ this ->returnValue ($ pageLayout ));
203219 $ settings ->expects ($ this ->once ())->method ('getLayoutUpdates ' )->willReturn (['update1 ' , 'update2 ' ]);
204-
205220 $ this ->catalogDesign ->expects ($ this ->any ())->method ('getDesignSettings ' )->will ($ this ->returnValue ($ settings ));
206221
207222 $ this ->action ->execute ();
208223 }
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+ }
209274}
0 commit comments