blob: 53ce23c193e8ef3cf02187272c192ce6684f0277 [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!');
Taufan Adityac0df5a22012-04-06 17:35:12 +070029
30 // Do normal insert
31 $this->assertTrue($this->db->insert('job', $job_data));
Taufan Aditya80c0e3d2012-04-07 01:15:53 +070032
Taufan Adityad4897472012-04-07 03:16:25 +070033 $jobs = $this->db->get('job')->result_array();
34 $job1 = $jobs[0];
Taufan Aditya80c0e3d2012-04-07 01:15:53 +070035
36 // Check the result
Taufan Adityad4897472012-04-07 03:16:25 +070037 $this->assertEquals('Grocery Sales', $job1['name']);
Taufan Aditya80c0e3d2012-04-07 01:15:53 +070038
Taufan Adityac0df5a22012-04-06 17:35:12 +070039 }
40
41 // ------------------------------------------------------------------------
42
43 /**
44 * @see ./mocks/schema/skeleton.php
45 */
46 public function test_insert_batch()
47 {
48 $job_datas = array(
Taufan Aditya81b6b5d2012-04-06 17:58:22 +070049 array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'),
50 array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'),
Taufan Adityac0df5a22012-04-06 17:35:12 +070051 );
52
Taufan Adityad4897472012-04-07 03:16:25 +070053 // Do insert batch except for sqlite driver
54 if (strpos(DB_DRIVER, 'sqlite') === FALSE)
55 {
Taufan Aditya5ce26c92012-04-07 03:19:35 +070056 $this->assertTrue($this->db->insert_batch('job', $job_datas));
Taufan Aditya80c0e3d2012-04-07 01:15:53 +070057
Taufan Adityad4897472012-04-07 03:16:25 +070058 $job_2 = $this->db->where('id', 2)->get('job')->row();
59 $job_3 = $this->db->where('id', 3)->get('job')->row();
Taufan Aditya80c0e3d2012-04-07 01:15:53 +070060
Taufan Adityad4897472012-04-07 03:16:25 +070061 // Check the result
62 $this->assertEquals('Commedian', $job_2->name);
63 $this->assertEquals('Cab Driver', $job_3->name);
64 }
Taufan Adityac0df5a22012-04-06 17:35:12 +070065 }
66
67}