Skip to content

Commit 44cb07a

Browse files
committed
Fixed integration tests
1 parent 8d05d0e commit 44cb07a

File tree

8 files changed

+49
-29
lines changed

8 files changed

+49
-29
lines changed

app/code/Magento/MediaContent/Model/ExtractAssetsFromContent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private function getAssetsByPaths(array $paths): array
104104
private function getPathStartingWithSlash(string $path): string
105105
{
106106
$normalizedPath = ltrim($path, '/');
107-
if (strpos($normalizedPath, '/') === false) {
107+
if (strpos($normalizedPath, '/') !== false) {
108108
return $normalizedPath;
109109
}
110110
return '/' . $normalizedPath;

app/code/Magento/MediaContent/Model/SaveContentAssetLinks.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Framework\App\ResourceConnection;
1111
use Magento\Framework\Exception\CouldNotSaveException;
1212
use Magento\MediaContentApi\Api\SaveContentAssetLinksInterface;
13-
use Magento\MediaContentApi\Api\Data\ContentIdentityInterface;
1413
use Magento\MediaContentApi\Api\Data\ContentAssetLinkInterface;
1514
use Psr\Log\LoggerInterface;
1615

app/code/Magento/MediaContent/Plugin/MediaGalleryAssetDeleteByDirectoryPath.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\DB\Adapter\AdapterInterface;
1212
use Magento\Framework\Exception\CouldNotDeleteException;
1313
use Magento\MediaContentApi\Api\DeleteContentAssetLinksByAssetIdsInterface;
14-
use Magento\MediaGalleryApi\Model\Asset\Command\DeleteByDirectoryPathInterface;
14+
use Magento\MediaGalleryApi\Api\DeleteDirectoriesByPathsInterface;
1515
use Psr\Log\LoggerInterface;
1616

1717
/**
@@ -54,22 +54,27 @@ public function __construct(
5454
/**
5555
* Around plugin on execute method
5656
*
57-
* @param DeleteByDirectoryPathInterface $subject
57+
* @param DeleteDirectoriesByPathsInterface $subject
5858
* @param \Closure $proceed
59-
* @param string $directoryPath
59+
* @param array $paths
6060
* @throws CouldNotDeleteException
6161
* @return void
6262
*
6363
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6464
*/
6565
public function aroundExecute(
66-
DeleteByDirectoryPathInterface $subject,
66+
DeleteDirectoriesByPathsInterface $subject,
6767
\Closure $proceed,
68-
string $directoryPath
68+
array $paths
6969
) : void {
70-
$assetIds = $this->getAssetIdsByDirectoryPath($directoryPath);
70+
$assetIdsArrays =[];
71+
foreach ($paths as $path) {
72+
$assetIdsArrays[] = $this->getAssetIdsByDirectoryPath($path);
73+
}
7174

72-
$proceed($directoryPath);
75+
$assetIds = array_unique(array_merge([], ...$assetIdsArrays));
76+
77+
$proceed($paths);
7378

7479
$this->deleteContentAssetLinksByAssetIds->execute($assetIds);
7580
}

app/code/Magento/MediaContent/Plugin/MediaGalleryAssetDeleteByPath.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
namespace Magento\MediaContent\Plugin;
99

1010
use Magento\Framework\Exception\CouldNotDeleteException;
11+
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\MediaContentApi\Api\DeleteContentAssetLinksByAssetIdsInterface;
12-
use Magento\MediaGalleryApi\Model\Asset\Command\DeleteByPathInterface;
13-
use Magento\MediaGalleryApi\Model\Asset\Command\GetByPathInterface;
13+
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
14+
use Magento\MediaGalleryApi\Api\DeleteAssetsByPathsInterface;
15+
use Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface;
1416
use Psr\Log\LoggerInterface;
1517

1618
/**
@@ -19,9 +21,9 @@
1921
class MediaGalleryAssetDeleteByPath
2022
{
2123
/**
22-
* @var GetByPathInterface
24+
* @var GetAssetsByPathsInterface
2325
*/
24-
private $getByPath;
26+
private $getByPaths;
2527

2628
/**
2729
* @var LoggerInterface
@@ -35,39 +37,47 @@ class MediaGalleryAssetDeleteByPath
3537

3638
/**
3739
* @param DeleteContentAssetLinksByAssetIdsInterface $deleteContentAssetLinksByAssetIds
38-
* @param GetByPathInterface $getByPath
40+
* @param GetAssetsByPathsInterface $getByPath
3941
* @param LoggerInterface $logger
4042
*/
4143
public function __construct(
4244
DeleteContentAssetLinksByAssetIdsInterface $deleteContentAssetLinksByAssetIds,
43-
GetByPathInterface $getByPath,
45+
GetAssetsByPathsInterface $getByPath,
4446
LoggerInterface $logger
4547
) {
4648
$this->deleteContentAssetLinksByAssetIds = $deleteContentAssetLinksByAssetIds;
47-
$this->getByPath = $getByPath;
49+
$this->getByPaths = $getByPath;
4850
$this->logger = $logger;
4951
}
5052

5153
/**
5254
* Around plugin on execute method
5355
*
54-
* @param DeleteByPathInterface $subject
56+
* @param DeleteAssetsByPathsInterface $subject
5557
* @param \Closure $proceed
56-
* @param string $mediaAssetPath
58+
* @param array $paths
5759
* @throws CouldNotDeleteException
60+
* @throws LocalizedException
5861
* @return void
5962
*
6063
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6164
*/
6265
public function aroundExecute(
63-
DeleteByPathInterface $subject,
66+
DeleteAssetsByPathsInterface $subject,
6467
\Closure $proceed,
65-
string $mediaAssetPath
68+
array $paths
6669
) : void {
67-
$asset = $this->getByPath->execute($mediaAssetPath);
70+
$assets = $this->getByPaths->execute($paths);
6871

69-
$proceed($mediaAssetPath);
72+
$proceed($paths);
7073

71-
$this->deleteContentAssetLinksByAssetIds->execute([$asset->getId()]);
74+
$assetIds = array_map(
75+
function (AssetInterface $asset) {
76+
return $asset->getId();
77+
},
78+
$assets
79+
);
80+
81+
$this->deleteContentAssetLinksByAssetIds->execute($assetIds);
7282
}
7383
}

app/code/Magento/MediaContent/etc/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
<preference for="Magento\MediaContentApi\Api\Data\ContentAssetLinkInterface" type="Magento\MediaContent\Model\ContentAssetLink"/>
1818
<preference for="Magento\MediaContentApi\Model\SearchPatternConfigInterface" type="Magento\MediaContent\Model\Content\SearchPatternConfig"/>
1919
<preference for="Magento\MediaContent\Model\Content\ConfigInterface" type="Magento\MediaContent\Model\Content\Config"/>
20-
<type name="Magento\MediaGalleryApi\Model\Asset\Command\DeleteByPathInterface">
20+
<type name="Magento\MediaGalleryApi\Api\DeleteAssetsByPathsInterface">
2121
<plugin name="remove_media_content_after_asset_is_removed_by_path" type="Magento\MediaContent\Plugin\MediaGalleryAssetDeleteByPath" />
2222
</type>
23-
<type name="Magento\MediaGalleryApi\Model\Asset\Command\DeleteByDirectoryPathInterface">
23+
<type name="Magento\MediaGalleryApi\Api\DeleteDirectoriesByPathsInterface">
2424
<plugin name="remove_media_content_after_asset_is_removed_by_directory_path" type="Magento\MediaContent\Plugin\MediaGalleryAssetDeleteByDirectoryPath" />
2525
</type>
2626
<virtualType name="Magento\MediaContent\Model\Content\Config\Reader" type="Magento\Framework\Config\Reader\Filesystem">

dev/tests/integration/testsuite/Magento/MediaContent/Model/ExtractAssetsFromContentTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,19 @@ public function contentProvider()
7474
'Relevant paths in content' => [
7575
'content {{media url="testDirectory/path.jpg"}} content',
7676
[
77-
55
77+
2020
78+
]
79+
],
80+
'Relevant wysiwyg paths in content' => [
81+
'content <img src="https://domain.com/media/testDirectory/path.jpg"}} content',
82+
[
83+
2020
7884
]
7985
],
8086
'Relevant path content' => [
8187
'/media/testDirectory/path.jpg',
8288
[
83-
55
89+
2020
8490
]
8591
],
8692
'Irrelevant paths in content' => [

dev/tests/integration/testsuite/Magento/MediaContent/Model/SaveDeleteContentAssetLinksTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function setUp(): void
6060
public function testAssignRetrieveAndUnassign(): void
6161
{
6262
$entityType = 'catalog_product';
63-
$entityId = '42';
63+
$entityId = 42;
6464
$field = 'description';
6565
$assetIds = [56, 78];
6666

dev/tests/integration/testsuite/Magento/MediaContent/Model/UpdateContentAssetLinksTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function setUp(): void
4747
public function testExecute(): void
4848
{
4949
$entityType = 'catalog_product';
50-
$entityId = '42';
50+
$entityId = 2020;
5151
$field = 'description';
5252
$contentWithoutAsset = '';
5353
$contentWithAsset = 'content {{media url="testDirectory/path.jpg"}} content';

0 commit comments

Comments
 (0)