fenom/tests/cases/Aspect/RenderTest.php

57 lines
1.4 KiB
PHP
Raw Normal View History

2013-01-25 18:36:16 +04:00
<?php
namespace Aspect;
use Aspect,
Aspect\Render;
class RenderTest extends \PHPUnit_Framework_TestCase {
/**
* @var Render
*/
public static $render;
public static function setUpBeforeClass() {
2013-02-13 20:51:27 +04:00
self::$render = new Render(Aspect::factory("."), function ($tpl) {
echo "It is render's function ".$tpl["render"];
}, array(
"name" => "render.tpl"
));
2013-01-25 18:36:16 +04:00
}
public function testCreate() {
2013-02-13 20:51:27 +04:00
$r = new Render(Aspect::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()));
}
public function testDisplay() {
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
}
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
*/
public function testFetchException() {
2013-02-13 20:51:27 +04:00
$render = new Render(Aspect::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());
}
}