13
13
use Magento \Framework \ZendEscaper ;
14
14
use PHPUnit \Framework \TestCase ;
15
15
use Psr \Log \LoggerInterface ;
16
+ use Magento \Framework \Translate \Inline \StateInterface ;
16
17
17
18
/**
18
19
* \Magento\Framework\Escaper test case
@@ -24,6 +25,11 @@ class EscaperTest extends TestCase
24
25
*/
25
26
protected $ escaper ;
26
27
28
+ /**
29
+ * @var ObjectManager
30
+ */
31
+ private $ objectManagerHelper ;
32
+
27
33
/**
28
34
* @var ZendEscaper
29
35
*/
@@ -44,14 +50,14 @@ class EscaperTest extends TestCase
44
50
*/
45
51
protected function setUp (): void
46
52
{
47
- $ objectManagerHelper = new ObjectManager ($ this );
53
+ $ this -> objectManagerHelper = new ObjectManager ($ this );
48
54
$ this ->escaper = new Escaper ();
49
55
$ this ->zendEscaper = new ZendEscaper ();
50
- $ this ->translateInline = $ objectManagerHelper ->getObject (Inline::class);
56
+ $ this ->translateInline = $ this -> objectManagerHelper ->getObject (Inline::class);
51
57
$ this ->loggerMock = $ this ->getMockForAbstractClass (LoggerInterface::class);
52
- $ objectManagerHelper ->setBackwardCompatibleProperty ($ this ->escaper , 'escaper ' , $ this ->zendEscaper );
53
- $ objectManagerHelper ->setBackwardCompatibleProperty ($ this ->escaper , 'logger ' , $ this ->loggerMock );
54
- $ objectManagerHelper ->setBackwardCompatibleProperty (
58
+ $ this -> objectManagerHelper ->setBackwardCompatibleProperty ($ this ->escaper , 'escaper ' , $ this ->zendEscaper );
59
+ $ this -> objectManagerHelper ->setBackwardCompatibleProperty ($ this ->escaper , 'logger ' , $ this ->loggerMock );
60
+ $ this -> objectManagerHelper ->setBackwardCompatibleProperty (
55
61
$ this ->escaper ,
56
62
'translateInline ' ,
57
63
$ this ->translateInline
@@ -169,6 +175,58 @@ public function testEscapeHtml($data, $expected, $allowedTags = [])
169
175
$ this ->assertEquals ($ expected , $ actual );
170
176
}
171
177
178
+ /**
179
+ * Tests escapeHtmlAttr method when Inline translate is configured.
180
+ *
181
+ * @param string $input
182
+ * @param string $output
183
+ * @return void
184
+ * @dataProvider escapeHtmlAttrWithInlineProvider
185
+ */
186
+ public function testEscapeHtmlAttrWithInline (string $ input , string $ output ): void
187
+ {
188
+ $ this ->objectManagerHelper ->setBackwardCompatibleProperty (
189
+ $ this ->translateInline ,
190
+ 'isAllowed ' ,
191
+ true
192
+ );
193
+ $ stateMock = $ this ->createMock (StateInterface::class);
194
+ $ stateMock ->method ('isEnabled ' )
195
+ ->willReturn (true );
196
+ $ this ->objectManagerHelper ->setBackwardCompatibleProperty (
197
+ $ this ->translateInline ,
198
+ 'state ' ,
199
+ $ stateMock
200
+ );
201
+
202
+
203
+ $ actual = $ this ->escaper ->escapeHtmlAttr ($ input );
204
+ $ this ->assertEquals ($ output , $ actual );
205
+ }
206
+
207
+ /**
208
+ * Data provider for escapeHtmlAttrWithInline test.
209
+ *
210
+ * @return array
211
+ */
212
+ public function escapeHtmlAttrWithInlineProvider (): array
213
+ {
214
+ return [
215
+ [
216
+ '{{{Search entire store here...}}} ' ,
217
+ '{{{Search entire store here...}}} ' ,
218
+ ],
219
+ [
220
+ '{{{Product search}}{{Translated to language}}{{themeMagento/Luma}}} ' ,
221
+ '{{{Product search}}{{Translated to language}}{{themeMagento/Luma}}} ' ,
222
+ ],
223
+ [
224
+ 'Simple string ' ,
225
+ 'Simple string ' ,
226
+ ],
227
+ ];
228
+ }
229
+
172
230
/**
173
231
* @covers \Magento\Framework\Escaper::escapeHtml
174
232
* @dataProvider escapeHtmlInvalidDataProvider
0 commit comments