47 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
49 $this->mediaConfigMock = $this->createMock(\
Magento\Catalog\Model\Product\Media\Config::class);
50 $this->writeInstanceMock = $this->createMock(\
Magento\Framework\Filesystem\Directory\WriteInterface::class);
51 $this->fileStorageDbMock = $this->createPartialMock(
52 \
Magento\MediaStorage\Helper\File\Storage\Database::class,
53 [
'checkDbUsage',
'getUniqueFilename',
'renameFile']
56 $this->storeManagerMock = $this->createPartialMock(\
Magento\Store\Model\StoreManager::class, [
'getStore']);
58 $this->imageFactoryMock = $this->createMock(\
Magento\Framework\Image\Factory::class);
60 $this->viewConfigMock = $this->createMock(\
Magento\Framework\View\Config::class);
62 $this->storeMock = $this->createPartialMock(\
Magento\Store\Model\Store::class, [
'getBaseUrl']);
64 $this->mediaDirectoryMock = $this->createMock(\
Magento\Framework\Filesystem\Directory\Write::class);
65 $this->fileSystemMock = $this->createPartialMock(\
Magento\Framework\Filesystem::class, [
'getDirectoryWrite']);
67 ->expects($this->any())
68 ->method(
'getDirectoryWrite')
69 ->will($this->returnValue($this->mediaDirectoryMock));
72 \
Magento\Swatches\Helper\Media::class,
74 'mediaConfig' => $this->mediaConfigMock,
75 'filesystem' => $this->fileSystemMock,
76 'fileStorageDb' => $this->fileStorageDbMock,
77 'storeManager' => $this->storeManagerMock,
78 'imageFactory' => $this->imageFactoryMock,
79 'configInterface' => $this->viewConfigMock,
89 $this->storeManagerMock
90 ->expects($this->once())
92 ->willReturn($this->storeMock);
95 ->expects($this->once())
96 ->method(
'getBaseUrl')
98 ->willReturn(
'http://url/pub/media/');
104 $result = $this->mediaHelperObject->getSwatchAttributeImage($swatchType,
'/f/i/file.png');
106 $this->assertEquals(
$result, $expectedResult);
117 'http://url/pub/media/attribute/swatch/swatch_image/30x20/f/i/file.png',
121 'http://url/pub/media/attribute/swatch/swatch_thumb/110x90/f/i/file.png',
128 $this->fileStorageDbMock->method(
'checkDbUsage')->willReturn(1);
129 $this->fileStorageDbMock->expects($this->atLeastOnce())->method(
'getUniqueFilename')->willReturn(
'file___1');
130 $this->fileStorageDbMock->method(
'renameFile')->will($this->returnSelf());
131 $this->mediaDirectoryMock->expects($this->exactly(2))->method(
'delete')->will($this->returnSelf());
132 $this->mediaHelperObject->moveImageFromTmp(
'file.tmp');
137 $this->fileStorageDbMock->method(
'checkDbUsage')->willReturn(
false);
138 $this->fileStorageDbMock->method(
'renameFile')->will($this->returnSelf());
139 $result = $this->mediaHelperObject->moveImageFromTmp(
'file.tmp');
145 $this->mediaDirectoryMock
146 ->expects($this->atLeastOnce())
147 ->method(
'getAbsolutePath')
148 ->willReturn(
'attribute/swatch/e/a/earth.png');
150 $image = $this->createPartialMock(\
Magento\Framework\Image::class, [
161 $this->imageFactoryMock->expects($this->any())->method(
'create')->willReturn(
$image);
163 $image->expects($this->any())->method(
'resize')->will($this->returnSelf());
164 $image->expects($this->atLeastOnce())->method(
'backgroundColor')->with([255, 255, 255])->willReturnSelf();
165 $this->mediaHelperObject->generateSwatchVariations(
'/e/a/earth.png');
170 $storeMock = $this->createPartialMock(\
Magento\Store\Model\Store::class, [
'getBaseUrl']);
172 $this->storeManagerMock
173 ->expects($this->once())
178 ->expects($this->once())
179 ->method(
'getBaseUrl')
181 ->willReturn(
'http://url/pub/media/');
183 $result = $this->mediaHelperObject->getSwatchMediaUrl();
185 $this->assertEquals(
$result,
'http://url/pub/media/attribute/swatch');
193 if ($imageConfig ===
null) {
196 $result = $this->mediaHelperObject->getFolderNameSize($swatchType, $imageConfig);
197 $this->assertEquals($expectedResult,
$result);
245 $this->mediaHelperObject->getImageConfig();
250 $configMock = $this->createMock(\
Magento\Framework\Config\View::class);
252 $this->viewConfigMock
253 ->expects($this->atLeastOnce())
254 ->method(
'getViewConfig')
255 ->willReturn($configMock);
268 $configMock->expects($this->any())->method(
'getMediaEntities')->willReturn($imageConfig);
273 $result = $this->mediaHelperObject->getAttributeSwatchPath(
'/m/a/magento.png');
274 $this->assertEquals(
$result,
'attribute/swatch/m/a/magento.png');
279 $this->assertEquals(
'attribute/swatch', $this->mediaHelperObject->getSwatchMediaPath());
287 $this->assertEquals($expectedResult, $this->mediaHelperObject->getSwatchCachePath($swatchType));
298 'attribute/swatch/swatch_image/',
302 'attribute/swatch/swatch_thumb/',