@@ -290,4 +290,64 @@ private function getTestDataWithAttributes(): array
290
290
],
291
291
];
292
292
}
293
+
294
+ /**
295
+ * @param array $data
296
+ * @param array $expected
297
+ * @dataProvider createDataProvider
298
+ */
299
+ public function testCreateWithSimpleProduct ($ data , $ expected )
300
+ {
301
+ $ imageId = 'test_image_id ' ;
302
+
303
+ $ productMock = $ this ->createMock (\Magento \Catalog \Model \Product::class);
304
+ $ simpleOptionMock = $ this ->createMock (\Magento \Wishlist \Model \Item \Option::class);
305
+ $ simpleProductMock = $ this ->createMock (\Magento \Catalog \Model \Product::class);
306
+
307
+ $ productMock ->expects ($ this ->once ())->method ('getCustomOption ' )
308
+ ->with ('simple_product ' )->willReturn ($ simpleOptionMock );
309
+
310
+ $ simpleOptionMock ->expects ($ this ->once ())->method ('getProduct ' )->willReturn ($ simpleProductMock );
311
+
312
+ $ helperMock = $ this ->createMock (\Magento \Catalog \Helper \Image::class);
313
+ $ helperMock ->expects ($ this ->once ())
314
+ ->method ('init ' )
315
+ ->with ($ simpleProductMock , $ imageId )
316
+ ->willReturnSelf ();
317
+ $ helperMock ->expects ($ this ->once ())
318
+ ->method ('getFrame ' )
319
+ ->willReturn ($ data ['frame ' ]);
320
+ $ helperMock ->expects ($ this ->once ())
321
+ ->method ('getUrl ' )
322
+ ->willReturn ($ data ['url ' ]);
323
+ $ helperMock ->expects ($ this ->exactly (2 ))
324
+ ->method ('getWidth ' )
325
+ ->willReturn ($ data ['width ' ]);
326
+ $ helperMock ->expects ($ this ->exactly (2 ))
327
+ ->method ('getHeight ' )
328
+ ->willReturn ($ data ['height ' ]);
329
+ $ helperMock ->expects ($ this ->once ())
330
+ ->method ('getLabel ' )
331
+ ->willReturn ($ data ['label ' ]);
332
+ $ helperMock ->expects ($ this ->once ())
333
+ ->method ('getResizedImageInfo ' )
334
+ ->willReturn ($ data ['imagesize ' ]);
335
+
336
+ $ this ->helperFactory ->expects ($ this ->once ())
337
+ ->method ('create ' )
338
+ ->willReturn ($ helperMock );
339
+
340
+ $ imageMock = $ this ->createMock (\Magento \Catalog \Block \Product \Image::class);
341
+
342
+ $ this ->imageFactory ->expects ($ this ->once ())
343
+ ->method ('create ' )
344
+ ->with ($ expected )
345
+ ->willReturn ($ imageMock );
346
+
347
+ $ this ->model ->setProduct ($ productMock );
348
+ $ this ->model ->setImageId ($ imageId );
349
+ $ this ->model ->setAttributes ($ data ['custom_attributes ' ]);
350
+
351
+ $ this ->assertInstanceOf (\Magento \Catalog \Block \Product \Image::class, $ this ->model ->create ());
352
+ }
293
353
}
0 commit comments