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'], []); }
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], [])); }
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], [])); }
/** * 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; }