Skip to content

Commit 35f7e8d

Browse files
author
Zach Nanninga
committed
ISSUE-28656 - Add basic unit test compatibility for new Inline app state dependency
1 parent c1eeed2 commit 35f7e8d

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

lib/internal/Magento/Framework/Translate/Inline.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ public function isAllowed()
131131
if (!$this->scope instanceof \Magento\Framework\App\ScopeInterface) {
132132
$scope = $this->scopeResolver->getScope($this->scope);
133133
}
134-
$this->isAllowed = $this->isAreaAllowed()
135-
&& $this->config->isActive($scope)
136-
&& $this->config->isDevAllowed($scope);
134+
$this->isAllowed = $this->config->isActive($scope)
135+
&& $this->config->isDevAllowed($scope)
136+
&& $this->isAreaAllowed();
137137
}
138138
return $this->state->isEnabled() && $this->isAllowed;
139139
}

lib/internal/Magento/Framework/Translate/Test/Unit/InlineTest.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
namespace Magento\Framework\Translate\Test\Unit;
99

10+
use Magento\Framework\App\Area;
1011
use Magento\Framework\App\Config\ScopeConfigInterface;
1112
use Magento\Framework\App\ScopeResolverInterface;
13+
use Magento\Framework\App\State as AppState;
1214
use Magento\Framework\Translate\Inline;
1315
use Magento\Framework\Translate\Inline\ConfigInterface;
1416
use Magento\Framework\Translate\Inline\ParserFactory;
@@ -51,6 +53,11 @@ class InlineTest extends TestCase
5153
*/
5254
protected $stateMock;
5355

56+
/**
57+
* @var AppState|MockObject
58+
*/
59+
protected $appStateMock;
60+
5461
protected function setUp(): void
5562
{
5663
$this->scopeResolverMock =
@@ -60,6 +67,7 @@ protected function setUp(): void
6067
$this->configMock = $this->getMockForAbstractClass(ConfigInterface::class);
6168
$this->parserMock = $this->getMockForAbstractClass(ParserInterface::class);
6269
$this->stateMock = $this->getMockForAbstractClass(StateInterface::class);
70+
$this->appStateMock = $this->createMock(AppState::class);
6371
}
6472

6573
/**
@@ -79,7 +87,8 @@ public function testIsAllowed($isEnabled, $isActive, $isDevAllowed, $result)
7987
$this->layoutMock,
8088
$this->configMock,
8189
$this->parserMock,
82-
$this->stateMock
90+
$this->stateMock,
91+
$this->appStateMock
8392
);
8493

8594
$this->assertEquals($result, $model->isAllowed());
@@ -111,7 +120,8 @@ public function testGetParser()
111120
$this->layoutMock,
112121
$this->configMock,
113122
$this->parserMock,
114-
$this->stateMock
123+
$this->stateMock,
124+
$this->appStateMock
115125
);
116126
$this->assertEquals($this->parserMock, $model->getParser());
117127
}
@@ -133,6 +143,7 @@ public function testProcessResponseBodyStripInline($body, $expected)
133143
$this->configMock,
134144
$this->parserMock,
135145
$this->stateMock,
146+
$this->appStateMock,
136147
'',
137148
'',
138149
$scope
@@ -201,6 +212,7 @@ public function testProcessResponseBody($scope, $body, $expected)
201212
$this->configMock,
202213
$this->parserMock,
203214
$this->stateMock,
215+
$this->appStateMock,
204216
'',
205217
'',
206218
$scope
@@ -266,6 +278,7 @@ public function testProcessResponseBodyGetInlineScript($scope, $body, $expected)
266278
$this->configMock,
267279
$this->parserMock,
268280
$this->stateMock,
281+
$this->appStateMock,
269282
'',
270283
'',
271284
$scope
@@ -292,8 +305,13 @@ public function processResponseBodyGetInlineScriptDataProvider()
292305
* @param bool $isDevAllowed
293306
* @param null|string $scope
294307
*/
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+
) {
297315
$scopeMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
298316
$this->stateMock->expects($this->any())->method('isEnabled')->willReturn($isEnabled);
299317
$this->scopeResolverMock->expects(
@@ -323,5 +341,13 @@ protected function prepareIsAllowed($isEnabled, $isActive, $isDevAllowed, $scope
323341
)->willReturn(
324342
$isDevAllowed
325343
);
344+
345+
$this->appStateMock->expects(
346+
($isActive && $isDevAllowed) ? $this->once() : $this->never()
347+
)->method(
348+
'getAreaCode'
349+
)->willReturn(
350+
$area
351+
);
326352
}
327353
}

0 commit comments

Comments
 (0)