Taufan Aditya | 4e607b0 | 2012-05-04 19:22:48 +0700 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class 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 Aditya | 1afd479 | 2012-05-04 20:34:30 +0700 | [diff] [blame^] | 25 | $jobs = $this->db->select('name') |
Taufan Aditya | 4e607b0 | 2012-05-04 19:22:48 +0700 | [diff] [blame] | 26 | ->from('job') |
Taufan Aditya | 1afd479 | 2012-05-04 20:34:30 +0700 | [diff] [blame^] | 27 | ->group_by('name') |
| 28 | ->get() |
| 29 | ->result_array(); |
| 30 | |
| 31 | // Check the result |
| 32 | $this->assertEquals(4, count($jobs)); |
| 33 | } |
| 34 | |
| 35 | // ------------------------------------------------------------------------ |
| 36 | |
| 37 | /** |
| 38 | * @see ./mocks/schema/skeleton.php |
| 39 | */ |
| 40 | public function test_having_by() |
| 41 | { |
| 42 | $jobs = $this->db->select('name') |
| 43 | ->from('job') |
| 44 | ->group_by('name') |
| 45 | ->having('SUM(id) > 2') |
Taufan Aditya | 4e607b0 | 2012-05-04 19:22:48 +0700 | [diff] [blame] | 46 | ->get() |
| 47 | ->result_array(); |
| 48 | |
| 49 | // Check the result |
| 50 | $this->assertEquals(2, count($jobs)); |
Taufan Aditya | 4e607b0 | 2012-05-04 19:22:48 +0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | } |