Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/code/Magento/MediaStorage/App/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ public function launch(): ResponseInterface
try {
$this->createLocalCopy();

if ($this->directoryPub->isReadable($this->relativeFileName)) {
if ($this->directoryPub->isReadable($this->relativeFileName)
&& $this->directoryPub->isFile($this->relativeFileName)
) {
$this->response->setFilePath($this->directoryPub->getAbsolutePath($this->relativeFileName));
} else {
$this->setPlaceholderImage();
Expand All @@ -214,7 +216,9 @@ private function createLocalCopy(): void
$synchronizer = $this->syncFactory->create(['directory' => $this->directoryPub]);
$synchronizer->synchronize($this->relativeFileName);

if ($this->directoryPub->isReadable($this->relativeFileName)) {
if ($this->directoryPub->isReadable($this->relativeFileName)
&& $this->directoryPub->isFile($this->relativeFileName)
) {
return;
}

Expand Down
36 changes: 36 additions & 0 deletions app/code/Magento/MediaStorage/Test/Unit/App/MediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ public function testProcessRequestCreatesConfigFileMediaDirectoryIsNotProvided()
->method('isReadable')
->with(self::RELATIVE_FILE_PATH)
->willReturn(true);
$this->directoryPubMock->expects(self::exactly(2))
->method('isFile')
->with(self::RELATIVE_FILE_PATH)
->willReturn(true);
$this->responseMock->expects(self::once())
->method('setFilePath')
->with($filePath);
Expand All @@ -158,6 +162,10 @@ public function testProcessRequestReturnsFileIfItsProperlySynchronized(): void
->method('isReadable')
->with(self::RELATIVE_FILE_PATH)
->willReturn(true);
$this->directoryPubMock->expects(self::exactly(2))
->method('isFile')
->with(self::RELATIVE_FILE_PATH)
->willReturn(true);
$this->directoryPubMock->expects(self::exactly(2))
->method('getAbsolutePath')
->with(self::RELATIVE_FILE_PATH)
Expand Down Expand Up @@ -186,6 +194,34 @@ public function testProcessRequestReturnsNotFoundIfFileIsNotSynchronized(): void
->method('isReadable')
->with(self::RELATIVE_FILE_PATH)
->willReturn(false);
$this->directoryPubMock->expects(self::never())
->method('isFile');
$this->configMock->expects($this->once())
->method('getMediaDirectory')
->willReturn('');
$this->directoryPubMock->method('getAbsolutePath')->willReturn('');

self::assertSame($this->responseMock, $this->mediaModel->launch());
}

public function testProcessRequestReturnsPlaceholderForDirectoryPath(): void
{
$this->mediaModel = $this->createMediaModel();

$this->sync->method('synchronize')
->with(self::RELATIVE_FILE_PATH);
$this->directoryMediaMock->expects(self::once())
->method('getAbsolutePath')
->with(null)
->willReturn(self::MEDIA_DIRECTORY);
$this->directoryPubMock->expects(self::atLeastOnce())
->method('isReadable')
->with(self::RELATIVE_FILE_PATH)
->willReturn(true);
$this->directoryPubMock->expects(self::exactly(2))
->method('isFile')
->with(self::RELATIVE_FILE_PATH)
->willReturn(false);
$this->configMock->expects($this->once())
->method('getMediaDirectory')
->willReturn('');
Expand Down