summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/database/query_builder/insert_test.php
blob: b86feeb7411fc5ddcc41661f9ea20c75a0ea8c84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

class Insert_test extends CI_TestCase {

	/**
	 * @var object Database/Query Builder holder
	 * @see ./mocks/schema/skeleton.php
	 */
	protected $db;

	public function set_up()
	{
		$this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);

		Mock_Database_Schema_Skeleton::create_tables();

		// Truncate the current datas
		$this->db->truncate('job');
	}

	// ------------------------------------------------------------------------

	/**
	 * @see ./mocks/schema/skeleton.php
	 */
	public function test_insert()
	{
		$job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!');
		
		// Do normal insert
		$this->assertTrue($this->db->insert('job', $job_data));

		$jobs = $this->db->get('job')->result_array();
		$job1 = $jobs[0];

		// Check the result
		$this->assertEquals('Grocery Sales', $job1['name']);

	}

	// ------------------------------------------------------------------------

	/**
	 * @see ./mocks/schema/skeleton.php
	 */
	public function test_insert_batch()
	{
		$job_datas = array(
			array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), 
			array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'),
		);
		
		// Do insert batch except for sqlite driver
		if (strpos(DB_DRIVER, 'sqlite') === FALSE)
		{
			$this->assertTrue($this->db->insert('job', $job_datas[0]));

			$job_2 = $this->db->where('id', 2)->get('job')->row();
			$job_3 = $this->db->where('id', 3)->get('job')->row();

			// Check the result
			$this->assertEquals('Commedian', $job_2->name);
			$this->assertEquals('Cab Driver', $job_3->name);
		}
	}
	
}