Skip to content

Commit bf6cf85

Browse files
ENGCOM-7490: Can not create a subfolder with the same name as the main folder #27976
- Merge Pull Request #27976 from engcom-Charlie/magento2:1270 - Merged commits: 1. ac3aa70
2 parents f442fa9 + ac3aa70 commit bf6cf85

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function execute(array $paths): void
6363
//phpcs:ignore Magento2.Functions.DiscouragedFunction
6464
$name = basename($path);
6565
//phpcs:ignore Magento2.Functions.DiscouragedFunction
66-
$folder = str_replace($name, '', $path);
66+
$folder = substr($path, 0, strrpos($path, $name));
6767

6868
$this->storage->createDirectory(
6969
$name,

dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathsTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,24 @@ public function notAllowedPathsProvider(): array
9494
];
9595
}
9696

97+
/**
98+
* Test create child directory with the same name as parent
99+
*/
100+
public function testCreateChildDirectoryTheSameNameAsParentDirectory(): void
101+
{
102+
$dir = self::TEST_DIRECTORY_NAME;
103+
$childPath = $dir . '/' . $dir;
104+
105+
$this->createByPaths->execute([$dir]);
106+
$this->assertFileExists($this->mediaDirectoryPath . $dir);
107+
$this->createByPaths->execute([$childPath]);
108+
$this->assertFileExists($this->mediaDirectoryPath . $childPath);
109+
}
110+
97111
/**
98112
* @throws \Magento\Framework\Exception\FileSystemException
99113
*/
100-
public static function tearDownAfterClass()
114+
protected function tearDown()
101115
{
102116
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
103117
->get(\Magento\Framework\Filesystem::class);

0 commit comments

Comments
 (0)