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!'); |
Andrey Andreev | 9d533ae | 2012-06-04 15:56:56 +0300 | [diff] [blame] | 29 | |
Taufan Aditya | c0df5a2 | 2012-04-06 17:35:12 +0700 | [diff] [blame] | 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 | 190c6bb | 2012-05-03 12:13:39 +0700 | [diff] [blame] | 33 | $job1 = $this->db->get('job')->row(); |
Taufan Aditya | 80c0e3d | 2012-04-07 01:15:53 +0700 | [diff] [blame] | 34 | |
| 35 | // Check the result |
Taufan Aditya | 190c6bb | 2012-05-03 12:13:39 +0700 | [diff] [blame] | 36 | $this->assertEquals('Grocery Sales', $job1->name); |
Taufan Aditya | 80c0e3d | 2012-04-07 01:15:53 +0700 | [diff] [blame] | 37 | |
Taufan Aditya | c0df5a2 | 2012-04-06 17:35:12 +0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | // ------------------------------------------------------------------------ |
| 41 | |
| 42 | /** |
| 43 | * @see ./mocks/schema/skeleton.php |
| 44 | */ |
| 45 | public function test_insert_batch() |
| 46 | { |
| 47 | $job_datas = array( |
Andrey Andreev | 9d533ae | 2012-06-04 15:56:56 +0300 | [diff] [blame] | 48 | array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), |
Taufan Aditya | 81b6b5d | 2012-04-06 17:58:22 +0700 | [diff] [blame] | 49 | array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'), |
Taufan Aditya | c0df5a2 | 2012-04-06 17:35:12 +0700 | [diff] [blame] | 50 | ); |
Andrey Andreev | 9d533ae | 2012-06-04 15:56:56 +0300 | [diff] [blame] | 51 | |
Taufan Aditya | d489747 | 2012-04-07 03:16:25 +0700 | [diff] [blame] | 52 | // Do insert batch except for sqlite driver |
| 53 | if (strpos(DB_DRIVER, 'sqlite') === FALSE) |
| 54 | { |
Andrey Andreev | a7001e9 | 2012-10-24 18:51:15 +0300 | [diff] [blame] | 55 | $this->assertEquals(2, $this->db->insert_batch('job', $job_datas)); |
Taufan Aditya | 80c0e3d | 2012-04-07 01:15:53 +0700 | [diff] [blame] | 56 | |
Taufan Aditya | d489747 | 2012-04-07 03:16:25 +0700 | [diff] [blame] | 57 | $job_2 = $this->db->where('id', 2)->get('job')->row(); |
| 58 | $job_3 = $this->db->where('id', 3)->get('job')->row(); |
Taufan Aditya | 80c0e3d | 2012-04-07 01:15:53 +0700 | [diff] [blame] | 59 | |
Taufan Aditya | d489747 | 2012-04-07 03:16:25 +0700 | [diff] [blame] | 60 | // Check the result |
| 61 | $this->assertEquals('Commedian', $job_2->name); |
| 62 | $this->assertEquals('Cab Driver', $job_3->name); |
| 63 | } |
Taufan Aditya | c0df5a2 | 2012-04-06 17:35:12 +0700 | [diff] [blame] | 64 | } |
Andrey Andreev | 9d533ae | 2012-06-04 15:56:56 +0300 | [diff] [blame] | 65 | |
Taufan Aditya | c0df5a2 | 2012-04-06 17:35:12 +0700 | [diff] [blame] | 66 | } |