Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class Get_test extends CI_TestCase { |
| 4 | |
| 5 | /** |
| 6 | * @var object Database/Query Builder holder |
| 7 | */ |
Taufan Aditya | 0793b1c | 2012-04-05 21:47:53 +0700 | [diff] [blame] | 8 | protected $db; |
Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 9 | |
| 10 | public function set_up() |
| 11 | { |
Taufan Aditya | 0793b1c | 2012-04-05 21:47:53 +0700 | [diff] [blame] | 12 | $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); |
Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 13 | |
Taufan Aditya | 55f622f | 2012-04-05 19:01:34 +0700 | [diff] [blame] | 14 | Mock_Database_Schema_Skeleton::create_tables(); |
| 15 | Mock_Database_Schema_Skeleton::create_data(); |
Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | // ------------------------------------------------------------------------ |
| 19 | |
| 20 | /** |
| 21 | * @see ./mocks/schema/skeleton.php |
| 22 | */ |
| 23 | public function test_get_simple() |
| 24 | { |
Taufan Aditya | 0793b1c | 2012-04-05 21:47:53 +0700 | [diff] [blame] | 25 | $jobs = $this->db->get('job')->result_array(); |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame^] | 26 | |
Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 27 | // Dummy jobs contain 4 rows |
| 28 | $this->assertCount(4, $jobs); |
| 29 | |
| 30 | // Check rows item |
| 31 | $this->assertEquals('Developer', $jobs[0]['name']); |
| 32 | $this->assertEquals('Politician', $jobs[1]['name']); |
| 33 | $this->assertEquals('Accountant', $jobs[2]['name']); |
| 34 | $this->assertEquals('Musician', $jobs[3]['name']); |
| 35 | } |
Taufan Aditya | 55f622f | 2012-04-05 19:01:34 +0700 | [diff] [blame] | 36 | |
| 37 | // ------------------------------------------------------------------------ |
| 38 | |
| 39 | /** |
| 40 | * @see ./mocks/schema/skeleton.php |
| 41 | */ |
| 42 | public function test_get_where() |
| 43 | { |
Taufan Aditya | 0793b1c | 2012-04-05 21:47:53 +0700 | [diff] [blame] | 44 | $job1 = $this->db->get('job', array('id' => 1))->result_array(); |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame^] | 45 | |
Taufan Aditya | 55f622f | 2012-04-05 19:01:34 +0700 | [diff] [blame] | 46 | // Dummy jobs contain 1 rows |
| 47 | $this->assertCount(1, $job1); |
| 48 | |
| 49 | // Check rows item |
| 50 | $this->assertEquals('Developer', $job1[0]['name']); |
| 51 | } |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame^] | 52 | |
Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 53 | } |