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