public function testGenerate()
 {
     $imageFile = 'image.jpg';
     $imageItem = $this->objectManager->getObject('Magento\\Framework\\Object', ['data' => ['file' => $imageFile]]);
     $this->mediaGalleryCollection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$imageItem]));
     $this->product->expects($this->any())->method('getMediaGalleryImages')->willReturn($this->mediaGalleryCollection);
     $this->config->expects($this->once())->method('getVars')->with('Magento_Catalog')->willReturn($this->getTestData());
     $this->viewConfig->expects($this->once())->method('getViewConfig')->with(['area' => Area::AREA_FRONTEND, 'themeModel' => 'Magento\\theme'])->willReturn($this->config);
     $this->themeCollection->expects($this->once())->method('loadRegisteredThemes')->willReturn(['Magento\\theme']);
     $this->imageHelper->expects($this->exactly(3))->method('init')->will($this->returnValueMap([[$this->product, 'image', $imageFile, $this->imageHelper], [$this->product, 'small_image', $imageFile, $this->imageHelper], [$this->product, 'thumbnail', $imageFile, $this->imageHelper]]));
     $this->imageHelper->expects($this->exactly(3))->method('resize')->will($this->returnValueMap([[300, 300, $this->imageHelper], [200, 200, $this->imageHelper], [100, 100, $this->imageHelper]]));
     $this->imageHelper->expects($this->exactly(3))->method('save')->will($this->returnSelf());
     $this->model->generate($this->product);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGenerate()
 {
     $imageFile = 'image.jpg';
     $imageItem = $this->objectManager->getObject('Magento\\Framework\\DataObject', ['data' => ['file' => $imageFile]]);
     $this->mediaGalleryCollection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$imageItem]));
     $this->product->expects($this->any())->method('getMediaGalleryImages')->willReturn($this->mediaGalleryCollection);
     $data = $this->getTestData();
     $this->config->expects($this->once())->method('getMediaEntities')->with('Magento_Catalog')->willReturn($data);
     $themeMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
     $themeMock->expects($this->exactly(3))->method('getCode')->willReturn('Magento\\theme');
     $this->themeCollection->expects($this->once())->method('loadRegisteredThemes')->willReturn([$themeMock]);
     $this->viewConfig->expects($this->once())->method('getViewConfig')->with(['area' => Area::AREA_FRONTEND, 'themeModel' => $themeMock])->willReturn($this->config);
     $this->imageHelper->expects($this->exactly(3))->method('init')->will($this->returnValueMap([[$this->product, 'product_image', $this->getImageData('product_image'), $this->imageHelper], [$this->product, 'product_small_image', $this->getImageData('product_small_image'), $this->imageHelper], [$this->product, 'product_thumbnail', $this->getImageData('product_thumbnail'), $this->imageHelper]]));
     $this->imageHelper->expects($this->exactly(3))->method('setImageFile')->with($imageFile)->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('keepAspectRatio')->with($data['product_image']['aspect_ratio'])->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('keepFrame')->with($data['product_image']['frame'])->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('keepTransparency')->with($data['product_image']['transparency'])->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('constrainOnly')->with($data['product_image']['constrain'])->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('backgroundColor')->with($data['product_image']['background'])->willReturnSelf();
     $this->imageHelper->expects($this->exactly(3))->method('save')->will($this->returnSelf());
     $this->model->generate($this->product);
 }
Exemple #3
0
 public function testGetProductThumbnailUrl()
 {
     $url = 'pub/media/catalog/product/cache/1/thumbnail/75x/9df78eab33525d08d6e5fb8d27136e95/_/_/__green.gif';
     $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
     $configView = $this->getMock('Magento\\Framework\\Config\\View', array('getVarValue'), array(), '', false);
     $configView->expects($this->any())->method('getVarValue')->will($this->returnValue(75));
     $this->_configManager->expects($this->any())->method('getViewConfig')->will($this->returnValue($configView));
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', array('isConfigurable', '__wakeup'), array(), '', false);
     $product->expects($this->any())->method('isConfigurable')->will($this->returnValue(true));
     $childProduct = $this->getMock('Magento\\Catalog\\Model\\Product', array('getThumbnail', 'getDataByKey', '__wakeup'), array(), '', false);
     $childProduct->expects($this->any())->method('getThumbnail')->will($this->returnValue('/_/_/__green.gif'));
     $this->_imageHelper->expects($this->any())->method('init')->will($this->returnValue($this->_imageHelper));
     $this->_imageHelper->expects($this->any())->method('resize')->will($this->returnValue($this->_imageHelper));
     $this->_imageHelper->expects($this->any())->method('__toString')->will($this->returnValue($url));
     $arguments = array('statusListFactory' => $this->getMock('Magento\\Sales\\Model\\Status\\ListFactory', array(), array(), '', false), 'productFactory' => $this->getMock('Magento\\Catalog\\Model\\ProductFactory', array(), array(), '', false), 'itemOptionFactory' => $this->getMock('Magento\\Sales\\Model\\Quote\\Item\\OptionFactory', array(), array(), '', false));
     $childItem = $objectManagerHelper->getObject('Magento\\Sales\\Model\\Quote\\Item', $arguments);
     $childItem->setData('product', $childProduct);
     $item = $objectManagerHelper->getObject('Magento\\Sales\\Model\\Quote\\Item', $arguments);
     $item->setData('product', $product);
     $item->addChild($childItem);
     $this->_renderer->setItem($item);
     $configurableUrl = $this->_renderer->getProductThumbnailUrl();
     $this->assertNotNull($configurableUrl);
 }
 /**
  * @param $data
  * @param $imageId
  */
 protected function prepareAttributes($data, $imageId)
 {
     $configViewMock = $this->getMockBuilder('Magento\\Framework\\Config\\View')->disableOriginalConstructor()->getMock();
     $configViewMock->expects($this->once())->method('getMediaAttributes')->with('Magento_Catalog', 'images', $imageId)->willReturn($data);
     $this->viewConfig->expects($this->once())->method('getViewConfig')->willReturn($configViewMock);
 }