Skip to content

Commit 29f6844

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-70599-V2' into EPAM-PR-53
2 parents 9f0473d + 61741bc commit 29f6844

File tree

9 files changed

+212
-5
lines changed

9 files changed

+212
-5
lines changed

app/code/Magento/Bundle/Test/Mftf/Test/AdminDeleteBundleDynamicProductTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<severity value="CRITICAL"/>
1717
<testCaseId value="MC-11016"/>
1818
<group value="mtf_migrated"/>
19+
<skip>
20+
<issueId value="MC-16393"/>
21+
</skip>
1922
</annotations>
2023
<before>
2124
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>

app/code/Magento/Checkout/Test/Mftf/Test/StorefrontAddBundleDynamicProductToShoppingCartTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<testCaseId value="MC-14715"/>
1616
<severity value="CRITICAL"/>
1717
<group value="mtf_migrated"/>
18+
<skip>
19+
<issueId value="MC-16269"/>
20+
</skip>
1821
</annotations>
1922

2023
<before>

app/code/Magento/Checkout/Test/Mftf/Test/StorefrontAddBundleDynamicProductToShoppingCartWithDisableMiniCartSidebarTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<testCaseId value="MC-14719"/>
1616
<severity value="CRITICAL"/>
1717
<group value="mtf_migrated"/>
18+
<skip>
19+
<issueId value="MC-16392"/>
20+
</skip>
1821
</annotations>
1922

2023
<before>

app/code/Magento/Checkout/Test/Mftf/Test/StorefrontAddGroupedProductToShoppingCartTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<testCaseId value="MC-14718"/>
1616
<severity value="CRITICAL"/>
1717
<group value="mtf_migrated"/>
18+
<skip>
19+
<issueId value="MC-16324"/>
20+
</skip>
1821
</annotations>
1922

2023
<before>

app/code/Magento/Checkout/Test/Mftf/Test/StorefrontAddTwoBundleMultiSelectOptionsToTheShoppingCartTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<testCaseId value="MC-14728"/>
1616
<severity value="CRITICAL"/>
1717
<group value="mtf_migrated"/>
18+
<skip>
19+
<issueId value="MC-16264"/>
20+
</skip>
1821
</annotations>
1922

2023
<before>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Translation\Model\Js;
79

810
use Magento\Framework\App\AreaList;
@@ -92,6 +94,6 @@ public function translate($content)
9294
*/
9395
protected function replaceCallback($matches)
9496
{
95-
return '"' . __($matches[1]) . '"';
97+
return '\'' . __($matches['translate']) . '\'';
9698
}
9799
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Translation\Test\Unit\Model\Js;
79

810
use Magento\Translation\Model\Js\PreProcessor;
911
use Magento\Translation\Model\Js\Config;
1012
use Magento\Framework\App\AreaList;
1113
use Magento\Framework\TranslateInterface;
1214

15+
/**
16+
* Class with unit tests for PreProcessor
17+
*/
1318
class PreProcessorTest extends \PHPUnit\Framework\TestCase
1419
{
1520
/**
@@ -46,8 +51,8 @@ public function testGetData()
4651
$chain = $this->createMock(\Magento\Framework\View\Asset\PreProcessor\Chain::class);
4752
$context = $this->createMock(\Magento\Framework\View\Asset\File\FallbackContext::class);
4853
$originalContent = 'content$.mage.__("hello1")content';
49-
$translatedContent = 'content"hello1"content';
50-
$patterns = ['~\$\.mage\.__\([\'|\"](.+?)[\'|\"]\)~'];
54+
$translatedContent = 'content\'hello1\'content';
55+
$patterns = ["~(?:\\$|jQuery)\\.mage\\.__\\((?s)[^'\\\")]*?(['\\\"])(?P<translate>.+?)(?<!\\\\)\\1(?s).*?\\)~"];
5156
$areaCode = 'adminhtml';
5257
$area = $this->createMock(\Magento\Framework\App\Area::class);
5358

app/code/Magento/Translation/etc/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
<argument name="patterns" xsi:type="array">
6666
<item name="i18n_translation" xsi:type="string"><![CDATA[~i18n\:\s*(["'])(.*?)(?<!\\)\1~]]></item>
6767
<item name="translate_wrapping" xsi:type="string"><![CDATA[~translate\=("')([^\'].*?)\'\"~]]></item>
68-
<item name="mage_translation_widget" xsi:type="string"><![CDATA[~(?:\$|jQuery)\.mage\.__\((?s)[^'"]*?(['"])(.+?)(?<!\\)\1(?s).*?\)~]]></item>
69-
<item name="mage_translation_static" xsi:type="string"><![CDATA[~\$t\((?s)[^'"]*?(["'])(.+?)\1(?s).*?\)~]]></item>
68+
<item name="mage_translation_widget" xsi:type="string"><![CDATA[~(?s)(?:\$|jQuery)\.mage\.__\(\s*(['"])(?<translate>.+?)(?<!\\)\1\s*(*SKIP)\)\s*(?s)~]]></item>
69+
<item name="mage_translation_static" xsi:type="string"><![CDATA[~(?s)\$t\(\s*(['"])(?<translate>.+?)(?<!\\)\1\s*(*SKIP)\)(?s)~]]></item>
7070
<item name="translate_args" xsi:type="string"><![CDATA[~translate args\=("|'|"')([^\'].*?)('"|'|")~]]></item>
7171
</argument>
7272
</arguments>
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Translation\Model\Js;
9+
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use Magento\Framework\View\FileSystem;
12+
use Magento\TestFramework\Helper\CacheCleaner;
13+
use Magento\Framework\Translate;
14+
use Magento\Framework\App\AreaList;
15+
use Magento\Framework\Phrase;
16+
use Magento\Framework\Phrase\RendererInterface;
17+
18+
/**
19+
* Class for testing translation.
20+
*/
21+
class PreProcessorTest extends \PHPUnit\Framework\TestCase
22+
{
23+
/**
24+
* @var PreProcessor
25+
*/
26+
private $model;
27+
28+
/**
29+
* @var RendererInterface
30+
*/
31+
private $origRenderer;
32+
33+
/**
34+
* Set up.
35+
*/
36+
protected function setUp()
37+
{
38+
$viewFileSystem = $this->createPartialMock(FileSystem::class, ['getLocaleFileName']);
39+
$viewFileSystem->expects($this->any())->method('getLocaleFileName')
40+
->willReturn(
41+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
42+
dirname(__DIR__) . '/_files/Magento/Store/i18n/en_AU.csv'
43+
);
44+
45+
$objectManager = Bootstrap::getObjectManager();
46+
$objectManager->addSharedInstance($viewFileSystem, FileSystem::class);
47+
$translator = $objectManager->create(Translate::class);
48+
$objectManager->addSharedInstance($translator, Translate::class);
49+
$areaList = $this->getMockBuilder(AreaList::class)->disableOriginalConstructor()->getMock();
50+
$this->origRenderer = Phrase::getRenderer();
51+
Phrase::setRenderer(
52+
$objectManager->get(RendererInterface::class)
53+
);
54+
55+
$this->model = $objectManager->create(
56+
PreProcessor::class,
57+
[
58+
'translate' => $translator,
59+
'areaList' => $areaList
60+
]
61+
);
62+
63+
$translator->setLocale('en_AU');
64+
$translator->loadData();
65+
}
66+
67+
/**
68+
* Tear down.
69+
*/
70+
protected function tearDown()
71+
{
72+
Phrase::setRenderer($this->origRenderer);
73+
}
74+
75+
/**
76+
* Test for backend translation strategy.
77+
*
78+
* @param string $content
79+
* @param string $translation
80+
* @return void
81+
* @dataProvider contentForTranslateDataProvider
82+
*/
83+
public function testProcess(string $content, string $translation)
84+
{
85+
CacheCleaner::cleanAll();
86+
$this->assertEquals($translation, $this->model->translate($content));
87+
}
88+
89+
/**
90+
* Data provider for translation.
91+
*
92+
* @return array
93+
*/
94+
public function contentForTranslateDataProvider()
95+
{
96+
return [
97+
'previousError' => [
98+
'setTranslateProp = function (el, original) {
99+
var location = $(el).prop(\'tagName\').toLowerCase(),
100+
translated = $.mage.__(original),
101+
translationData = {
102+
shown: translated,
103+
translated: translated,
104+
original: original
105+
},
106+
translateAttr = composeTranslateAttr(translationData, location);
107+
108+
$(el).attr(\'data-translate\', translateAttr);
109+
110+
setText(el, translationData.shown);
111+
},',
112+
'setTranslateProp = function (el, original) {
113+
var location = $(el).prop(\'tagName\').toLowerCase(),
114+
translated = $.mage.__(original),
115+
translationData = {
116+
shown: translated,
117+
translated: translated,
118+
original: original
119+
},
120+
translateAttr = composeTranslateAttr(translationData, location);
121+
122+
$(el).attr(\'data-translate\', translateAttr);
123+
124+
setText(el, translationData.shown);
125+
},'
126+
],
127+
'checkTranslationWithWhiteSpaces' => [
128+
<<<i18n
129+
title: $.mage.__(
130+
'Original value for Magento_Store module'
131+
),
132+
title: \$t(
133+
'Original value for Magento_Store module'
134+
);
135+
i18n
136+
,
137+
<<<i18n
138+
title: 'Translated value for Magento_Store module in en_AU',
139+
title: 'Translated value for Magento_Store module in en_AU';
140+
i18n
141+
],
142+
'checkTranslationWithReplace' => [
143+
<<<i18n
144+
$.mage.__('The maximum you may purchase is %1.').replace('%1', params.maxAllowed);
145+
\$t('The maximum you may purchase is %1.').replace('%1', params.maxAllowed);
146+
i18n
147+
,
148+
<<<i18n
149+
'The maximum you may purchase is %1.'.replace('%1', params.maxAllowed);
150+
'The maximum you may purchase is %1.'.replace('%1', params.maxAllowed);
151+
i18n
152+
],
153+
'checkAvoidingMatching' => [
154+
<<<i18n
155+
\$t('Payment ' + this.getTitle() + ' can\'t be initialized')
156+
\$t(
157+
'Set unique country-state combinations within the same fixed product tax. ' +
158+
'Verify the combinations and try again.'
159+
)
160+
i18n
161+
,
162+
<<<i18n
163+
\$t('Payment ' + this.getTitle() + ' can\'t be initialized')
164+
\$t(
165+
'Set unique country-state combinations within the same fixed product tax. ' +
166+
'Verify the combinations and try again.'
167+
)
168+
i18n
169+
],
170+
'checkAvoidMatchingPhtml' => [
171+
<<<i18n
172+
globalMessageList.addErrorMessage({
173+
message: \$t(<?= /* @noEscape */ json_encode(\$params['error_msg'])?>)
174+
});
175+
i18n
176+
,
177+
<<<i18n
178+
globalMessageList.addErrorMessage({
179+
message: \$t(<?= /* @noEscape */ json_encode(\$params['error_msg'])?>)
180+
});
181+
i18n
182+
]
183+
];
184+
}
185+
}

0 commit comments

Comments
 (0)