- Added gettext support
[haanga.git] / tests / templateTest.php
blobb16f716887a0844d3418a8614cfdf1f94f999e23
1 <?php
3 /**
4 * @runTestsInSeparateProcess
5 */
6 class templateTest extends PHPUnit_Framework_TestCase
8 public function testInit()
10 /* setup */
11 @mkdir("tmp/");
12 foreach (glob("tmp/*") as $file) {
13 unlink($file);
17 /**
18 * @dataProvider tplProvider
20 public function testRuntime($test_file, $data, $expected)
22 TestSuite::init();
23 $output = Haanga::Load($test_file, $data, TRUE);
24 /*$output = str_replace(" ", '\s', $output);
25 $expected = str_replace(" ", '\s', $expected);/**/
26 $this->assertEquals($output, $expected);
29 /**
30 * @dataProvider tplProvider
32 public function testIsCached($test_file, $data, $expected)
34 /* same as above, but we ensure that the file wasn't compiled */
35 TestSuite::init();
36 $output = Haanga::Load($test_file, $data, TRUE);
37 $this->assertEquals($output, $expected);
38 $this->assertFalse(Haanga::$has_compiled);
42 /**
43 * @dataProvider tplProvider
45 public function testCLICompiler($test_file, $data, $expected)
47 TestSuite::init();
48 $GLOBALS['argv'][1] = $test_file;
49 $GLOBALS['argv'][2] = '--notags';
51 ob_start();
52 Haanga_Compiler::main_cli();
53 $code = ob_get_clean();
55 eval($code);
57 $file = basename($test_file);
58 $pos = strpos($file,'.');
59 $function = substr($file, 0, $pos).'_template';
60 $output = call_user_func($function, $data, TRUE);
62 $this->assertEquals($output, $expected);
65 public function tplProvider()
67 $datas = array();
68 foreach (glob("assert_templates/*.tpl") as $test_file) {
69 $data = array();
70 $data_file = substr($test_file, 0, -3)."php";
71 $expected = substr($test_file, 0, -3)."html";
72 if (!is_file($expected)) {
73 if (!is_file($expected.".php")) {
74 continue;
76 $expected .= ".php";
77 ob_start();
78 require $expected;
79 $expected = ob_get_clean();
80 } else {
81 $expected = file_get_contents($expected);
84 if (is_file($data_file)) {
85 try {
86 include $data_file;
87 } Catch (Exception $e) {
88 continue;
91 $datas[] = array($test_file, $data, $expected);
94 return $datas;