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') 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') 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 - tests/codeigniter/libraries/Table_test.php | 291 ++++++++++++++++++++++++++++ 2 files changed, 291 insertions(+), 2 deletions(-) create mode 100644 tests/codeigniter/libraries/Table_test.php (limited to 'tests/codeigniter/libraries') 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 @@ table = new CI_table(); + + $this->ci_instance($obj); + + $this->table = $obj->table; + } + + + // Setter Methods + // -------------------------------------------------------------------- + + public function testSetTemplate() + { + $this->assertFalse($this->table->set_template('not an array')); + + $template = array( + 'a' => 'b' + ); + + $this->table->set_template($template); + $this->assertEquals($template, $this->table->template); + } + + public function testSetEmpty() + { + $this->table->set_empty('nada'); + $this->assertEquals('nada', $this->table->empty_cells); + } + + public function testSetCaption() + { + $this->table->set_caption('awesome cap'); + $this->assertEquals('awesome cap', $this->table->caption); + } + + + /* + * @depends testPrepArgs + */ + public function testSetHeading() + { + // uses _prep_args internally, so we'll just do a quick + // check to verify that func_get_args and prep_args are + // being called. + + $this->table->set_heading('name', 'color', 'size'); + + $this->assertEquals( + array( + array('data' => 'name'), + array('data' => 'color'), + array('data' => 'size') + ), + $this->table->heading + ); + } + + + /* + * @depends testPrepArgs + */ + public function testAddRow() + { + // uses _prep_args internally, so we'll just do a quick + // check to verify that func_get_args and prep_args are + // being called. + + $this->table->add_row('my', 'pony', 'sings'); + $this->table->add_row('your', 'pony', 'stinks'); + $this->table->add_row('my pony', '>', 'your pony'); + + $this->assertEquals(count($this->table->rows), 3); + + $this->assertEquals( + array( + array('data' => 'your'), + array('data' => 'pony'), + array('data' => 'stinks') + ), + $this->table->rows[1] + ); + } + + + // Uility Methods + // -------------------------------------------------------------------- + + public function testPrepArgs() + { + $expected = array( + array('data' => 'name'), + array('data' => 'color'), + array('data' => 'size') + ); + + // test what would be discreet args, + // basically means a single array as the calling method + // will use func_get_args() + $this->assertEquals( + $expected, + $this->table->_prep_args(array( + 'name', 'color', 'size' + )), + 'discreet'); + + + // test what would be a single array argument. Again, nested + // due to func_get_args on calling methods + $this->assertEquals( + $expected, + $this->table->_prep_args(array( + array('name', 'color', 'size') + )), + 'array'); + + + // with cell attributes + + // need to add that new argument row to our expected outcome + $expected[] = array('data' => 'weight', 'class' => 'awesome'); + + $this->assertEquals( + $expected, + $this->table->_prep_args(array( + array('name', 'color', 'size', + array('data' => 'weight', 'class' => 'awesome') + ) + )), + 'attributes'); + } + + public function testDefaultTemplateKeys() + { + $deft_template = $this->table->_default_template(); + $keys = array( + 'table_open', + 'thead_open', 'thead_close', + 'heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', + 'tbody_open', 'tbody_close', + 'row_start', 'row_end', 'cell_start', 'cell_end', + 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', + 'table_close' + ); + + foreach ($keys as $key) + { + $this->assertArrayHasKey($key, $deft_template); + } + } + + public function testCompileTemplate() + { + $this->assertFalse($this->table->set_template('invalid_junk')); + + // non default key + $this->table->set_template(array('nonsense' => 'foo')); + $this->table->_compile_template(); + + $this->assertArrayHasKey('nonsense', $this->table->template); + $this->assertEquals('foo', $this->table->template['nonsense']); + + // override default + $this->table->set_template(array('table_close' => '')); + $this->table->_compile_template(); + + $this->assertArrayHasKey('table_close', $this->table->template); + $this->assertEquals('', $this->table->template['table_close']); + } + + public function testMakeColumns() + { + // Test bogus parameters + $this->assertFalse($this->table->make_columns('invalid_junk')); + $this->assertFalse( $this->table->make_columns(array())); + // $this->assertFalse( + // $this->table->make_columns(array('one', 'two')), + // '2.5' // not an integer! + // ); + + + // Now on to the actual column creation + + $five_values = array( + 'Laura', 'Red', '15', + 'Katie', 'Blue' + ); + + // No column count - no changes to the array + $this->assertEquals( + $five_values, + $this->table->make_columns($five_values) + ); + + // Column count of 3 leaves us with one   + $this->assertEquals( + array( + array('Laura', 'Red', '15'), + array('Katie', 'Blue', ' ') + ), + $this->table->make_columns($five_values, 3) + ); + + $this->markTestSkipped('Look at commented assertFalse above'); + } + + public function testClear() + { + $this->table->set_heading('Name', 'Color', 'Size'); + + // Make columns changes auto_heading + $rows = $this->table->make_columns(array( + 'Laura', 'Red', '15', + 'Katie', 'Blue' + ), 3); + + foreach ($rows as $row) + { + $this->table->add_row($row); + } + + $this->assertFalse($this->table->auto_heading); + $this->assertEquals(count($this->table->heading), 3); + $this->assertEquals(count($this->table->rows), 2); + + $this->table->clear(); + + $this->assertTrue($this->table->auto_heading); + $this->assertEmpty($this->table->heading); + $this->assertEmpty($this->table->rows); + } + + + public function testSetFromArray() + { + $this->assertFalse($this->table->_set_from_array('bogus')); + $this->assertFalse($this->table->_set_from_array(array())); + + $data = array( + array('name', 'color', 'number'), + array('Laura', 'Red', '22'), + array('Katie', 'Blue') + ); + + $this->table->_set_from_array($data, FALSE); + $this->assertEmpty($this->table->heading); + + $this->table->clear(); + + $expected_heading = array( + array('data' => 'name'), + array('data' => 'color'), + array('data' => 'number') + ); + + $expected_second = array( + array('data' => 'Katie'), + array('data' => 'Blue'), + ); + + $this->table->_set_from_array($data); + $this->assertEquals(count($this->table->rows), 2); + + $this->assertEquals( + $expected_heading, + $this->table->heading + ); + + $this->assertEquals( + $expected_second, + $this->table->rows[1] + ); + } + + function testSetFromObject() + { + $this->markTestSkipped('Not yet implemented.'); + } + + // Test main generate method + // -------------------------------------------------------------------- +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 2cadade8e3598fc4d19a3029db0b861a8d3bfc80 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 15:00:49 -0500 Subject: Adding typography library test. --- tests/codeigniter/libraries/Typography_test.php | 191 ++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 tests/codeigniter/libraries/Typography_test.php (limited to 'tests/codeigniter/libraries') diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php new file mode 100644 index 000000000..242a6e944 --- /dev/null +++ b/tests/codeigniter/libraries/Typography_test.php @@ -0,0 +1,191 @@ +type = new CI_Typography(); + + $this->ci_instance($obj); + + $this->type = $obj->type; + } + + // -------------------------------------------------------------------- + + /** + * Tests the format_characters() function. + * + * this can and should grow. + */ + public function testFormatCharacters() + { + $strs = array( + '"double quotes"' => '“double quotes”', + '"testing" in "theory" that is' => '“testing” in “theory” that is', + "Here's what I'm" => 'Here’s what I’m', + '&' => '&', + '&' => '&', + ' ' => ' ', + '--' => '—', + 'foo...' => 'foo…', + 'foo..' => 'foo..', + 'foo...bar.' => 'foo…bar.', + 'test. new' => 'test.  new', + ); + + foreach ($strs as $str => $expected) + { + $this->assertEquals($expected, $this->type->format_characters($str)); + } + } + + // -------------------------------------------------------------------- + + public function testNl2brExceptPre() + { + $str = << +I am inside a pre tag. Please don't mess with me. + +k? + + +That's my story and I'm sticking to it. + +The End. +EOH; + + $expected = << +
+I like to skip.
+
+Jump
+
+and sing.
+
+
+I am inside a pre tag.  Please don't mess with me.
+
+k?
+

+
+That's my story and I'm sticking to it.
+
+The End. +EOH; + + $this->assertEquals($expected, + $this->type->nl2br_except_pre($str)); + } + + // -------------------------------------------------------------------- + + public function testAutoTypography() + { + $this->_blank_string(); + $this->_standardize_new_lines(); + $this->_reduce_linebreaks(); + $this->_remove_comments(); + $this->_protect_pre(); + $this->_no_opening_block(); + $this->_protect_braced_quotes(); + } + + // -------------------------------------------------------------------- + + private function _blank_string() + { + // Test blank string + $this->assertEquals('', $this->type->auto_typography('')); + } + + // -------------------------------------------------------------------- + + private function _standardize_new_lines() + { + $strs = array( + "My string\rhas return characters" => "

My string
\nhas return characters

", + 'This one does not!' => '

This one does not!

' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, $this->type->auto_typography($str)); + } + } + + // -------------------------------------------------------------------- + + private function _reduce_linebreaks() + { + $str = "This has way too many linebreaks.\n\n\n\nSee?"; + $expect = "

This has way too many linebreaks.

\n\n

See?

"; + + $this->assertEquals($expect, $this->type->auto_typography($str, TRUE)); + } + + // -------------------------------------------------------------------- + + private function _remove_comments() + { + $str = ' But no!'; + $expect = '

  But no!

'; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + } + + // -------------------------------------------------------------------- + + private function _protect_pre() + { + $str = '

My Sentence

var_dump($this);
'; + $expect = '

My Sentence

var_dump($this);
'; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + } + + // -------------------------------------------------------------------- + + private function _no_opening_block() + { + $str = 'My Sentence
var_dump($this);
'; + $expect = '

My Sentence

var_dump($this);
'; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + } + + // -------------------------------------------------------------------- + + public function _protect_braced_quotes() + { + $this->type->protect_braced_quotes = TRUE; + + $str = 'Test {parse="foobar"}'; + $expect = '

Test {parse="foobar"}

'; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + + $this->type->protect_braced_quotes = FALSE; + + $str = 'Test {parse="foobar"}'; + $expect = '

Test {parse=“foobar”}

'; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + + + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9512ab8a22ff14a3789cba6e5ace03aed4196e23 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 15:10:48 -0500 Subject: Adding user agent library test. Needs some work, but is a good start. --- tests/codeigniter/libraries/User_agent_test.php | 91 +++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/codeigniter/libraries/User_agent_test.php (limited to 'tests/codeigniter/libraries') diff --git a/tests/codeigniter/libraries/User_agent_test.php b/tests/codeigniter/libraries/User_agent_test.php new file mode 100644 index 000000000..d1d950cd9 --- /dev/null +++ b/tests/codeigniter/libraries/User_agent_test.php @@ -0,0 +1,91 @@ +_user_agent; + + $obj = new StdClass; + $obj->agent = new CI_User_agent(); + + $this->ci_instance($obj); + + $this->agent = $obj->agent; + } + + // -------------------------------------------------------------------- + + public function testAcceptLang() + { + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en'; + + $this->assertEquals('en', $this->agent->accept_lang()); + + unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); + } + + // -------------------------------------------------------------------- + + public function testMobile() + { + // Mobile Not Set + $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua; + $this->assertEquals('', $this->agent->mobile()); + unset($_SERVER['HTTP_USER_AGENT']); + } + + // -------------------------------------------------------------------- + + public function testUtilIsFunctions() + { + $this->assertTrue($this->agent->is_browser()); + $this->assertFalse($this->agent->is_robot()); + $this->assertFalse($this->agent->is_mobile()); + $this->assertFalse($this->agent->is_referral()); + } + + // -------------------------------------------------------------------- + + public function testAgentString() + { + $this->assertEquals($this->_user_agent, $this->agent->agent_string()); + } + + // -------------------------------------------------------------------- + + public function testBrowserInfo() + { + $this->assertEquals('Mac OS X', $this->agent->platform()); + $this->assertEquals('Safari', $this->agent->browser()); + $this->assertEquals('533.20.27', $this->agent->version()); + $this->assertEquals('', $this->agent->robot()); + $this->assertEquals('', $this->agent->referrer()); + } + + // -------------------------------------------------------------------- + + public function testCharsets() + { + $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8'; + + $charsets = $this->agent->charsets(); + + $this->assertEquals('utf8', $charsets[0]); + + unset($_SERVER['HTTP_ACCEPT_CHARSET']); + + $this->assertFalse($this->agent->accept_charset()); + } + + // -------------------------------------------------------------------- + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 68286a4dcc1ed4d904ad992173c1b3621bf6fced Mon Sep 17 00:00:00 2001 From: Eric Barnes 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 ++++---- tests/codeigniter/libraries/Table_test.php | 26 ++++++++++++------------- tests/codeigniter/libraries/Typography_test.php | 8 ++++---- tests/codeigniter/libraries/User_agent_test.php | 14 ++++++------- 4 files changed, 28 insertions(+), 28 deletions(-) (limited to 'tests/codeigniter/libraries') 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(); diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index ded4c22c1..133179f3a 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -5,7 +5,7 @@ require BASEPATH.'libraries/Table.php'; class Table_test extends CI_TestCase { - public function setUp() + public function set_up() { $obj = new StdClass; $obj->table = new CI_table(); @@ -19,7 +19,7 @@ class Table_test extends CI_TestCase // Setter Methods // -------------------------------------------------------------------- - public function testSetTemplate() + public function test_set_template() { $this->assertFalse($this->table->set_template('not an array')); @@ -31,13 +31,13 @@ class Table_test extends CI_TestCase $this->assertEquals($template, $this->table->template); } - public function testSetEmpty() + public function test_set_empty() { $this->table->set_empty('nada'); $this->assertEquals('nada', $this->table->empty_cells); } - public function testSetCaption() + public function test_set_caption() { $this->table->set_caption('awesome cap'); $this->assertEquals('awesome cap', $this->table->caption); @@ -47,7 +47,7 @@ class Table_test extends CI_TestCase /* * @depends testPrepArgs */ - public function testSetHeading() + public function test_set_heading() { // uses _prep_args internally, so we'll just do a quick // check to verify that func_get_args and prep_args are @@ -69,7 +69,7 @@ class Table_test extends CI_TestCase /* * @depends testPrepArgs */ - public function testAddRow() + public function test_add_row() { // uses _prep_args internally, so we'll just do a quick // check to verify that func_get_args and prep_args are @@ -95,7 +95,7 @@ class Table_test extends CI_TestCase // Uility Methods // -------------------------------------------------------------------- - public function testPrepArgs() + public function test_prep_args() { $expected = array( array('data' => 'name'), @@ -139,7 +139,7 @@ class Table_test extends CI_TestCase 'attributes'); } - public function testDefaultTemplateKeys() + public function test_default_template_keys() { $deft_template = $this->table->_default_template(); $keys = array( @@ -158,7 +158,7 @@ class Table_test extends CI_TestCase } } - public function testCompileTemplate() + public function test_compile_template() { $this->assertFalse($this->table->set_template('invalid_junk')); @@ -177,7 +177,7 @@ class Table_test extends CI_TestCase $this->assertEquals('', $this->table->template['table_close']); } - public function testMakeColumns() + public function test_make_columns() { // Test bogus parameters $this->assertFalse($this->table->make_columns('invalid_junk')); @@ -213,7 +213,7 @@ class Table_test extends CI_TestCase $this->markTestSkipped('Look at commented assertFalse above'); } - public function testClear() + public function test_clear() { $this->table->set_heading('Name', 'Color', 'Size'); @@ -240,7 +240,7 @@ class Table_test extends CI_TestCase } - public function testSetFromArray() + public function test_set_from_array() { $this->assertFalse($this->table->_set_from_array('bogus')); $this->assertFalse($this->table->_set_from_array(array())); @@ -281,7 +281,7 @@ class Table_test extends CI_TestCase ); } - function testSetFromObject() + function test_set_from_object() { $this->markTestSkipped('Not yet implemented.'); } diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php index 242a6e944..a0533bae0 100644 --- a/tests/codeigniter/libraries/Typography_test.php +++ b/tests/codeigniter/libraries/Typography_test.php @@ -5,7 +5,7 @@ require BASEPATH.'libraries/Typography.php'; class Typography_test extends CI_TestCase { - public function setUp() + public function set_up() { $obj = new StdClass; $obj->type = new CI_Typography(); @@ -22,7 +22,7 @@ class Typography_test extends CI_TestCase * * this can and should grow. */ - public function testFormatCharacters() + public function test_format_characters() { $strs = array( '"double quotes"' => '“double quotes”', @@ -46,7 +46,7 @@ class Typography_test extends CI_TestCase // -------------------------------------------------------------------- - public function testNl2brExceptPre() + public function test_nl2br_except_pre() { $str = <<_blank_string(); $this->_standardize_new_lines(); diff --git a/tests/codeigniter/libraries/User_agent_test.php b/tests/codeigniter/libraries/User_agent_test.php index d1d950cd9..277c12ed0 100644 --- a/tests/codeigniter/libraries/User_agent_test.php +++ b/tests/codeigniter/libraries/User_agent_test.php @@ -9,7 +9,7 @@ class UserAgent_test extends CI_TestCase protected $_user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'; protected $_mobile_ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'; - public function setUp() + public function set_up() { // set a baseline user agent $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent; @@ -24,7 +24,7 @@ class UserAgent_test extends CI_TestCase // -------------------------------------------------------------------- - public function testAcceptLang() + public function test_accept_lang() { $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en'; @@ -35,7 +35,7 @@ class UserAgent_test extends CI_TestCase // -------------------------------------------------------------------- - public function testMobile() + public function test_mobile() { // Mobile Not Set $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua; @@ -45,7 +45,7 @@ class UserAgent_test extends CI_TestCase // -------------------------------------------------------------------- - public function testUtilIsFunctions() + public function test_util_is_functions() { $this->assertTrue($this->agent->is_browser()); $this->assertFalse($this->agent->is_robot()); @@ -55,14 +55,14 @@ class UserAgent_test extends CI_TestCase // -------------------------------------------------------------------- - public function testAgentString() + public function test_agent_string() { $this->assertEquals($this->_user_agent, $this->agent->agent_string()); } // -------------------------------------------------------------------- - public function testBrowserInfo() + public function test_browser_info() { $this->assertEquals('Mac OS X', $this->agent->platform()); $this->assertEquals('Safari', $this->agent->browser()); @@ -73,7 +73,7 @@ class UserAgent_test extends CI_TestCase // -------------------------------------------------------------------- - public function testCharsets() + public function test_charsets() { $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8'; -- cgit v1.2.3-24-g4f1b From 051a317e1e51c2ab50920e3ced50732bc7041bd7 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 27 Nov 2011 00:49:25 -0500 Subject: Fixed accept lang test to account for boolean results. --- tests/codeigniter/libraries/User_agent_test.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tests/codeigniter/libraries') diff --git a/tests/codeigniter/libraries/User_agent_test.php b/tests/codeigniter/libraries/User_agent_test.php index 277c12ed0..6f9e87196 100644 --- a/tests/codeigniter/libraries/User_agent_test.php +++ b/tests/codeigniter/libraries/User_agent_test.php @@ -8,17 +8,17 @@ class UserAgent_test extends CI_TestCase { protected $_user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'; protected $_mobile_ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'; - + public function set_up() { // set a baseline user agent $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent; - + $obj = new StdClass; $obj->agent = new CI_User_agent(); - + $this->ci_instance($obj); - + $this->agent = $obj->agent; } @@ -27,10 +27,10 @@ class UserAgent_test extends CI_TestCase public function test_accept_lang() { $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en'; - - $this->assertEquals('en', $this->agent->accept_lang()); - + $this->assertTrue($this->agent->accept_lang()); unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); + $this->assertTrue($this->agent->accept_lang('en')); + $this->assertFalse($this->agent->accept_lang('fr')); } // -------------------------------------------------------------------- @@ -70,19 +70,19 @@ class UserAgent_test extends CI_TestCase $this->assertEquals('', $this->agent->robot()); $this->assertEquals('', $this->agent->referrer()); } - + // -------------------------------------------------------------------- public function test_charsets() { $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8'; - + $charsets = $this->agent->charsets(); - + $this->assertEquals('utf8', $charsets[0]); - + unset($_SERVER['HTTP_ACCEPT_CHARSET']); - + $this->assertFalse($this->agent->accept_charset()); } -- cgit v1.2.3-24-g4f1b From e39728c55d3745ff60742d7dd1c5114ec690d1db Mon Sep 17 00:00:00 2001 From: tiyowan Date: Sat, 10 Mar 2012 02:10:44 +0400 Subject: Fix issue #1148 Rewrote tests to use reflection to access protected/private functions of Table class. This fixes fatal errors that prevent the test suite from executing other tests. Signed-off-by: tiyowan --- tests/codeigniter/libraries/Table_test.php | 64 +++++++++++++++++++----------- 1 file changed, 41 insertions(+), 23 deletions(-) (limited to 'tests/codeigniter/libraries') diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 133179f3a..045216b16 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -106,42 +106,50 @@ class Table_test extends CI_TestCase // test what would be discreet args, // basically means a single array as the calling method // will use func_get_args() + + $reflectionOfTable = new ReflectionClass($this->table); + $method = $reflectionOfTable->getMethod('_prep_args'); + + $method->setAccessible(true); + $this->assertEquals( $expected, - $this->table->_prep_args(array( - 'name', 'color', 'size' - )), - 'discreet'); - + $method->invokeArgs( + $this->table, array(array('name', 'color', 'size'), 'discreet') + ) + ); // test what would be a single array argument. Again, nested // due to func_get_args on calling methods $this->assertEquals( $expected, - $this->table->_prep_args(array( - array('name', 'color', 'size') - )), - 'array'); + $method->invokeArgs( + $this->table, array(array('name', 'color', 'size'), 'array') + ) + ); // with cell attributes // need to add that new argument row to our expected outcome $expected[] = array('data' => 'weight', 'class' => 'awesome'); - + $this->assertEquals( $expected, - $this->table->_prep_args(array( - array('name', 'color', 'size', - array('data' => 'weight', 'class' => 'awesome') - ) - )), - 'attributes'); + $method->invokeArgs( + $this->table, array(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')), 'attributes') + ) + ); } public function test_default_template_keys() { - $deft_template = $this->table->_default_template(); + $reflectionOfTable = new ReflectionClass($this->table); + $method = $reflectionOfTable->getMethod('_default_template'); + + $method->setAccessible(true); + + $deft_template = $method->invoke($this->table); $keys = array( 'table_open', 'thead_open', 'thead_close', @@ -160,18 +168,23 @@ class Table_test extends CI_TestCase public function test_compile_template() { + $reflectionOfTable = new ReflectionClass($this->table); + $method = $reflectionOfTable->getMethod('_compile_template'); + + $method->setAccessible(true); + $this->assertFalse($this->table->set_template('invalid_junk')); // non default key $this->table->set_template(array('nonsense' => 'foo')); - $this->table->_compile_template(); + $method->invoke($this->table); $this->assertArrayHasKey('nonsense', $this->table->template); $this->assertEquals('foo', $this->table->template['nonsense']); // override default $this->table->set_template(array('table_close' => '')); - $this->table->_compile_template(); + $method->invoke($this->table); $this->assertArrayHasKey('table_close', $this->table->template); $this->assertEquals('', $this->table->template['table_close']); @@ -242,8 +255,13 @@ class Table_test extends CI_TestCase public function test_set_from_array() { - $this->assertFalse($this->table->_set_from_array('bogus')); - $this->assertFalse($this->table->_set_from_array(array())); + $reflectionOfTable = new ReflectionClass($this->table); + $method = $reflectionOfTable->getMethod('_set_from_array'); + + $method->setAccessible(true); + + $this->assertFalse($method->invokeArgs($this->table, array('bogus'))); + $this->assertFalse($method->invoke($this->table, array())); $data = array( array('name', 'color', 'number'), @@ -251,7 +269,7 @@ class Table_test extends CI_TestCase array('Katie', 'Blue') ); - $this->table->_set_from_array($data, FALSE); + $method->invokeArgs($this->table, array($data, FALSE)); $this->assertEmpty($this->table->heading); $this->table->clear(); @@ -267,7 +285,7 @@ class Table_test extends CI_TestCase array('data' => 'Blue'), ); - $this->table->_set_from_array($data); + $method->invokeArgs($this->table, array($data)); $this->assertEquals(count($this->table->rows), 2); $this->assertEquals( -- cgit v1.2.3-24-g4f1b From 8749bc7e836c196dfef37d3b7b5a67736a15092c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sun, 11 Mar 2012 05:43:45 +0700 Subject: Fix incomplete and skipped test --- tests/codeigniter/libraries/Table_test.php | 51 +++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'tests/codeigniter/libraries') diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 045216b16..0208a465a 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -194,11 +194,8 @@ class Table_test extends CI_TestCase { // Test bogus parameters $this->assertFalse($this->table->make_columns('invalid_junk')); - $this->assertFalse( $this->table->make_columns(array())); - // $this->assertFalse( - // $this->table->make_columns(array('one', 'two')), - // '2.5' // not an integer! - // ); + $this->assertFalse($this->table->make_columns(array())); + $this->assertFalse($this->table->make_columns(array('one', 'two'), '2.5')); // Now on to the actual column creation @@ -222,8 +219,6 @@ class Table_test extends CI_TestCase ), $this->table->make_columns($five_values, 3) ); - - $this->markTestSkipped('Look at commented assertFalse above'); } public function test_clear() @@ -301,7 +296,47 @@ class Table_test extends CI_TestCase function test_set_from_object() { - $this->markTestSkipped('Not yet implemented.'); + $reflectionOfTable = new ReflectionClass($this->table); + $method = $reflectionOfTable->getMethod('_set_from_object'); + + $method->setAccessible(true); + + // Make a stub of query instance + $query = new CI_TestCase(); + $query->list_fields = function(){ + return array('name', 'email'); + }; + $query->result_array = function(){ + return array( + array('name' => 'John Doe', 'email' => 'john@doe.com'), + array('name' => 'Foo Bar', 'email' => 'foo@bar.com'), + ); + }; + $query->num_rows = function(){ + return 2; + }; + + $expected_heading = array( + array('data' => 'name'), + array('data' => 'email') + ); + + $expected_second = array( + 'name' => array('data' => 'Foo Bar'), + 'email' => array('data' => 'foo@bar.com'), + ); + + $method->invokeArgs($this->table, array($query)); + + $this->assertEquals( + $expected_heading, + $this->table->heading + ); + + $this->assertEquals( + $expected_second, + $this->table->rows[1] + ); } // Test main generate method -- cgit v1.2.3-24-g4f1b