fenom/tests/cases/Fenom/RenderTest.php

61 lines
1.4 KiB
PHP
Raw Normal View History

2013-01-25 18:36:16 +04:00
<?php
2013-06-28 11:53:53 +04:00
namespace Fenom;
2014-02-27 16:30:44 +04:00
2013-06-28 11:53:53 +04:00
use Fenom,
Fenom\Render;
2013-01-25 18:36:16 +04:00
2017-04-22 15:59:20 +03:00
class RenderTest extends TestCase
2013-07-29 14:58:14 +04:00
{
2013-01-25 18:36:16 +04:00
/**
* @var Render
*/
public static $render;
2023-02-20 00:14:08 +03:00
public static function setUpBeforeClass(): void
2013-07-29 14:58:14 +04:00
{
2013-06-28 11:53:53 +04:00
self::$render = new Render(Fenom::factory("."), function ($tpl) {
2013-07-29 14:58:14 +04:00
echo "It is render's function " . $tpl["render"];
2013-02-13 20:51:27 +04:00
}, array(
"name" => "render.tpl"
));
2013-01-25 18:36:16 +04:00
}
2013-07-29 14:58:14 +04:00
public function testCreate()
{
2013-06-28 11:53:53 +04:00
$r = new Render(Fenom::factory("."), function () {
2013-01-25 18:36:16 +04:00
echo "Test render";
2013-02-13 20:51:27 +04:00
}, array(
"name" => "test.render.tpl"
));
2013-01-25 18:36:16 +04:00
$this->assertSame("Test render", $r->fetch(array()));
}
2013-07-29 14:58:14 +04:00
public function testDisplay()
{
2013-01-25 18:36:16 +04:00
ob_start();
self::$render->display(array("render" => "display"));
$out = ob_get_clean();
2013-02-13 20:51:27 +04:00
$this->assertSame("It is render's function display", $out);
2013-01-25 18:36:16 +04:00
}
2013-07-29 14:58:14 +04:00
public function testFetch()
{
2013-02-13 20:51:27 +04:00
$this->assertSame("It is render's function fetch", self::$render->fetch(array("render" => "fetch")));
2013-01-25 18:36:16 +04:00
}
2013-07-29 14:58:14 +04:00
public function testFetchException()
{
2023-02-23 23:50:12 +03:00
$this->expectException(Fenom\Error\TemplateException::class);
2013-06-28 11:53:53 +04:00
$render = new Render(Fenom::factory("."), function () {
2013-01-25 18:36:16 +04:00
echo "error";
throw new \RuntimeException("template error");
2013-02-13 20:51:27 +04:00
}, array(
"name" => "render.tpl"
));
2013-01-25 18:36:16 +04:00
$render->fetch(array());
}
}