blob: 50a062c9f8c9cf7a8cebd8a3947110a194f88234 [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 */
8 protected $query_builder;
9
10 public function set_up()
11 {
12 $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 $this->query_builder = $db;
18 }
19
20 // ------------------------------------------------------------------------
21
22 /**
23 * @see ./mocks/schema/skeleton.php
24 */
25 public function test_select_only_one_collumn()
26 {
27 $jobs_name = $this->query_builder->select('name')
28 ->get('job')
29 ->result_array();
30
31 // Check rows item
32 $this->assertArrayHasKey('name',$jobs_name[0]);
33 $this->assertFalse(array_key_exists('id', $jobs_name[0]));
34 $this->assertFalse(array_key_exists('description', $jobs_name[0]));
35 }
Taufan Adityafdc0ea82012-04-05 19:08:00 +070036
37 // ------------------------------------------------------------------------
38
39 /**
40 * @see ./mocks/schema/skeleton.php
41 */
42 public function test_select_min()
43 {
44 $job_min = $this->query_builder->select_min('id')
45 ->get('job')
46 ->result_array();
47
48 // Minimum id was 1
49 $this->assertEquals('1', $job_min[0]['id']);
50 }
51
52 // ------------------------------------------------------------------------
53
54 /**
55 * @see ./mocks/schema/skeleton.php
56 */
57 public function test_select_max()
58 {
59 $job_max = $this->query_builder->select_max('id')
60 ->get('job')
61 ->result_array();
62
63 // Maximum id was 4
64 $this->assertEquals('4', $job_max[0]['id']);
65 }
66
67 // ------------------------------------------------------------------------
68
69 /**
70 * @see ./mocks/schema/skeleton.php
71 */
72 public function test_select_avg()
73 {
74 $job_avg = $this->query_builder->select_avg('id')
75 ->get('job')
76 ->result_array();
77
78 // Average should be 2.5
79 $this->assertEquals('2.5', $job_avg[0]['id']);
80 }
81
82 // ------------------------------------------------------------------------
83
84 /**
85 * @see ./mocks/schema/skeleton.php
86 */
87 public function test_select_sum()
88 {
89 $job_sum = $this->query_builder->select_sum('id')
90 ->get('job')
91 ->result_array();
92
93 // Sum of ids should be 10
94 $this->assertEquals('10', $job_sum[0]['id']);
95 }
Taufan Aditya55f622f2012-04-05 19:01:34 +070096
97}