From fbe667ecd9134ce3088aabf3aa32051ba89161b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCnch?= Date: Thu, 18 Jan 2018 09:58:08 +0100 Subject: [PATCH 1/2] Translate attribute label with default translation helper function Adds the translation function to customer attribute labels in Magento admin. This gives a chance to translate a label in the locale of a backend user. --- .../DataProvider/Product/Form/Modifier/EavTest.php | 14 +++++++------- .../Ui/DataProvider/Product/Form/Modifier/Eav.php | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php index b91a7e1fa99fd..7f3427c356c04 100755 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php @@ -187,7 +187,7 @@ class EavTest extends AbstractModifierTest * @var ObjectManager */ protected $objectManager; - + /** * @var Eav */ @@ -324,7 +324,7 @@ protected function setUp() $this->eavAttributeMock->expects($this->any()) ->method('load') ->willReturnSelf(); - + $this->eav =$this->getModel(); $this->objectManager->setBackwardCompatibleProperty( $this->eav, @@ -561,7 +561,7 @@ private function defaultNullProdNotNewAndRequired() 'required' => true, 'notice' => null, 'default' => null, - 'label' => null, + 'label' => new Phrase(''), 'code' => 'code', 'source' => 'product-details', 'scopeLabel' => '', @@ -588,7 +588,7 @@ private function defaultNullProdNotNewAndNotRequired() 'required' => false, 'notice' => null, 'default' => null, - 'label' => null, + 'label' => new Phrase(''), 'code' => 'code', 'source' => 'product-details', 'scopeLabel' => '', @@ -615,7 +615,7 @@ private function defaultNullProdNewAndNotRequired() 'required' => false, 'notice' => null, 'default' => 'required_value', - 'label' => null, + 'label' => new Phrase(''), 'code' => 'code', 'source' => 'product-details', 'scopeLabel' => '', @@ -642,7 +642,7 @@ private function defaultNullProdNewAndRequired() 'required' => false, 'notice' => null, 'default' => 'required_value', - 'label' => null, + 'label' => new Phrase(''), 'code' => 'code', 'source' => 'product-details', 'scopeLabel' => '', @@ -669,7 +669,7 @@ private function defaultNullProdNewAndRequiredAndFilledNotice() 'required' => false, 'notice' => __('example notice'), 'default' => 'required_value', - 'label' => null, + 'label' => new Phrase(''), 'code' => 'code', 'source' => 'product-details', 'scopeLabel' => '', diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php index 7b18bfcd4ec9c..ee6d483c9d4fb 100755 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php @@ -580,7 +580,7 @@ public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupC 'required' => $attribute->getIsRequired(), 'notice' => $attribute->getNote() === null ? null : __($attribute->getNote()), 'default' => (!$this->isProductExists()) ? $attribute->getDefaultValue() : null, - 'label' => $attribute->getDefaultFrontendLabel(), + 'label' => __($attribute->getDefaultFrontendLabel()), 'code' => $attribute->getAttributeCode(), 'source' => $groupCode, 'scopeLabel' => $this->getScopeLabel($attribute), From 63c5459e56a7ad412c985544f863d2f290820f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mu=CC=88nch?= Date: Thu, 18 Jan 2018 15:25:41 +0100 Subject: [PATCH 2/2] Fix for missing context reset of ComponentRegistrar This test tries to setup a test environment with two modules and one theme to test the generator. During the test run, the test environment and the complete module stack is processed by the generator. So the test takes on my machine 25 seconds with xdebug enabled. After resetting the registrar the complete test runs in ~50ms with xdebug enabled. Without the reset ~12.000 files are scanned. With the reset only 5 files are scanned. This test is not a unit test. It is an integration test. --- .../DataProvider/Product/Form/Modifier/EavTest.php | 14 +++++++++----- .../Setup/Module/I18n/Dictionary/GeneratorTest.php | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php index 7f3427c356c04..a29379647b9e1 100755 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php @@ -490,6 +490,10 @@ public function testSetupAttributeMetaDefaultAttribute($productId, $productRequi ->method('getNote') ->willReturn($note); + $this->productAttributeMock->expects($this->any()) + ->method('getDefaultFrontendLabel') + ->willReturn(new Phrase('mylabel')); + $attributeMock = $this->getMockBuilder(AttributeInterface::class) ->setMethods(['getValue']) ->disableOriginalConstructor() @@ -561,7 +565,7 @@ private function defaultNullProdNotNewAndRequired() 'required' => true, 'notice' => null, 'default' => null, - 'label' => new Phrase(''), + 'label' => new Phrase('mylabel'), 'code' => 'code', 'source' => 'product-details', 'scopeLabel' => '', @@ -588,7 +592,7 @@ private function defaultNullProdNotNewAndNotRequired() 'required' => false, 'notice' => null, 'default' => null, - 'label' => new Phrase(''), + 'label' => new Phrase('mylabel'), 'code' => 'code', 'source' => 'product-details', 'scopeLabel' => '', @@ -615,7 +619,7 @@ private function defaultNullProdNewAndNotRequired() 'required' => false, 'notice' => null, 'default' => 'required_value', - 'label' => new Phrase(''), + 'label' => new Phrase('mylabel'), 'code' => 'code', 'source' => 'product-details', 'scopeLabel' => '', @@ -642,7 +646,7 @@ private function defaultNullProdNewAndRequired() 'required' => false, 'notice' => null, 'default' => 'required_value', - 'label' => new Phrase(''), + 'label' => new Phrase('mylabel'), 'code' => 'code', 'source' => 'product-details', 'scopeLabel' => '', @@ -669,7 +673,7 @@ private function defaultNullProdNewAndRequiredAndFilledNotice() 'required' => false, 'notice' => __('example notice'), 'default' => 'required_value', - 'label' => new Phrase(''), + 'label' => new Phrase('mylabel'), 'code' => 'code', 'source' => 'product-details', 'scopeLabel' => '', diff --git a/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Dictionary/GeneratorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Dictionary/GeneratorTest.php index 7bcdb3d9fce0d..5b486f4d3bd2c 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Dictionary/GeneratorTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Dictionary/GeneratorTest.php @@ -6,6 +6,7 @@ namespace Magento\Setup\Module\I18n\Dictionary; use Magento\Framework\Component\ComponentRegistrar; +use Magento\Setup\Module\I18n\Dictionary\Generator; use Magento\Setup\Module\I18n\ServiceLocator; class GeneratorTest extends \PHPUnit\Framework\TestCase @@ -46,6 +47,7 @@ protected function setUp() $paths = $reflection->getProperty('paths'); $paths->setAccessible(true); $this->backupRegistrar = $paths->getValue(); + $paths->setValue(['module' => [], 'theme' => []]); $paths->setAccessible(false); $this->testDir = realpath(__DIR__ . '/_files');