コード例 #1
0
{
    public function load($template, $renderer = 'php')
    {
        return new sfTemplateStorageString($template, 'foo');
    }
    public function compile($template)
    {
        return 'COMPILED';
    }
}
class FooTemplateRenderer extends sfTemplateRenderer
{
    public function evaluate(sfTemplateStorage $template, array $parameters = array())
    {
        return 'foo';
    }
}
$t->diag('compilable templates');
$engine = new ProjectTemplateEngine(new CompilableTemplateLoader(), array('foo' => new FooTemplateRenderer()));
$t->is($engine->render('index'), 'foo', '->load() takes into account the renderer embedded in the sfTemplateStorage instance if not null');
// ->escape()
$t->diag('->escape()');
$engine = new ProjectTemplateEngine($loader);
$t->is($engine->escape('<br />'), '&lt;br /&gt;', '->escape() escapes strings');
$t->is($engine->escape($foo = new stdClass()), $foo, '->escape() does nothing on non strings');
// ->getCharset() ->setCharset()
$t->diag('->getCharset() ->setCharset()');
$engine = new ProjectTemplateEngine($loader);
$t->is($engine->getCharset(), 'UTF-8', '->getCharset() returns UTF-8 by default');
$engine->setCharset('ISO-8859-1');
$t->is($engine->getCharset(), 'ISO-8859-1', '->setCharset() changes the default charset to use');
コード例 #2
0
ファイル: PhpEngineTest.php プロジェクト: ehough/templating
 public function testGlobalsGetPassedToTemplate()
 {
     $engine = new ProjectTemplateEngine(new ehough_templating_TemplateNameParser(), $this->loader);
     $engine->addGlobal('global', 'global variable');
     $this->loader->setTemplate('global.php', '<?php echo $global; ?>');
     $this->assertEquals($engine->render('global.php'), 'global variable');
     $this->assertEquals($engine->render('global.php', array('global' => 'overwritten')), 'overwritten');
 }