From 69c97a71476e4eaa6c629022fcd4ec7f36d4ec0d Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 20 Apr 2011 21:44:54 -0400 Subject: Adding early bootstrap ideas for core test suite --- tests/codeigniter/libraries/Parser_test.php | 125 ++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 tests/codeigniter/libraries/Parser_test.php (limited to 'tests/codeigniter/libraries/Parser_test.php') diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php new file mode 100644 index 000000000..a8de108f0 --- /dev/null +++ b/tests/codeigniter/libraries/Parser_test.php @@ -0,0 +1,125 @@ +load->library('parser'); + self::$cls = get_class($CI->parser); + } + + // -------------------------------------------------------------------- + + public function setUp() + { + $cls = self::$cls; + $this->parser = new $cls; + } + // -------------------------------------------------------------------- + + 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)); + } + + // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a7f9b251b03f7fb17251951d3024cb11fc1f881f Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:54:59 -0500 Subject: Parser test. --- tests/codeigniter/libraries/Parser_test.php | 42 +++++++++++------------------ 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'tests/codeigniter/libraries/Parser_test.php') diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php index a8de108f0..3f63bd589 100644 --- a/tests/codeigniter/libraries/Parser_test.php +++ b/tests/codeigniter/libraries/Parser_test.php @@ -2,24 +2,19 @@ // OLD TEST FORMAT: DO NOT COPY -class Parser_test extends PHPUnit_Framework_TestCase -{ - static $cls; - protected $parser; - - public static function setUpBeforeClass() - { - $CI = get_instance(); - $CI->load->library('parser'); - self::$cls = get_class($CI->parser); - } +require BASEPATH.'libraries/Parser.php'; - // -------------------------------------------------------------------- +class Parser_test extends CI_TestCase +{ public function setUp() { - $cls = self::$cls; - $this->parser = new $cls; + $obj = new StdClass; + $obj->parser = new CI_Parser(); + + $this->ci_instance($obj); + + $this->parser = $obj->parser; } // -------------------------------------------------------------------- @@ -61,23 +56,23 @@ class Parser_test extends PHPUnit_Framework_TestCase } // -------------------------------------------------------------------- - + 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( @@ -95,9 +90,9 @@ class Parser_test extends PHPUnit_Framework_TestCase $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE)); } - + // -------------------------------------------------------------------- - + private function _mismatched_var_pair() { $data = array( @@ -117,9 +112,4 @@ class Parser_test extends PHPUnit_Framework_TestCase } // -------------------------------------------------------------------- - - // -------------------------------------------------------------------- - - // -------------------------------------------------------------------- - } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 57fb5180092fef3de867b88a06c4e3ec232b4cd5 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:58:26 -0500 Subject: Cleanup in Parser_test...Adding Table_test Pascal did earlier. --- tests/codeigniter/libraries/Parser_test.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/codeigniter/libraries/Parser_test.php') diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php index 3f63bd589..44269ad2c 100644 --- a/tests/codeigniter/libraries/Parser_test.php +++ b/tests/codeigniter/libraries/Parser_test.php @@ -1,7 +1,5 @@ Date: Thu, 21 Apr 2011 22:00:33 -0400 Subject: Reworked unit tests to match rest of framework and added a few more. --- tests/codeigniter/libraries/Parser_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter/libraries/Parser_test.php') diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php index 44269ad2c..b4580a4b1 100644 --- a/tests/codeigniter/libraries/Parser_test.php +++ b/tests/codeigniter/libraries/Parser_test.php @@ -5,7 +5,7 @@ require BASEPATH.'libraries/Parser.php'; class Parser_test extends CI_TestCase { - public function setUp() + public function set_up() { $obj = new StdClass; $obj->parser = new CI_Parser(); @@ -16,7 +16,7 @@ class Parser_test extends CI_TestCase } // -------------------------------------------------------------------- - public function testSetDelimiters() + public function test_set_delimiters() { // Make sure default delimiters are there $this->assertEquals('{', $this->parser->l_delim); @@ -39,7 +39,7 @@ class Parser_test extends CI_TestCase // -------------------------------------------------------------------- - public function testParseSimpleString() + public function test_parse_simple_string() { $data = array( 'title' => 'Page Title', @@ -55,7 +55,7 @@ class Parser_test extends CI_TestCase // -------------------------------------------------------------------- - public function testParse() + public function test_parse() { $this->_parse_no_template(); $this->_parse_var_pair(); -- cgit v1.2.3-24-g4f1b