From 05983fcb5b8f04fb895c025e28ef6ffc44a5f602 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 11 Feb 2014 16:51:43 +0200 Subject: A bug fix and optimizations in CI_Table --- tests/codeigniter/libraries/Table_test.php | 47 +++++++++++++++++------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'tests/codeigniter/libraries') diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index ce04b6a6d..4bfbdd623 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -200,16 +200,14 @@ 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(NULL)); - $data = array( array('name', 'color', 'number'), array('Laura', 'Red', '22'), array('Katie', 'Blue') ); - $this->table->set_from_array($data, FALSE); + $this->table->auto_heading = FALSE; + $this->table->set_from_array($data); $this->assertEmpty($this->table->heading); $this->table->clear(); @@ -235,22 +233,14 @@ class Table_test extends CI_TestCase { public function test_set_from_object() { - // 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; - }; - - $this->table->set_from_object($query); + // This needs to be passed by reference to CI_DB_result::__construct() + $dummy = new stdClass(); + $dummy->conn_id = NULL; + $dummy->result_id = NULL; + + $db_result = new DB_result_dummy($dummy); + + $this->table->set_from_db_result($db_result); $expected = array( array('data' => 'name'), @@ -290,4 +280,21 @@ class Table_test extends CI_TestCase { $this->assertTrue(strpos($table, 'Small') !== FALSE); } +} + +// We need this for the _set_from_db_result() test +class DB_result_dummy extends CI_DB_result +{ + public function list_fields() + { + return array('name', 'email'); + } + + public function result_array() + { + return array( + array('name' => 'John Doe', 'email' => 'john@doe.com'), + array('name' => 'Foo Bar', 'email' => 'foo@bar.com') + ); + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b