-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-71201: Improved calculating version hash for the js-translati…
…on.json file. #10378
- Loading branch information
Showing
6 changed files
with
170 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Translation\Model\Inline; | ||
|
||
use Magento\Framework\Translate\ResourceInterface; | ||
use Magento\Framework\Locale\ResolverInterface; | ||
use Magento\Framework\Serialize\Serializer\Json; | ||
|
||
/** | ||
* Prepares content of inline translations file. | ||
*/ | ||
class File | ||
{ | ||
/** | ||
* @var ResourceInterface | ||
*/ | ||
private $translateResource; | ||
|
||
/** | ||
* @var ResolverInterface | ||
*/ | ||
private $localeResolver; | ||
|
||
/** | ||
* @var Json | ||
*/ | ||
private $jsonSerializer; | ||
|
||
/** | ||
* Initialize dependencies | ||
* | ||
* @param ResourceInterface $translateResource | ||
* @param ResolverInterface $localeResolver | ||
* @param Json $jsonSerializer | ||
*/ | ||
public function __construct( | ||
ResourceInterface $translateResource, | ||
ResolverInterface $localeResolver, | ||
Json $jsonSerializer | ||
) { | ||
$this->translateResource = $translateResource; | ||
$this->localeResolver = $localeResolver; | ||
$this->jsonSerializer = $jsonSerializer; | ||
} | ||
|
||
/** | ||
* Generate translation file content for the current locale. | ||
* | ||
* @return string | ||
*/ | ||
public function getTranslationFileContent() | ||
{ | ||
$translations = $this->translateResource->getTranslationArray(null, $this->localeResolver->getLocale()); | ||
$translations = $this->jsonSerializer->serialize($translations); | ||
return $translations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/code/Magento/Translation/Test/Unit/Model/Inline/FileTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Translation\Test\Unit\Model\Inline; | ||
|
||
class FileTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var \Magento\Translation\Model\Inline\File | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var \Magento\Framework\Translate\ResourceInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $translateResourceMock; | ||
|
||
/** | ||
* @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $localeResolverMock; | ||
|
||
/** | ||
* @var \Magento\Framework\Serialize\Serializer\Json | ||
*/ | ||
private $jsonSerializer; | ||
|
||
protected function setUp() | ||
{ | ||
$this->translateResourceMock = $this->getMockBuilder(\Magento\Framework\Translate\ResourceInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->localeResolverMock = $this->getMockBuilder(\Magento\Framework\Locale\ResolverInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->jsonSerializer = new \Magento\Framework\Serialize\Serializer\Json(); | ||
|
||
$this->model = new \Magento\Translation\Model\Inline\File( | ||
$this->translateResourceMock, | ||
$this->localeResolverMock, | ||
$this->jsonSerializer | ||
); | ||
} | ||
|
||
public function testGetTranslationFileContent() | ||
{ | ||
$translations = ['string' => 'translatedString']; | ||
|
||
$this->localeResolverMock->expects($this->atLeastOnce())->method('getLocale')->willReturn('en_US'); | ||
$this->translateResourceMock->expects($this->atLeastOnce())->method('getTranslationArray') | ||
->willReturn($translations); | ||
|
||
$this->assertEquals( | ||
$this->jsonSerializer->serialize($translations), | ||
$this->model->getTranslationFileContent() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters