Skip to content

Commit 75b7201

Browse files
authored
ENGCOM-5863: Resolved select from gallery option not working in theme design configuration #24430 #24431
2 parents b7c3e0a + 2a759b4 commit 75b7201

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

app/code/Magento/Theme/Model/Design/Backend/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private function getMime()
247247
*/
248248
private function getRelativeMediaPath(string $path): string
249249
{
250-
return preg_replace('/\/(pub\/)?media\//', '', $path);
250+
return preg_split('/\/(pub\/)?media\//', $path)[1] ?? preg_replace('/\/(pub\/)?media\//', '', $path);
251251
}
252252

253253
/**

app/code/Magento/Theme/Test/Unit/Model/Design/Backend/FileTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,35 @@ public function testBeforeSaveWithExistingFile()
282282
$this->fileBackend->getValue()
283283
);
284284
}
285+
286+
/**
287+
* Test for getRelativeMediaPath method.
288+
*
289+
* @param string $path
290+
* @param string $filename
291+
* @dataProvider getRelativeMediaPathDataProvider
292+
*/
293+
public function testGetRelativeMediaPath(string $path, string $filename)
294+
{
295+
$reflection = new \ReflectionClass($this->fileBackend);
296+
$method = $reflection->getMethod('getRelativeMediaPath');
297+
$method->setAccessible(true);
298+
$this->assertEquals(
299+
$filename,
300+
$method->invoke($this->fileBackend, $path . $filename)
301+
);
302+
}
303+
304+
/**
305+
* Data provider for testGetRelativeMediaPath.
306+
*
307+
* @return array
308+
*/
309+
public function getRelativeMediaPathDataProvider(): array
310+
{
311+
return [
312+
'Normal path' => ['pub/media/', 'filename.jpg'],
313+
'Complex path' => ['somepath/pub/media/', 'filename.jpg'],
314+
];
315+
}
285316
}

0 commit comments

Comments
 (0)