Skip to content

Commit 28c9ac1

Browse files
author
Oleksandr Dubovyk
committed
Merge remote-tracking branch 'chaika/MAGETWO-71591' into PR_in_2.1
2 parents 0b08c0a + 8636ad3 commit 28c9ac1

File tree

9 files changed

+192
-85
lines changed

9 files changed

+192
-85
lines changed

app/code/Magento/Authorizenet/view/frontend/web/js/view/payment/method-renderer/authorizenet-directpost.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
define(
66
[
77
'jquery',
8-
'Magento_Payment/js/view/payment/iframe'
8+
'Magento_Payment/js/view/payment/iframe',
9+
'mage/translate'
910
],
10-
function ($, Component) {
11+
function ($, Component, $t) {
1112
'use strict';
1213

1314
return Component.extend({
1415
defaults: {
1516
template: 'Magento_Authorizenet/payment/authorizenet-directpost',
16-
timeoutMessage: 'Sorry, but something went wrong. Please contact the seller.'
17+
timeoutMessage: $t('Sorry, but something went wrong. Please contact the seller.')
1718
},
1819
placeOrderHandler: null,
1920
validateHandler: null,

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\Framework\View\Asset\File\FallbackContext;
1313
use Magento\Framework\App\AreaList;
1414
use Magento\Framework\TranslateInterface;
15+
use Magento\Framework\App\ObjectManager;
16+
use Magento\Framework\View\DesignInterface;
1517

1618
/**
1719
* PreProcessor responsible for providing js translation dictionary
@@ -42,29 +44,38 @@ class PreProcessor implements PreProcessorInterface
4244
*/
4345
protected $translate;
4446

47+
/**
48+
* @var DesignInterface
49+
*/
50+
private $design;
51+
4552
/**
4653
* @param Config $config
4754
* @param DataProviderInterface $dataProvider
4855
* @param AreaList $areaList
4956
* @param TranslateInterface $translate
57+
* @param DesignInterface|null $design
5058
*/
5159
public function __construct(
5260
Config $config,
5361
DataProviderInterface $dataProvider,
5462
AreaList $areaList,
55-
TranslateInterface $translate
63+
TranslateInterface $translate,
64+
DesignInterface $design = null
5665
) {
5766
$this->config = $config;
5867
$this->dataProvider = $dataProvider;
5968
$this->areaList = $areaList;
6069
$this->translate = $translate;
70+
$this->design = $design ?: ObjectManager::getInstance()->get(DesignInterface::class);
6171
}
6272

6373
/**
6474
* Transform content and/or content type for the specified preprocessing chain object
6575
*
6676
* @param Chain $chain
6777
* @return void
78+
* @throws \Exception
6879
*/
6980
public function process(Chain $chain)
7081
{
@@ -77,7 +88,10 @@ public function process(Chain $chain)
7788
if ($context instanceof FallbackContext) {
7889
$themePath = $context->getThemePath();
7990
$areaCode = $context->getAreaCode();
80-
$this->translate->setLocale($context->getLocale());
91+
$this->design->setDesignTheme($themePath, $areaCode);
92+
$this->translate
93+
->setLocale($context->getLocale())
94+
->loadData($areaCode);
8195
}
8296

8397
$area = $this->areaList->getArea($areaCode);

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Translation\Test\Unit\Model\Json;
78

89
use Magento\Translation\Model\Js\Config;
@@ -36,17 +37,35 @@ class PreProcessorTest extends \PHPUnit_Framework_TestCase
3637
*/
3738
protected $translateMock;
3839

40+
/**
41+
* @var \Magento\Framework\View\DesignInterface|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $designMock;
44+
3945
protected function setUp()
4046
{
4147
$this->configMock = $this->getMock('Magento\Translation\Model\Js\Config', [], [], '', false);
4248
$this->dataProviderMock = $this->getMock('Magento\Translation\Model\Js\DataProvider', [], [], '', false);
4349
$this->areaListMock = $this->getMock('Magento\Framework\App\AreaList', [], [], '', false);
44-
$this->translateMock = $this->getMockForAbstractClass('Magento\Framework\TranslateInterface');
50+
$this->translateMock = $this->getMockBuilder(\Magento\Framework\Translate::class)
51+
->disableOriginalConstructor()
52+
->getMock();
53+
54+
$this->translateMock
55+
->expects($this->once())
56+
->method('setLocale')
57+
->willReturn($this->translateMock);
58+
59+
$this->designMock = $this->getMockBuilder(\Magento\Framework\View\DesignInterface::class)
60+
->disableOriginalConstructor()
61+
->getMock();
62+
4563
$this->model = new PreProcessor(
4664
$this->configMock,
4765
$this->dataProviderMock,
4866
$this->areaListMock,
49-
$this->translateMock
67+
$this->translateMock,
68+
$this->designMock
5069
);
5170
}
5271

@@ -97,6 +116,16 @@ public function testGetData()
97116
->method('setContentType')
98117
->with('json');
99118

119+
$this->designMock
120+
->expects($this->once())
121+
->method('setDesignTheme')
122+
->with($themePath, $areaCode)
123+
->willReturn($this->translateMock);
124+
$this->translateMock
125+
->expects($this->once())
126+
->method('loadData')
127+
->willReturn($this->translateMock);
128+
100129
$this->model->process($chain);
101130
}
102131
}

dev/tests/integration/testsuite/Magento/Framework/TranslateTest.php

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function setUp()
1818
/** @var \Magento\Framework\View\FileSystem $viewFileSystem */
1919
$viewFileSystem = $this->getMock(
2020
'Magento\Framework\View\FileSystem',
21-
['getLocaleFileName', 'getDesignTheme'],
21+
['getLocaleFileName'],
2222
[],
2323
'',
2424
false
@@ -27,15 +27,16 @@ protected function setUp()
2727
$viewFileSystem->expects($this->any())
2828
->method('getLocaleFileName')
2929
->will(
30-
$this->returnValue(dirname(__DIR__) . '/Theme/Model/_files/design/frontend/Test/default/i18n/en_US.csv')
30+
$this->returnValue(
31+
dirname(__DIR__) . '/Translation/Model/_files/Magento/design/Magento/theme/i18n/en_US.csv'
32+
)
3133
);
3234

3335
/** @var \Magento\Framework\View\Design\ThemeInterface $theme */
3436
$theme = $this->getMock('Magento\Framework\View\Design\ThemeInterface', []);
35-
$theme->expects($this->any())->method('getId')->will($this->returnValue(10));
36-
37-
$viewFileSystem->expects($this->any())->method('getDesignTheme')->will($this->returnValue($theme));
37+
$theme->expects($this->once())->method('getThemePath')->will($this->returnValue('Magento/luma'));
3838

39+
/** @var \Magento\TestFramework\ObjectManager $objectManager */
3940
$objectManager = Bootstrap::getObjectManager();
4041
$objectManager->addSharedInstance($viewFileSystem, 'Magento\Framework\View\FileSystem');
4142

@@ -67,7 +68,7 @@ protected function setUp()
6768
]
6869
);
6970

70-
$designModel->expects($this->any())->method('getDesignTheme')->will($this->returnValue($theme));
71+
$designModel->expects($this->once())->method('getDesignTheme')->will($this->returnValue($theme));
7172

7273
$objectManager->addSharedInstance($designModel, 'Magento\Theme\Model\View\Design\Proxy');
7374

@@ -95,9 +96,34 @@ public function translateDataProvider()
9596
{
9697
return [
9798
['', ''],
98-
['Text with different translation on different modules', 'Text translation that was last loaded'],
99-
['text_with_no_translation', 'text_with_no_translation'],
100-
['Design value to translate', 'Design translated value']
99+
[
100+
'Theme phrase will be translated',
101+
'Theme phrase is translated',
102+
],
103+
[
104+
'Magento_Store module phrase will be translated',
105+
'Magento_Store module translated phrase',
106+
],
107+
[
108+
'Magento_Catalog module phrase will be translated',
109+
'Magento_Catalog module translated phrase',
110+
],
111+
[
112+
'Phrase in Magento_Store module that doesn\'t need translation',
113+
'Phrase in Magento_Store module that doesn\'t need translation',
114+
],
115+
[
116+
'Phrase in Magento_Catalog module that doesn\'t need translation',
117+
'Phrase in Magento_Catalog module that doesn\'t need translation',
118+
],
119+
[
120+
'Magento_Store module phrase will be override by theme translation',
121+
'Magento_Store module phrase is override by theme translation',
122+
],
123+
[
124+
'Magento_Catalog module phrase will be override by theme translation',
125+
'Magento_Catalog module phrase is override by theme translation',
126+
],
101127
];
102128
}
103129
}

dev/tests/integration/testsuite/Magento/Translation/Model/_files/Magento/Catalog/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
"Some non-translated value for Magento_Catalog","Translation for some value for Magento_Catalog"
33
"Another non-translated value for Magento_Catalog","Translation for another value for Magento_Catalog"
44
"Text with different translation on different modules","Text translation that was last loaded"
5+
"Magento_Catalog module phrase will be translated","Magento_Catalog module translated phrase"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
"%s","%s"
22
"Original value for Magento_Store module","Translated value for Magento_Store module"
33
"Text with different translation on different modules","Text translation that was last loaded"
4+
"Magento_Store module phrase will be translated","Magento_Store module translated phrase"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"Theme phrase will be translated","Theme phrase is translated"
2+
"Magento_Catalog module phrase will be override by theme translation","Magento_Catalog module phrase is override by theme translation"
3+
"Magento_Store module phrase will be override by theme translation","Magento_Store module phrase is override by theme translation"

lib/internal/Magento/Framework/Test/Unit/TranslateTest.php

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,57 @@ protected function setUp()
104104
* @param string $area
105105
* @param bool $forceReload
106106
* @param array $cachedData
107+
* @dataProvider dataProviderLoadDataCachedTranslation
108+
*/
109+
public function testLoadDataCachedTranslation($area, $forceReload, $cachedData)
110+
{
111+
$this->expectsSetConfig('Magento/luma');
112+
$this->cache->expects($this->once())
113+
->method('load')
114+
->will($this->returnValue(serialize($cachedData)));
115+
116+
$this->appState->expects($this->exactly($area ? 0 : 1))
117+
->method('getAreaCode')
118+
->will($this->returnValue('frontend'));
119+
120+
$this->translate->loadData($area, $forceReload);
121+
$this->assertEquals($cachedData, $this->translate->getData());
122+
}
123+
124+
public function dataProviderLoadDataCachedTranslation()
125+
{
126+
$cachedData = ['cached 1' => 'translated 1', 'cached 2' => 'translated 2'];
127+
return [
128+
['adminhtml', false, $cachedData],
129+
['frontend', false, $cachedData],
130+
[null, false, $cachedData],
131+
];
132+
}
133+
134+
/**
135+
* @param string $area
136+
* @param bool $forceReload
107137
* @dataProvider dataProviderForTestLoadData
108138
* @SuppressWarnings(PHPMD.NPathComplexity)
109139
*/
110-
public function testLoadData($area, $forceReload, $cachedData)
140+
public function testLoadData($area, $forceReload)
111141
{
112-
$this->expectsSetConfig('themeId');
113-
142+
$this->expectsSetConfig('Magento/luma');
143+
$this->appState->expects($this->exactly($area ? 0 : 1))
144+
->method('getAreaCode')
145+
->will($this->returnValue('frontend'));
114146
$this->cache->expects($this->exactly($forceReload ? 0 : 1))
115147
->method('load')
116-
->will($this->returnValue(serialize($cachedData)));
117-
118-
if (!$forceReload && $cachedData !== false) {
119-
$this->translate->loadData($area, $forceReload);
120-
$this->assertEquals($cachedData, $this->translate->getData());
121-
return;
122-
}
148+
->will($this->returnValue(false));
123149

124150
$this->directory->expects($this->any())->method('isExist')->will($this->returnValue(true));
125151

126152
// _loadModuleTranslation()
127-
$this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue(['name']));
153+
$modules = ['some_module', 'other_module', 'another_module', 'current_module'];
154+
$this->request->expects($this->any())
155+
->method('getControllerModule')
156+
->willReturn('current_module');
157+
$this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue($modules));
128158
$moduleData = [
129159
'module original' => 'module translated',
130160
'module theme' => 'module-theme original translated',
@@ -170,9 +200,7 @@ public function testLoadData($area, $forceReload, $cachedData)
170200
];
171201
$this->resource->expects($this->any())->method('getTranslationArray')->will($this->returnValue($dbData));
172202

173-
if (!$forceReload) {
174-
$this->cache->expects($this->exactly(1))->method('save');
175-
}
203+
$this->cache->expects($this->exactly($forceReload ? 0 : 1))->method('save');
176204

177205
$this->translate->loadData($area, $forceReload);
178206

@@ -190,20 +218,13 @@ public function testLoadData($area, $forceReload, $cachedData)
190218

191219
public function dataProviderForTestLoadData()
192220
{
193-
$cachedData = ['cached 1' => 'translated 1', 'cached 2' => 'translated 2'];
194221
return [
195-
['adminhtml', true, false],
196-
['adminhtml', true, $cachedData],
197-
['adminhtml', false, $cachedData],
198-
['adminhtml', false, false],
199-
['frontend', true, false],
200-
['frontend', true, $cachedData],
201-
['frontend', false, $cachedData],
202-
['frontend', false, false],
203-
[null, true, false],
204-
[null, true, $cachedData],
205-
[null, false, $cachedData],
206-
[null, false, false]
222+
['adminhtml', true],
223+
['adminhtml', false],
224+
['frontend', true],
225+
['frontend', false],
226+
[null, true],
227+
[null, false]
207228
];
208229
}
209230

@@ -292,7 +313,14 @@ protected function expectsSetConfig($themeId, $localeCode = 'en_US')
292313
]
293314
)
294315
);
295-
$designTheme = new \Magento\Framework\DataObject(['id' => $themeId]);
316+
$designTheme = $this->getMockBuilder(\Magento\Theme\Model\Theme::class)
317+
->disableOriginalConstructor()
318+
->getMock();
319+
320+
$designTheme->expects($this->once())
321+
->method('getThemePath')
322+
->willReturn($themeId);
323+
296324
$this->viewDesign->expects($this->any())->method('getDesignTheme')->will($this->returnValue($designTheme));
297325
}
298326
}

0 commit comments

Comments
 (0)