Skip to content

Commit 2275b89

Browse files
author
Alexander Akimov
authored
Merge pull request #1703 from magento-chaika/PR_in_2.2
[Chaika] bugfixes 2.2
2 parents 7750efe + 0f5b693 commit 2275b89

File tree

8 files changed

+208
-109
lines changed

8 files changed

+208
-109
lines changed

app/code/Magento/Deploy/Service/DeployPackage.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Deploy\Service;
78

89
use Magento\Deploy\Package\Package;
910
use Magento\Deploy\Package\PackageFile;
11+
use Magento\Framework\App\ObjectManager;
1012
use Magento\Framework\App\State as AppState;
1113
use Magento\Framework\Locale\ResolverInterface as LocaleResolver;
1214
use Magento\Framework\View\Asset\ContentProcessorException;
1315
use Magento\Deploy\Console\InputValidator;
16+
use Magento\Framework\View\Design\Theme\ListInterface;
17+
use Magento\Framework\View\DesignInterface;
1418
use Psr\Log\LoggerInterface;
1519

1620
/**
@@ -91,15 +95,15 @@ public function __construct(
9195
* @param array $options
9296
* @param bool $skipLogging
9397
* @return bool true on success
98+
* @throws \Exception
9499
*/
95100
public function deploy(Package $package, array $options, $skipLogging = false)
96101
{
97102
$result = $this->appState->emulateAreaCode(
98-
$package->getArea() == Package::BASE_AREA ? 'global' : $package->getArea(),
103+
$package->getArea() === Package::BASE_AREA ? 'global' : $package->getArea(),
99104
function () use ($package, $options, $skipLogging) {
100105
// emulate application locale needed for correct file path resolving
101106
$this->localeResolver->setLocale($package->getLocale());
102-
103107
$this->deployEmulated($package, $options, $skipLogging);
104108
}
105109
);
@@ -111,7 +115,7 @@ function () use ($package, $options, $skipLogging) {
111115
* @param Package $package
112116
* @param array $options
113117
* @param bool $skipLogging
114-
* @return int
118+
* @return bool
115119
*/
116120
public function deployEmulated(Package $package, array $options, $skipLogging = false)
117121
{
@@ -200,14 +204,14 @@ private function processFile(PackageFile $file, Package $package)
200204
private function checkIfCanCopy(PackageFile $file, Package $package, Package $parentPackage = null)
201205
{
202206
return $parentPackage
203-
&& $file->getOrigPackage() !== $package
204-
&& (
205-
$file->getArea() !== $package->getArea()
206-
|| $file->getTheme() !== $package->getTheme()
207-
|| $file->getLocale() !== $package->getLocale()
208-
)
209-
&& $file->getOrigPackage() == $parentPackage
210-
&& $this->deployStaticFile->readFile($file->getDeployedFileId(), $parentPackage->getPath());
207+
&& $file->getOrigPackage() !== $package
208+
&& (
209+
$file->getArea() !== $package->getArea()
210+
|| $file->getTheme() !== $package->getTheme()
211+
|| $file->getLocale() !== $package->getLocale()
212+
)
213+
&& $file->getOrigPackage() === $parentPackage
214+
&& $this->deployStaticFile->readFile($file->getDeployedFileId(), $parentPackage->getPath());
211215
}
212216

213217
/**
@@ -219,10 +223,10 @@ private function checkIfCanCopy(PackageFile $file, Package $package, Package $pa
219223
*/
220224
private function checkFileSkip($filePath, array $options)
221225
{
222-
if ($filePath != '.') {
226+
if ($filePath !== '.') {
223227
$ext = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
224228
$basename = pathinfo($filePath, PATHINFO_BASENAME);
225-
if ($ext == 'less' && strpos($basename, '_') === 0) {
229+
if ($ext === 'less' && strpos($basename, '_') === 0) {
226230
return true;
227231
}
228232
$option = isset(InputValidator::$fileExtensionOptionMap[$ext])

app/code/Magento/Deploy/Service/DeployStaticContent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public function deploy(array $options)
112112
$deployRjsConfig = $this->objectManager->create(DeployRequireJsConfig::class, [
113113
'logger' => $this->logger
114114
]);
115+
/** @var DeployTranslationsDictionary $deployI18n */
115116
$deployI18n = $this->objectManager->create(DeployTranslationsDictionary::class, [
116117
'logger' => $this->logger
117118
]);

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

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

9+
use Magento\Framework\App\AreaList;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\TranslateInterface;
12+
use Magento\Framework\View\Asset\File\FallbackContext;
13+
use Magento\Framework\View\Asset\PreProcessor\Chain;
814
use Magento\Framework\View\Asset\PreProcessorInterface;
15+
use Magento\Framework\View\DesignInterface;
916
use Magento\Translation\Model\Js\Config;
1017
use Magento\Translation\Model\Js\DataProviderInterface;
11-
use Magento\Framework\View\Asset\PreProcessor\Chain;
12-
use Magento\Framework\View\Asset\File\FallbackContext;
13-
use Magento\Framework\App\AreaList;
14-
use Magento\Framework\TranslateInterface;
1518

1619
/**
1720
* PreProcessor responsible for providing js translation dictionary
@@ -41,30 +44,38 @@ class PreProcessor implements PreProcessorInterface
4144
* @var TranslateInterface
4245
*/
4346
protected $translate;
47+
/**
48+
* @var DesignInterface
49+
*/
50+
private $viewDesign;
4451

4552
/**
4653
* @param Config $config
4754
* @param DataProviderInterface $dataProvider
4855
* @param AreaList $areaList
4956
* @param TranslateInterface $translate
57+
* @param DesignInterface|null $viewDesign
5058
*/
5159
public function __construct(
5260
Config $config,
5361
DataProviderInterface $dataProvider,
5462
AreaList $areaList,
55-
TranslateInterface $translate
63+
TranslateInterface $translate,
64+
DesignInterface $viewDesign = null
5665
) {
5766
$this->config = $config;
5867
$this->dataProvider = $dataProvider;
5968
$this->areaList = $areaList;
6069
$this->translate = $translate;
70+
$this->viewDesign = $viewDesign ?: 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,12 @@ 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+
92+
$this->viewDesign->setDesignTheme($themePath, $areaCode);
93+
94+
$this->translate
95+
->setLocale($context->getLocale())
96+
->loadData($areaCode);
8197
}
8298

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

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © 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;
@@ -41,7 +42,15 @@ protected function setUp()
4142
$this->configMock = $this->createMock(\Magento\Translation\Model\Js\Config::class);
4243
$this->dataProviderMock = $this->createMock(\Magento\Translation\Model\Js\DataProvider::class);
4344
$this->areaListMock = $this->createMock(\Magento\Framework\App\AreaList::class);
44-
$this->translateMock = $this->getMockForAbstractClass(\Magento\Framework\TranslateInterface::class);
45+
$this->translateMock = $this->getMockBuilder(\Magento\Framework\Translate::class)
46+
->disableOriginalConstructor()
47+
->getMock();
48+
49+
$this->translateMock
50+
->expects($this->once())
51+
->method('setLocale')
52+
->willReturn($this->translateMock);
53+
4554
$this->model = new PreProcessor(
4655
$this->configMock,
4756
$this->dataProviderMock,
@@ -97,6 +106,11 @@ public function testGetData()
97106
->method('setContentType')
98107
->with('json');
99108

109+
$this->translateMock
110+
->expects($this->once())
111+
->method('loadData')
112+
->willReturn($this->translateMock);
113+
100114
$this->model->process($chain);
101115
}
102116
}

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

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,43 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Framework;
78

89
use Magento\TestFramework\Helper\Bootstrap;
910
use Magento\TestFramework\Helper\CacheCleaner;
11+
use PHPUnit\Framework\TestCase;
12+
use PHPUnit_Framework_MockObject_MockObject;
1013

1114
/**
1215
* @magentoAppIsolation enabled
1316
* @magentoCache all disabled
1417
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1518
*/
16-
class TranslateTest extends \PHPUnit\Framework\TestCase
19+
class TranslateTest extends TestCase
1720
{
1821
/** @var \Magento\Framework\Translate */
1922
private $translate;
2023

2124
protected function setUp()
2225
{
23-
/** @var \Magento\Framework\View\FileSystem $viewFileSystem */
26+
/** @var \Magento\Framework\View\FileSystem | PHPUnit_Framework_MockObject_MockObject $viewFileSystem */
2427
$viewFileSystem = $this->createPartialMock(
2528
\Magento\Framework\View\FileSystem::class,
26-
['getLocaleFileName', 'getDesignTheme']
29+
['getLocaleFileName']
2730
);
2831

2932
$viewFileSystem->expects($this->any())
3033
->method('getLocaleFileName')
3134
->will(
32-
$this->returnValue(dirname(__DIR__) . '/Theme/Model/_files/design/frontend/Test/default/i18n/en_US.csv')
35+
$this->returnValue(
36+
dirname(__DIR__) . '/Translation/Model/_files/Magento/design/Magento/theme/i18n/en_US.csv'
37+
)
3338
);
3439

35-
/** @var \Magento\Framework\View\Design\ThemeInterface $theme */
40+
/** @var \Magento\Framework\View\Design\ThemeInterface | PHPUnit_Framework_MockObject_MockObject $theme */
3641
$theme = $this->createMock(\Magento\Framework\View\Design\ThemeInterface::class);
37-
$theme->expects($this->any())->method('getId')->will($this->returnValue(10));
38-
39-
$viewFileSystem->expects($this->any())->method('getDesignTheme')->will($this->returnValue($theme));
42+
$theme->expects($this->any())->method('getThemePath')->will($this->returnValue('Magento/luma'));
4043

4144
/** @var \Magento\TestFramework\ObjectManager $objectManager */
4245
$objectManager = Bootstrap::getObjectManager();
@@ -55,7 +58,7 @@ protected function setUp()
5558
dirname(__DIR__) . '/Translation/Model/_files/Magento/Catalog/i18n'
5659
);
5760

58-
/** @var \Magento\Theme\Model\View\Design $designModel */
61+
/** @var \Magento\Theme\Model\View\Design | \PHPUnit_Framework_MockObject_MockObject $designModel */
5962
$designModel = $this->getMockBuilder(\Magento\Theme\Model\View\Design::class)
6063
->setMethods(['getDesignTheme'])
6164
->setConstructorArgs(
@@ -96,6 +99,9 @@ public function testLoadData()
9699
/**
97100
* @magentoCache all disabled
98101
* @dataProvider translateDataProvider
102+
* @param string $inputText
103+
* @param string $expectedTranslation
104+
* @throws Exception\LocalizedException
99105
*/
100106
public function testTranslate($inputText, $expectedTranslation)
101107
{
@@ -111,9 +117,26 @@ public function translateDataProvider()
111117
{
112118
return [
113119
['', ''],
114-
['Text with different translation on different modules', 'Text translation that was last loaded'],
115-
['text_with_no_translation', 'text_with_no_translation'],
116-
['Design value to translate', 'Design translated value']
120+
[
121+
'Theme phrase will be translated',
122+
'Theme phrase is translated',
123+
],
124+
[
125+
'Phrase in Magento_Store module that doesn\'t need translation',
126+
'Phrase in Magento_Store module that doesn\'t need translation',
127+
],
128+
[
129+
'Phrase in Magento_Catalog module that doesn\'t need translation',
130+
'Phrase in Magento_Catalog module that doesn\'t need translation',
131+
],
132+
[
133+
'Magento_Store module phrase will be override by theme translation',
134+
'Magento_Store module phrase is override by theme translation',
135+
],
136+
[
137+
'Magento_Catalog module phrase will be override by theme translation',
138+
'Magento_Catalog module phrase is override by theme translation',
139+
],
117140
];
118141
}
119142
}
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"

0 commit comments

Comments
 (0)