blob: b40e5e507e042a05ac990b0fab7dd6610a5d29b6 [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 Aditya1afd4792012-05-04 20:34:30 +070025 $jobs = $this->db->select('name')
Andrey Andreevc1862882012-06-09 23:16:58 +030026 ->from('job')
27 ->group_by('name')
28 ->get()
29 ->result_array();
30
Andrey Andreev20d9b0a2017-12-20 19:57:39 +020031 $this->assertCount(4, $jobs);
Taufan Aditya1afd4792012-05-04 20:34:30 +070032 }
33
34 // ------------------------------------------------------------------------
35
36 /**
37 * @see ./mocks/schema/skeleton.php
38 */
39 public function test_having_by()
40 {
41 $jobs = $this->db->select('name')
Andrey Andreevc1862882012-06-09 23:16:58 +030042 ->from('job')
43 ->group_by('name')
44 ->having('SUM(id) > 2')
45 ->get()
46 ->result_array();
47
Andrey Andreev20d9b0a2017-12-20 19:57:39 +020048 $this->assertCount(2, $jobs);
Taufan Aditya4e607b02012-05-04 19:22:48 +070049 }
Andrey Andreev20d9b0a2017-12-20 19:57:39 +020050}