summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/codeigniter/database/query_builder/group_test.php24
-rwxr-xr-xtests/mocks/database/ci_test.sqlitebin19456 -> 19456 bytes
-rw-r--r--tests/mocks/database/schema/skeleton.php12
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
--- 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 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'),