public function testConvertFrom() { $this->mediaGalleryEntryMock->expects($this->once())->method('getId')->willReturn('5'); $this->mediaGalleryEntryMock->expects($this->once())->method('getFile')->willReturn('/s/a/sample_3.jpg'); $this->mediaGalleryEntryMock->expects($this->once())->method('getLabel')->willReturn(''); $this->mediaGalleryEntryMock->expects($this->once())->method('getPosition')->willReturn('4'); $this->mediaGalleryEntryMock->expects($this->once())->method('isDisabled')->willReturn('0'); $this->mediaGalleryEntryMock->expects($this->once())->method('getTypes')->willReturn([0 => 'image', 1 => 'swatch_image']); $imageContentInterface = $this->getMock('Magento\\Framework\\Api\\Data\\ImageContentInterface', [], [], '', false); $imageContentInterface->expects($this->once())->method('getBase64EncodedData')->willReturn(base64_encode('some_content')); $imageContentInterface->expects($this->once())->method('getType')->willReturn('image/jpeg'); $imageContentInterface->expects($this->once())->method('getName')->willReturn('/s/a/sample_3.jpg'); $this->mediaGalleryEntryMock->expects($this->once())->method('getContent')->willReturn($imageContentInterface); $expectedResult = ['value_id' => '5', 'file' => '/s/a/sample_3.jpg', 'label' => '', 'position' => '4', 'disabled' => '0', 'types' => [0 => 'image', 1 => 'swatch_image'], 'content' => ['data' => ['base64_encoded_data' => base64_encode('some_content'), 'type' => 'image/jpeg', 'name' => '/s/a/sample_3.jpg']], 'media_type' => null]; $this->assertEquals($expectedResult, $this->modelObject->convertFrom($this->mediaGalleryEntryMock)); }
/** * {@inheritdoc} */ public function convertFrom(ProductAttributeMediaGalleryEntryInterface $entry) { $dataFromPreviewImageEntry = parent::convertFrom($entry); $videoContent = $entry->getExtensionAttributes()->getVideoContent(); $entryArray = ['video_provider' => $videoContent->getVideoProvider(), 'video_url' => $videoContent->getVideoUrl(), 'video_title' => $videoContent->getVideoTitle(), 'video_description' => $videoContent->getVideoDescription(), 'video_metadata' => $videoContent->getVideoMetadata()]; $entryArray = array_merge($dataFromPreviewImageEntry, $entryArray); return $entryArray; }