Skip to content

Commit 8efacdf

Browse files
merge magento/2.4-develop into magento-performance/MC-33086-catalog-event
2 parents 1427d53 + 60fb8c2 commit 8efacdf

File tree

12 files changed

+285
-48
lines changed

12 files changed

+285
-48
lines changed

app/code/Magento/Translation/Model/FileManager.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
use Magento\Framework\App\Filesystem\DirectoryList;
1111
use Magento\Framework\Filesystem\Driver\File;
12+
use Magento\Framework\Serialize\Serializer\Json;
1213
use Magento\Framework\View\Asset\Repository;
1314

1415
/**
15-
* A service for handling Translation config files
16+
* A service for handling Translation config files.
1617
*/
1718
class FileManager
1819
{
@@ -36,23 +37,31 @@ class FileManager
3637
*/
3738
private $driverFile;
3839

40+
/**
41+
* @var Json
42+
*/
43+
private $serializer;
44+
3945
/**
4046
* @param Repository $assetRepo
4147
* @param DirectoryList $directoryList
4248
* @param File $driverFile
49+
* @param Json $serializer
4350
*/
4451
public function __construct(
4552
Repository $assetRepo,
4653
DirectoryList $directoryList,
47-
File $driverFile
54+
File $driverFile,
55+
Json $serializer
4856
) {
4957
$this->assetRepo = $assetRepo;
5058
$this->directoryList = $directoryList;
5159
$this->driverFile = $driverFile;
60+
$this->serializer = $serializer;
5261
}
5362

5463
/**
55-
* Create a view asset representing the requirejs config.config property for inline translation
64+
* Create a view asset representing the RequireJS config.config property for inline translation.
5665
*
5766
* @return \Magento\Framework\View\Asset\File
5867
*/
@@ -65,7 +74,7 @@ public function createTranslateConfigAsset()
6574
}
6675

6776
/**
68-
* Gets current js-translation.json timestamp
77+
* Get current js-translation.json timestamp.
6978
*
7079
* @return string|void
7180
*/
@@ -81,7 +90,7 @@ public function getTranslationFileTimestamp()
8190
}
8291

8392
/**
84-
* Retrieve full path for translation file
93+
* Retrieve full path for translation file.
8594
*
8695
* @return string
8796
*/
@@ -95,7 +104,7 @@ protected function getTranslationFileFullPath()
95104
}
96105

97106
/**
98-
* Retrieve path for translation file
107+
* Retrieve path for translation file.
99108
*
100109
* @return string
101110
*/
@@ -105,10 +114,9 @@ public function getTranslationFilePath()
105114
}
106115

107116
/**
108-
* Update translation file with content
109-
*
110-
* @param string $content
117+
* Update translation file with content.
111118
*
119+
* @param array $content
112120
* @return void
113121
*/
114122
public function updateTranslationFileContent($content)
@@ -119,9 +127,18 @@ public function updateTranslationFileContent($content)
119127

120128
if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) {
121129
$this->driverFile->createDirectory($translationDir);
130+
$originalFileContent = '';
131+
} else {
132+
$originalFileContent = $this->driverFile->fileGetContents($this->getTranslationFileFullPath());
122133
}
123-
124-
$this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content);
134+
$originalFileTranslationPhrases = !empty($originalFileContent)
135+
? $this->serializer->unserialize($originalFileContent)
136+
: [];
137+
$updatedTranslationPhrases = array_merge($originalFileTranslationPhrases, $content);
138+
$this->driverFile->filePutContents(
139+
$this->getTranslationFileFullPath(),
140+
$this->serializer->serialize($updatedTranslationPhrases)
141+
);
125142
}
126143

127144
/**

app/code/Magento/Translation/Model/Inline/CacheManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@ public function __construct(
5252
}
5353

5454
/**
55-
* Clears cache and updates translations file
55+
* Clear cache and update translations file.
5656
*
5757
* @return array
5858
*/
5959
public function updateAndGetTranslations()
6060
{
6161
$this->eventManager->dispatch('adminhtml_cache_flush_system');
6262
$translations = $this->translateResource->getTranslationArray(null, $this->localeResolver->getLocale());
63-
$this->fileManager->updateTranslationFileContent(json_encode($translations));
63+
$this->fileManager->updateTranslationFileContent($translations);
64+
6465
return $translations;
6566
}
6667
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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\Inline;
9+
10+
use Magento\Framework\Phrase\RendererInterface;
11+
12+
/**
13+
* Inline Translate phrase renderer for DataProvider.
14+
*/
15+
class Renderer implements RendererInterface
16+
{
17+
/**
18+
* @inheritdoc
19+
*/
20+
public function render(array $source, array $arguments)
21+
{
22+
return end($source);
23+
}
24+
}

app/code/Magento/Translation/Test/Mftf/ActionGroup/AdminTranslateElementActionGroup.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11-
<actionGroup name="AdminTranslateElementActionGroup">
11+
<actionGroup name="AdminTranslateElementActionGroup" deprecated="Avoid using super-ActionGroups. Use StorefrontOpenInlineTranslationPopupActionGroup, StorefrontFillCustomTranslationFieldActionGroup and StorefrontSubmitInlineTranslationFormActionGroup">
1212
<arguments>
1313
<argument name="elementSelector" type="string"/>
1414
<argument name="translateText" type="string"/>
1515
</arguments>
16-
16+
1717
<executeJS function="jQuery('{{elementSelector}}').mousemove()" stepKey="moveMouseOverSelector"/>
1818
<executeJS function="jQuery('{{InlineTranslationModeSection.bookIcon}}').click()" stepKey="clickBookIcon"/>
1919
<waitForPageLoad stepKey="waitForLoadWindow"/>
@@ -23,4 +23,4 @@
2323
<fillField userInput="{{translateText}}" selector="{{InlineTranslationModeSection.inputCustomTranslate}}" stepKey="addTranslate"/>
2424
<click selector="{{InlineTranslationModeSection.buttonSubmit}}" stepKey="clickSubmitButton"/>
2525
</actionGroup>
26-
</actionGroups>
26+
</actionGroups>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontFillCustomTranslationFieldActionGroup">
12+
<annotations>
13+
<description>Fill the field in the Inline Translation form by provided text on Storefront.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="translateText" type="string" defaultValue="Translated"/>
17+
</arguments>
18+
19+
<clearField selector="{{InlineTranslationModeSection.inputCustomTranslate}}" stepKey="clearCustomTranslateField"/>
20+
<fillField selector="{{InlineTranslationModeSection.inputCustomTranslate}}" userInput="{{translateText}}" stepKey="fillCustomTranslateField"/>
21+
</actionGroup>
22+
</actionGroups>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontOpenInlineTranslationPopupActionGroup">
12+
<annotations>
13+
<description>Open the Inline Translation popup for provided element on Storefront.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="elementSelector" type="string" defaultValue="{{StorefrontHeaderSection.welcomeMessage}}"/>
17+
</arguments>
18+
19+
<executeJS function="jQuery('{{elementSelector}}').mousemove()" stepKey="moveMouseOverSelector"/>
20+
<executeJS function="jQuery('{{InlineTranslationModeSection.bookIcon}}').click()" stepKey="clickBookIcon"/>
21+
<waitForElementVisible selector="{{InlineTranslationModeSection.popUpTranslate}}" stepKey="waitForTranslationPopupAppear"/>
22+
<seeElement selector="{{InlineTranslationModeSection.popUpTranslate}}" stepKey="seeTranslateForm"/>
23+
</actionGroup>
24+
</actionGroups>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontSubmitInlineTranslationFormActionGroup">
12+
<annotations>
13+
<description>Click on the Inline Translation form submit button on Storefront.</description>
14+
</annotations>
15+
16+
<click selector="{{InlineTranslationModeSection.buttonSubmit}}" stepKey="clickSubmitButton"/>
17+
<waitForElementNotVisible selector="{{InlineTranslationModeSection.popUpTranslate}}" stepKey="waitForTranslationPopupDisappear"/>
18+
<dontSeeElement selector="{{InlineTranslationModeSection.popUpTranslate}}" stepKey="dontSeeTranslateForm"/>
19+
</actionGroup>
20+
</actionGroups>

app/code/Magento/Translation/Test/Mftf/Test/StorefrontButtonsInlineTranslationTest.xml

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,52 @@
1212
<annotations>
1313
<features value="Translation"/>
1414
<stories value="Inline Translation"/>
15-
<title value="[Inline Translation] Buttons inline translation"/>
16-
<description value="[Inline Translation] Buttons inline translation"/>
15+
<title value="Buttons inline translation"/>
16+
<description value="A merchant should be able to translate buttons by an inline translation tool"/>
1717
<severity value="CRITICAL"/>
18-
<testCaseId value="MC-12735"/>
18+
<testCaseId value="MC-27118"/>
19+
<useCaseId value="MC-24186"/>
1920
<group value="translation"/>
20-
<skip>
21-
<issueId value="MC-20127"/>
22-
</skip>
21+
<group value="catalog"/>
22+
<group value="developer_mode_only"/>
2323
</annotations>
2424
<before>
25+
<!-- Enable Translate Inline For Storefront -->
26+
<magentoCLI command="config:set {{EnableTranslateInlineForStorefront.path}} {{EnableTranslateInlineForStorefront.value}}" stepKey="enableTranslateInlineForStorefront"/>
27+
<!-- Create Category -->
28+
<createData entity="ApiCategory" stepKey="createCategory"/>
2529
<!-- Create Simple Product -->
26-
<createData entity="SimpleProduct2" stepKey="createProduct"/>
27-
<!-- Enable Translate Inline For Storefront-->
28-
<magentoCLI
29-
command="config:set {{EnableTranslateInlineForStorefront.path}} {{EnableTranslateInlineForStorefront.value}}"
30-
stepKey="enableTranslateInlineForStorefront"/>
31-
<!-- Set developer mode -->
32-
<magentoCLI command="deploy:mode:set developer" stepKey="setDeveloperMode"/>
33-
<magentoCLI command="cache:flush" stepKey="flushCache"/>
30+
<createData entity="ApiSimpleProduct" stepKey="createProduct">
31+
<requiredEntity createDataKey="createCategory"/>
32+
</createData>
3433
</before>
3534
<after>
3635
<!-- Disable Translate Inline For Storefront -->
37-
<magentoCLI
38-
command="config:set {{DisableTranslateInlineForStorefront.path}} {{DisableTranslateInlineForStorefront.value}}"
39-
stepKey="disableTranslateInlineForStorefront"/>
40-
<!-- Set production mode -->
41-
<magentoCLI command="deploy:mode:set production" stepKey="setProductionMode"/>
42-
36+
<magentoCLI command="config:set {{DisableTranslateInlineForStorefront.path}} {{DisableTranslateInlineForStorefront.value}}" stepKey="disableTranslateInlineForStorefront"/>
4337
<!-- Delete Simple Product -->
4438
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
39+
<!-- Delete Category -->
40+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
4541
</after>
4642

4743
<!-- Add product to cart on storefront -->
48-
<actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="addProductToCart">
49-
<argument name="product" value="$$createProduct$$"/>
44+
<amOnPage url="{{StorefrontCategoryPage.url($createCategory.custom_attributes[url_key]$)}}" stepKey="goToCategoryPage"/>
45+
<waitForPageLoad stepKey="waitForCategoryPageLoad"/>
46+
<actionGroup ref="StorefrontAddProductToCartFromCategoryActionGroup" stepKey="addProductToCart">
47+
<argument name="productName" value="$createProduct.name$"/>
5048
</actionGroup>
5149

52-
<!-- Click on cart button on the top -->
53-
<click selector="{{StorefrontMiniCartSection.show}}" stepKey="showMiniCart"/>
54-
55-
<!-- Small cart popup appeared. -->
56-
<waitForElementVisible selector="{{StorefrontMinicartSection.productName}}" stepKey="seeProductNameAppeared"/>
50+
<!-- Open Mini Cart -->
51+
<actionGroup ref="StorefrontOpenMiniCartActionGroup" stepKey="openMiniCart"/>
5752

5853
<!-- Check button "Proceed to Checkout". There must be red borders and "book" icons on labels that can be translated. -->
5954
<actionGroup ref="AssertElementInTranslateInlineModeActionGroup" stepKey="assertRedBordersAndBookIcon">
6055
<argument name="elementSelector" value="{{StorefrontMinicartSection.goToCheckout}}"/>
6156
</actionGroup>
6257

63-
<actionGroup ref="AdminTranslateElementActionGroup" stepKey="translateProceedToCheckoutButtonText">
58+
<!-- Open Inline Translation popup -->
59+
<actionGroup ref="StorefrontOpenInlineTranslationPopupActionGroup" stepKey="openInlineTranslationPopup">
6460
<argument name="elementSelector" value="{{StorefrontMinicartSection.goToCheckout}}"/>
65-
<argument name="translateText" value="Proceed to Checkout Translated"/>
6661
</actionGroup>
6762
</test>
6863
</tests>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@
4949
</argument>
5050
</arguments>
5151
</type>
52+
<virtualType name="dataProviderCompositeRenderer" type="Magento\Framework\Phrase\Renderer\Composite">
53+
<arguments>
54+
<argument name="renderers" xsi:type="array">
55+
<item name="inline" xsi:type="object">Magento\Translation\Model\Inline\Renderer</item>
56+
</argument>
57+
</arguments>
58+
</virtualType>
59+
<type name="Magento\Translation\Model\Js\DataProvider">
60+
<arguments>
61+
<argument name="translate" xsi:type="object">dataProviderCompositeRenderer</argument>
62+
</arguments>
63+
</type>
5264
<type name="Magento\Framework\Phrase\Renderer\Translate">
5365
<arguments>
5466
<argument name="translator" xsi:type="object">Magento\Framework\Translate</argument>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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\Framework\Api;
9+
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
12+
/**
13+
* Test of building the Data Object
14+
*/
15+
class SortOrderBuilderTest extends \PHPUnit\Framework\TestCase
16+
{
17+
/**
18+
* @var SortOrderBuilder
19+
*/
20+
private $interceptedBuilder;
21+
22+
/**
23+
* @inheritdoc
24+
*/
25+
protected function setUp()
26+
{
27+
parent::setUp();
28+
$this->interceptedBuilder = Bootstrap::getObjectManager()->get(SortOrderBuilder::class . '\Interceptor');
29+
}
30+
31+
/**
32+
* Test Builder successfully creates object when Interceptor instance is provided.
33+
*
34+
* @return void
35+
*/
36+
public function testCreate(): void
37+
{
38+
$this->assertEquals(SortOrder::class, get_class($this->interceptedBuilder->create()));
39+
}
40+
}

0 commit comments

Comments
 (0)