From 3cdf59bf24fbc3fd44484826b810645c23a8d53f Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 19 Aug 2007 08:15:12 +0000 Subject: [PATCH] Adding a TemplateTest.php file and all the associated template files along with it --- UnitTest/AllTests.php | 3 + UnitTest/TemplateTest.php | 66 +++++++++++++++++++ UnitTest/templates/fetch.if.nested.test.tpl | 1 + UnitTest/templates/fetch.if.noelse.test.tpl | 1 + UnitTest/templates/fetch.if.test.tpl | 1 + .../fetch.lang.indexmissing.test.tpl | 1 + .../templates/fetch.lang.invalid.test.tpl | 1 + UnitTest/templates/fetch.lang.tag.test.tpl | 1 + UnitTest/templates/fetch.lang.test.tpl | 1 + UnitTest/templates/fetch.php.nested.test.tpl | 1 + UnitTest/templates/fetch.php.test.tpl | 1 + UnitTest/tests.config.php.new | 3 + 12 files changed, 81 insertions(+) create mode 100644 UnitTest/TemplateTest.php create mode 100644 UnitTest/templates/fetch.if.nested.test.tpl create mode 100644 UnitTest/templates/fetch.if.noelse.test.tpl create mode 100644 UnitTest/templates/fetch.if.test.tpl create mode 100644 UnitTest/templates/fetch.lang.indexmissing.test.tpl create mode 100644 UnitTest/templates/fetch.lang.invalid.test.tpl create mode 100644 UnitTest/templates/fetch.lang.tag.test.tpl create mode 100644 UnitTest/templates/fetch.lang.test.tpl create mode 100644 UnitTest/templates/fetch.php.nested.test.tpl create mode 100644 UnitTest/templates/fetch.php.test.tpl diff --git a/UnitTest/AllTests.php b/UnitTest/AllTests.php index 063e495..3e4bf63 100644 --- a/UnitTest/AllTests.php +++ b/UnitTest/AllTests.php @@ -34,6 +34,9 @@ class AllTests require_once 'AppTest.php'; $suite->addTestSuite('AppTest'); + require_once 'TemplateTest.php'; + $suite->addTestSuite('TemplateTest'); + require_once 'XmlTest.php'; $suite->addTestSuite('XmlTest'); diff --git a/UnitTest/TemplateTest.php b/UnitTest/TemplateTest.php new file mode 100644 index 0000000..935c3de --- /dev/null +++ b/UnitTest/TemplateTest.php @@ -0,0 +1,66 @@ +fixture = BSApp::LoadModule('Template'); + $this->fixture->setTemplateDirectory(TEST_TEMPLATE_PATH); + $this->fixture->setExtension('test.tpl'); + } + + public function testFetchInvalidTemplate() + { + try + { + $this->fixture->fetch('--invalid--'); + $this->fail('exception expected'); + } + catch (Exception $e) + {} + } + + public function testFetch() + { + $result = $this->fixture->fetch('fetch.lang'); + $this->assertEquals('this is a test of " . gettext(\'language\') . " strings', $result); + + $result = $this->fixture->fetch('fetch.if'); + $this->assertEquals('this " . (($a == $b) ? "is cool" : "sucks") . "!', $result); + + $result = $this->fixture->fetch('fetch.php'); + $this->assertEquals('this is " . (date(\'Y\', time()) . " today\'s year', $result); + + // TODO: pass test + // $result = $this->fixture->fetch('fetch.php.nested'); + // $this->assertEquals('this is a " . strpos(\'somestr{\', \'}\') . " nested token', $result); + + $result = $this->fixture->fetch('fetch.lang.tag'); + $this->assertEquals('this is a " . sprintf(\'" . gettext(\'a %1$s b %2$s\') . "\', "hello", "there") . " test', $result); + + $result = $this->fixture->fetch('fetch.if.nested'); + $this->assertEquals('this " . (($c == $d) ? "foo " . (($e == $f) ? "e" : "f") . "" : "moo " . (($g == $h) ? "g" : "h") . "") . " rules!', $result); + + $result = $this->fixture->fetch('fetch.if.noelse'); + $this->assertEquals('this is a test " . (($foo != \'moo\') ? "without else" : "") . "!', $result); + + try + { + $this->fixture->fetch('fetch.lang.invalid'); + $this->fail('exception expected'); + } + catch (Exception $e) + {} + + $result = $this->fixture->fetch('fetch.lang.indexmissing'); + $this->assertEquals('missing " . sprintf(\'" . gettext(\'1 %1$s 2 %2$s 3 %3$s\') . "\', "a", "[MISSING SUBSTITUTION INDEX: 2]", "b") . " index', $result); + } +} + +?> \ No newline at end of file diff --git a/UnitTest/templates/fetch.if.nested.test.tpl b/UnitTest/templates/fetch.if.nested.test.tpl new file mode 100644 index 0000000..c887bae --- /dev/null +++ b/UnitTest/templates/fetch.if.nested.test.tpl @@ -0,0 +1 @@ +this foo efmoo gh rules! \ No newline at end of file diff --git a/UnitTest/templates/fetch.if.noelse.test.tpl b/UnitTest/templates/fetch.if.noelse.test.tpl new file mode 100644 index 0000000..ee01881 --- /dev/null +++ b/UnitTest/templates/fetch.if.noelse.test.tpl @@ -0,0 +1 @@ +this is a test without else! \ No newline at end of file diff --git a/UnitTest/templates/fetch.if.test.tpl b/UnitTest/templates/fetch.if.test.tpl new file mode 100644 index 0000000..b67ebf7 --- /dev/null +++ b/UnitTest/templates/fetch.if.test.tpl @@ -0,0 +1 @@ +this is coolsucks! \ No newline at end of file diff --git a/UnitTest/templates/fetch.lang.indexmissing.test.tpl b/UnitTest/templates/fetch.lang.indexmissing.test.tpl new file mode 100644 index 0000000..94e48a7 --- /dev/null +++ b/UnitTest/templates/fetch.lang.indexmissing.test.tpl @@ -0,0 +1 @@ +missing {@"1 %1$s 2 %2$s 3 %3$s"} index \ No newline at end of file diff --git a/UnitTest/templates/fetch.lang.invalid.test.tpl b/UnitTest/templates/fetch.lang.invalid.test.tpl new file mode 100644 index 0000000..02bc0cb --- /dev/null +++ b/UnitTest/templates/fetch.lang.invalid.test.tpl @@ -0,0 +1 @@ +this is invalid language \ No newline at end of file diff --git a/UnitTest/templates/fetch.lang.tag.test.tpl b/UnitTest/templates/fetch.lang.tag.test.tpl new file mode 100644 index 0000000..be9ab16 --- /dev/null +++ b/UnitTest/templates/fetch.lang.tag.test.tpl @@ -0,0 +1 @@ +this is a {@"a %1$s b %2$s"} test \ No newline at end of file diff --git a/UnitTest/templates/fetch.lang.test.tpl b/UnitTest/templates/fetch.lang.test.tpl new file mode 100644 index 0000000..6269352 --- /dev/null +++ b/UnitTest/templates/fetch.lang.test.tpl @@ -0,0 +1 @@ +this is a test of {@"language"} strings \ No newline at end of file diff --git a/UnitTest/templates/fetch.php.nested.test.tpl b/UnitTest/templates/fetch.php.nested.test.tpl new file mode 100644 index 0000000..637d459 --- /dev/null +++ b/UnitTest/templates/fetch.php.nested.test.tpl @@ -0,0 +1 @@ +this is a {strpos('somestr{', '}')} nested token \ No newline at end of file diff --git a/UnitTest/templates/fetch.php.test.tpl b/UnitTest/templates/fetch.php.test.tpl new file mode 100644 index 0000000..f357940 --- /dev/null +++ b/UnitTest/templates/fetch.php.test.tpl @@ -0,0 +1 @@ +this is {date('Y', time()} today's year \ No newline at end of file diff --git a/UnitTest/tests.config.php.new b/UnitTest/tests.config.php.new index f542215..5213c2d 100644 --- a/UnitTest/tests.config.php.new +++ b/UnitTest/tests.config.php.new @@ -34,6 +34,9 @@ define('TEST_DB_MYSQL_HOST', 'localhost'); // mysql database to use define('TEST_DB_MYSQL_DATABASE', 'issotest'); +// path to the ISSO test templates directory +define('TEST_TEMPLATE_PATH', '/usr/local/apache2/htdocs/isso/UnitTest/templates'); + /*=====================================================================* || ################################################################### || # $HeadURL$ -- 2.43.5