blob: dbf432a7cc98afebca397950a10b48437ff51d2d [file] [log] [blame]
Taufan Aditya55f622f2012-04-05 19:01:34 +07001<?php
2
3class Select_test extends CI_TestCase {
4
5 /**
6 * @var object Database/Query Builder holder
7 */
Taufan Aditya0793b1c2012-04-05 21:47:53 +07008 protected $db;
Taufan Aditya55f622f2012-04-05 19:01:34 +07009
10 public function set_up()
11 {
Taufan Aditya0793b1c2012-04-05 21:47:53 +070012 $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
Taufan Aditya55f622f2012-04-05 19:01:34 +070013
14 Mock_Database_Schema_Skeleton::create_tables();
15 Mock_Database_Schema_Skeleton::create_data();
Taufan Aditya55f622f2012-04-05 19:01:34 +070016 }
17
18 // ------------------------------------------------------------------------
19
20 /**
21 * @see ./mocks/schema/skeleton.php
22 */
23 public function test_select_only_one_collumn()
24 {
Taufan Aditya0793b1c2012-04-05 21:47:53 +070025 $jobs_name = $this->db->select('name')
26 ->get('job')
27 ->result_array();
Taufan Aditya55f622f2012-04-05 19:01:34 +070028
29 // Check rows item
30 $this->assertArrayHasKey('name',$jobs_name[0]);
31 $this->assertFalse(array_key_exists('id', $jobs_name[0]));
32 $this->assertFalse(array_key_exists('description', $jobs_name[0]));
33 }
Taufan Adityafdc0ea82012-04-05 19:08:00 +070034
35 // ------------------------------------------------------------------------
36
37 /**
38 * @see ./mocks/schema/skeleton.php
39 */
40 public function test_select_min()
41 {
Taufan Aditya0793b1c2012-04-05 21:47:53 +070042 $job_min = $this->db->select_min('id')
43 ->get('job')
44 ->result_array();
Taufan Adityafdc0ea82012-04-05 19:08:00 +070045
46 // Minimum id was 1
47 $this->assertEquals('1', $job_min[0]['id']);
48 }
49
50 // ------------------------------------------------------------------------
51
52 /**
53 * @see ./mocks/schema/skeleton.php
54 */
55 public function test_select_max()
56 {
Taufan Aditya0793b1c2012-04-05 21:47:53 +070057 $job_max = $this->db->select_max('id')
58 ->get('job')
59 ->result_array();
Taufan Adityafdc0ea82012-04-05 19:08:00 +070060
61 // Maximum id was 4
62 $this->assertEquals('4', $job_max[0]['id']);
63 }
64
65 // ------------------------------------------------------------------------
66
67 /**
68 * @see ./mocks/schema/skeleton.php
69 */
70 public function test_select_avg()
71 {
Taufan Aditya0793b1c2012-04-05 21:47:53 +070072 $job_avg = $this->db->select_avg('id')
73 ->get('job')
74 ->result_array();
Taufan Adityafdc0ea82012-04-05 19:08:00 +070075
76 // Average should be 2.5
77 $this->assertEquals('2.5', $job_avg[0]['id']);
78 }
79
80 // ------------------------------------------------------------------------
81
82 /**
83 * @see ./mocks/schema/skeleton.php
84 */
85 public function test_select_sum()
86 {
Taufan Aditya0793b1c2012-04-05 21:47:53 +070087 $job_sum = $this->db->select_sum('id')
88 ->get('job')
89 ->result_array();
Taufan Adityafdc0ea82012-04-05 19:08:00 +070090
91 // Sum of ids should be 10
92 $this->assertEquals('10', $job_sum[0]['id']);
93 }
Taufan Aditya55f622f2012-04-05 19:01:34 +070094
95}