/** * @param Product $product * @param array $rowData * @return ProductAttributeMediaGalleryEntryInterface */ public function convertTo(Product $product, array $rowData) { $entry = parent::convertTo($product, $rowData); $videoEntry = $this->videoEntryFactory->create(); $this->dataObjectHelper->populateWithArray($videoEntry, $rowData, 'Magento\\Framework\\Api\\Data\\VideoContentInterface'); $entryExtension = $this->mediaGalleryEntryExtensionFactory->create(); $entryExtension->setVideoContent($videoEntry); $entry->setExtensionAttributes($entryExtension); return $entry; }
protected function setUp() { $this->mediaGalleryEntryFactoryMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterfaceFactory', ['create'], [], '', false); $this->mediaGalleryEntryMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface', ['getId', 'setId', 'getMediaType', 'setMediaType', 'getLabel', 'setLabel', 'getPosition', 'setPosition', 'isDisabled', 'setDisabled', 'getTypes', 'setTypes', 'getFile', 'setFile', 'getContent', 'setContent', 'getExtensionAttributes', 'setExtensionAttributes'], [], '', false); $this->mediaGalleryEntryFactoryMock->expects($this->any())->method('create')->willReturn($this->mediaGalleryEntryMock); $this->dataObjectHelperMock = $this->getMock('\\Magento\\Framework\\Api\\DataObjectHelper', [], [], '', false); $this->videoEntryFactoryMock = $this->getMock('\\Magento\\Framework\\Api\\Data\\VideoContentInterfaceFactory', ['create'], [], '', false); $this->videoEntryMock = $this->getMock('\\Magento\\Framework\\Api\\Data\\VideoContentInterface', [], [], '', false); $this->videoEntryFactoryMock->expects($this->any())->method('create')->willReturn($this->videoEntryMock); $this->mediaGalleryEntryExtensionFactoryMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryExtensionFactory', ['create'], [], '', false); $this->mediaGalleryEntryExtensionMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryExtension', ['setVideoContent', 'getVideoContent', 'getVideoProvider'], [], '', false); $this->mediaGalleryEntryExtensionMock->expects($this->any())->method('setVideoContent')->willReturn(null); $this->mediaGalleryEntryExtensionFactoryMock->expects($this->any())->method('create')->willReturn($this->mediaGalleryEntryExtensionMock); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->modelObject = $objectManager->getObject('\\Magento\\ProductVideo\\Model\\Product\\Attribute\\Media\\ExternalVideoEntryConverter', ['mediaGalleryEntryFactory' => $this->mediaGalleryEntryFactoryMock, 'dataObjectHelper' => $this->dataObjectHelperMock, 'videoEntryFactory' => $this->videoEntryFactoryMock, 'mediaGalleryEntryExtensionFactory' => $this->mediaGalleryEntryExtensionFactoryMock]); }