Adding a TemplateTest.php file and all the associated template files along with it
[isso.git] / UnitTest / TemplateTest.php
1 <?php
2
3 require_once 'PHPUnit/Framework.php';
4
5 class TemplateTest extends PHPUnit_Framework_TestCase
6 {
7 private $fixture;
8
9 public function setUp()
10 {
11 require_once 'ISSO/App.php';
12
13 $this->fixture = BSApp::LoadModule('Template');
14 $this->fixture->setTemplateDirectory(TEST_TEMPLATE_PATH);
15 $this->fixture->setExtension('test.tpl');
16 }
17
18 public function testFetchInvalidTemplate()
19 {
20 try
21 {
22 $this->fixture->fetch('--invalid--');
23 $this->fail('exception expected');
24 }
25 catch (Exception $e)
26 {}
27 }
28
29 public function testFetch()
30 {
31 $result = $this->fixture->fetch('fetch.lang');
32 $this->assertEquals('this is a test of " . gettext(\'language\') . " strings', $result);
33
34 $result = $this->fixture->fetch('fetch.if');
35 $this->assertEquals('this " . (($a == $b) ? "is cool" : "sucks") . "!', $result);
36
37 $result = $this->fixture->fetch('fetch.php');
38 $this->assertEquals('this is " . (date(\'Y\', time()) . " today\'s year', $result);
39
40 // TODO: pass test
41 // $result = $this->fixture->fetch('fetch.php.nested');
42 // $this->assertEquals('this is a " . strpos(\'somestr{\', \'}\') . " nested token', $result);
43
44 $result = $this->fixture->fetch('fetch.lang.tag');
45 $this->assertEquals('this is a " . sprintf(\'" . gettext(\'a %1$s b %2$s\') . "\', "hello", "there") . " test', $result);
46
47 $result = $this->fixture->fetch('fetch.if.nested');
48 $this->assertEquals('this " . (($c == $d) ? "foo " . (($e == $f) ? "e" : "f") . "" : "moo " . (($g == $h) ? "g" : "h") . "") . " rules!', $result);
49
50 $result = $this->fixture->fetch('fetch.if.noelse');
51 $this->assertEquals('this is a test " . (($foo != \'moo\') ? "without else" : "") . "!', $result);
52
53 try
54 {
55 $this->fixture->fetch('fetch.lang.invalid');
56 $this->fail('exception expected');
57 }
58 catch (Exception $e)
59 {}
60
61 $result = $this->fixture->fetch('fetch.lang.indexmissing');
62 $this->assertEquals('missing " . sprintf(\'" . gettext(\'1 %1$s 2 %2$s 3 %3$s\') . "\', "a", "<strong>[MISSING SUBSTITUTION INDEX: 2]</strong>", "b") . " index', $result);
63 }
64 }
65
66 ?>