Skip to content

Commit e7a78fa

Browse files
committed
#27499: Fixed directory integration tests
1 parent 96d3862 commit e7a78fa

File tree

6 files changed

+78
-139
lines changed

6 files changed

+78
-139
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function execute(array $paths): void
4747
$failedPaths = [];
4848
foreach ($paths as $path) {
4949
try {
50-
$name = end(explode('/', $path));
50+
$name = basename($path);
5151
$this->storage->createDirectory(
5252
$name,
5353
$this->storage->getCmsWysiwygImages()->getStorageRoot() . $path
@@ -62,7 +62,9 @@ public function execute(array $paths): void
6262
throw new CouldNotSaveException(
6363
__(
6464
'Could not save directories: %paths',
65-
implode(' ,', $failedPaths)
65+
[
66+
'paths' => implode(' ,', $failedPaths)
67+
]
6668
)
6769
);
6870
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public function execute(array $paths): void
5858
throw new CouldNotDeleteException(
5959
__(
6060
'Could not delete directories: %paths',
61-
implode(' ,', $failedPaths)
61+
[
62+
'paths' => implode(' ,', $failedPaths)
63+
]
6264
)
6365
);
6466
}

app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ public function __construct(
6969
public function execute(array $assetIds): array
7070
{
7171
try {
72-
$this->getAssetKeywords($this->getKeywordsData($assetIds));
72+
return $this->getAssetKeywords($this->getKeywordsData($assetIds));
7373
} catch (\Exception $exception) {
7474
$this->logger->critical($exception);
75-
$message = __('An error occurred during get asset keywords: %1', $exception->getMessage());
76-
throw new IntegrationException($message, $exception);
75+
throw new IntegrationException(__('Could not retrieve asset keywords.'), $exception);
7776
}
7877
}
7978

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

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,88 @@
1010

1111
use Magento\Framework\App\Filesystem\DirectoryList;
1212
use Magento\Framework\Filesystem;
13-
use Magento\MediaGalleryApi\Model\Directory\Command\CreateByPathInterface;
13+
use Magento\MediaGalleryApi\Api\CreateDirectoriesByPathsInterface;
1414
use Magento\TestFramework\Helper\Bootstrap;
1515

1616
/**
1717
* Test methods of class CreateByPath
1818
*/
19-
class CreateByPathTest extends \PHPUnit\Framework\TestCase
19+
class CreateByPathsTest extends \PHPUnit\Framework\TestCase
2020
{
2121
/**
2222
* Test directory name
2323
*/
2424
private const TEST_DIRECTORY_NAME = 'testCreateDirectory';
2525

2626
/**
27-
* Absolute path to the media direcrory
27+
* Absolute path to the media directory
2828
*/
2929
private $mediaDirectoryPath;
3030

3131
/**
32-
* @var CreateByPathInterface
32+
* @var CreateDirectoriesByPathsInterface
3333
*/
34-
private $createByPath;
34+
private $createByPaths;
3535

3636
/**
3737
* @inheritdoc
3838
*/
3939
public function setUp()
4040
{
41-
$this->createByPath = Bootstrap::getObjectManager()->get(CreateByPathInterface::class);
41+
$this->createByPaths = Bootstrap::getObjectManager()->get(CreateDirectoriesByPathsInterface::class);
4242
$this->mediaDirectoryPath = Bootstrap::getObjectManager()->get(Filesystem::class)
4343
->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
4444
}
4545

4646
/**
47-
* @return void
4847
* @throws \Magento\Framework\Exception\CouldNotSaveException
4948
*/
5049
public function testCreateDirectory(): void
5150
{
52-
$fullPath = $this->mediaDirectoryPath . self::TEST_DIRECTORY_NAME;
53-
$this->createByPath->execute('', self::TEST_DIRECTORY_NAME);
54-
$this->assertFileExists($fullPath);
51+
$this->createByPaths->execute([self::TEST_DIRECTORY_NAME]);
52+
$this->assertFileExists($this->mediaDirectoryPath . self::TEST_DIRECTORY_NAME);
5553
}
5654

5755
/**
58-
* @return void
5956
* @throws \Magento\Framework\Exception\CouldNotSaveException
6057
* @expectedException \Magento\Framework\Exception\CouldNotSaveException
6158
*/
6259
public function testCreateDirectoryThatAlreadyExist(): void
6360
{
64-
$this->createByPath->execute('', self::TEST_DIRECTORY_NAME);
61+
$this->createByPaths->execute([self::TEST_DIRECTORY_NAME]);
62+
$this->assertFileExists($this->mediaDirectoryPath . self::TEST_DIRECTORY_NAME);
63+
$this->createByPaths->execute([self::TEST_DIRECTORY_NAME]);
6564
}
6665

6766
/**
68-
* @return void
67+
* @param array $paths
6968
* @throws \Magento\Framework\Exception\CouldNotSaveException
7069
* @expectedException \Magento\Framework\Exception\CouldNotSaveException
70+
* @dataProvider notAllowedPathsProvider
7171
*/
72-
public function testCreateDirectoryWithRelativePath(): void
72+
public function testCreateDirectoryWithRelativePath(array $paths): void
7373
{
74-
$this->createByPath->execute('../../pub/', self::TEST_DIRECTORY_NAME);
74+
$this->createByPaths->execute($paths);
75+
}
76+
77+
/**
78+
* Provider of paths that are not allowed for deletion
79+
*
80+
* @return array
81+
*/
82+
public function notAllowedPathsProvider(): array
83+
{
84+
return [
85+
[
86+
['../../pub/' . self::TEST_DIRECTORY_NAME]
87+
],
88+
[
89+
['theme/' . self::TEST_DIRECTORY_NAME]
90+
],
91+
[
92+
['../../pub/media', 'theme']
93+
]
94+
];
7595
}
7696

7797
/**

dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php renamed to dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathsTest.php

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,75 +10,90 @@
1010

1111
use Magento\Framework\App\Filesystem\DirectoryList;
1212
use Magento\Framework\Filesystem;
13-
use Magento\MediaGalleryApi\Model\Directory\Command\DeleteByPathInterface;
13+
use Magento\MediaGalleryApi\Api\DeleteDirectoriesByPathsInterface;
1414
use Magento\TestFramework\Helper\Bootstrap;
1515

1616
/**
1717
* Test methods of class DeleteByPath
1818
*/
19-
class DeleteByPathTest extends \PHPUnit\Framework\TestCase
19+
class DeleteByPathsTest extends \PHPUnit\Framework\TestCase
2020
{
2121
/**
22-
* @var DeleteByPathInterface
22+
* @var DeleteDirectoriesByPathsInterface
2323
*/
24-
private $deleteByPath;
24+
private $deleteByPaths;
2525

2626
/**
2727
* @var string
2828
*/
2929
private $testDirectoryName = 'testDeleteDirectory';
3030

31+
/**
32+
* @var Filesystem
33+
*/
34+
private $filesystem;
35+
3136
/**
3237
* @inheritdoc
3338
*/
3439
public function setUp()
3540
{
36-
$this->deleteByPath = Bootstrap::getObjectManager()->create(DeleteByPathInterface::class);
41+
$this->deleteByPaths = Bootstrap::getObjectManager()->get(DeleteDirectoriesByPathsInterface::class);
42+
$this->filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
3743
}
3844

3945
/**
4046
* @throws \Magento\Framework\Exception\CouldNotDeleteException
4147
* @throws \Magento\Framework\Exception\FileSystemException
4248
*/
43-
public function testDeleteDirectoryWithExistingDirectoryAndCorrectAbsolutePath(): void
49+
public function testDeleteDirectory(): void
4450
{
4551
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $mediaDirectory */
46-
$mediaDirectory = Bootstrap::getObjectManager()->get(Filesystem::class)
47-
->getDirectoryRead(DirectoryList::MEDIA);
52+
$mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
4853
$mediaDirectory->create($this->testDirectoryName);
4954
$fullPath = $mediaDirectory->getAbsolutePath($this->testDirectoryName);
5055
$this->assertFileExists($fullPath);
51-
$this->deleteByPath->execute($this->testDirectoryName);
56+
$this->deleteByPaths->execute([$this->testDirectoryName]);
5257
$this->assertFileNotExists($fullPath);
5358
}
5459

5560
/**
61+
* @param array $paths
5662
* @throws \Magento\Framework\Exception\CouldNotDeleteException
5763
* @expectedException \Magento\Framework\Exception\CouldNotDeleteException
64+
* @dataProvider notAllowedPathsProvider
5865
*/
59-
public function testDeleteDirectoryWithRelativePathUnderMediaFolder(): void
66+
public function testDeleteDirectoryThatIsNotAllowed(array $paths): void
6067
{
61-
$this->deleteByPath->execute('../../pub/media');
68+
$this->deleteByPaths->execute($paths);
6269
}
6370

6471
/**
65-
* @throws \Magento\Framework\Exception\CouldNotDeleteException
66-
* @expectedException \Magento\Framework\Exception\CouldNotDeleteException
72+
* Provider of paths that are not allowed for deletion
73+
*
74+
* @return array
6775
*/
68-
public function testDeleteDirectoryThatIsNotAllowed(): void
76+
public function notAllowedPathsProvider(): array
6977
{
70-
$this->deleteByPath->execute('theme');
78+
return [
79+
[
80+
['../../pub/media']
81+
],
82+
[
83+
['theme']
84+
],
85+
[
86+
['../../pub/media', 'theme']
87+
]
88+
];
7189
}
7290

7391
/**
7492
* @throws \Magento\Framework\Exception\FileSystemException
7593
*/
7694
public function tearDown()
7795
{
78-
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
79-
->get(\Magento\Framework\Filesystem::class);
80-
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */
81-
$directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
96+
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
8297
if ($directory->isExist($this->testDirectoryName)) {
8398
$directory->delete($this->testDirectoryName);
8499
}

dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)