public function testExtendRender() { $engine =
new ProjectTemplateEngine(new TemplateNameParser(),
$this->loader,
[]);
try { $engine->
render('name'
);
$this->
fail('->render() throws an InvalidArgumentException if the template does not exist'
);
} catch (\Exception
$e) { $this->
assertInstanceOf(\InvalidArgumentException::
class,
$e, '->render() throws an InvalidArgumentException if the template does not exist'
);
$this->
assertEquals('The template "name" does not exist.',
$e->
getMessage(), '->render() throws an InvalidArgumentException if the template does not exist'
);
} $engine =
new ProjectTemplateEngine(new TemplateNameParser(),
$this->loader,
[new SlotsHelper()]);
$engine->
set(new \Symfony\Component\Templating\Tests\Fixtures\
SimpleHelper('bar'
));
$this->loader->
setTemplate('foo.php', '<?php $this->extend("layout.php"); echo $this[\'foo\'].$foo ?>'
);
$this->loader->
setTemplate('layout.php', '-<?php echo $this[\'slots\']->get("_content") ?>-'
);
$this->
assertEquals('-barfoo-',
$engine->
render('foo.php',
['foo' => 'foo'
]), '->render() uses the decorator to decorate the template'
);
$engine =
new ProjectTemplateEngine(new TemplateNameParser(),
$this->loader,
[new SlotsHelper()]);
$engine->
set(new \Symfony\Component\Templating\Tests\Fixtures\
SimpleHelper('bar'
));
$this->loader->
setTemplate('bar.php', 'bar'
);
$this->loader->
setTemplate('foo.php', '<?php $this->extend("layout.php"); echo $foo ?>'
);
$this->loader->
setTemplate('layout.php', '<?php echo $this->render("bar.php") ?>-<?php echo $this[\'slots\']->get("_content") ?>-'
);
$this->
assertEquals('bar-foo-',
$engine->
render('foo.php',
['foo' => 'foo', 'bar' => 'bar'
]), '->render() supports render() calls in templates'
);
}