7
7
8
8
namespace Magento \Framework \Translate \Test \Unit ;
9
9
10
+ use Magento \Framework \App \Area ;
10
11
use Magento \Framework \App \Config \ScopeConfigInterface ;
11
12
use Magento \Framework \App \ScopeResolverInterface ;
13
+ use Magento \Framework \App \State as AppState ;
12
14
use Magento \Framework \Translate \Inline ;
13
15
use Magento \Framework \Translate \Inline \ConfigInterface ;
14
16
use Magento \Framework \Translate \Inline \ParserFactory ;
@@ -51,6 +53,11 @@ class InlineTest extends TestCase
51
53
*/
52
54
protected $ stateMock ;
53
55
56
+ /**
57
+ * @var AppState|MockObject
58
+ */
59
+ protected $ appStateMock ;
60
+
54
61
protected function setUp (): void
55
62
{
56
63
$ this ->scopeResolverMock =
@@ -60,6 +67,7 @@ protected function setUp(): void
60
67
$ this ->configMock = $ this ->getMockForAbstractClass (ConfigInterface::class);
61
68
$ this ->parserMock = $ this ->getMockForAbstractClass (ParserInterface::class);
62
69
$ this ->stateMock = $ this ->getMockForAbstractClass (StateInterface::class);
70
+ $ this ->appStateMock = $ this ->createMock (AppState::class);
63
71
}
64
72
65
73
/**
@@ -79,7 +87,8 @@ public function testIsAllowed($isEnabled, $isActive, $isDevAllowed, $result)
79
87
$ this ->layoutMock ,
80
88
$ this ->configMock ,
81
89
$ this ->parserMock ,
82
- $ this ->stateMock
90
+ $ this ->stateMock ,
91
+ $ this ->appStateMock
83
92
);
84
93
85
94
$ this ->assertEquals ($ result , $ model ->isAllowed ());
@@ -111,7 +120,8 @@ public function testGetParser()
111
120
$ this ->layoutMock ,
112
121
$ this ->configMock ,
113
122
$ this ->parserMock ,
114
- $ this ->stateMock
123
+ $ this ->stateMock ,
124
+ $ this ->appStateMock
115
125
);
116
126
$ this ->assertEquals ($ this ->parserMock , $ model ->getParser ());
117
127
}
@@ -133,6 +143,7 @@ public function testProcessResponseBodyStripInline($body, $expected)
133
143
$ this ->configMock ,
134
144
$ this ->parserMock ,
135
145
$ this ->stateMock ,
146
+ $ this ->appStateMock ,
136
147
'' ,
137
148
'' ,
138
149
$ scope
@@ -201,6 +212,7 @@ public function testProcessResponseBody($scope, $body, $expected)
201
212
$ this ->configMock ,
202
213
$ this ->parserMock ,
203
214
$ this ->stateMock ,
215
+ $ this ->appStateMock ,
204
216
'' ,
205
217
'' ,
206
218
$ scope
@@ -266,6 +278,7 @@ public function testProcessResponseBodyGetInlineScript($scope, $body, $expected)
266
278
$ this ->configMock ,
267
279
$ this ->parserMock ,
268
280
$ this ->stateMock ,
281
+ $ this ->appStateMock ,
269
282
'' ,
270
283
'' ,
271
284
$ scope
@@ -292,8 +305,13 @@ public function processResponseBodyGetInlineScriptDataProvider()
292
305
* @param bool $isDevAllowed
293
306
* @param null|string $scope
294
307
*/
295
- protected function prepareIsAllowed ($ isEnabled , $ isActive , $ isDevAllowed , $ scope = null )
296
- {
308
+ protected function prepareIsAllowed (
309
+ $ isEnabled ,
310
+ $ isActive ,
311
+ $ isDevAllowed ,
312
+ $ scope = null ,
313
+ $ area = Area::AREA_FRONTEND
314
+ ) {
297
315
$ scopeMock = $ this ->getMockForAbstractClass (ScopeConfigInterface::class);
298
316
$ this ->stateMock ->expects ($ this ->any ())->method ('isEnabled ' )->willReturn ($ isEnabled );
299
317
$ this ->scopeResolverMock ->expects (
@@ -323,5 +341,13 @@ protected function prepareIsAllowed($isEnabled, $isActive, $isDevAllowed, $scope
323
341
)->willReturn (
324
342
$ isDevAllowed
325
343
);
344
+
345
+ $ this ->appStateMock ->expects (
346
+ ($ isActive && $ isDevAllowed ) ? $ this ->once () : $ this ->never ()
347
+ )->method (
348
+ 'getAreaCode '
349
+ )->willReturn (
350
+ $ area
351
+ );
326
352
}
327
353
}
0 commit comments