/**
  * Create image block
  *
  * @return \Magento\Catalog\Block\Product\Image
  */
 public function create()
 {
     /** @var \Magento\Catalog\Helper\Image $helper */
     $helper = $this->helperFactory->create()->init($this->product, $this->imageId);
     $template = $helper->getFrame() ? 'Magento_Catalog::product/image.phtml' : 'Magento_Catalog::product/image_with_borders.phtml';
     $imagesize = $helper->getResizedImageInfo();
     $data = ['data' => ['template' => $template, 'image_url' => $helper->getUrl(), 'width' => $helper->getWidth(), 'height' => $helper->getHeight(), 'label' => $helper->getLabel(), 'ratio' => $this->getRatio($helper), 'custom_attributes' => $this->getCustomAttributes(), 'resized_image_width' => !empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth(), 'resized_image_height' => !empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight()]];
     return $this->imageFactory->create($data);
 }
 /**
  * @param array $data
  * @dataProvider createDataProvider
  */
 public function testCreate($data, $expected)
 {
     $imageId = 'test_image_id';
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $helperMock = $this->getMockBuilder('Magento\\Catalog\\Helper\\Image')->disableOriginalConstructor()->getMock();
     $helperMock->expects($this->once())->method('init')->with($productMock, $imageId)->willReturnSelf();
     $helperMock->expects($this->once())->method('getFrame')->willReturn($data['frame']);
     $helperMock->expects($this->once())->method('getUrl')->willReturn($data['url']);
     $helperMock->expects($this->exactly(2))->method('getWidth')->willReturn($data['width']);
     $helperMock->expects($this->exactly(2))->method('getHeight')->willReturn($data['height']);
     $helperMock->expects($this->once())->method('getLabel')->willReturn($data['label']);
     $helperMock->expects($this->once())->method('getResizedImageInfo')->willReturn($data['imagesize']);
     $this->helperFactory->expects($this->once())->method('create')->willReturn($helperMock);
     $imageMock = $this->getMockBuilder('Magento\\Catalog\\Block\\Product\\Image')->disableOriginalConstructor()->getMock();
     $this->imageFactory->expects($this->once())->method('create')->with($expected)->willReturn($imageMock);
     $this->model->setProduct($productMock);
     $this->model->setImageId($imageId);
     $this->model->setAttributes($data['custom_attributes']);
     $this->assertInstanceOf('Magento\\Catalog\\Block\\Product\\Image', $this->model->create());
 }
 protected function mockImage()
 {
     $this->imageFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\ImageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->image = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Image')->disableOriginalConstructor()->getMock();
     $this->imageFactory->expects($this->any())->method('create')->willReturn($this->image);
 }