Exemplo n.º 1
0
 public function testExtendRender()
 {
     $engine = new ProjectTemplateEngine(new ehough_templating_TemplateNameParser(), $this->loader, array(), array(new ehough_templating_helper_SlotsHelper()));
     try {
         $engine->render('name');
         $this->fail('->render() throws an InvalidArgumentException if the template does not exist');
     } catch (Exception $e) {
         $this->assertInstanceOf('InvalidArgumentException', $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 ehough_templating_TemplateNameParser(), $this->loader, array(new ehough_templating_helper_SlotsHelper()));
     $engine->set(new ehough_templating_test_helper_SimpleHelper('bar'));
     $this->loader->setTemplate('foo.php', '<?php $view->extend("layout.php"); echo $view[\'foo\'].$foo ?>');
     $this->loader->setTemplate('layout.php', '-<?php echo $view[\'slots\']->get("_content") ?>-');
     $this->assertEquals('-barfoo-', $engine->render('foo.php', array('foo' => 'foo')), '->render() uses the decorator to decorate the template');
     $engine = new ProjectTemplateEngine(new ehough_templating_TemplateNameParser(), $this->loader, array(new ehough_templating_helper_SlotsHelper()));
     $engine->set(new ehough_templating_test_helper_SimpleHelper('bar'));
     $this->loader->setTemplate('bar.php', 'bar');
     $this->loader->setTemplate('foo.php', '<?php $view->extend("layout.php"); echo $foo ?>');
     $this->loader->setTemplate('layout.php', '<?php echo $view->render("bar.php") ?>-<?php echo $view[\'slots\']->get("_content") ?>-');
     $this->assertEquals('bar-foo-', $engine->render('foo.php', array('foo' => 'foo', 'bar' => 'bar')), '->render() supports render() calls in templates');
 }
Exemplo n.º 2
0
$engine = new ProjectTemplateEngine($loader);
$engine->setHelperSet(new sfTemplateHelperSet(array('foo' => $helper = new SimpleHelper('bar'))));
$t->is((string) $engine->getHelperSet()->get('foo'), 'bar', '->setHelperSet() sets a helper set');
// __get()
$t->diag('__get()');
$t->is($engine->foo, $helper, '->__get() returns the value of a helper');
try {
    $engine->bar;
    $t->fail('->__get() throws an InvalidArgumentException if the helper is not defined');
} catch (InvalidArgumentException $e) {
    $t->pass('->__get() throws an InvalidArgumentException if the helper is not defined');
}
// ->get() ->set() ->has()
$t->diag('->get() ->set() ->has()');
$engine = new ProjectTemplateEngine($loader);
$engine->set('foo', 'bar');
$t->is($engine->get('foo'), 'bar', '->set() sets a slot value');
$t->is($engine->get('bar', 'bar'), 'bar', '->get() takes a default value to return if the slot does not exist');
$t->ok($engine->has('foo'), '->has() returns true if the slot exists');
$t->ok(!$engine->has('bar'), '->has() returns false if the slot does not exist');
// ->output()
$t->diag('->output()');
ob_start();
$ret = $engine->output('foo');
$output = ob_get_clean();
$t->is($output, 'bar', '->output() outputs the content of a slot');
$t->is($ret, true, '->output() returns true if the slot exists');
ob_start();
$ret = $engine->output('bar', 'bar');
$output = ob_get_clean();
$t->is($output, 'bar', '->output() takes a default value to return if the slot does not exist');