blob: a8de108f027241a5c416b59ce9ac9bcb44414636 [file] [log] [blame]
Pascal Kriete69c97a72011-04-20 21:44:54 -04001<?php
2
3// OLD TEST FORMAT: DO NOT COPY
4
5class Parser_test extends PHPUnit_Framework_TestCase
6{
7 static $cls;
8 protected $parser;
9
10 public static function setUpBeforeClass()
11 {
12 $CI = get_instance();
13 $CI->load->library('parser');
14 self::$cls = get_class($CI->parser);
15 }
16
17 // --------------------------------------------------------------------
18
19 public function setUp()
20 {
21 $cls = self::$cls;
22 $this->parser = new $cls;
23 }
24 // --------------------------------------------------------------------
25
26 public function testSetDelimiters()
27 {
28 // Make sure default delimiters are there
29 $this->assertEquals('{', $this->parser->l_delim);
30 $this->assertEquals('}', $this->parser->r_delim);
31
32 // Change them to square brackets
33 $this->parser->set_delimiters('[', ']');
34
35 // Make sure they changed
36 $this->assertEquals('[', $this->parser->l_delim);
37 $this->assertEquals(']', $this->parser->r_delim);
38
39 // Reset them
40 $this->parser->set_delimiters();
41
42 // Make sure default delimiters are there
43 $this->assertEquals('{', $this->parser->l_delim);
44 $this->assertEquals('}', $this->parser->r_delim);
45 }
46
47 // --------------------------------------------------------------------
48
49 public function testParseSimpleString()
50 {
51 $data = array(
52 'title' => 'Page Title',
53 'body' => 'Lorem ipsum dolor sit amet.'
54 );
55
56 $template = "{title}\n{body}";
57
58 $result = implode("\n", $data);
59
60 $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
61 }
62
63 // --------------------------------------------------------------------
64
65 public function testParse()
66 {
67 $this->_parse_no_template();
68 $this->_parse_var_pair();
69 $this->_mismatched_var_pair();
70 }
71
72 // --------------------------------------------------------------------
73
74 private function _parse_no_template()
75 {
76 $this->assertFalse($this->parser->parse_string('', '', TRUE));
77 }
78
79 // --------------------------------------------------------------------
80
81 private function _parse_var_pair()
82 {
83 $data = array(
84 'title' => 'Super Heroes',
85 'powers' => array(
86 array(
87 'invisibility' => 'yes',
88 'flying' => 'no'),
89 )
90 );
91
92 $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}";
93
94 $result = "Super Heroes\nyes\nno";
95
96 $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
97 }
98
99 // --------------------------------------------------------------------
100
101 private function _mismatched_var_pair()
102 {
103 $data = array(
104 'title' => 'Super Heroes',
105 'powers' => array(
106 array(
107 'invisibility' => 'yes',
108 'flying' => 'no'),
109 )
110 );
111
112 $template = "{title}\n{powers}{invisibility}\n{flying}";
113
114 $result = "Super Heroes\n{powers}{invisibility}\n{flying}";
115
116 $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
117 }
118
119 // --------------------------------------------------------------------
120
121 // --------------------------------------------------------------------
122
123 // --------------------------------------------------------------------
124
125}