Пример #1
0
 public function testRenderByText()
 {
     $text = 'original text';
     $result = 'rendered text';
     $this->_translator->expects($this->once())->method('getTheme')->will($this->returnValue('theme'));
     $this->_translator->expects($this->once())->method('getData')->will($this->returnValue(['theme::' . $text => $result, $text => $result]));
     $this->assertEquals($result, $this->_renderer->render([$text], []));
 }
Пример #2
0
 public function testRenderException()
 {
     $message = 'something went wrong';
     $exception = new \Exception($message);
     $this->provider->expects($this->once())->method('get')->willThrowException($exception);
     $this->setExpectedException('Exception', $message);
     $this->renderer->render(['text'], []);
 }
Пример #3
0
 public function testRender()
 {
     $text = 'text';
     $translatedText = 'translated text';
     $translate = 'translate';
     $this->_translator->expects($this->exactly(2))->method('getData')->will($this->returnValue([$translatedText => $translate]));
     $this->assertEquals($translate, $this->_renderer->render([$translatedText], []));
     $this->assertEquals($text, $this->_renderer->render([$text], []));
 }
Пример #4
0
 /**
  * Get translation data
  *
  * @param string $themePath
  * @return array
  * @throws \Exception
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getData($themePath)
 {
     $areaCode = $this->appState->getAreaCode();
     $files = array_merge($this->filesUtility->getJsFiles('base', $themePath), $this->filesUtility->getJsFiles($areaCode, $themePath), $this->filesUtility->getStaticHtmlFiles('base', $themePath), $this->filesUtility->getStaticHtmlFiles($areaCode, $themePath));
     $dictionary = [];
     foreach ($files as $filePath) {
         /** @var \Magento\Framework\Filesystem\File\Read $read */
         $read = $this->fileReadFactory->create($filePath[0], \Magento\Framework\Filesystem\DriverPool::FILE);
         $content = $read->readAll();
         foreach ($this->getPhrases($content) as $phrase) {
             $translatedPhrase = $this->translate->render([$phrase], []);
             if ($phrase != $translatedPhrase) {
                 $dictionary[$phrase] = $translatedPhrase;
             }
         }
     }
     return $dictionary;
 }
 /**
  * @return void
  */
 public function testGetData()
 {
     $themePath = 'blank';
     $areaCode = 'adminhtml';
     $filePaths = [['path1'], ['path2'], ['path3'], ['path4']];
     $jsFilesMap = [['base', $themePath, '*', '*', [$filePaths[0]]], [$areaCode, $themePath, '*', '*', [$filePaths[1]]]];
     $staticFilesMap = [['base', $themePath, '*', '*', [$filePaths[2]]], [$areaCode, $themePath, '*', '*', [$filePaths[3]]]];
     $expectedResult = ['hello1' => 'hello1translated', 'hello2' => 'hello2translated', 'hello3' => 'hello3translated', 'hello4' => 'hello4translated'];
     $contentsMap = ['content1$.mage.__("hello1")content1', 'content2$.mage.__("hello2")content2', 'content2$.mage.__("hello3")content3', 'content2$.mage.__("hello4")content4'];
     $translateMap = [[['hello1'], [], 'hello1translated'], [['hello2'], [], 'hello2translated'], [['hello3'], [], 'hello3translated'], [['hello4'], [], 'hello4translated']];
     $patterns = ['~\\$\\.mage\\.__\\(([\'"])(.+?)\\1\\)~'];
     $this->appStateMock->expects($this->once())->method('getAreaCode')->willReturn($areaCode);
     $this->filesUtilityMock->expects($this->any())->method('getJsFiles')->willReturnMap($jsFilesMap);
     $this->filesUtilityMock->expects($this->any())->method('getStaticHtmlFiles')->willReturnMap($staticFilesMap);
     foreach ($contentsMap as $index => $content) {
         $this->fileReadMock->expects($this->at($index))->method('readAll')->willReturn($content);
     }
     $this->configMock->expects($this->any())->method('getPatterns')->willReturn($patterns);
     $this->translateMock->expects($this->any())->method('render')->willReturnMap($translateMap);
     $this->assertEquals($expectedResult, $this->model->getData($themePath));
 }