public function testGetImage()
 {
     $imageId = 'test_image_id';
     $attributes = [];
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $imageMock = $this->getMockBuilder('Magento\\Catalog\\Block\\Product\\Image')->disableOriginalConstructor()->getMock();
     $this->imageBuilder->expects($this->once())->method('setProduct')->with($productMock)->willReturnSelf();
     $this->imageBuilder->expects($this->once())->method('setImageId')->with($imageId)->willReturnSelf();
     $this->imageBuilder->expects($this->once())->method('setAttributes')->with($attributes)->willReturnSelf();
     $this->imageBuilder->expects($this->once())->method('create')->willReturn($imageMock);
     $this->assertInstanceOf('Magento\\Catalog\\Block\\Product\\Image', $this->_block->getImage($productMock, $imageId, $attributes));
 }
 /**
  * @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());
 }
Example #3
0
 /**
  * Retrieve product image
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param string $imageId
  * @param array $attributes
  * @return \Magento\Catalog\Block\Product\Image
  */
 public function getImage($product, $imageId, $attributes = [])
 {
     return $this->imageBuilder->setProduct($product)->setImageId($imageId)->setAttributes($attributes)->create();
 }