4 static $Bar = 'haanga';
5 static $Arr = array('foo', 'Bar' => 'Foo');
7 static function something()
14 * @runTestsInSeparateProcess
16 class templateTest
extends PHPUnit_Framework_TestCase
18 public function testInit()
22 foreach (glob("tmp/*/*") as $file) {
28 public function init($test_file, &$expected)
30 if ($test_file == 'assert_templates/strip_whitespace.tpl') {
31 Haanga_Compiler
::setOption('strip_whitespace', TRUE);
32 $expected = rtrim($expected). ' '; /* weird output */
34 Haanga_Compiler
::setOption('strip_whitespace', FALSE);
38 * @dataProvider tplProvider
40 public function testRuntime($test_file, $data, $expected)
42 $this->init($test_file, $expected);
43 $output = Haanga
::Load($test_file, $data, TRUE);
44 $this->assertEquals($output, $expected);
48 * @dataProvider tplProvider
50 public function testLambda($test_file, $data, $expected)
52 $this->init($test_file, $expected);
53 $callback = Haanga
::compile(file_get_contents($test_file), $data);
54 $output = $callback($data);
55 $this->assertEquals($output, $expected);
60 * @dataProvider tplProvider
62 public function testIsCached($test_file, $data, $expected)
64 /* same as above, but we ensure that the file wasn't compiled */
65 $this->init($test_file, $expected);
66 $output = Haanga
::Load($test_file, $data, TRUE);
67 $this->assertEquals($output, $expected);
68 $this->assertFalse(Haanga
::$has_compiled);
72 * @dataProvider tplProvider
74 public function testCLICompiler($test_file, $data, $expected)
77 $GLOBALS['argv'][1] = $test_file;
78 $GLOBALS['argv'][2] = '--notags';
81 Haanga_Compiler::main_cli();
82 $code = ob_get_clean();
86 $file = basename($test_file);
87 $pos = strpos($file,'.');
88 $function = substr($file, 0, $pos).'_template';
89 $output = call_user_func($function, $data, TRUE);
91 $this->assertEquals($output, $expected);
95 public function tplProvider()
98 foreach (glob("assert_templates/*.tpl") as $test_file) {
100 $data_file = substr($test_file, 0, -3)."php";
101 $expected = substr($test_file, 0, -3)."html";
102 if (!is_file($expected)) {
103 if (!is_file($expected.".php")) {
109 $expected = ob_get_clean();
111 $expected = file_get_contents($expected);
114 if (is_file($data_file)) {
117 } Catch (Exception
$e) {
121 $datas[] = array($test_file, $data, $expected);