public function testSetTemplateContext() { $template = 'themedir/template.phtml'; $context = new \Magento\Framework\DataObject(); $this->_validator->expects($this->once())->method('isValid')->with($template)->will($this->returnValue(true)); $this->_templateEngine->expects($this->once())->method('render')->with($context); $this->_block->setTemplateContext($context); $this->_block->fetchView($template); }
/** * Test is file valid * * @param string $file * @param bool $expectedResult * * @dataProvider testIsValidDataProvider * * @return void */ public function testIsValid($file, $expectedResult) { $this->rootDirectoryMock->expects($this->any())->method('isFile')->will($this->returnValue(true)); $this->assertEquals($expectedResult, $this->_validator->isValid($file)); }
/** * 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->validator->isValid($fileName)) { $extension = pathinfo($fileName, PATHINFO_EXTENSION); $templateEngine = $this->templateEnginePool->get($extension); $html = $templateEngine->render($this->templateContext, $fileName, $this->_viewVars); } else { $html = ''; $templatePath = $fileName ?: $this->getTemplate(); $this->_logger->critical("Invalid template file: '{$templatePath}' in module: '{$this->getModuleName()}'" . " block's name: '{$this->getNameInLayout()}'"); } \Magento\Framework\Profiler::stop('TEMPLATE:' . $fileName); return $html; }