public function testGet() { $engine = $this->getMock('Magento\\Framework\\View\\TemplateEngineInterface'); $this->_factory->expects($this->once())->method('create')->with('test')->will($this->returnValue($engine)); $this->assertSame($engine, $this->_model->get('test')); // Make sure factory is invoked only once and the same instance is returned afterwards $this->assertSame($engine, $this->_model->get('test')); }
public function testRender() { $template = 'test_template'; $result = 'result'; $path = 'path'; $this->viewInterfaceMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponentInterface'); $templateEngineMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\TemplateEngineInterface'); $this->templateEnginePoolMock->expects($this->once())->method('get')->willReturn($templateEngineMock); $this->filesystemMock->expects($this->once())->method('getTemplateFileName')->with($template)->willReturn($path); $templateEngineMock->expects($this->once())->method('render')->with($this->viewInterfaceMock, $path)->willReturn($result); $this->assertEquals($result, $this->html->render($this->viewInterfaceMock, $template)); }
/** * Render data * * @param UiComponentInterface $view * @param string $template * @return string */ public function render(UiComponentInterface $view, $template = '') { $templateEngine = false; if ($template) { $extension = pathinfo($template, PATHINFO_EXTENSION); $templateEngine = $this->templateEnginePool->get($extension); } if ($templateEngine) { $path = $this->filesystem->getTemplateFileName($template); $result = $templateEngine->render($view, $path); } else { $result = ''; } return $result; }
/** * Render data * * @param UiComponentInterface $view * @param string $template * @return string * @throws \Exception */ public function render(UiComponentInterface $view, $template = '') { $templateEngine = false; if ($template) { $extension = pathinfo($template, PATHINFO_EXTENSION); $templateEngine = $this->templateEnginePool->get($extension); } if ($templateEngine) { $path = $this->filesystem->getTemplateFileName($template); $result = $templateEngine->render($view, $path); } else { $result = $this->getDataXml($view); } throw new \Exception('Please implement XML renderer'); }
/** * Retrieve block view from file (template) * * @param string $fileName * @return string */ public function fetchView($fileName) { $relativeFilePath = $this->getRootDirectory()->getRelativePath($fileName); \Magento\Framework\Profiler::start('TEMPLATE:' . $fileName, ['group' => 'TEMPLATE', 'file_name' => $relativeFilePath]); if ($this->isTemplateFileValid($fileName)) { $extension = pathinfo($fileName, PATHINFO_EXTENSION); $templateEngine = $this->templateEnginePool->get($extension); $html = $templateEngine->render($this->templateContext, $fileName, $this->_viewVars); } else { $html = ''; $this->_logger->critical("Invalid template file: '{$fileName}'"); } \Magento\Framework\Profiler::stop('TEMPLATE:' . $fileName); return $html; }