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
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
class RenderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Render
|
|
|
|
*/
|
|
|
|
public static $render;
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
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-02-13 20:51:27 +04:00
|
|
|
* @expectedException \RuntimeException
|
2013-01-25 18:36:16 +04:00
|
|
|
* @expectedExceptionMessage template error
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testFetchException()
|
|
|
|
{
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|