summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2012-05-15 00:00:06 +0200
committerPhil Sturgeon <email@philsturgeon.co.uk>2012-05-15 00:00:06 +0200
commit212b0470e1aa288ba4f4d47d13647d6cd150fd15 (patch)
treef800288e4d064c8b9e1f1f1aa6f1a3c075918cb2
parentfff6c2a3caa1ce14e58fcb3ee0d937d17985eea1 (diff)
parent82196b945e291c65fdb66b35e3205f786ce8e921 (diff)
Merge pull request #1324 from toopay/db-tests
Improved DB tests
-rw-r--r--system/database/drivers/pdo/pdo_result.php19
-rw-r--r--tests/README.md6
-rw-r--r--tests/codeigniter/Setup_test.php10
-rw-r--r--tests/codeigniter/database/query_builder/count_test.php44
-rw-r--r--tests/codeigniter/database/query_builder/delete_test.php72
-rw-r--r--tests/codeigniter/database/query_builder/distinct_test.php34
-rw-r--r--tests/codeigniter/database/query_builder/empty_test.php39
-rw-r--r--tests/codeigniter/database/query_builder/from_test.php51
-rw-r--r--tests/codeigniter/database/query_builder/group_test.php53
-rw-r--r--tests/codeigniter/database/query_builder/insert_test.php5
-rw-r--r--tests/codeigniter/database/query_builder/join_test.php38
-rw-r--r--tests/codeigniter/database/query_builder/like_test.php90
-rw-r--r--tests/codeigniter/database/query_builder/limit_test.php49
-rw-r--r--tests/codeigniter/database/query_builder/order_test.php55
-rw-r--r--tests/codeigniter/database/query_builder/select_test.php16
-rw-r--r--tests/codeigniter/database/query_builder/truncate_test.php61
-rw-r--r--tests/codeigniter/database/query_builder/update_test.php71
-rw-r--r--tests/codeigniter/database/query_builder/where_test.php144
-rwxr-xr-xtests/mocks/database/ci_test.sqlitebin17408 -> 19456 bytes
-rw-r--r--tests/mocks/database/schema/skeleton.php28
-rw-r--r--tests/travis/mysql.phpunit.xml6
-rw-r--r--tests/travis/pdo/mysql.phpunit.xml4
-rw-r--r--tests/travis/pdo/pgsql.phpunit.xml6
-rw-r--r--tests/travis/pdo/sqlite.phpunit.xml6
-rw-r--r--tests/travis/pgsql.phpunit.xml6
-rw-r--r--tests/travis/sqlite.phpunit.xml6
26 files changed, 856 insertions, 63 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/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/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 @@
+<?php
+
+class Count_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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 @@
+<?php
+
+class Delete_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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 @@
+<?php
+
+class Distinct_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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 @@
+<?php
+
+class Empty_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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 @@
+<?php
+
+class From_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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..7d8abc33f
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/group_test.php
@@ -0,0 +1,53 @@
+<?php
+
+class Group_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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')
+ ->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));
+ }
+
+} \ No newline at end of file
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/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 @@
+<?php
+
+class Join_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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/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 @@
+<?php
+
+class Like_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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 @@
+<?php
+
+class Limit_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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 @@
+<?php
+
+class Order_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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
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 @@
+<?php
+
+class Truncate_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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 @@
+<?php
+
+class Update_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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 @@
+<?php
+
+class Where_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
index 86d868af2..23a3de2a4 100755
--- a/tests/mocks/database/ci_test.sqlite
+++ b/tests/mocks/database/ci_test.sqlite
Binary files differ
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index a3d5bac65..671336cc4 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -50,6 +50,28 @@ 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,
+ ),
+ 'country' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40,
+ ),
+ ));
+ 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 +99,12 @@ class Mock_Database_Schema_Skeleton {
{
// Job Data
$data = array(
+ 'user' => array(
+ 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'),
array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'),
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 @@
</php>
<testsuites>
<testsuite name="CodeIgniter Core Test Suite">
- <file>../codeigniter/Setup_test.php</file>
- <directory suffix="test.php">../codeigniter/core</directory>
- <directory suffix="test.php">../codeigniter/helpers</directory>
- <directory suffix="test.php">../codeigniter/libraries</directory>
- <directory suffix="test.php">../codeigniter/database</directory>
+ <directory suffix="test.php">../codeigniter</directory>
</testsuite>
</testsuites>
<filters>
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 @@
</php>
<testsuites>
<testsuite name="CodeIgniter Core Test Suite">
- <file>../../codeigniter/Setup_test.php</file>
- <directory suffix="test.php">../../codeigniter/core</directory>
- <directory suffix="test.php">../../codeigniter/helpers</directory>
- <directory suffix="test.php">../../codeigniter/libraries</directory>
<directory suffix="test.php">../../codeigniter/database</directory>
</testsuite>
</testsuites>
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 @@
</php>
<testsuites>
<testsuite name="CodeIgniter Core Test Suite">
- <file>../../codeigniter/Setup_test.php</file>
- <directory suffix="test.php">../../codeigniter/core</directory>
- <directory suffix="test.php">../../codeigniter/helpers</directory>
- <directory suffix="test.php">../../codeigniter/libraries</directory>
- <directory suffix="test.php">../../codeigniter/database</directory>
+ <directory suffix="test.php">../../codeigniter</directory>
</testsuite>
</testsuites>
<filters>
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 @@
</php>
<testsuites>
<testsuite name="CodeIgniter Core Test Suite">
- <file>../../codeigniter/Setup_test.php</file>
- <directory suffix="test.php">../../codeigniter/core</directory>
- <directory suffix="test.php">../../codeigniter/helpers</directory>
- <directory suffix="test.php">../../codeigniter/libraries</directory>
- <directory suffix="test.php">../../codeigniter/database</directory>
+ <directory suffix="test.php">../../codeigniter</directory>
</testsuite>
</testsuites>
<filters>
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 @@
</php>
<testsuites>
<testsuite name="CodeIgniter Core Test Suite">
- <file>../codeigniter/Setup_test.php</file>
- <directory suffix="test.php">../codeigniter/core</directory>
- <directory suffix="test.php">../codeigniter/helpers</directory>
- <directory suffix="test.php">../codeigniter/libraries</directory>
- <directory suffix="test.php">../codeigniter/database</directory>
+ <directory suffix="test.php">../codeigniter</directory>
</testsuite>
</testsuites>
<filters>
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 @@
</php>
<testsuites>
<testsuite name="CodeIgniter Core Test Suite">
- <file>../codeigniter/Setup_test.php</file>
- <directory suffix="test.php">../codeigniter/core</directory>
- <directory suffix="test.php">../codeigniter/helpers</directory>
- <directory suffix="test.php">../codeigniter/libraries</directory>
- <directory suffix="test.php">../codeigniter/database</directory>
+ <directory suffix="test.php">../codeigniter</directory>
</testsuite>
</testsuites>
<filters>