42 $this->mediaGalleryEntryFactoryMock =
43 $this->createPartialMock(
44 \
Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory::class,
48 $this->mediaGalleryEntryMock =
49 $this->createPartialMock(\
Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface::class, [
66 'getExtensionAttributes',
67 'setExtensionAttributes' 70 $this->mediaGalleryEntryFactoryMock->expects($this->any())->method(
'create')->willReturn(
71 $this->mediaGalleryEntryMock
74 $this->dataObjectHelperMock = $this->createMock(\
Magento\Framework\Api\DataObjectHelper::class);
76 $this->productMock = $this->createMock(\
Magento\Catalog\Model\Product::class);
78 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
83 'mediaGalleryEntryFactory' => $this->mediaGalleryEntryFactoryMock,
84 'dataObjectHelper' => $this->dataObjectHelperMock
91 $this->assertEquals($this->modelObject->getMediaEntryType(),
'image');
98 'file' =>
'/s/a/sample-1_1.jpg',
99 'media_type' =>
'image',
104 'label_default' =>
null,
105 'position_default' =>
'5',
106 'disabled_default' =>
'0',
110 'image' =>
'/s/a/sample_3.jpg',
111 'small_image' =>
'/s/a/sample-1_1.jpg',
112 'thumbnail' =>
'/s/a/sample-1_1.jpg',
113 'swatch_image' =>
'/s/a/sample_3.jpg',
116 $this->productMock->expects($this->any())->method(
'getMediaAttributeValues')->willReturn($productImages);
118 $object = $this->modelObject->convertTo($this->productMock, $rowData);
119 $this->assertNotNull($object);
124 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getId')->willReturn(
'5');
125 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getFile')->willReturn(
'/s/a/sample_3.jpg');
126 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getLabel')->willReturn(
'');
127 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getPosition')->willReturn(
'4');
128 $this->mediaGalleryEntryMock->expects($this->once())->method(
'isDisabled')->willReturn(
'0');
129 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getTypes')->willReturn(
135 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getContent')->willReturn(
null);
139 'file' =>
'/s/a/sample_3.jpg',
148 'media_type' =>
null,
151 $this->assertEquals($expectedResult, $this->modelObject->convertFrom($this->mediaGalleryEntryMock));
156 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getId')->willReturn(
'5');
157 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getFile')->willReturn(
'/s/a/sample_3.jpg');
158 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getLabel')->willReturn(
'');
159 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getPosition')->willReturn(
'4');
160 $this->mediaGalleryEntryMock->expects($this->once())->method(
'isDisabled')->willReturn(
'0');
161 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getTypes')->willReturn(
167 $imageContentInterface = $this->createMock(\
Magento\Framework\Api\Data\ImageContentInterface::class);
169 $imageContentInterface->expects($this->once())->method(
'getBase64EncodedData')->willReturn(
170 base64_encode(
'some_content')
172 $imageContentInterface->expects($this->once())->method(
'getType')->willReturn(
'image/jpeg');
173 $imageContentInterface->expects($this->once())->method(
'getName')->willReturn(
'/s/a/sample_3.jpg');
175 $this->mediaGalleryEntryMock->expects($this->once())->method(
'getContent')->willReturn($imageContentInterface);
179 'file' =>
'/s/a/sample_3.jpg',
189 'base64_encoded_data' => base64_encode(
'some_content'),
190 'type' =>
'image/jpeg',
191 'name' =>
'/s/a/sample_3.jpg' 194 'media_type' =>
null,
197 $this->assertEquals($expectedResult, $this->modelObject->convertFrom($this->mediaGalleryEntryMock));
testConvertFromNullContent()
$mediaGalleryEntryFactoryMock