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