public function testAfterExecuteNoVideo()
 {
     $mediaData = ['images' => [['value_id' => '7', 'file' => '/h/d/hd_image.jpg', 'media_type' => 'image', 'entity_id' => '1', 'label' => '', 'position' => '4', 'disabled' => '0', 'label_default' => null, 'position_default' => '4', 'disabled_default' => '0']], 'values' => []];
     $this->product->expects($this->once())->method('getData')->with('media_gallery')->willReturn($mediaData);
     $this->resourceModel->expects($this->never())->method('loadDataFromTableByValueId');
     $this->mediaGalleryReadHandler->expects($this->any())->method('getAttribute')->willReturn($this->attribute);
     $this->subject->afterExecute($this->mediaGalleryReadHandler, $this->product);
 }
Beispiel #2
0
 protected function setUp()
 {
     $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->galleryHandler = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product\\Gallery\\ReadHandler')->disableOriginalConstructor()->setMethods(['execute'])->getMock();
     $this->jsonEncoder = $this->getMock('\\Magento\\Framework\\Json\\EncoderInterface');
     $this->jsonDecoder = $this->getMock('\\Magento\\Framework\\Json\\DecoderInterface');
     $productMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['getTypeId', 'getTypeInstance'])->disableOriginalConstructor()->getMock();
     $variationProduct = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['setMediaGalleryEntries', 'getSku', 'getMediaGalleryImages', 'getImage', 'getData'])->disableOriginalConstructor()->getMock();
     $image = new \Magento\Framework\DataObject(['media_type' => 'type', 'video_url' => 'url', 'file' => 'image.jpg']);
     $variationProduct->expects($this->any())->method('setMediaGalleryEntries')->willReturn([]);
     $variationProduct->expects($this->any())->method('getSku')->willReturn('sku');
     $variationProduct->expects($this->any())->method('getMediaGalleryImages')->willReturn([$image]);
     $variationProduct->expects($this->any())->method('getImage')->willReturn('image.jpg');
     $variationProduct->expects($this->any())->method('getData')->with('configurable_attribute')->willReturn(1);
     $this->galleryHandler->expects($this->once())->method('execute')->with('', $variationProduct);
     $configurableType = $this->getMockBuilder('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable')->disableOriginalConstructor()->setMethods(['getUsedProducts', 'getConfigurableAttributesAsArray'])->getMock();
     $configurableType->expects($this->any())->method('getUsedProducts')->with($productMock)->willReturn([$variationProduct]);
     $configurableType->expects($this->any())->method('getConfigurableAttributesAsArray')->with($productMock)->willReturn([['attribute_code' => 'configurable_attribute']]);
     $productMock->expects($this->any())->method('getTypeId')->willReturn('configurable');
     $productMock->expects($this->any())->method('getTypeInstance')->willReturn($configurableType);
     $this->plugin = $helper->getObject('\\Magento\\ConfigurableProduct\\Block\\Plugin\\Product\\Media\\Gallery', ['productGalleryReadHandler' => $this->galleryHandler, 'jsonEncoder' => $this->jsonEncoder, 'jsonDecoder' => $this->jsonDecoder]);
     $this->plugin->setData('product', $productMock);
 }