public function testVoltMacros()
{
$this->specify("Volt macros don't work", function () {
$this->removeFiles([PATH_DATA . 'views/macro/hello.volt.php', PATH_DATA . 'views/macro/conditionaldate.volt.php', PATH_DATA . 'views/macro/my_input.volt.php', PATH_DATA . 'views/macro/error_messages.volt.php', PATH_DATA . 'views/macro/related_links.volt.php', PATH_DATA . 'views/macro/strtotime.volt.php']);
Di::reset();
$view = new View();
$di = new Di();
$di->set('escaper', function () {
return new Escaper();
});
$di->set('tag', function () {
return new Tag();
});
$di->set('url', function () {
return (new Url())->setBaseUri('/');
});
$view->setDI($di);
$view->setViewsDir(PATH_DATA . 'views/');
$view->registerEngines(array('.volt' => function ($view, $di) {
$volt = new Volt($view, $di);
$compiler = $volt->getCompiler();
$compiler->addFunction('strtotime', 'strtotime');
return $volt;
}));
$view->start();
$view->render('macro', 'hello');
$view->finish();
expect($view->getContent())->equals('Hello World');
$view->start();
$view->render('macro', 'conditionaldate');
$view->finish();
expect($view->getContent())->equals(sprintf('from <br/>%s, %s UTC', date('Y-m-d'), date('H:i')));
$view->start();
$view->render('macro', 'my_input');
$view->finish();
expect($view->getContent())->equals('<p><input type="text" id="name" name="name" class="input-text" /></p>');
$view->start();
$view->render('macro', 'error_messages');
$view->finish();
expect($view->getContent())->equals('<div><span class="error-type">Invalid</span><span class="error-field">name</span><span class="error-message">The name is invalid</span></div>');
$view->setVar('links', array((object) array('url' => 'localhost', 'text' => 'Menu item', 'title' => 'Menu title')));
$view->start();
$view->render('macro', 'related_links');
$view->finish();
expect($view->getContent())->equals('<ul><li><a href="/localhost" title="Menu title">Menu item</a></li></ul>');
$view->setVar('date', new DateTime());
$view->start();
$view->render('macro', 'strtotime');
$view->finish();
$content = $view->getContent();
$content = explode('%', $content);
expect($content)->count(3);
expect($content[0])->equals($content[1]);
expect($content[1])->equals($content[2]);
expect($content[2])->equals($content[0]);
$this->removeFiles([PATH_DATA . 'views/macro/hello.volt.php', PATH_DATA . 'views/macro/conditionaldate.volt.php', PATH_DATA . 'views/macro/my_input.volt.php', PATH_DATA . 'views/macro/error_messages.volt.php', PATH_DATA . 'views/macro/related_links.volt.php', PATH_DATA . 'views/macro/strtotime.volt.php']);
});
}