コード例 #1
0
 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], []));
 }
コード例 #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
ファイル: Inline.php プロジェクト: shabbirvividads/magento2
 /**
  * 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;
 }
コード例 #4
0
 /**
  * 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;
 }