blob: 3f63bd5899df67f025d7779d28497a03531e31b7 [file] [log] [blame]
<?php
// OLD TEST FORMAT: DO NOT COPY
require BASEPATH.'libraries/Parser.php';
class Parser_test extends CI_TestCase
{
public function setUp()
{
$obj = new StdClass;
$obj->parser = new CI_Parser();
$this->ci_instance($obj);
$this->parser = $obj->parser;
}
// --------------------------------------------------------------------
public function testSetDelimiters()
{
// 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 testParseSimpleString()
{
$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 testParse()
{
$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));
}
// --------------------------------------------------------------------
}