Skip to content

Commit 8a52ac7

Browse files
committed
MC-31733: Media gallery breaks in some filesystems
1 parent 525cf22 commit 8a52ac7

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

app/code/Magento/Theme/Helper/Storage.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,7 @@ public function getCurrentPath()
255255
if ($path && $path !== self::NODE_ROOT) {
256256
$path = $this->convertIdToPath($path);
257257

258-
$realPath = $this->filesystemDriver->getRealPathSafety($path);
259-
260-
$path = $realPath ?: $path;
258+
$path = $this->filesystemDriver->getRealPathSafety($path);
261259

262260
if (strpos($path, $currentPath) !== 0) {
263261
$path = $currentPath;

app/code/Magento/Theme/Test/Unit/Helper/StorageTest.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ public function testGetAllowedExtensionsByType()
274274
*/
275275
public function testGetThumbnailPathNotFound()
276276
{
277+
$this->filesystemDriver->method('getRealpathSafety')
278+
->willReturnArgument(0);
277279
$image = 'notFoundImage.png';
278280
$root = '/image';
279281
$sourceNode = '/not/a/root';
@@ -452,6 +454,20 @@ public function testGetThemeNotFound()
452454
$helper->getStorageRoot();
453455
}
454456

457+
/**
458+
* @dataProvider getCurrentPathDataProvider
459+
*/
460+
public function testGetCurrentPathCachesResult()
461+
{
462+
$this->request->expects($this->once())
463+
->method('getParam')
464+
->with(Storage::PARAM_NODE)
465+
->willReturn(Storage::NODE_ROOT);
466+
467+
$actualPath = $this->helper->getCurrentPath();
468+
self::assertSame('/image', $actualPath);
469+
}
470+
455471
/**
456472
* @dataProvider getCurrentPathDataProvider
457473
*/
@@ -479,8 +495,7 @@ public function testGetCurrentPath(
479495
->willReturnArgument(0);
480496
}
481497

482-
$this->request->expects($this->once())
483-
->method('getParam')
498+
$this->request->method('getParam')
484499
->with(Storage::PARAM_NODE)
485500
->willReturn($requestedPath);
486501

@@ -494,11 +509,11 @@ public function getCurrentPathDataProvider(): array
494509
$rootPath = '/' . \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE;
495510

496511
return [
497-
[$rootPath, Storage::NODE_ROOT],
498-
[$rootPath, $rootPath . '/foo'],
499-
[$rootPath, $rootPath . '/something', true, null, '/bar'],
500-
['foo/', $rootPath . '/foo', true, 'foo/'],
501-
[$rootPath, $rootPath . '/foo', false],
512+
'requested path "root" should short-circuit' => [$rootPath, Storage::NODE_ROOT],
513+
'non-existent directory should default to the base path' => [$rootPath, $rootPath . '/foo'],
514+
'requested path that resolves to a bad path should default to root' =>
515+
[$rootPath, $rootPath . '/something', true, null, '/bar'],
516+
'real path should resolve to relative path' => ['foo/', $rootPath . '/foo', true, 'foo/'],
502517
];
503518
}
504519
}

0 commit comments

Comments
 (0)