public function testRenderIfInlineTranslationIsNotAllowed() { $text = 'test'; $inlineTranslate = $this->getMock('Magento\\Framework\\Translate\\InlineInterface', [], [], '', []); $inlineTranslate->expects($this->once())->method('isAllowed')->will($this->returnValue(false)); $this->provider->expects($this->once())->method('get')->will($this->returnValue($inlineTranslate)); $this->assertEquals($text, $this->renderer->render([$text], [])); }
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'], []); }
/** * Render source text * * @param [] $source * @param [] $arguments * @return string */ public function render(array $source, array $arguments) { $text = end($source); if (!$this->inlineProvider->get()->isAllowed()) { return $text; } if (strpos($text, '{{{') === false || strpos($text, '}}}') === false || strpos($text, '}}{{') === false) { $text = '{{{' . implode('}}{{', array_reverse($source)) . '}}{{' . $this->translator->getTheme() . '}}}'; } return $text; }
/** * Render source text * * @param [] $source * @param [] $arguments * @return string * @throws \Exception * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function render(array $source, array $arguments) { $text = end($source); try { if (!$this->inlineProvider->get()->isAllowed()) { return $text; } if (strpos($text, '{{{') === false || strpos($text, '}}}') === false || strpos($text, '}}{{') === false) { $text = '{{{' . implode('}}{{', array_reverse($source)) . '}}{{' . $this->translator->getTheme() . '}}}'; } } catch (\Exception $e) { $this->logger->critical($e->getMessage()); throw $e; } return $text; }