Skip to content

Commit

Permalink
[troll] MC-39990: Unexpected displayed visual swatch attribute of the…
Browse files Browse the repository at this point in the history
… Configurable product (#6474)

* MC-39990: Unexpected displayed visual swatch attribute of the Configurable product
  • Loading branch information
duhon authored Dec 19, 2020
1 parent b0934fe commit 2ea738a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/code/Magento/Swatches/Helper/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ public function moveImageFromTmp($file)
} else {
$this->mediaDirectory->renameFile(
$this->mediaConfig->getTmpMediaPath($file),
$this->getAttributeSwatchPath($destinationFile)
$this->mediaDirectory->getDriver()->getRealPathSafety(
$this->getAttributeSwatchPath($destinationFile)
)
);
}

Expand All @@ -197,7 +199,7 @@ protected function getUniqueFileName($file)
$file
);
} else {
$destFile = rtrim(dirname($file), '/.') . '/' . \Magento\MediaStorage\Model\File\Uploader::getNewFileName(
$destFile = dirname($file) . '/' . \Magento\MediaStorage\Model\File\Uploader::getNewFileName(
$this->getOriginalFilePath($file)
);
}
Expand Down
12 changes: 11 additions & 1 deletion app/code/Magento/Swatches/Test/Unit/Helper/MediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Framework\Filesystem\Directory\ReadInterface;
use Magento\Framework\Filesystem\Directory\Write;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\Framework\Filesystem\DriverInterface;
use Magento\Framework\Image;
use Magento\Framework\Image\Factory;
use Magento\Framework\ObjectManagerInterface;
Expand Down Expand Up @@ -174,11 +175,20 @@ public function testMoveImageFromTmp()
public function testMoveImageFromTmpNoDb()
{
$this->fileStorageDbMock->method('checkDbUsage')->willReturn(false);
$this->fileStorageDbMock->method('renameFile')->willReturnSelf();
$this->mediaDirectoryMock
->expects($this->atLeastOnce())
->method('getAbsolutePath')
->willReturn('attribute/swatch/f/i/file.tmp');
$this->mediaDirectoryMock
->expects($this->atLeastOnce())
->method('renameFile')
->willReturnSelf();
$driver = $this->getMockBuilder(DriverInterface::class)
->getMockForAbstractClass();
$driver->method('getAbsolutePath')->willReturn('file');
$this->mediaDirectoryMock
->method('getDriver')
->willReturn($driver);
$result = $this->mediaHelperObject->moveImageFromTmp('file.tmp');
$this->assertNotNull($result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
'image-height' => 90,
'image-name' => $imageName,
]);
$imagePath = $swatchesMedia->moveImageFromTmp($imageName);
$imagePath = substr($swatchesMedia->moveImageFromTmp($imageName), 1);
$swatchesMedia->generateSwatchVariations($imagePath);

// Add attribute data
Expand Down

0 comments on commit 2ea738a

Please sign in to comment.