Taufan Aditya | c0df5a2 | 2012-04-06 17:35:12 +0700 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class Insert_test extends CI_TestCase { |
| 4 | |
| 5 | /** |
| 6 | * @var object Database/Query Builder holder |
Taufan Aditya | fc92fc2 | 2012-04-06 18:00:55 +0700 | [diff] [blame] | 7 | * @see ./mocks/schema/skeleton.php |
Taufan Aditya | c0df5a2 | 2012-04-06 17:35:12 +0700 | [diff] [blame] | 8 | */ |
| 9 | protected $db; |
| 10 | |
| 11 | public function set_up() |
| 12 | { |
| 13 | $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); |
| 14 | |
| 15 | Mock_Database_Schema_Skeleton::create_tables(); |
Taufan Aditya | fc92fc2 | 2012-04-06 18:00:55 +0700 | [diff] [blame] | 16 | |
| 17 | // Truncate the current datas |
| 18 | $this->db->truncate('job'); |
Taufan Aditya | c0df5a2 | 2012-04-06 17:35:12 +0700 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | // ------------------------------------------------------------------------ |
| 22 | |
| 23 | /** |
| 24 | * @see ./mocks/schema/skeleton.php |
| 25 | */ |
| 26 | public function test_insert() |
| 27 | { |
Taufan Aditya | 81b6b5d | 2012-04-06 17:58:22 +0700 | [diff] [blame] | 28 | $job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!'); |
Taufan Aditya | c0df5a2 | 2012-04-06 17:35:12 +0700 | [diff] [blame] | 29 | |
| 30 | // Do normal insert |
| 31 | $this->assertTrue($this->db->insert('job', $job_data)); |
Taufan Aditya | 80c0e3d | 2012-04-07 01:15:53 +0700 | [diff] [blame] | 32 | |
Taufan Aditya | d489747 | 2012-04-07 03:16:25 +0700 | [diff] [blame] | 33 | $jobs = $this->db->get('job')->result_array(); |
| 34 | $job1 = $jobs[0]; |
Taufan Aditya | 80c0e3d | 2012-04-07 01:15:53 +0700 | [diff] [blame] | 35 | |
| 36 | // Check the result |
Taufan Aditya | d489747 | 2012-04-07 03:16:25 +0700 | [diff] [blame] | 37 | $this->assertEquals('Grocery Sales', $job1['name']); |
Taufan Aditya | 80c0e3d | 2012-04-07 01:15:53 +0700 | [diff] [blame] | 38 | |
Taufan Aditya | c0df5a2 | 2012-04-06 17:35:12 +0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | // ------------------------------------------------------------------------ |
| 42 | |
| 43 | /** |
| 44 | * @see ./mocks/schema/skeleton.php |
| 45 | */ |
| 46 | public function test_insert_batch() |
| 47 | { |
| 48 | $job_datas = array( |
Taufan Aditya | 81b6b5d | 2012-04-06 17:58:22 +0700 | [diff] [blame] | 49 | array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), |
| 50 | array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'), |
Taufan Aditya | c0df5a2 | 2012-04-06 17:35:12 +0700 | [diff] [blame] | 51 | ); |
| 52 | |
Taufan Aditya | d489747 | 2012-04-07 03:16:25 +0700 | [diff] [blame] | 53 | // Do insert batch except for sqlite driver |
| 54 | if (strpos(DB_DRIVER, 'sqlite') === FALSE) |
| 55 | { |
Taufan Aditya | 5ce26c9 | 2012-04-07 03:19:35 +0700 | [diff] [blame^] | 56 | $this->assertTrue($this->db->insert_batch('job', $job_datas)); |
Taufan Aditya | 80c0e3d | 2012-04-07 01:15:53 +0700 | [diff] [blame] | 57 | |
Taufan Aditya | d489747 | 2012-04-07 03:16:25 +0700 | [diff] [blame] | 58 | $job_2 = $this->db->where('id', 2)->get('job')->row(); |
| 59 | $job_3 = $this->db->where('id', 3)->get('job')->row(); |
Taufan Aditya | 80c0e3d | 2012-04-07 01:15:53 +0700 | [diff] [blame] | 60 | |
Taufan Aditya | d489747 | 2012-04-07 03:16:25 +0700 | [diff] [blame] | 61 | // Check the result |
| 62 | $this->assertEquals('Commedian', $job_2->name); |
| 63 | $this->assertEquals('Cab Driver', $job_3->name); |
| 64 | } |
Taufan Aditya | c0df5a2 | 2012-04-06 17:35:12 +0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | } |