Beispiel #1
0
 /**
  * Clears cache and updates translations file
  *
  * @return array
  */
 public function updateAndGetTranslations()
 {
     $this->eventManager->dispatch('adminhtml_cache_flush_system');
     $translations = $this->translateResource->getTranslationArray(null, $this->localeResolver->getLocale());
     $this->fileManager->updateTranslationFileContent(json_encode($translations));
     return $translations;
 }
Beispiel #2
0
 public function testGetTranslationFilePath()
 {
     $path = 'path';
     $contextMock = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\ContextInterface', [], '', true, true, true, ['getPath']);
     $this->assetRepoMock->expects($this->atLeastOnce())->method('getStaticViewFileContext')->willReturn($contextMock);
     $contextMock->expects($this->atLeastOnce())->method('getPath')->willReturn($path);
     $this->assertEquals($path, $this->model->getTranslationFilePath());
 }
Beispiel #3
0
 /**
  * Include RequireJs inline translation configuration as an asset on the page
  * @return void
  */
 private function addInlineTranslationConfig()
 {
     if ($this->inline->isAllowed()) {
         $after = RequireJsConfig::REQUIRE_JS_FILE_NAME;
         $tConfig = $this->fileManager->createTranslateConfigAsset();
         $assetCollection = $this->pageConfig->getAssetCollection();
         $assetCollection->insert($tConfig->getFilePath(), $tConfig, $after);
     }
 }
 public function testUpdateAndGetTranslations()
 {
     $translations = ['phrase1' => 'translated1', 'phrase2' => 'translated2'];
     $this->eventManagerMock->expects($this->once())->method('dispatch');
     $this->translateResourceMock->expects($this->once())->method('getTranslationArray')->willReturn($translations);
     $this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn('en_US');
     $this->fileManagerMock->expects($this->once())->method('updateTranslationFileContent');
     $this->assertEquals($translations, $this->model->updateAndGetTranslations());
 }
 public function testCreateTranslateConfigAsset()
 {
     $path = 'relative path';
     $expectedPath = $path . '/' . FileManager::TRANSLATION_CONFIG_FILE_NAME;
     $fileMock = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $contextMock = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\ContextInterface', [], '', true, true, true, ['getPath']);
     $this->assetRepoMock->expects($this->once())->method('getStaticViewFileContext')->willReturn($contextMock);
     $contextMock->expects($this->once())->method('getPath')->willReturn($path);
     $this->assetRepoMock->expects($this->once())->method('createArbitrary')->with($expectedPath, '')->willReturn($fileMock);
     $this->assertSame($fileMock, $this->model->createTranslateConfigAsset());
 }
Beispiel #6
0
 /**
  * @return string
  */
 public function getTranslationFilePath()
 {
     return $this->fileManager->getTranslationFilePath();
 }