blob: dd248ae9a1ea6d9854ccf8e127d745b42824b776 [file] [log] [blame]
Taufan Aditya4e607b02012-05-04 19:22:48 +07001<?php
2
3class Group_test extends CI_TestCase {
4
5 /**
6 * @var object Database/Query Builder holder
7 */
8 protected $db;
9
10 public function set_up()
11 {
12 $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
13
14 Mock_Database_Schema_Skeleton::create_tables();
15 Mock_Database_Schema_Skeleton::create_data();
16 }
17
18 // ------------------------------------------------------------------------
19
20 /**
21 * @see ./mocks/schema/skeleton.php
22 */
23 public function test_group_by()
24 {
Taufan Adityaf7377ab2012-05-04 19:42:24 +070025 $jobs = $this->db->select('job.name as job_name, job.id as job_id')
Taufan Aditya4e607b02012-05-04 19:22:48 +070026 ->from('job')
Taufan Adityaf7377ab2012-05-04 19:42:24 +070027 ->group_by('job_name HAVING SUM(job_id) > 2')
Taufan Aditya4e607b02012-05-04 19:22:48 +070028 ->get()
29 ->result_array();
30
31 // Check the result
32 $this->assertEquals(2, count($jobs));
Taufan Adityaf7377ab2012-05-04 19:42:24 +070033 $this->assertEquals('Accountant', $jobs[0]['job_name']);
34 $this->assertEquals('Musician', $jobs[1]['job_name']);
Taufan Aditya4e607b02012-05-04 19:22:48 +070035 }
36
37}