Skip to content

Commit f4d980a

Browse files
committed
#27499: Integration tests
1 parent e7a78fa commit f4d980a

File tree

13 files changed

+686
-11
lines changed

13 files changed

+686
-11
lines changed

app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ public function execute(array $paths): void
8181
*/
8282
private function deleteAssetsByDirectoryPath(string $path): void
8383
{
84-
// Make sure that the path has a trailing slash
85-
$path = rtrim($path, '/') . '/';
86-
8784
/** @var AdapterInterface $connection */
8885
$connection = $this->resourceConnection->getConnection();
8986
$tableName = $this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private function getAssetKeywords(array $keywordsData): array
112112

113113
$assetKeywords = [];
114114
foreach ($keywordsByAsset as $assetId => $keywords) {
115-
$assetKeywords[] = $this->assetKeywordsFactory->create(
115+
$assetKeywords[$assetId] = $this->assetKeywordsFactory->create(
116116
[
117117
'data' => [
118118
'asset_id' => $assetId,

app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
namespace Magento\MediaGalleryApi\Api;
1010

11-
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
12-
1311
/**
1412
* A command which executes the media gallery asset save operation.
1513
* @api
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MediaGallery\Model;
9+
10+
use Magento\MediaGalleryApi\Api\Data\KeywordInterfaceFactory;
11+
use Magento\MediaGalleryApi\Api\Data\AssetInterfaceFactory;
12+
use Magento\MediaGalleryApi\Api\Data\AssetKeywordsInterfaceFactory;
13+
use Magento\MediaGalleryApi\Api\Data\AssetKeywordsInterface;
14+
use Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface;
15+
use Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface;
16+
use Magento\MediaGalleryApi\Api\GetAssetsKeywordsInterface;
17+
use Magento\MediaGalleryApi\Api\SaveAssetsInterface;
18+
use Magento\MediaGalleryApi\Api\SaveAssetsKeywordsInterface;
19+
use Magento\MediaGalleryApi\Api\DeleteAssetsByPathsInterface;
20+
use Magento\TestFramework\Helper\Bootstrap;
21+
use PHPUnit\Framework\TestCase;
22+
23+
/**
24+
* Testing assets keywords save and get
25+
*/
26+
class AssetEndToEndTest extends TestCase
27+
{
28+
/**
29+
* @var GetAssetsKeywordsInterface
30+
*/
31+
private $saveAssetsKeywords;
32+
33+
/**
34+
* @var GetAssetsKeywordsInterface
35+
*/
36+
private $getAssetsKeywords;
37+
38+
/**
39+
* @var AssetKeywordsInterfaceFactory
40+
*/
41+
private $assetsKeywordsFactory;
42+
43+
/**
44+
* @var AssetInterfaceFactory
45+
*/
46+
private $assetFactory;
47+
48+
/**
49+
* @var KeywordInterfaceFactory
50+
*/
51+
private $keywordFactory;
52+
53+
/**
54+
* @var SaveAssetsInterface
55+
*/
56+
private $saveAssets;
57+
58+
/**
59+
* @var GetAssetsByIdsInterface
60+
*/
61+
private $getAssetsByIds;
62+
63+
/**
64+
* @var GetAssetsByPathsInterface
65+
*/
66+
private $getAssetsByPath;
67+
68+
/**
69+
* @var DeleteAssetsByPathsInterface
70+
*/
71+
private $deleteAssetsByPaths;
72+
73+
/**
74+
* @inheritdoc
75+
*/
76+
public function setUp()
77+
{
78+
$this->saveAssetsKeywords = Bootstrap::getObjectManager()->get(SaveAssetsKeywordsInterface::class);
79+
$this->getAssetsKeywords = Bootstrap::getObjectManager()->get(GetAssetsKeywordsInterface::class);
80+
$this->assetsKeywordsFactory = Bootstrap::getObjectManager()->get(AssetKeywordsInterfaceFactory::class);
81+
$this->assetFactory = Bootstrap::getObjectManager()->get(AssetInterfaceFactory::class);
82+
$this->keywordFactory = Bootstrap::getObjectManager()->get(KeywordInterfaceFactory::class);
83+
$this->saveAssets = Bootstrap::getObjectManager()->get(SaveAssetsInterface::class);
84+
$this->getAssetsByIds = Bootstrap::getObjectManager()->get(GetAssetsByIdsInterface::class);
85+
$this->getAssetsByPath = Bootstrap::getObjectManager()->get(GetAssetsByPathsInterface::class);
86+
$this->deleteAssetsByPaths = Bootstrap::getObjectManager()->get(DeleteAssetsByPathsInterface::class);
87+
}
88+
89+
/**
90+
* Testing assets keywords save and get
91+
*/
92+
public function testExecute(): void
93+
{
94+
$keyword1 = $this->keywordFactory->create(
95+
[
96+
'data' => [
97+
'keyword' => 'pear'
98+
]
99+
]
100+
);
101+
102+
$keyword2 = $this->keywordFactory->create(
103+
[
104+
'data' => [
105+
'keyword' => 'plum'
106+
]
107+
]
108+
);
109+
110+
$asset = $this->assetFactory->create(
111+
[
112+
'data' => [
113+
'path' => 'fruit.jpg'
114+
]
115+
]
116+
);
117+
$this->saveAssets->execute([$asset]);
118+
$loadedAssets = $this->getAssetsByPath->execute([$asset->getPath()]);
119+
$loadedAsset = $loadedAssets[0];
120+
121+
$this->assertEquals(1, count($loadedAssets));
122+
123+
$assetKeywords = $this->assetsKeywordsFactory->create(
124+
[
125+
'data' => [
126+
'asset_id' => $loadedAsset->getId(),
127+
'keywords' => [
128+
$keyword1,
129+
$keyword2
130+
]
131+
]
132+
]
133+
);
134+
135+
$this->saveAssetsKeywords->execute([$assetKeywords]);
136+
$loadedAssetKeywords = $this->getAssetsKeywords->execute([$loadedAsset->getId()]);
137+
138+
$this->assertEquals(1, count($loadedAssetKeywords));
139+
140+
/** @var AssetKeywordsInterface $loadedAssetKeywords1 */
141+
$loadedAssetKeywords1 = current($loadedAssetKeywords);
142+
143+
$loadedKeywords = $loadedAssetKeywords1->getKeywords();
144+
145+
$this->assertEquals(2, count($loadedKeywords));
146+
147+
foreach ($loadedKeywords as $theKeyword) {
148+
$this->assertTrue(in_array($theKeyword->getKeyword(), ['pear', 'plum']));
149+
}
150+
151+
$this->deleteAssetsByPaths->execute(['fruit.jpg']);
152+
}
153+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\TestFramework\Helper\Bootstrap;
1515

1616
/**
17-
* Test methods of class CreateByPath
17+
* Test for CreateDirectoriesByPathsInterface
1818
*/
1919
class CreateByPathsTest extends \PHPUnit\Framework\TestCase
2020
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\TestFramework\Helper\Bootstrap;
1515

1616
/**
17-
* Test methods of class DeleteByPath
17+
* Test for DeleteDirectoriesByPathsInterface
1818
*/
1919
class DeleteByPathsTest extends \PHPUnit\Framework\TestCase
2020
{
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MediaGallery\Model;
9+
10+
use Magento\MediaGalleryApi\Api\IsPathBlacklistedInterface;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Test methods of class CreateByPath
16+
*/
17+
class CreateByPathsTest extends TestCase
18+
{
19+
20+
/**
21+
* @var IsPathBlacklistedInterface
22+
*/
23+
private $service;
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
public function setUp()
29+
{
30+
$this->service = Bootstrap::getObjectManager()->get(IsPathBlacklistedInterface::class);
31+
}
32+
33+
/**
34+
* Testing the blacklisted paths
35+
*
36+
* @param string $path
37+
* @param bool $isBlacklisted
38+
* @dataProvider pathsProvider
39+
*/
40+
public function testExecute(string $path, bool $isBlacklisted): void
41+
{
42+
$this->assertEquals($isBlacklisted, $this->service->execute($path));
43+
}
44+
45+
/**
46+
* Provider of paths and if the path should be in the blacklist
47+
*
48+
* @return array
49+
*/
50+
public function pathsProvider(): array
51+
{
52+
return [
53+
['theme', true],
54+
['.thumbs', true],
55+
['catalog/product/somedir', true],
56+
['catalog/category', false]
57+
];
58+
}
59+
}

0 commit comments

Comments
 (0)