blob: 3f63bd5899df67f025d7779d28497a03531e31b7 [file] [log] [blame]
Pascal Kriete69c97a72011-04-20 21:44:54 -04001<?php
2
3// OLD TEST FORMAT: DO NOT COPY
4
Greg Akera7f9b252011-04-21 14:54:59 -05005require BASEPATH.'libraries/Parser.php';
Pascal Kriete69c97a72011-04-20 21:44:54 -04006
Greg Akera7f9b252011-04-21 14:54:59 -05007class Parser_test extends CI_TestCase
8{
Pascal Kriete69c97a72011-04-20 21:44:54 -04009
10 public function setUp()
11 {
Greg Akera7f9b252011-04-21 14:54:59 -050012 $obj = new StdClass;
13 $obj->parser = new CI_Parser();
14
15 $this->ci_instance($obj);
16
17 $this->parser = $obj->parser;
Pascal Kriete69c97a72011-04-20 21:44:54 -040018 }
19 // --------------------------------------------------------------------
20
21 public function testSetDelimiters()
22 {
23 // Make sure default delimiters are there
24 $this->assertEquals('{', $this->parser->l_delim);
25 $this->assertEquals('}', $this->parser->r_delim);
26
27 // Change them to square brackets
28 $this->parser->set_delimiters('[', ']');
29
30 // Make sure they changed
31 $this->assertEquals('[', $this->parser->l_delim);
32 $this->assertEquals(']', $this->parser->r_delim);
33
34 // Reset them
35 $this->parser->set_delimiters();
36
37 // Make sure default delimiters are there
38 $this->assertEquals('{', $this->parser->l_delim);
39 $this->assertEquals('}', $this->parser->r_delim);
40 }
41
42 // --------------------------------------------------------------------
43
44 public function testParseSimpleString()
45 {
46 $data = array(
47 'title' => 'Page Title',
48 'body' => 'Lorem ipsum dolor sit amet.'
49 );
50
51 $template = "{title}\n{body}";
52
53 $result = implode("\n", $data);
54
55 $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
56 }
57
58 // --------------------------------------------------------------------
Greg Akera7f9b252011-04-21 14:54:59 -050059
Pascal Kriete69c97a72011-04-20 21:44:54 -040060 public function testParse()
61 {
62 $this->_parse_no_template();
63 $this->_parse_var_pair();
64 $this->_mismatched_var_pair();
65 }
Greg Akera7f9b252011-04-21 14:54:59 -050066
Pascal Kriete69c97a72011-04-20 21:44:54 -040067 // --------------------------------------------------------------------
Greg Akera7f9b252011-04-21 14:54:59 -050068
Pascal Kriete69c97a72011-04-20 21:44:54 -040069 private function _parse_no_template()
70 {
71 $this->assertFalse($this->parser->parse_string('', '', TRUE));
72 }
Greg Akera7f9b252011-04-21 14:54:59 -050073
Pascal Kriete69c97a72011-04-20 21:44:54 -040074 // --------------------------------------------------------------------
Greg Akera7f9b252011-04-21 14:54:59 -050075
Pascal Kriete69c97a72011-04-20 21:44:54 -040076 private function _parse_var_pair()
77 {
78 $data = array(
79 'title' => 'Super Heroes',
80 'powers' => array(
81 array(
82 'invisibility' => 'yes',
83 'flying' => 'no'),
84 )
85 );
86
87 $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}";
88
89 $result = "Super Heroes\nyes\nno";
90
91 $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
92 }
Greg Akera7f9b252011-04-21 14:54:59 -050093
Pascal Kriete69c97a72011-04-20 21:44:54 -040094 // --------------------------------------------------------------------
Greg Akera7f9b252011-04-21 14:54:59 -050095
Pascal Kriete69c97a72011-04-20 21:44:54 -040096 private function _mismatched_var_pair()
97 {
98 $data = array(
99 'title' => 'Super Heroes',
100 'powers' => array(
101 array(
102 'invisibility' => 'yes',
103 'flying' => 'no'),
104 )
105 );
106
107 $template = "{title}\n{powers}{invisibility}\n{flying}";
108
109 $result = "Super Heroes\n{powers}{invisibility}\n{flying}";
110
111 $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
112 }
113
114 // --------------------------------------------------------------------
Pascal Kriete69c97a72011-04-20 21:44:54 -0400115}