Skip to content

Commit a624019

Browse files
Merge remote-tracking branch 'remotes/github/MC-10938' into EPAM-PR-40
2 parents 8cd2549 + 5fd9eee commit a624019

File tree

2 files changed

+57
-11
lines changed

2 files changed

+57
-11
lines changed

app/code/Magento/Translation/Model/Json/PreProcessor.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
namespace Magento\Translation\Model\Json;
88

9+
use Magento\Framework\App\Area;
910
use Magento\Framework\App\AreaList;
1011
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\TranslateInterface;
1213
use Magento\Framework\View\Asset\File\FallbackContext;
1314
use Magento\Framework\View\Asset\PreProcessor\Chain;
1415
use Magento\Framework\View\Asset\PreProcessorInterface;
1516
use Magento\Framework\View\DesignInterface;
17+
use Magento\Backend\App\Area\FrontNameResolver;
1618
use Magento\Translation\Model\Js\Config;
1719
use Magento\Translation\Model\Js\DataProviderInterface;
1820

@@ -83,7 +85,7 @@ public function process(Chain $chain)
8385
$context = $chain->getAsset()->getContext();
8486

8587
$themePath = '*/*';
86-
$areaCode = \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE;
88+
$areaCode = FrontNameResolver::AREA_CODE;
8789

8890
if ($context instanceof FallbackContext) {
8991
$themePath = $context->getThemePath();
@@ -92,8 +94,10 @@ public function process(Chain $chain)
9294
$this->viewDesign->setDesignTheme($themePath, $areaCode);
9395
}
9496

95-
$area = $this->areaList->getArea($areaCode);
96-
$area->load(\Magento\Framework\App\Area::PART_TRANSLATE);
97+
if ($areaCode !== FrontNameResolver::AREA_CODE) {
98+
$area = $this->areaList->getArea($areaCode);
99+
$area->load(Area::PART_TRANSLATE);
100+
}
97101

98102
$this->translate->setLocale($context->getLocale())->loadData($areaCode, true);
99103

app/code/Magento/Translation/Test/Unit/Model/Json/PreProcessorTest.php

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,43 @@
88
use Magento\Translation\Model\Js\Config;
99
use Magento\Translation\Model\Js\DataProvider;
1010
use Magento\Translation\Model\Json\PreProcessor;
11+
use Magento\Backend\App\Area\FrontNameResolver;
1112

1213
class PreProcessorTest extends \PHPUnit\Framework\TestCase
1314
{
1415
/**
1516
* @var PreProcessor
1617
*/
17-
protected $model;
18+
private $model;
1819

1920
/**
2021
* @var Config|\PHPUnit_Framework_MockObject_MockObject
2122
*/
22-
protected $configMock;
23+
private $configMock;
2324

2425
/**
2526
* @var DataProvider|\PHPUnit_Framework_MockObject_MockObject
2627
*/
27-
protected $dataProviderMock;
28+
private $dataProviderMock;
2829

2930
/**
3031
* @var \Magento\Framework\App\AreaList|\PHPUnit_Framework_MockObject_MockObject
3132
*/
32-
protected $areaListMock;
33+
private $areaListMock;
3334

3435
/**
3536
* @var \Magento\Framework\TranslateInterface|\PHPUnit_Framework_MockObject_MockObject
3637
*/
37-
protected $translateMock;
38+
private $translateMock;
3839

3940
/**
4041
* @var \Magento\Framework\View\DesignInterface|\PHPUnit_Framework_MockObject_MockObject
4142
*/
4243
private $designMock;
4344

45+
/**
46+
* @inheritdoc
47+
*/
4448
protected function setUp()
4549
{
4650
$this->configMock = $this->createMock(\Magento\Translation\Model\Js\Config::class);
@@ -57,7 +61,14 @@ protected function setUp()
5761
);
5862
}
5963

60-
public function testGetData()
64+
/**
65+
* Test 'process' method.
66+
*
67+
* @param array $data
68+
* @param array $expects
69+
* @dataProvider processDataProvider
70+
*/
71+
public function testProcess(array $data, array $expects)
6172
{
6273
$chain = $this->createMock(\Magento\Framework\View\Asset\PreProcessor\Chain::class);
6374
$asset = $this->createMock(\Magento\Framework\View\Asset\File::class);
@@ -66,8 +77,10 @@ public function testGetData()
6677
$targetPath = 'path/js-translation.json';
6778
$themePath = '*/*';
6879
$dictionary = ['hello' => 'bonjour'];
69-
$areaCode = 'adminhtml';
80+
$areaCode = $data['area_code'];
81+
7082
$area = $this->createMock(\Magento\Framework\App\Area::class);
83+
$area->expects($expects['area_load'])->method('load')->willReturnSelf();
7184

7285
$chain->expects($this->once())
7386
->method('getTargetAssetPath')
@@ -93,7 +106,7 @@ public function testGetData()
93106

94107
$this->designMock->expects($this->once())->method('setDesignTheme')->with($themePath, $areaCode);
95108

96-
$this->areaListMock->expects($this->once())
109+
$this->areaListMock->expects($expects['areaList_getArea'])
97110
->method('getArea')
98111
->with($areaCode)
99112
->willReturn($area);
@@ -114,4 +127,33 @@ public function testGetData()
114127

115128
$this->model->process($chain);
116129
}
130+
131+
/**
132+
* Data provider for 'process' method test.
133+
*
134+
* @return array
135+
*/
136+
public function processDataProvider()
137+
{
138+
return [
139+
[
140+
[
141+
'area_code' => FrontNameResolver::AREA_CODE
142+
],
143+
[
144+
'areaList_getArea' => $this->never(),
145+
'area_load' => $this->never(),
146+
]
147+
],
148+
[
149+
[
150+
'area_code' => 'frontend'
151+
],
152+
[
153+
'areaList_getArea' => $this->once(),
154+
'area_load' => $this->once(),
155+
]
156+
],
157+
];
158+
}
117159
}

0 commit comments

Comments
 (0)