From 190c6bb125447f83793d9437f1bea28feada910a Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 3 May 2012 12:13:39 +0700 Subject: Cleaning up --- tests/codeigniter/database/query_builder/insert_test.php | 5 ++--- tests/codeigniter/database/query_builder/select_test.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 53ce23c19..8ba60e242 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -30,11 +30,10 @@ class Insert_test extends CI_TestCase { // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); - $jobs = $this->db->get('job')->result_array(); - $job1 = $jobs[0]; + $job1 = $this->db->get('job')->row(); // Check the result - $this->assertEquals('Grocery Sales', $job1['name']); + $this->assertEquals('Grocery Sales', $job1->name); } diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index dbf432a7c..0d299ed16 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -41,10 +41,10 @@ class Select_test extends CI_TestCase { { $job_min = $this->db->select_min('id') ->get('job') - ->result_array(); + ->row(); // Minimum id was 1 - $this->assertEquals('1', $job_min[0]['id']); + $this->assertEquals('1', $job_min->id); } // ------------------------------------------------------------------------ @@ -56,10 +56,10 @@ class Select_test extends CI_TestCase { { $job_max = $this->db->select_max('id') ->get('job') - ->result_array(); + ->row(); // Maximum id was 4 - $this->assertEquals('4', $job_max[0]['id']); + $this->assertEquals('4', $job_max->id); } // ------------------------------------------------------------------------ @@ -71,10 +71,10 @@ class Select_test extends CI_TestCase { { $job_avg = $this->db->select_avg('id') ->get('job') - ->result_array(); + ->row(); // Average should be 2.5 - $this->assertEquals('2.5', $job_avg[0]['id']); + $this->assertEquals('2.5', $job_avg->id); } // ------------------------------------------------------------------------ @@ -86,10 +86,10 @@ class Select_test extends CI_TestCase { { $job_sum = $this->db->select_sum('id') ->get('job') - ->result_array(); + ->row(); // Sum of ids should be 10 - $this->assertEquals('10', $job_sum[0]['id']); + $this->assertEquals('10', $job_sum->id); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6e131cbd0a5243f29a5ad9f56c80715e534e4267 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 3 May 2012 12:14:19 +0700 Subject: FROM clause API code-coverage --- .../database/query_builder/from_test.php | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/from_test.php diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php new file mode 100644 index 000000000..95ae4dfdb --- /dev/null +++ b/tests/codeigniter/database/query_builder/from_test.php @@ -0,0 +1,51 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_from_simple() + { + $jobs = $this->db->from('job') + ->get() + ->result_array(); + + // Check items + $this->assertEquals(4, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_from_with_where() + { + $job1 = $this->db->from('job') + ->where('id', 1) + ->get() + ->row(); + + // Check the result + $this->assertEquals('1', $job1->id); + $this->assertEquals('Developer', $job1->name); + $this->assertEquals('Awesome job, but sometimes makes you bored', $job1->description); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 17f799e1017d1688a2890a1ba78e4f53d80af77e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 3 May 2012 15:15:40 +0700 Subject: Add user entity into schema skeleton --- tests/mocks/database/schema/skeleton.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index a3d5bac65..fbd533bfb 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -50,6 +50,24 @@ class Mock_Database_Schema_Skeleton { */ public static function create_tables() { + // User Table + static::$forge->add_field(array( + 'id' => array( + 'type' => 'INTEGER', + 'constraint' => 3, + ), + 'name' => array( + 'type' => 'VARCHAR', + 'constraint' => 40, + ), + 'email' => array( + 'type' => 'VARCHAR', + 'constraint' => 100, + ), + )); + static::$forge->add_key('id', TRUE); + static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE)); + // Job Table static::$forge->add_field(array( 'id' => array( @@ -77,6 +95,12 @@ class Mock_Database_Schema_Skeleton { { // Job Data $data = array( + 'user' => array( + array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com'), + array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'), + array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'), + array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'), + ) 'job' => array( array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'), array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'), -- cgit v1.2.3-24-g4f1b From d6b41bb2659f959da01aee0ddb38bb4bce6cd4b6 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 15:05:22 +0700 Subject: JOIN clause API code-coverage --- .../database/query_builder/join_test.php | 38 ++++++++++++++++++++++ tests/mocks/database/schema/skeleton.php | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/codeigniter/database/query_builder/join_test.php diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php new file mode 100644 index 000000000..e05329d67 --- /dev/null +++ b/tests/codeigniter/database/query_builder/join_test.php @@ -0,0 +1,38 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_join_simple() + { + $job_user = $this->db->select('job.id as job_id, job.name as job_name, user.id as user_id, user.name as user_name') + ->from('job') + ->join('user', 'user.id = job.id') + ->get() + ->result_array(); + + // Check the result + $this->assertEquals('1', $job_user[0]['job_id']); + $this->assertEquals('1', $job_user[0]['user_id']); + $this->assertEquals('Derek Jones', $job_user[0]['user_name']); + $this->assertEquals('Developer', $job_user[0]['job_name']); + } + +} \ No newline at end of file diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index fbd533bfb..9ebd6e85f 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -100,7 +100,7 @@ class Mock_Database_Schema_Skeleton { array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'), array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'), array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'), - ) + ), 'job' => array( array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'), array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'), -- cgit v1.2.3-24-g4f1b From 12f5475e2b279d1c2361ad5fc85bc2ba0d0f9033 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 15:46:39 +0700 Subject: WHERE clause API code-coverage --- .../database/query_builder/where_test.php | 144 +++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/where_test.php diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php new file mode 100644 index 000000000..607eaa076 --- /dev/null +++ b/tests/codeigniter/database/query_builder/where_test.php @@ -0,0 +1,144 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_simple_key_value() + { + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + // Check the result + $this->assertEquals('1', $job1->id); + $this->assertEquals('Developer', $job1->name); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_custom_key_value() + { + $jobs = $this->db->where('id !=', 1) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_associative_array() + { + $where = array('id >' => 2, 'name !=' => 'Accountant'); + $jobs = $this->db->where($where) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(1, count($jobs)); + + // Should be Musician + $job = current($jobs); + + $this->assertEquals('Musician', $job['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_custom_string() + { + $where = "id > 2 AND name != 'Accountant'"; + $jobs = $this->db->where($where) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(1, count($jobs)); + + // Should be Musician + $job = current($jobs); + + $this->assertEquals('Musician', $job['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_or() + { + $jobs = $this->db->where('name !=', 'Accountant') + ->or_where('id >', 3) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Politician', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_in() + { + $jobs = $this->db->where_in('name', array('Politician', 'Accountant')) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Accountant', $jobs[1]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_not_in() + { + $jobs = $this->db->where_not_in('name', array('Politician', 'Accountant')) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Musician', $jobs[1]['name']); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f78018ec6b081518e4be24934448862a31bda9f8 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 15:53:55 +0700 Subject: LIKE clause API code-coverage --- .../database/query_builder/like_test.php | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/like_test.php diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php new file mode 100644 index 000000000..df98c713f --- /dev/null +++ b/tests/codeigniter/database/query_builder/like_test.php @@ -0,0 +1,90 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_like() + { + $job1 = $this->db->like('name', 'veloper') + ->get('job') + ->row(); + + // Check the result + $this->assertEquals('1', $job1->id); + $this->assertEquals('Developer', $job1->name); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_or_like() + { + $jobs = $this->db->like('name', 'ian') + ->or_like('name', 'veloper') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Politician', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_not_like() + { + $jobs = $this->db->not_like('name', 'veloper') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Accountant', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_or_not_like() + { + $jobs = $this->db->like('name', 'an') + ->or_not_like('name', 'veloper') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Accountant', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4e607b00b2c56b7fdcc5f1d1a290be2363c74a46 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 19:22:48 +0700 Subject: GROUP BY clause API code-coverage --- .travis.yml | 3 +- .../database/query_builder/group_test.php | 37 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/codeigniter/database/query_builder/group_test.php diff --git a/.travis.yml b/.travis.yml index 97ea0422d..971f62f38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,4 +25,5 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml branches: only: - develop - - master \ No newline at end of file + - master + - db-tests \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php new file mode 100644 index 000000000..ddb2d0d6a --- /dev/null +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -0,0 +1,37 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_group_by() + { + $jobs = $this->db->select('name') + ->from('job') + ->group_by('name HAVING SUM(id) > 2') + ->get() + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Accountant', $jobs[0]['name']); + $this->assertEquals('Musician', $jobs[1]['name']); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f7377abee2ef1e165a362edc9a1c650373a002ca Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 19:42:24 +0700 Subject: Trace error --- .../database/query_builder/group_test.php | 8 ++++---- tests/mocks/database/ci_test.sqlite | Bin 17408 -> 19456 bytes 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php index ddb2d0d6a..dd248ae9a 100644 --- a/tests/codeigniter/database/query_builder/group_test.php +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -22,16 +22,16 @@ class Group_test extends CI_TestCase { */ public function test_group_by() { - $jobs = $this->db->select('name') + $jobs = $this->db->select('job.name as job_name, job.id as job_id') ->from('job') - ->group_by('name HAVING SUM(id) > 2') + ->group_by('job_name HAVING SUM(job_id) > 2') ->get() ->result_array(); // Check the result $this->assertEquals(2, count($jobs)); - $this->assertEquals('Accountant', $jobs[0]['name']); - $this->assertEquals('Musician', $jobs[1]['name']); + $this->assertEquals('Accountant', $jobs[0]['job_name']); + $this->assertEquals('Musician', $jobs[1]['job_name']); } } \ No newline at end of file diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index 86d868af2..e4128b23f 100755 Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ -- cgit v1.2.3-24-g4f1b From 1afd479059c3d6f7c46aa0c36aa56cfba7f94226 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 20:34:30 +0700 Subject: HAVING clause API code-coverage --- .../database/query_builder/group_test.php | 24 +++++++++++++++++---- tests/mocks/database/ci_test.sqlite | Bin 19456 -> 19456 bytes tests/mocks/database/schema/skeleton.php | 12 +++++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php index dd248ae9a..7d8abc33f 100644 --- a/tests/codeigniter/database/query_builder/group_test.php +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -22,16 +22,32 @@ class Group_test extends CI_TestCase { */ public function test_group_by() { - $jobs = $this->db->select('job.name as job_name, job.id as job_id') + $jobs = $this->db->select('name') ->from('job') - ->group_by('job_name HAVING SUM(job_id) > 2') + ->group_by('name') + ->get() + ->result_array(); + + // Check the result + $this->assertEquals(4, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_having_by() + { + $jobs = $this->db->select('name') + ->from('job') + ->group_by('name') + ->having('SUM(id) > 2') ->get() ->result_array(); // Check the result $this->assertEquals(2, count($jobs)); - $this->assertEquals('Accountant', $jobs[0]['job_name']); - $this->assertEquals('Musician', $jobs[1]['job_name']); } } \ No newline at end of file diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index e4128b23f..d48e3317f 100755 Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 9ebd6e85f..671336cc4 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -64,6 +64,10 @@ class Mock_Database_Schema_Skeleton { 'type' => 'VARCHAR', 'constraint' => 100, ), + 'country' => array( + 'type' => 'VARCHAR', + 'constraint' => 40, + ), )); static::$forge->add_key('id', TRUE); static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE)); @@ -96,10 +100,10 @@ class Mock_Database_Schema_Skeleton { // Job Data $data = array( 'user' => array( - array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com'), - array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'), - array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'), - array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'), + array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com', 'country' => 'US'), + array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com', 'country' => 'Iran'), + array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com', 'country' => 'US'), + array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK'), ), 'job' => array( array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'), -- cgit v1.2.3-24-g4f1b From 44d8d881b401238661d81fc9db10482604b4cf43 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 20:43:45 +0700 Subject: DISTINCT clause API code-coverage --- .../database/query_builder/distinct_test.php | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/distinct_test.php diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php new file mode 100644 index 000000000..925eadb19 --- /dev/null +++ b/tests/codeigniter/database/query_builder/distinct_test.php @@ -0,0 +1,34 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_distinct() + { + $users = $this->db->select('country') + ->distinct() + ->get('user') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($users)); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8ca31f34c855c783689198f0d352e6efec352b4d Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 23:57:46 +0700 Subject: PDO SQLite bug fixed, for result_object --- system/database/drivers/pdo/pdo_result.php | 19 +++++++------------ tests/mocks/database/ci_test.sqlite | Bin 19456 -> 19456 bytes 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php index 19aee1dfc..0b8937cc5 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -84,19 +84,14 @@ class CI_DB_pdo_result extends CI_DB_result { // Define the output $output = array('assoc', 'object'); + // Initial value + $this->result_assoc = array() and $this->result_object = array(); + // Fetch the result - foreach ($output as $type) + while ($row = $this->_fetch_assoc()) { - // Define the method and handler - $res_method = '_fetch_'.$type; - $res_handler = 'result_'.$type; - - $this->$res_handler = array(); - - while ($row = $this->$res_method()) - { - $this->{$res_handler}[] = $row; - } + $this->result_assoc[] = $row; + $this->result_object[] = (object) $row; } // Save this as buffer and marked the fetch flag @@ -249,7 +244,7 @@ class CI_DB_pdo_result extends CI_DB_result { */ protected function _fetch_object() { - return $this->result_id->fetchObject(); + return $this->result_id->fetch(PDO::FETCH_OBJ); } } diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index d48e3317f..23a3de2a4 100755 Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ -- cgit v1.2.3-24-g4f1b From d2d329a99f60bebc36eebc1c7b3c1a94b9789b49 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:33:04 +0700 Subject: ORDER BY clause API code-coverage --- .../database/query_builder/order_test.php | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/order_test.php diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php new file mode 100644 index 000000000..01aa1c2b4 --- /dev/null +++ b/tests/codeigniter/database/query_builder/order_test.php @@ -0,0 +1,55 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_order_ascending() + { + $jobs = $this->db->order_by('name', 'asc') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(4, count($jobs)); + $this->assertEquals('Accountant', $jobs[0]['name']); + $this->assertEquals('Developer', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + $this->assertEquals('Politician', $jobs[3]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_order_descending() + { + $jobs = $this->db->order_by('name', 'desc') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(4, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Musician', $jobs[1]['name']); + $this->assertEquals('Developer', $jobs[2]['name']); + $this->assertEquals('Accountant', $jobs[3]['name']); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From be6fb4271ce723376930507dbe534f91344f26c7 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:35:41 +0700 Subject: LIMIT clause API code-coverage --- .../database/query_builder/limit_test.php | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/limit_test.php diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php new file mode 100644 index 000000000..704f3b651 --- /dev/null +++ b/tests/codeigniter/database/query_builder/limit_test.php @@ -0,0 +1,49 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_limit() + { + $jobs = $this->db->limit(2) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_limit_and_offset() + { + $jobs = $this->db->limit(2, 2) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Accountant', $jobs[0]['name']); + $this->assertEquals('Musician', $jobs[1]['name']); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c386b2a363c289afcfa07eea081050e35c1e86d8 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:42:02 +0700 Subject: count code-coverage --- .../database/query_builder/count_test.php | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/count_test.php diff --git a/tests/codeigniter/database/query_builder/count_test.php b/tests/codeigniter/database/query_builder/count_test.php new file mode 100644 index 000000000..5e691692d --- /dev/null +++ b/tests/codeigniter/database/query_builder/count_test.php @@ -0,0 +1,44 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_count_all() + { + $job_count = $this->db->count_all('job'); + + // Check the result + $this->assertEquals(4, $job_count); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_count_all_results() + { + $job_count = $this->db->like('name', 'ian') + ->count_all_results('job'); + + // Check the result + $this->assertEquals(2, $job_count); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9ec507badf60952750e76b5d83da54874dd19119 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:55:39 +0700 Subject: UPDATE and SET clause code-coverage --- .../database/query_builder/update_test.php | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/update_test.php diff --git a/tests/codeigniter/database/query_builder/update_test.php b/tests/codeigniter/database/query_builder/update_test.php new file mode 100644 index 000000000..f5bbffd4f --- /dev/null +++ b/tests/codeigniter/database/query_builder/update_test.php @@ -0,0 +1,71 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_update() + { + // Check initial record + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + $this->assertEquals('Developer', $job1->name); + + // Do the update + $job_data = array('name' => 'Programmer'); + + $this->db->where('id', 1) + ->update('job', $job_data); + + // Check updated record + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + $this->assertEquals('Programmer', $job1->name); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_update_with_set() + { + // Check initial record + $job1 = $this->db->where('id', 4) + ->get('job') + ->row(); + + $this->assertEquals('Musician', $job1->name); + + // Do the update + $this->db->set('name', 'Vocalist'); + $this->db->update('job', NULL, 'id = 4'); + + // Check updated record + $job1 = $this->db->where('id', 4) + ->get('job') + ->row(); + + $this->assertEquals('Vocalist', $job1->name); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6657cc1672f3f466655b1e476028b9d46a16bd1c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:06:41 +0700 Subject: DELETE code-coverage --- .../database/query_builder/delete_test.php | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/delete_test.php diff --git a/tests/codeigniter/database/query_builder/delete_test.php b/tests/codeigniter/database/query_builder/delete_test.php new file mode 100644 index 000000000..84ea7616f --- /dev/null +++ b/tests/codeigniter/database/query_builder/delete_test.php @@ -0,0 +1,72 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_delete() + { + // Check initial record + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + $this->assertEquals('Developer', $job1->name); + + // Do the delete + $this->db->delete('job', array('id' => 1)); + + // Check the record + $job1 = $this->db->where('id', 1) + ->get('job'); + + $this->assertEmpty($job1->result_array()); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_delete_several_tables() + { + // Check initial record + $user4 = $this->db->where('id', 4) + ->get('user') + ->row(); + + $job4 = $this->db->where('id', 4) + ->get('job') + ->row(); + + $this->assertEquals('Musician', $job4->name); + $this->assertEquals('Chris Martin', $user4->name); + + // Do the delete + $this->db->delete(array('job', 'user'), array('id' => 4)); + + // Check the record + $job4 = $this->db->where('id', 4)->get('job'); + $user4 = $this->db->where('id', 4)->get('user'); + + $this->assertEmpty($job4->result_array()); + $this->assertEmpty($user4->result_array()); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 85859b212e480e2e1a59aae50c759367d6794ecd Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:26:51 +0700 Subject: empty table API code-coverage --- .../database/query_builder/empty_test.php | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/empty_test.php diff --git a/tests/codeigniter/database/query_builder/empty_test.php b/tests/codeigniter/database/query_builder/empty_test.php new file mode 100644 index 000000000..d1f56285f --- /dev/null +++ b/tests/codeigniter/database/query_builder/empty_test.php @@ -0,0 +1,39 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_empty_table() + { + // Check initial record + $jobs = $this->db->get('job')->result_array(); + + $this->assertEquals(4, count($jobs)); + + // Do the empty + $this->db->empty_table('job'); + + // Check the record + $jobs = $this->db->get('job'); + + $this->assertEmpty($jobs->result_array()); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 39f35fde6d023433e98904105f55f305483b6b5e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:29:13 +0700 Subject: TRUNCATE code-coverage --- .../database/query_builder/truncate_test.php | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/truncate_test.php diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php new file mode 100644 index 000000000..2a9c8a91e --- /dev/null +++ b/tests/codeigniter/database/query_builder/truncate_test.php @@ -0,0 +1,61 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_truncate() + { + // Check initial record + $jobs = $this->db->get('job')->result_array(); + + $this->assertEquals(4, count($jobs)); + + // Do the empty + $this->db->truncate('job'); + + // Check the record + $jobs = $this->db->get('job'); + + $this->assertEmpty($jobs->result_array()); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_truncate_with_from() + { + // Check initial record + $users = $this->db->get('user')->result_array(); + + $this->assertEquals(4, count($users)); + + // Do the empty + $this->db->from('user') + ->truncate(); + + // Check the record + $users = $this->db->get('user'); + + $this->assertEmpty($users->result_array()); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 51a7c0b98df29205d39bb404c2bcd12bfb4ed4cb Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:43:08 +0700 Subject: Clean up --- tests/README.md | 6 ------ tests/codeigniter/Setup_test.php | 10 +++++----- tests/travis/mysql.phpunit.xml | 6 +----- tests/travis/pdo/mysql.phpunit.xml | 4 ---- tests/travis/pdo/pgsql.phpunit.xml | 6 +----- tests/travis/pdo/sqlite.phpunit.xml | 6 +----- tests/travis/pgsql.phpunit.xml | 6 +----- tests/travis/sqlite.phpunit.xml | 6 +----- 8 files changed, 10 insertions(+), 40 deletions(-) diff --git a/tests/README.md b/tests/README.md index 6d83c34d8..b46f344cb 100644 --- a/tests/README.md +++ b/tests/README.md @@ -2,12 +2,6 @@ Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=feature/unit-tests)](http://travis-ci.org/EllisLab/CodeIgniter) -*Do not merge to default until these issues have been addressed* - -- Clean up naming conventions -- Figure out config stuff -- Figure out database testing - ### Introduction: This is the preliminary CodeIgniter testing documentation. It diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php index 550245f2f..b48e32bfb 100644 --- a/tests/codeigniter/Setup_test.php +++ b/tests/codeigniter/Setup_test.php @@ -2,12 +2,12 @@ class Setup_test extends PHPUnit_Framework_TestCase { - function test_nonsense() + function test_bootstrap_constants() { - $this->markTestIncomplete('not implemented'); - // ensure that our bootstrapped test environment - // is a good representation of an isolated CI install - //die('here'); + $this->assertTrue(defined('PROJECT_BASE')); + $this->assertTrue(defined('BASEPATH')); + $this->assertTrue(defined('APPPATH')); + $this->assertTrue(defined('VIEWPATH')); } } \ No newline at end of file diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml index e9556f758..c5fcf1335 100644 --- a/tests/travis/mysql.phpunit.xml +++ b/tests/travis/mysql.phpunit.xml @@ -14,11 +14,7 @@ - ../codeigniter/Setup_test.php - ../codeigniter/core - ../codeigniter/helpers - ../codeigniter/libraries - ../codeigniter/database + ../codeigniter diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml index 69eece24f..f6fcc1c39 100644 --- a/tests/travis/pdo/mysql.phpunit.xml +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -14,10 +14,6 @@ - ../../codeigniter/Setup_test.php - ../../codeigniter/core - ../../codeigniter/helpers - ../../codeigniter/libraries ../../codeigniter/database diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml index e68c3e028..6a23227db 100644 --- a/tests/travis/pdo/pgsql.phpunit.xml +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -14,11 +14,7 @@ - ../../codeigniter/Setup_test.php - ../../codeigniter/core - ../../codeigniter/helpers - ../../codeigniter/libraries - ../../codeigniter/database + ../../codeigniter diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml index 1871f6221..b85b7308a 100644 --- a/tests/travis/pdo/sqlite.phpunit.xml +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -14,11 +14,7 @@ - ../../codeigniter/Setup_test.php - ../../codeigniter/core - ../../codeigniter/helpers - ../../codeigniter/libraries - ../../codeigniter/database + ../../codeigniter diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml index ad8aeded2..78b6046cf 100644 --- a/tests/travis/pgsql.phpunit.xml +++ b/tests/travis/pgsql.phpunit.xml @@ -14,11 +14,7 @@ - ../codeigniter/Setup_test.php - ../codeigniter/core - ../codeigniter/helpers - ../codeigniter/libraries - ../codeigniter/database + ../codeigniter diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml index 628370e93..46e3d5073 100644 --- a/tests/travis/sqlite.phpunit.xml +++ b/tests/travis/sqlite.phpunit.xml @@ -14,11 +14,7 @@ - ../codeigniter/Setup_test.php - ../codeigniter/core - ../codeigniter/helpers - ../codeigniter/libraries - ../codeigniter/database + ../codeigniter -- cgit v1.2.3-24-g4f1b From 82196b945e291c65fdb66b35e3205f786ce8e921 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:52:47 +0700 Subject: Remove temporary branch from travis whitelist --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 971f62f38..97ea0422d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,5 +25,4 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml branches: only: - develop - - master - - db-tests \ No newline at end of file + - master \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d41f423528b21d97ff0eb268e10947b257f5a90e Mon Sep 17 00:00:00 2001 From: Soesapto Joeni Hantoro Date: Fri, 11 May 2012 11:00:42 +0700 Subject: Generate better conditions statement on boolean field type. Actually boolean field type need TRUE or FALSE value. Common DBMS (e.g., MySQL) can substite this value with 1 or 0, but it can't be implemented on PostgreSQL. So, its better to use TRUE or FALSE value for boolean field type. --- system/database/DB_query_builder.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index d0af66de1..969a25acb 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -432,7 +432,21 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $k .= ' IS NULL'; } - if ( ! is_null($v)) + if ( is_bool($v)) + { + if ($escape === TRUE) + { + $k = $this->protect_identifiers($k, FALSE, $escape); + + $v = ' '.($v ? 'TRUE' : 'FALSE'); + } + + if ( ! $this->_has_operator($k)) + { + $k .= ' ='; + } + } + else if ( ! is_null($v)) { if ($escape === TRUE) { -- cgit v1.2.3-24-g4f1b From b01d96f65a78528323b3917eec31c4ed8b58eb7b Mon Sep 17 00:00:00 2001 From: Soesapto Joeni Hantoro Date: Fri, 11 May 2012 11:18:38 +0700 Subject: simpler script, add boolean handling on DB_driver/escape --- system/database/DB_query_builder.php | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 969a25acb..8fa67ea06 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -432,26 +432,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $k .= ' IS NULL'; } - if ( is_bool($v)) + if ( ! is_null($v)) { if ($escape === TRUE) { $k = $this->protect_identifiers($k, FALSE, $escape); - - $v = ' '.($v ? 'TRUE' : 'FALSE'); + $v = ' '.$this->escape($v); } - - if ( ! $this->_has_operator($k)) + else if (is_bool($v)) { - $k .= ' ='; - } - } - else if ( ! is_null($v)) - { - if ($escape === TRUE) - { - $k = $this->protect_identifiers($k, FALSE, $escape); - $v = ' '.$this->escape($v); + $v = ' '.($v ? 'TRUE' : 'FALSE'); } if ( ! $this->_has_operator($k)) -- cgit v1.2.3-24-g4f1b From 938c7ef59991ed12b8634b292e2f8fc9fa385264 Mon Sep 17 00:00:00 2001 From: Soesapto Joeni Hantoro Date: Fri, 11 May 2012 11:21:43 +0700 Subject: Escaping boolean data type, some DBMS (e.g., postgre) need it --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index ef77b594e..09513e267 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -696,7 +696,7 @@ abstract class CI_DB_driver { } elseif (is_bool($str)) { - return ($str === FALSE) ? 0 : 1; + return ($str === FALSE) ? "FALSE" : "TRUE"; } elseif (is_null($str)) { -- cgit v1.2.3-24-g4f1b From f25b9295557f9d5fda1e0b2342964f17e26a390e Mon Sep 17 00:00:00 2001 From: Soesapto Joeni Hantoro Date: Tue, 15 May 2012 08:10:31 +0700 Subject: Escaping boolean data type on postgre --- system/database/drivers/postgre/postgre_driver.php | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 84bf768ee..915763ad7 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -310,6 +310,35 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * "Smart" Escape String + * + * Escapes data based on type + * Sets boolean and null types + * + * @param string + * @return mixed + */ + public function escape($str) + { + if (is_string($str) OR method_exists($str, '__toString')) + { + return "'".$this->escape_str($str)."'"; + } + elseif (is_bool($str)) + { + return $str ? "TRUE" : "FALSE"; + } + elseif (is_null($str)) + { + return 'NULL'; + } + + return $str; + } + + // -------------------------------------------------------------------- + /** * Affected Rows * @@ -557,6 +586,78 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Where + * + * Called by where() or or_where() + * + * @param mixed + * @param mixed + * @param string + * @return object + * + */ + protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) + { + $type = $this->_group_get_type($type); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + // If the escape value was not set will will base it on the global setting + if ( ! is_bool($escape)) + { + $escape = $this->_protect_identifiers; + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type; + + if (is_null($v) && ! $this->_has_operator($k)) + { + // value appears not to have been set, assign the test to IS NULL + $k .= ' IS NULL'; + } + + if ( ! is_null($v)) + { + if ($escape === TRUE) + { + $k = $this->protect_identifiers($k, FALSE, $escape); + $v = ' '.$this->escape($v); + } + else if (is_bool($v)) + { + $v = ' '.($v ? 'TRUE' : 'FALSE'); + } + + if ( ! $this->_has_operator($k)) + { + $k .= ' = '; + } + } + else + { + $k = $this->protect_identifiers($k, FALSE, $escape); + } + + $this->qb_where[] = $prefix.$k.$v; + if ($this->qb_caching === TRUE) + { + $this->qb_cache_where[] = $prefix.$k.$v; + $this->qb_cache_exists[] = 'where'; + } + + } + + return $this; + } + + // -------------------------------------------------------------------- + /** * Close DB Connection * -- cgit v1.2.3-24-g4f1b From 68fe7935a391b20dcf0cbdde9c1b49c697a6443b Mon Sep 17 00:00:00 2001 From: Soesapto Joeni Hantoro Date: Tue, 15 May 2012 08:19:29 +0700 Subject: Rollback changes, move it to postgre_driver --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 09513e267..ef77b594e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -696,7 +696,7 @@ abstract class CI_DB_driver { } elseif (is_bool($str)) { - return ($str === FALSE) ? "FALSE" : "TRUE"; + return ($str === FALSE) ? 0 : 1; } elseif (is_null($str)) { -- cgit v1.2.3-24-g4f1b From f79bdda8d823495b1f6524bd0cafb985860b7331 Mon Sep 17 00:00:00 2001 From: Soesapto Joeni Hantoro Date: Tue, 15 May 2012 08:20:24 +0700 Subject: Rollback changes, move it to postgre_driver --- system/database/DB_query_builder.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 8fa67ea06..d0af66de1 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -439,10 +439,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $k = $this->protect_identifiers($k, FALSE, $escape); $v = ' '.$this->escape($v); } - else if (is_bool($v)) - { - $v = ' '.($v ? 'TRUE' : 'FALSE'); - } if ( ! $this->_has_operator($k)) { -- cgit v1.2.3-24-g4f1b From d2574db779d97f2a1ff8351b5a7c31c028601e17 Mon Sep 17 00:00:00 2001 From: Soesapto Joeni Hantoro Date: Tue, 15 May 2012 16:28:16 +0700 Subject: Escaping boolean data type for postgre --- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 915763ad7..4b2fb7a9e 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -327,7 +327,7 @@ class CI_DB_postgre_driver extends CI_DB { } elseif (is_bool($str)) { - return $str ? "TRUE" : "FALSE"; + return ($str) ? 'TRUE' : 'FALSE'; } elseif (is_null($str)) { @@ -629,7 +629,7 @@ class CI_DB_postgre_driver extends CI_DB { $k = $this->protect_identifiers($k, FALSE, $escape); $v = ' '.$this->escape($v); } - else if (is_bool($v)) + elseif (is_bool($v)) { $v = ' '.($v ? 'TRUE' : 'FALSE'); } -- cgit v1.2.3-24-g4f1b From 5963db71348a06c14b38e7ce998df4249d4fd45a Mon Sep 17 00:00:00 2001 From: Soesapto Joeni Hantoro Date: Tue, 15 May 2012 16:31:18 +0700 Subject: escaping boolean data type for postgre change log --- user_guide_src/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index a70531901..77c7e2ca4 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -100,6 +100,7 @@ Release Date: Not Released - Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge `. - Added MSSQL, SQLSRV support for optimize_table() in :doc:`Database Utility `. - Improved CUBRID support for list_databases() in :doc:`Database Utility ` (until now only the currently used database was returned). + - Added escaping boolean data type for PosgreSQL - Libraries -- cgit v1.2.3-24-g4f1b From dabeaa11ca2076935e5091e0f9e90ff9c4593962 Mon Sep 17 00:00:00 2001 From: Soesapto Joeni Hantoro Date: Tue, 15 May 2012 16:37:46 +0700 Subject: Escaping boolean data type for postgre --- system/database/drivers/postgre/postgre_driver.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 4b2fb7a9e..670eb549d 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -321,20 +321,12 @@ class CI_DB_postgre_driver extends CI_DB { */ public function escape($str) { - if (is_string($str) OR method_exists($str, '__toString')) - { - return "'".$this->escape_str($str)."'"; - } - elseif (is_bool($str)) + if (is_bool($str)) { return ($str) ? 'TRUE' : 'FALSE'; } - elseif (is_null($str)) - { - return 'NULL'; - } - return $str; + return parent::escape($str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 242925bc084e4d606d5f34bdb49bdf9f5235ec32 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 15 May 2012 13:03:51 +0300 Subject: Minor changes on the pull #1355 additions --- system/database/drivers/postgre/postgre_driver.php | 8 ++++---- user_guide_src/source/changelog.rst | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 670eb549d..17bd37b38 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -328,7 +328,7 @@ class CI_DB_postgre_driver extends CI_DB { return parent::escape($str); } - + // -------------------------------------------------------------------- /** @@ -623,7 +623,7 @@ class CI_DB_postgre_driver extends CI_DB { } elseif (is_bool($v)) { - $v = ' '.($v ? 'TRUE' : 'FALSE'); + $v = ($v ? ' TRUE' : ' FALSE'); } if ( ! $this->_has_operator($k)) @@ -647,7 +647,7 @@ class CI_DB_postgre_driver extends CI_DB { return $this; } - + // -------------------------------------------------------------------- /** @@ -664,4 +664,4 @@ class CI_DB_postgre_driver extends CI_DB { } /* End of file postgre_driver.php */ -/* Location: ./system/database/drivers/postgre/postgre_driver.php */ +/* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 2f2ebce98..d33a6a635 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -77,6 +77,7 @@ Release Date: Not Released - pg_version() is now used to get the database version number, when possible. - Added db_set_charset() support. - Added _optimize_table() support for the :doc:`Database Utility Class ` (rebuilds table indexes). + - Added boolean data type support in escape(). - Added a constructor to the DB_result class and moved all driver-specific properties and logic out of the base DB_driver class to allow better abstraction. - Removed limit() and order_by() support for UPDATE and DELETE queries in PostgreSQL driver. Postgres does not support those features. - Removed protect_identifiers() and renamed internal method _protect_identifiers() to it instead - it was just an alias. @@ -100,7 +101,6 @@ Release Date: Not Released - Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge `. - Added MSSQL, SQLSRV support for optimize_table() in :doc:`Database Utility `. - Improved CUBRID support for list_databases() in :doc:`Database Utility ` (until now only the currently used database was returned). - - Added escaping boolean data type for PosgreSQL - Libraries -- cgit v1.2.3-24-g4f1b From 570e77cd78e0c704b032c3e7702372ca63d5ddaa Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 18:47:24 +0700 Subject: Benchmark code-coverage --- tests/codeigniter/core/Benchmark_test.php | 42 +++++++++++++++++++++++++++++++ tests/mocks/core/benchmark.php | 3 +++ 2 files changed, 45 insertions(+) create mode 100644 tests/codeigniter/core/Benchmark_test.php create mode 100644 tests/mocks/core/benchmark.php diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php new file mode 100644 index 000000000..2790b582e --- /dev/null +++ b/tests/codeigniter/core/Benchmark_test.php @@ -0,0 +1,42 @@ +benchmark = new Mock_Core_Benchmark(); + } + + // -------------------------------------------------------------------- + + public function test_mark() + { + $this->assertEmpty($this->benchmark->marker); + + $this->benchmark->mark('code_start'); + + $this->assertEquals(1, count($this->benchmark->marker)); + $this->assertArrayHasKey('code_start', $this->benchmark->marker); + } + + // -------------------------------------------------------------------- + + public function test_elapsed_time() + { + $this->assertEquals('{elapsed_time}', $this->benchmark->elapsed_time()); + $this->assertEmpty($this->benchmark->elapsed_time('undefined_point')); + + $this->benchmark->mark('code_start'); + sleep(1); + $this->benchmark->mark('code_end'); + + $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 3)); + } + + // -------------------------------------------------------------------- + + public function test_memory_usage() + { + $this->assertEquals('{memory_usage}', $this->benchmark->memory_usage()); + } +} \ No newline at end of file diff --git a/tests/mocks/core/benchmark.php b/tests/mocks/core/benchmark.php new file mode 100644 index 000000000..d92be21db --- /dev/null +++ b/tests/mocks/core/benchmark.php @@ -0,0 +1,3 @@ + Date: Tue, 15 May 2012 18:48:45 +0700 Subject: Clean up autoloader annotation --- tests/mocks/autoloader.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index f1bdb5d6f..92c9bea59 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -6,7 +6,6 @@ // // Prototype : // -// include_once('Mock_Core_Loader') // Will load ./mocks/core/loader.php // $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php // $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php // and so on... -- cgit v1.2.3-24-g4f1b From 8af88f3f729b7bcfd2a106f858b5445deafe5ed0 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 21:52:53 +0700 Subject: Security Code coverage --- tests/Bootstrap.php | 3 ++ tests/codeigniter/core/Security_test.php | 79 ++++++++++++++++++++++++++++++++ tests/mocks/core/security.php | 27 +++++++++++ tests/mocks/libraries/table.php | 2 +- 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 tests/codeigniter/core/Security_test.php create mode 100644 tests/mocks/core/security.php diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 9f89d1be8..2bec364ef 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -12,6 +12,9 @@ define('BASEPATH', PROJECT_BASE.'system/'); define('APPPATH', PROJECT_BASE.'application/'); define('VIEWPATH', PROJECT_BASE.''); +// Set cookie for security test +$_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE)); + // Prep our test environment require_once 'vfsStream/vfsStream.php'; include_once $dir.'/mocks/core/common.php'; diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php new file mode 100644 index 000000000..c3b526965 --- /dev/null +++ b/tests/codeigniter/core/Security_test.php @@ -0,0 +1,79 @@ +ci_set_config('csrf_protection', TRUE); + $this->ci_set_config('csrf_token_name', 'ci_csrf_token'); + // @see : ./Bootstrap.php Line 16 + $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie'); + $this->ci_set_config('csrf_expire', 7200); + $this->ci_set_config('csrf_regenerate', TRUE); + $this->ci_set_config('csrf_exclude_uris', array()); + + $this->ci_set_config('cookie_prefix', ""); + $this->ci_set_config('cookie_domain', ""); + $this->ci_set_config('cookie_path', "/"); + $this->ci_set_config('cookie_secure', FALSE); + $this->ci_set_config('cookie_httponly', FALSE); + + $this->security = new Mock_Core_Security(); + } + + // -------------------------------------------------------------------- + + public function test_csrf_verify() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + + $this->assertInstanceOf('CI_Security', $this->security->csrf_verify()); + } + + // -------------------------------------------------------------------- + + public function test_csrf_verify_invalid() + { + // Without issuing $_POST[csrf_token_name], this request will triggering CSRF error + $_SERVER['REQUEST_METHOD'] = 'POST'; + + $this->setExpectedException('RuntimeException', 'CI Error: The action you have requested is not allowed'); + + $this->security->csrf_verify(); + } + + // -------------------------------------------------------------------- + + public function test_csrf_verify_valid() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST[$this->security->csrf_token_name] = $this->security->csrf_hash; + + $this->assertInstanceOf('CI_Security', $this->security->csrf_verify()); + } + + // -------------------------------------------------------------------- + + public function test_get_csrf_hash() + { + $this->assertEquals($this->security->csrf_hash, $this->security->get_csrf_hash()); + } + + // -------------------------------------------------------------------- + + public function test_get_csrf_token_name() + { + $this->assertEquals('ci_csrf_token', $this->security->get_csrf_token_name()); + } + + // -------------------------------------------------------------------- + + public function test_xss_clean() + { + $harm_string = "Hello, i try to your site"; + + $harmless_string = $this->security->xss_clean($harm_string); + + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless_string); + } +} \ No newline at end of file diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php new file mode 100644 index 000000000..de8e44710 --- /dev/null +++ b/tests/mocks/core/security.php @@ -0,0 +1,27 @@ +{'_'.$property}) ? $this->{'_'.$property} : NULL; + } + + // Overide inaccesible protected method + public function __call($method, $params) + { + if (is_callable(array($this, '_'.$method))) + { + return call_user_func_array(array($this, '_'.$method), $params); + } + + throw new BadMethodCallException('Method '.$method.' was not found'); + } + +} \ No newline at end of file diff --git a/tests/mocks/libraries/table.php b/tests/mocks/libraries/table.php index 1a6ff8d35..97fbb30bd 100644 --- a/tests/mocks/libraries/table.php +++ b/tests/mocks/libraries/table.php @@ -2,7 +2,7 @@ class Mock_Libraries_Table extends CI_Table { - // Overide inaccesible private or protected method + // Overide inaccesible protected method public function __call($method, $params) { if (is_callable(array($this, '_'.$method))) -- cgit v1.2.3-24-g4f1b From d40a545e9e7e4dc222d58fe46fe23f3691f043ee Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 22:00:14 +0700 Subject: Comment block for explanation --- tests/mocks/core/security.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php index de8e44710..c5269fbc5 100644 --- a/tests/mocks/core/security.php +++ b/tests/mocks/core/security.php @@ -4,6 +4,9 @@ class Mock_Core_Security extends CI_Security { public function csrf_set_cookie() { + // We cannot set cookie in CLI mode, so for csrf test, who rely on $_COOKIE, + // we superseded set_cookie with directly set the cookie variable, + // @see : ./Bootstrap.php, line 16 return $this; } -- cgit v1.2.3-24-g4f1b From 7756af5df0a53930019e9fd7b828504f0c2c5427 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 23:57:05 +0700 Subject: Input class code-coverage --- tests/Bootstrap.php | 3 - tests/codeigniter/core/Input_test.php | 144 +++++++++++++++++++++++++++++++ tests/codeigniter/core/Security_test.php | 14 +-- tests/mocks/core/input.php | 31 +++++++ tests/mocks/core/security.php | 2 +- tests/mocks/core/utf8.php | 27 ++++++ 6 files changed, 207 insertions(+), 14 deletions(-) create mode 100644 tests/codeigniter/core/Input_test.php create mode 100644 tests/mocks/core/input.php create mode 100644 tests/mocks/core/utf8.php diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 2bec364ef..9f89d1be8 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -12,9 +12,6 @@ define('BASEPATH', PROJECT_BASE.'system/'); define('APPPATH', PROJECT_BASE.'application/'); define('VIEWPATH', PROJECT_BASE.''); -// Set cookie for security test -$_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE)); - // Prep our test environment require_once 'vfsStream/vfsStream.php'; include_once $dir.'/mocks/core/common.php'; diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php new file mode 100644 index 000000000..fd0576e38 --- /dev/null +++ b/tests/codeigniter/core/Input_test.php @@ -0,0 +1,144 @@ +ci_set_config('allow_get_array', TRUE); + $this->ci_set_config('global_xss_filtering', FALSE); + $this->ci_set_config('csrf_protection', FALSE); + + $security = new Mock_Core_Security(); + $utf8 = new Mock_Core_Utf8(); + + $this->input = new Mock_Core_Input($security, $utf8); + } + + // -------------------------------------------------------------------- + + public function test_get_not_exists() + { + $this->assertEmpty($this->input->get()); + $this->assertEmpty($this->input->get('foo')); + + $this->assertTrue( ! $this->input->get()); + $this->assertTrue( ! $this->input->get('foo')); + + $this->assertTrue($this->input->get() == FALSE); + $this->assertTrue($this->input->get('foo') == FALSE); + + $this->assertTrue($this->input->get() === FALSE); + $this->assertTrue($this->input->get('foo') === FALSE); + } + + // -------------------------------------------------------------------- + + public function test_get_exist() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET['foo'] = 'bar'; + + $this->assertArrayHasKey('foo', $this->input->get()); + $this->assertEquals('bar', $this->input->get('foo')); + } + + // -------------------------------------------------------------------- + + public function test_get_exist_with_xss_clean() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET['harm'] = "Hello, i try to your site"; + + $this->assertArrayHasKey('harm', $this->input->get()); + $this->assertEquals("Hello, i try to your site", $this->input->get('harm')); + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $this->input->get('harm', TRUE)); + } + + // -------------------------------------------------------------------- + + public function test_post_not_exists() + { + $this->assertEmpty($this->input->post()); + $this->assertEmpty($this->input->post('foo')); + + $this->assertTrue( ! $this->input->post()); + $this->assertTrue( ! $this->input->post('foo')); + + $this->assertTrue($this->input->post() == FALSE); + $this->assertTrue($this->input->post('foo') == FALSE); + + $this->assertTrue($this->input->post() === FALSE); + $this->assertTrue($this->input->post('foo') === FALSE); + } + + // -------------------------------------------------------------------- + + public function test_post_exist() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['foo'] = 'bar'; + + $this->assertArrayHasKey('foo', $this->input->post()); + $this->assertEquals('bar', $this->input->post('foo')); + } + + // -------------------------------------------------------------------- + + public function test_post_exist_with_xss_clean() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['harm'] = "Hello, i try to your site"; + + $this->assertArrayHasKey('harm', $this->input->post()); + $this->assertEquals("Hello, i try to your site", $this->input->post('harm')); + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $this->input->post('harm', TRUE)); + } + + // -------------------------------------------------------------------- + + public function test_get_post() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['foo'] = 'bar'; + + $this->assertEquals('bar', $this->input->get_post('foo')); + } + + // -------------------------------------------------------------------- + + public function test_cookie() + { + $_COOKIE['foo'] = 'bar'; + + $this->assertEquals('bar', $this->input->cookie('foo')); + } + + // -------------------------------------------------------------------- + + public function test_server() + { + $this->assertEquals('GET', $this->input->server('REQUEST_METHOD')); + } + + // -------------------------------------------------------------------- + + public function test_fetch_from_array() + { + $data = array( + 'foo' => 'bar', + 'harm' => 'Hello, i try to your site', + ); + + $foo = $this->input->fetch_from_array($data, 'foo'); + $harm = $this->input->fetch_from_array($data, 'harm'); + $harmless = $this->input->fetch_from_array($data, 'harm', TRUE); + + $this->assertEquals('bar', $foo); + $this->assertEquals("Hello, i try to your site", $harm); + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless); + } +} \ No newline at end of file diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index c3b526965..1796ba74d 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -4,19 +4,13 @@ class Security_test extends CI_TestCase { public function set_up() { + // Set cookie for security test + $_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE)); + + // Set config for Security class $this->ci_set_config('csrf_protection', TRUE); $this->ci_set_config('csrf_token_name', 'ci_csrf_token'); - // @see : ./Bootstrap.php Line 16 $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie'); - $this->ci_set_config('csrf_expire', 7200); - $this->ci_set_config('csrf_regenerate', TRUE); - $this->ci_set_config('csrf_exclude_uris', array()); - - $this->ci_set_config('cookie_prefix', ""); - $this->ci_set_config('cookie_domain', ""); - $this->ci_set_config('cookie_path', "/"); - $this->ci_set_config('cookie_secure', FALSE); - $this->ci_set_config('cookie_httponly', FALSE); $this->security = new Mock_Core_Security(); } diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php new file mode 100644 index 000000000..8a337d2ef --- /dev/null +++ b/tests/mocks/core/input.php @@ -0,0 +1,31 @@ +_allow_get_array = (config_item('allow_get_array') === TRUE); + $this->_enable_xss = (config_item('global_xss_filtering') === TRUE); + $this->_enable_csrf = (config_item('csrf_protection') === TRUE); + + // Assign Security and Utf8 classes + $this->security = $security; + $this->uni = $utf8; + + // Sanitize global arrays + $this->_sanitize_globals(); + } + + public function fetch_from_array($array, $index = '', $xss_clean = FALSE) + { + return parent::_fetch_from_array($array, $index, $xss_clean); + } + +} \ No newline at end of file diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php index c5269fbc5..d7ea0e6bd 100644 --- a/tests/mocks/core/security.php +++ b/tests/mocks/core/security.php @@ -6,7 +6,7 @@ class Mock_Core_Security extends CI_Security { { // We cannot set cookie in CLI mode, so for csrf test, who rely on $_COOKIE, // we superseded set_cookie with directly set the cookie variable, - // @see : ./Bootstrap.php, line 16 + // @see : ./tests/codeigniter/core/Security_test.php, line 8 return $this; } diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php new file mode 100644 index 000000000..b77d717e7 --- /dev/null +++ b/tests/mocks/core/utf8.php @@ -0,0 +1,27 @@ + Date: Wed, 16 May 2012 00:08:05 +0700 Subject: Remove unused hardcoded reference from *phpunit.xml files --- tests/travis/mysql.phpunit.xml | 2 -- tests/travis/pdo/mysql.phpunit.xml | 4 +--- tests/travis/pdo/pgsql.phpunit.xml | 2 -- tests/travis/pdo/sqlite.phpunit.xml | 2 -- tests/travis/pgsql.phpunit.xml | 2 -- tests/travis/sqlite.phpunit.xml | 2 -- 6 files changed, 1 insertion(+), 13 deletions(-) diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml index c5fcf1335..1792ae38d 100644 --- a/tests/travis/mysql.phpunit.xml +++ b/tests/travis/mysql.phpunit.xml @@ -21,8 +21,6 @@ PEAR_INSTALL_DIR PHP_LIBDIR - PROJECT_BASE.'tests' - '../../system/core/CodeIgniter.php' \ No newline at end of file diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml index f6fcc1c39..602030d4e 100644 --- a/tests/travis/pdo/mysql.phpunit.xml +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -14,15 +14,13 @@ - ../../codeigniter/database + ../../codeigniter PEAR_INSTALL_DIR PHP_LIBDIR - PROJECT_BASE.'tests' - '../../../system/core/CodeIgniter.php' \ No newline at end of file diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml index 6a23227db..77e1493c6 100644 --- a/tests/travis/pdo/pgsql.phpunit.xml +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -21,8 +21,6 @@ PEAR_INSTALL_DIR PHP_LIBDIR - PROJECT_BASE.'tests' - '../../../system/core/CodeIgniter.php' \ No newline at end of file diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml index b85b7308a..cdccef017 100644 --- a/tests/travis/pdo/sqlite.phpunit.xml +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -21,8 +21,6 @@ PEAR_INSTALL_DIR PHP_LIBDIR - PROJECT_BASE.'tests' - '../../../system/core/CodeIgniter.php' \ No newline at end of file diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml index 78b6046cf..dfc1bff1c 100644 --- a/tests/travis/pgsql.phpunit.xml +++ b/tests/travis/pgsql.phpunit.xml @@ -21,8 +21,6 @@ PEAR_INSTALL_DIR PHP_LIBDIR - PROJECT_BASE.'tests' - '../../system/core/CodeIgniter.php' \ No newline at end of file diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml index 46e3d5073..3223da5e7 100644 --- a/tests/travis/sqlite.phpunit.xml +++ b/tests/travis/sqlite.phpunit.xml @@ -21,8 +21,6 @@ PEAR_INSTALL_DIR PHP_LIBDIR - PROJECT_BASE.'tests' - '../../system/core/CodeIgniter.php' \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 04d4091dfa551475998c351e09858e5ebdcf4482 Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Mon, 30 Apr 2012 16:04:43 +0100 Subject: fix backtrace filtering The backtrace was filtered to remove CI system files, but the filter was buggy. It would also filter out application files which happened to contain the string "system"... or ALL files, if the application directory is under /system/ (Perhaps the latter comes as a surprise, but it's explicitly mentioned in index.php and ). Instead, we should test whether the file is underneath BASEPATH (using realpath() to make sure we have the same sort of slashes). --- application/errors/error_php.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/application/errors/error_php.php b/application/errors/error_php.php index 3855720de..b76dc8a9e 100644 --- a/application/errors/error_php.php +++ b/application/errors/error_php.php @@ -40,12 +40,15 @@

Backtrace:

- + +

File:
Line:
Function:

+

-- cgit v1.2.3-24-g4f1b From 09a1b5e7fb3c930aa9a50e246236227a499b5d28 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 16 May 2012 22:18:00 +0700 Subject: Reduce decimal points, since there is a micro differencess on runtime and update travis status --- tests/README.md | 2 +- tests/codeigniter/core/Benchmark_test.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/README.md b/tests/README.md index b46f344cb..c8fc608e8 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,6 +1,6 @@ # CodeIgniter Unit Tests # -Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=feature/unit-tests)](http://travis-ci.org/EllisLab/CodeIgniter) +Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=develop)](http://travis-ci.org/EllisLab/CodeIgniter) ### Introduction: diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php index 2790b582e..109b38821 100644 --- a/tests/codeigniter/core/Benchmark_test.php +++ b/tests/codeigniter/core/Benchmark_test.php @@ -29,8 +29,8 @@ class Benchmark_test extends CI_TestCase { $this->benchmark->mark('code_start'); sleep(1); $this->benchmark->mark('code_end'); - - $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 3)); + + $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1)); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b