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);
 }
 /**
  *  Test for `save` method for duplicated product
  */
 public function testSaveAndDuplicate()
 {
     $this->imageCache->expects($this->once())->method('generate')->with($this->model);
     $this->imageCacheFactory->expects($this->once())->method('create')->willReturn($this->imageCache);
     $this->model->setIsDuplicate(true);
     $this->configureSaveTest();
     $this->model->beforeSave();
     $this->model->afterSave();
 }