blob: 30c055680f60db5c2a9b8d01eb7e9e0f010e0e5f [file] [log] [blame]
Taufan Adityac0df5a22012-04-06 17:35:12 +07001<?php
2
3class Insert_test extends CI_TestCase {
4
5 /**
6 * @var object Database/Query Builder holder
Taufan Adityafc92fc22012-04-06 18:00:55 +07007 * @see ./mocks/schema/skeleton.php
Taufan Adityac0df5a22012-04-06 17:35:12 +07008 */
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 Adityafc92fc22012-04-06 18:00:55 +070016
17 // Truncate the current datas
18 $this->db->truncate('job');
Taufan Adityac0df5a22012-04-06 17:35:12 +070019 }
20
21 // ------------------------------------------------------------------------
22
23 /**
24 * @see ./mocks/schema/skeleton.php
25 */
26 public function test_insert()
27 {
Taufan Aditya81b6b5d2012-04-06 17:58:22 +070028 $job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!');
Andrey Andreev9d533ae2012-06-04 15:56:56 +030029
Taufan Adityac0df5a22012-04-06 17:35:12 +070030 // Do normal insert
31 $this->assertTrue($this->db->insert('job', $job_data));
Taufan Aditya80c0e3d2012-04-07 01:15:53 +070032
Taufan Aditya190c6bb2012-05-03 12:13:39 +070033 $job1 = $this->db->get('job')->row();
Taufan Aditya80c0e3d2012-04-07 01:15:53 +070034
35 // Check the result
Taufan Aditya190c6bb2012-05-03 12:13:39 +070036 $this->assertEquals('Grocery Sales', $job1->name);
Taufan Aditya80c0e3d2012-04-07 01:15:53 +070037
Taufan Adityac0df5a22012-04-06 17:35:12 +070038 }
39
40 // ------------------------------------------------------------------------
41
42 /**
43 * @see ./mocks/schema/skeleton.php
44 */
45 public function test_insert_batch()
46 {
47 $job_datas = array(
Andrey Andreev9d533ae2012-06-04 15:56:56 +030048 array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'),
Taufan Aditya81b6b5d2012-04-06 17:58:22 +070049 array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'),
Taufan Adityac0df5a22012-04-06 17:35:12 +070050 );
Andrey Andreev9d533ae2012-06-04 15:56:56 +030051
Taufan Adityad4897472012-04-07 03:16:25 +070052 // Do insert batch except for sqlite driver
53 if (strpos(DB_DRIVER, 'sqlite') === FALSE)
54 {
Andrey Andreeva7001e92012-10-24 18:51:15 +030055 $this->assertEquals(2, $this->db->insert_batch('job', $job_datas));
Taufan Aditya80c0e3d2012-04-07 01:15:53 +070056
Taufan Adityad4897472012-04-07 03:16:25 +070057 $job_2 = $this->db->where('id', 2)->get('job')->row();
58 $job_3 = $this->db->where('id', 3)->get('job')->row();
Taufan Aditya80c0e3d2012-04-07 01:15:53 +070059
Taufan Adityad4897472012-04-07 03:16:25 +070060 // Check the result
61 $this->assertEquals('Commedian', $job_2->name);
62 $this->assertEquals('Cab Driver', $job_3->name);
63 }
Taufan Adityac0df5a22012-04-06 17:35:12 +070064 }
Andrey Andreev9d533ae2012-06-04 15:56:56 +030065
Taufan Adityac0df5a22012-04-06 17:35:12 +070066}