summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/libraries/Parser_test.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-03-20 14:19:19 +0100
committerAndrey Andreev <narf@bofh.bg>2012-03-20 14:19:19 +0100
commitde85d022e4704123028ad9b4a99407048c628d28 (patch)
tree02192d979c650b0407db23870f350b490167d659 /tests/codeigniter/libraries/Parser_test.php
parenta3b83d6562ca3f9ed0b429a2a6f3272b9f8bd72e (diff)
parent820999cb0d82c80d6dc5dde133568812c8113e29 (diff)
Merge upstream branch
Diffstat (limited to 'tests/codeigniter/libraries/Parser_test.php')
-rw-r--r--tests/codeigniter/libraries/Parser_test.php113
1 files changed, 113 insertions, 0 deletions
diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php
new file mode 100644
index 000000000..b4580a4b1
--- /dev/null
+++ b/tests/codeigniter/libraries/Parser_test.php
@@ -0,0 +1,113 @@
+<?php
+
+require BASEPATH.'libraries/Parser.php';
+
+class Parser_test extends CI_TestCase
+{
+
+ public function set_up()
+ {
+ $obj = new StdClass;
+ $obj->parser = new CI_Parser();
+
+ $this->ci_instance($obj);
+
+ $this->parser = $obj->parser;
+ }
+ // --------------------------------------------------------------------
+
+ public function test_set_delimiters()
+ {
+ // Make sure default delimiters are there
+ $this->assertEquals('{', $this->parser->l_delim);
+ $this->assertEquals('}', $this->parser->r_delim);
+
+ // Change them to square brackets
+ $this->parser->set_delimiters('[', ']');
+
+ // Make sure they changed
+ $this->assertEquals('[', $this->parser->l_delim);
+ $this->assertEquals(']', $this->parser->r_delim);
+
+ // Reset them
+ $this->parser->set_delimiters();
+
+ // Make sure default delimiters are there
+ $this->assertEquals('{', $this->parser->l_delim);
+ $this->assertEquals('}', $this->parser->r_delim);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_parse_simple_string()
+ {
+ $data = array(
+ 'title' => 'Page Title',
+ 'body' => 'Lorem ipsum dolor sit amet.'
+ );
+
+ $template = "{title}\n{body}";
+
+ $result = implode("\n", $data);
+
+ $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_parse()
+ {
+ $this->_parse_no_template();
+ $this->_parse_var_pair();
+ $this->_mismatched_var_pair();
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _parse_no_template()
+ {
+ $this->assertFalse($this->parser->parse_string('', '', TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _parse_var_pair()
+ {
+ $data = array(
+ 'title' => 'Super Heroes',
+ 'powers' => array(
+ array(
+ 'invisibility' => 'yes',
+ 'flying' => 'no'),
+ )
+ );
+
+ $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}";
+
+ $result = "Super Heroes\nyes\nno";
+
+ $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _mismatched_var_pair()
+ {
+ $data = array(
+ 'title' => 'Super Heroes',
+ 'powers' => array(
+ array(
+ 'invisibility' => 'yes',
+ 'flying' => 'no'),
+ )
+ );
+
+ $template = "{title}\n{powers}{invisibility}\n{flying}";
+
+ $result = "Super Heroes\n{powers}{invisibility}\n{flying}";
+
+ $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+ }
+
+ // --------------------------------------------------------------------
+} \ No newline at end of file