54 $this->mediaGalleryEntryFactoryMock =
55 $this->createPartialMock(
56 \
Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory::class,
60 $this->mediaGalleryEntryMock =
61 $this->createPartialMock(\
Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface::class, [
78 'getExtensionAttributes',
79 'setExtensionAttributes' 82 $this->mediaGalleryEntryFactoryMock->expects($this->any())->method(
'create')->willReturn(
83 $this->mediaGalleryEntryMock
86 $this->dataObjectHelperMock = $this->createMock(\
Magento\Framework\Api\DataObjectHelper::class);
88 $this->videoEntryFactoryMock =
89 $this->createPartialMock(\
Magento\Framework\Api\Data\VideoContentInterfaceFactory::class, [
'create']);
91 $this->videoEntryMock = $this->createMock(\
Magento\Framework\Api\Data\VideoContentInterface::class);
93 $this->videoEntryFactoryMock->expects($this->any())->method(
'create')->willReturn($this->videoEntryMock);
95 $this->mediaGalleryEntryExtensionFactoryMock =
96 $this->createPartialMock(
97 \
Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryExtensionFactory::class,
101 $this->mediaGalleryEntryExtensionMock = $this->createPartialMock(
102 \
Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryExtension::class,
103 [
'setVideoContent',
'getVideoContent',
'getVideoProvider']
106 $this->mediaGalleryEntryExtensionMock->expects($this->any())->method(
'setVideoContent')->willReturn(
null);
107 $this->mediaGalleryEntryExtensionFactoryMock->expects($this->any())->method(
'create')->willReturn(
108 $this->mediaGalleryEntryExtensionMock
111 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
114 \
Magento\ProductVideo\Model\Product\Attribute\Media\ExternalVideoEntryConverter::class,
116 'mediaGalleryEntryFactory' => $this->mediaGalleryEntryFactoryMock,
117 'dataObjectHelper' => $this->dataObjectHelperMock,
118 'videoEntryFactory' => $this->videoEntryFactoryMock,
119 'mediaGalleryEntryExtensionFactory' => $this->mediaGalleryEntryExtensionFactoryMock
126 $this->assertEquals($this->modelObject->getMediaEntryType(),
'external-video');
129 public function testConvertTo()
136 'file' =>
'/i/n/index111111.jpg',
142 'label_default' =>
null,
143 'position_default' =>
'3',
144 'disabled_default' =>
'0',
145 'video_provider' =>
null,
146 'video_url' =>
'https://www.youtube.com/watch?v=abcdefghij',
147 'video_title' =>
'111',
148 'video_description' =>
null,
149 'video_metadata' =>
null,
153 'image' =>
'/s/a/sample_3.jpg',
154 'small_image' =>
'/s/a/sample-1_1.jpg',
155 'thumbnail' =>
'/s/a/sample-1_1.jpg',
156 'swatch_image' =>
'/s/a/sample_3.jpg',
159 $product->expects($this->once())->method(
'getMediaAttributeValues')->willReturn($productImages);
161 $this->mediaGalleryEntryMock->expects($this->once())->method(
'setExtensionAttributes')->will(
165 $this->modelObject->convertTo(
$product, $rowData);
170 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getId')->willReturn(
'4');
171 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getFile')->willReturn(
'/i/n/index111111.jpg');
172 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getLabel')->willReturn(
'Some Label');
173 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getPosition')->willReturn(
'3');
174 $this->mediaGalleryEntryMock->expects($this->once())->method(
'isDisabled')->willReturn(
'0');
175 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getTypes')->willReturn([]);
176 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getContent')->willReturn(
null);
178 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getExtensionAttributes')->willReturn(
179 $this->mediaGalleryEntryExtensionMock
183 $this->createMock(\
Magento\ProductVideo\Model\Product\Attribute\Media\VideoEntry::class);
185 $videoContentMock->expects($this->once())->method(
'getVideoProvider')->willReturn(
'youtube');
186 $videoContentMock->expects($this->once())->method(
'getVideoUrl')->willReturn(
187 'https://www.youtube.com/watch?v=abcdefghij' 189 $videoContentMock->expects($this->once())->method(
'getVideoTitle')->willReturn(
'Some video title');
190 $videoContentMock->expects($this->once())->method(
'getVideoDescription')->willReturn(
'Some video description');
191 $videoContentMock->expects($this->once())->method(
'getVideoMetadata')->willReturn(
'Meta data');
193 $this->mediaGalleryEntryExtensionMock->expects($this->once())->method(
'getVideoContent')->willReturn(
199 'file' =>
'/i/n/index111111.jpg',
200 'label' =>
'Some Label',
204 'media_type' =>
null,
206 'video_provider' =>
'youtube',
207 'video_url' =>
'https://www.youtube.com/watch?v=abcdefghij',
208 'video_title' =>
'Some video title',
209 'video_description' =>
'Some video description',
210 'video_metadata' =>
'Meta data',
213 $result = $this->modelObject->convertFrom($this->mediaGalleryEntryMock);
214 $this->assertEquals($expectedResult,
$result);