4 * @runTestsInSeparateProcess
6 class templateTest
extends PHPUnit_Framework_TestCase
8 public function testInit()
12 foreach (glob("tmp/*/*") as $file) {
18 public function init($test_file, &$expected)
20 if ($test_file == 'assert_templates/strip_whitespace.tpl') {
21 Haanga_Compiler
::setOption('strip_whitespace', TRUE);
22 $expected = rtrim($expected). ' '; /* weird output */
24 Haanga_Compiler
::setOption('strip_whitespace', FALSE);
28 * @dataProvider tplProvider
30 public function testRuntime($test_file, $data, $expected)
32 $this->init($test_file, $expected);
33 $output = Haanga
::Load($test_file, $data, TRUE);
34 $this->assertEquals($output, $expected);
38 * @dataProvider tplProvider
40 public function testLambda($test_file, $data, $expected)
42 $this->init($test_file, $expected);
43 $callback = Haanga
::compile(file_get_contents($test_file), $data);
44 $output = $callback($data);
45 $this->assertEquals($output, $expected);
50 * @dataProvider tplProvider
52 public function testIsCached($test_file, $data, $expected)
54 /* same as above, but we ensure that the file wasn't compiled */
55 $this->init($test_file, $expected);
56 $output = Haanga
::Load($test_file, $data, TRUE);
57 $this->assertEquals($output, $expected);
58 $this->assertFalse(Haanga
::$has_compiled);
62 * @dataProvider tplProvider
64 public function testCLICompiler($test_file, $data, $expected)
67 $GLOBALS['argv'][1] = $test_file;
68 $GLOBALS['argv'][2] = '--notags';
71 Haanga_Compiler::main_cli();
72 $code = ob_get_clean();
76 $file = basename($test_file);
77 $pos = strpos($file,'.');
78 $function = substr($file, 0, $pos).'_template';
79 $output = call_user_func($function, $data, TRUE);
81 $this->assertEquals($output, $expected);
85 public function tplProvider()
88 foreach (glob("assert_templates/*.tpl") as $test_file) {
90 $data_file = substr($test_file, 0, -3)."php";
91 $expected = substr($test_file, 0, -3)."html";
92 if (!is_file($expected)) {
93 if (!is_file($expected.".php")) {
99 $expected = ob_get_clean();
101 $expected = file_get_contents($expected);
104 if (is_file($data_file)) {
107 } Catch (Exception
$e) {
111 $datas[] = array($test_file, $data, $expected);