Skip to content

Commit 2ec9f68

Browse files
committed
#1504: [2.1-develop] Insert rendition images to the content from media gallery instead of original images - Revised integration test
1 parent 79cc0e4 commit 2ec9f68

File tree

10 files changed

+116
-400
lines changed

10 files changed

+116
-400
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\MediaGalleryRenditions\Test\Integration\Model;
10+
11+
use Magento\MediaContentApi\Api\ExtractAssetsFromContentInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Test for Extracting assets from rendition paths/urls in content
17+
*/
18+
class ExtractAssetsFromContentWithRenditionTest extends TestCase
19+
{
20+
/**
21+
* @var ExtractAssetsFromContentInterface
22+
*/
23+
private $extractAssetsFromContent;
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
protected function setUp(): void
29+
{
30+
$this->extractAssetsFromContent = Bootstrap::getObjectManager()
31+
->get(ExtractAssetsFromContentInterface::class);
32+
}
33+
34+
/**
35+
* Assert rendition urls/path in the content are associated with an asset
36+
*
37+
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
38+
*
39+
* @dataProvider contentProvider
40+
* @param string $content
41+
* @param array $assetIds
42+
*/
43+
public function testExecute(string $content, array $assetIds): void
44+
{
45+
$assets = $this->extractAssetsFromContent->execute($content);
46+
47+
$extractedAssetIds = [];
48+
foreach ($assets as $asset) {
49+
$extractedAssetIds[] = $asset->getId();
50+
}
51+
52+
sort($assetIds);
53+
sort($extractedAssetIds);
54+
55+
$this->assertEquals($assetIds, $extractedAssetIds);
56+
}
57+
58+
/**
59+
* Data provider for testExecute
60+
*
61+
* @return array
62+
*/
63+
public function contentProvider()
64+
{
65+
return [
66+
'Empty Content' => [
67+
'',
68+
[]
69+
],
70+
'No paths in content' => [
71+
'content without paths',
72+
[]
73+
],
74+
'Relevant rendition path in content' => [
75+
'content {{media url=".renditions/testDirectory/path.jpg"}} content',
76+
[
77+
2020
78+
]
79+
],
80+
'Relevant wysiwyg rendition path in content' => [
81+
'content <img src="https://domain.com/media/.renditions/testDirectory/path.jpg"}} content',
82+
[
83+
2020
84+
]
85+
],
86+
'Relevant rendition path content with pub' => [
87+
'/pub/media/.renditions/testDirectory/path.jpg',
88+
[
89+
2020
90+
]
91+
],
92+
'Relevant rendition path content' => [
93+
'/media/.renditions/testDirectory/path.jpg',
94+
[
95+
2020
96+
]
97+
],
98+
'Relevant existing media paths w/o rendition in content' => [
99+
'content {{media url="testDirectory/path.jpg"}} content',
100+
[
101+
2020
102+
]
103+
],
104+
'Relevant existing paths w/o rendition in content with pub' => [
105+
'/pub/media/testDirectory/path.jpg',
106+
[
107+
2020
108+
]
109+
],
110+
'Non-existing rendition paths in content' => [
111+
'content {{media url=".renditions/non-existing-path.png"}} content',
112+
[]
113+
]
114+
];
115+
}
116+
}

MediaGalleryRenditions/Test/Integration/Model/ResourceModel/GetAssetIdsByContentFieldTest.php

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

MediaGalleryRenditions/Test/Integration/_files/catalog/category_with_asset.php

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

MediaGalleryRenditions/Test/Integration/_files/catalog/category_with_asset_rollback.php

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

MediaGalleryRenditions/Test/Integration/_files/catalog/product_with_asset.php

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

0 commit comments

Comments
 (0)