From 801e90d9a3979a8159cee4abfae535b2965b2638 Mon Sep 17 00:00:00 2001 From: Navarr Barnier Date: Wed, 7 Apr 2021 13:01:10 -0400 Subject: [PATCH 1/2] Improve JS Translation DataProviderTest Currently, DataProviderTest checks that the entire dictionary matches only its translations. When third party extensions are installed that have translation files, this test may fail. This fix ensures that it is only testing the task it is performing. --- .../Translation/Model/Js/DataProviderTest.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Translation/Model/Js/DataProviderTest.php b/dev/tests/integration/testsuite/Magento/Translation/Model/Js/DataProviderTest.php index e1795dafd38a7..278b2f757b9ea 100644 --- a/dev/tests/integration/testsuite/Magento/Translation/Model/Js/DataProviderTest.php +++ b/dev/tests/integration/testsuite/Magento/Translation/Model/Js/DataProviderTest.php @@ -18,6 +18,10 @@ */ class DataProviderTest extends TestCase { + private const STRING_TO_TRANSLATE = 'Proceed to Checkout'; + + private const STRING_TRANSLATION = 'Proceed to Checkout - Translated'; + /** * @var StringUtils */ @@ -52,12 +56,11 @@ protected function setUp(): void */ public function testGetData() { - $expectedDictionary = ['Proceed to Checkout' => 'Proceed to Checkout - Translated']; - - $this->stringUtils->saveTranslate('Proceed to Checkout', 'Proceed to Checkout - Translated'); + $this->stringUtils->saveTranslate(static::STRING_TO_TRANSLATE, static::STRING_TRANSLATION); $this->translate->setLocale('en_US')->loadData('frontend', true); $dictionary = $this->translationDataProvider->getData('Magento/luma'); - $this->assertEquals($expectedDictionary, $dictionary); + $this->assertArrayHasKey(static::STRING_TO_TRANSLATE, $dictionary); + $this->assertEquals(static::STRING_TRANSLATION, $dictionary[static::STRING_TO_TRANSLATE]); } /** @@ -66,7 +69,7 @@ public function testGetData() protected function tearDown(): void { try { - $this->stringUtils->deleteTranslate('Proceed to Checkout'); + $this->stringUtils->deleteTranslate(static::STRING_TO_TRANSLATE); } catch (NoSuchEntityException $exception) { // translate already deleted } From ef9539a039375c9ac5bcd4b0c44d261d27f651d5 Mon Sep 17 00:00:00 2001 From: Navarr Barnier Date: Thu, 8 Apr 2021 10:26:30 -0400 Subject: [PATCH 2/2] Use `self` instead of `static` for referring to constants Co-authored-by: Eduard Chitoraga --- .../Magento/Translation/Model/Js/DataProviderTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Translation/Model/Js/DataProviderTest.php b/dev/tests/integration/testsuite/Magento/Translation/Model/Js/DataProviderTest.php index 278b2f757b9ea..5611c63eb9d7e 100644 --- a/dev/tests/integration/testsuite/Magento/Translation/Model/Js/DataProviderTest.php +++ b/dev/tests/integration/testsuite/Magento/Translation/Model/Js/DataProviderTest.php @@ -56,11 +56,11 @@ protected function setUp(): void */ public function testGetData() { - $this->stringUtils->saveTranslate(static::STRING_TO_TRANSLATE, static::STRING_TRANSLATION); + $this->stringUtils->saveTranslate(self::STRING_TO_TRANSLATE, self::STRING_TRANSLATION); $this->translate->setLocale('en_US')->loadData('frontend', true); $dictionary = $this->translationDataProvider->getData('Magento/luma'); - $this->assertArrayHasKey(static::STRING_TO_TRANSLATE, $dictionary); - $this->assertEquals(static::STRING_TRANSLATION, $dictionary[static::STRING_TO_TRANSLATE]); + $this->assertArrayHasKey(self::STRING_TO_TRANSLATE, $dictionary); + $this->assertEquals(self::STRING_TRANSLATION, $dictionary[self::STRING_TO_TRANSLATE]); } /** @@ -69,7 +69,7 @@ public function testGetData() protected function tearDown(): void { try { - $this->stringUtils->deleteTranslate(static::STRING_TO_TRANSLATE); + $this->stringUtils->deleteTranslate(self::STRING_TO_TRANSLATE); } catch (NoSuchEntityException $exception) { // translate already deleted }