8
8
9
9
namespace Magento \Cms \Test \Integration \Model \Wysiwyg \Images ;
10
10
11
+ use Magento \Backend \Helper \Data as BackendHelper ;
11
12
use Magento \Cms \Helper \Wysiwyg \Images as ImagesHelper ;
12
13
use Magento \Cms \Model \Wysiwyg \Images \GetInsertImageContent ;
14
+ use Magento \Framework \Url \EncoderInterface ;
13
15
use Magento \TestFramework \Helper \Bootstrap ;
14
16
use PHPUnit \Framework \TestCase ;
15
17
@@ -27,13 +29,25 @@ class GetInsertImageContentTest extends TestCase
27
29
*/
28
30
private $ imagesHelper ;
29
31
32
+ /**
33
+ * @var EncoderInterface
34
+ */
35
+ private $ urlEncoder ;
36
+
37
+ /**
38
+ * @var BackendHelper
39
+ */
40
+ protected $ _backendData ;
41
+
30
42
/**
31
43
* @inheritdoc
32
44
*/
33
45
protected function setUp (): void
34
46
{
35
47
$ this ->getInsertImageContent = Bootstrap::getObjectManager ()->get (GetInsertImageContent::class);
36
48
$ this ->imagesHelper = Bootstrap::getObjectManager ()->get (ImagesHelper::class);
49
+ $ this ->urlEncoder = Bootstrap::getObjectManager ()->get (EncoderInterface::class);
50
+ $ this ->_backendData = Bootstrap::getObjectManager ()->get (BackendHelper::class);
37
51
}
38
52
39
53
/**
@@ -44,12 +58,14 @@ protected function setUp(): void
44
58
* @param bool $forceStaticPath
45
59
* @param bool $renderAsTag
46
60
* @param int|null $storeId
61
+ * @param string|null $expectedResult
47
62
*/
48
63
public function testExecute (
49
64
string $ encodedFilename ,
50
65
bool $ forceStaticPath ,
51
66
bool $ renderAsTag ,
52
- ?int $ storeId = null
67
+ ?int $ storeId = null ,
68
+ ?string $ expectedResult = null
53
69
): void {
54
70
$ getImageForInsert = $ this ->getInsertImageContent ->execute (
55
71
$ encodedFilename ,
@@ -58,35 +74,21 @@ public function testExecute(
58
74
$ storeId
59
75
);
60
76
61
- if (!$ forceStaticPath ) {
62
- if ($ renderAsTag ) {
63
- $ html = $ this ->imagesHelper ->getImageHtmlDeclaration (
64
- self ::TEST_IMAGE_FILE ,
65
- true
66
- );
67
- $ this ->assertEquals (
68
- $ getImageForInsert ,
69
- $ html
70
- );
71
- } else {
72
- $ html = $ this ->imagesHelper ->getImageHtmlDeclaration (
73
- self ::TEST_IMAGE_FILE ,
74
- false
75
- );
76
- $ this ->assertEquals (
77
- $ getImageForInsert ,
78
- $ html
77
+ if (!$ forceStaticPath && !$ renderAsTag ) {
78
+ if (!$ this ->imagesHelper ->isUsingStaticUrlsAllowed ()) {
79
+
80
+ $ encodedDirective = $ this ->urlEncoder ->encode ($ expectedResult );
81
+ $ expectedResult = $ this ->_backendData ->getUrl (
82
+ 'cms/wysiwyg/directive ' ,
83
+ [
84
+ '___directive ' => $ encodedDirective ,
85
+ '_escape_params ' => false ,
86
+ ]
79
87
);
80
88
}
81
- } else {
82
- $ this ->assertEquals (
83
- $ getImageForInsert ,
84
- parse_url (
85
- $ this ->imagesHelper ->getCurrentUrl () . self ::TEST_IMAGE_FILE ,
86
- PHP_URL_PATH
87
- )
88
- );
89
89
}
90
+
91
+ $ this ->assertEquals ($ getImageForInsert , $ expectedResult );
90
92
}
91
93
92
94
/**
@@ -102,30 +104,35 @@ public function imageDataProvider(): array
102
104
false ,
103
105
true ,
104
106
1 ,
107
+ '<img src="{{media url=" ' . self ::TEST_IMAGE_FILE . '"}}" alt="" /> '
105
108
],
106
109
[
107
110
'L3Rlc3QtaW1hZ2UuanBn ' ,
108
111
true ,
109
112
false ,
110
113
1 ,
114
+ '/pub/media/ ' . self ::TEST_IMAGE_FILE
111
115
],
112
116
[
113
117
'L3Rlc3QtaW1hZ2UuanBn ' ,
114
118
false ,
115
119
false ,
116
120
1 ,
121
+ '{{media url=" ' . self ::TEST_IMAGE_FILE . '"}} '
117
122
],
118
123
[
119
124
'L3Rlc3QtaW1hZ2UuanBn ' ,
120
125
false ,
121
126
true ,
122
127
2 ,
128
+ '<img src="{{media url=" ' . self ::TEST_IMAGE_FILE . '"}}" alt="" /> '
123
129
],
124
130
[
125
131
'L3Rlc3QtaW1hZ2UuanBn ' ,
126
132
false ,
127
133
true ,
128
134
null ,
135
+ '<img src="{{media url=" ' . self ::TEST_IMAGE_FILE . '"}}" alt="" /> '
129
136
],
130
137
];
131
138
}
0 commit comments