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 testRenderException() { $message = 'something went wrong'; $exception = new \Exception($message); $this->_translator->expects($this->once())->method('getData')->willThrowException($exception); $this->setExpectedException('Exception', $message); $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], [])); }
/** * @magentoDataFixture Magento/Translation/_files/db_translate.php * @magentoDataFixture Magento/Backend/controllers/_files/cache/all_types_enabled.php * @covers \Magento\Translation\Model\Resource\Translate::getStoreId * @covers \Magento\Translation\Model\Resource\String::getStoreId */ public function testLoadDataCaching() { /** @var \Magento\Translation\Model\Resource\String $translateString */ $translateString = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Translation\\Model\\Resource\\String'); $translateString->saveTranslate('Fixture String', 'New Db Translation'); $this->_model->loadData(\Magento\Framework\App\Area::AREA_FRONTEND); $this->assertEquals('Fixture Db Translation', __('Fixture String'), 'Translation is expected to be cached'); $this->_model->loadData(\Magento\Framework\App\Area::AREA_FRONTEND, true); $this->assertEquals('New Db Translation', __('Fixture String'), 'Forced load should not use cache'); }
public function testLoadDataNoTheme() { $forceReload = true; $this->expectsSetConfig(null, null); $this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue([])); $this->appState->expects($this->once())->method('getAreaCode')->will($this->returnValue('frontend')); $this->packDictionary->expects($this->once())->method('getDictionary')->will($this->returnValue([])); $this->resource->expects($this->any())->method('getTranslationArray')->will($this->returnValue([])); $this->assertEquals($this->translate, $this->translate->loadData(null, $forceReload)); }
public function __() { $args = func_get_args(); return parent::translate($args); }