blob: ab9d97f56beb9dea6345f516ec9ec4ced654a5ea [file] [log] [blame]
Taufan Aditya6657cc12012-05-05 01:06:41 +07001<?php
2
3class Delete_test extends CI_TestCase {
4
5 /**
6 * @var object Database/Query Builder holder
7 */
8 protected $db;
9
10 public function set_up()
11 {
12 $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
13
14 Mock_Database_Schema_Skeleton::create_tables();
15 Mock_Database_Schema_Skeleton::create_data();
16 }
17
18 // ------------------------------------------------------------------------
19
20 /**
21 * @see ./mocks/schema/skeleton.php
22 */
23 public function test_delete()
24 {
25 // Check initial record
Andrey Andreevc1862882012-06-09 23:16:58 +030026 $job1 = $this->db->where('id', 1)->get('job')->row();
Taufan Aditya6657cc12012-05-05 01:06:41 +070027
28 $this->assertEquals('Developer', $job1->name);
29
30 // Do the delete
31 $this->db->delete('job', array('id' => 1));
32
33 // Check the record
Andrey Andreevc1862882012-06-09 23:16:58 +030034 $job1 = $this->db->where('id', 1)->get('job');
Taufan Aditya6657cc12012-05-05 01:06:41 +070035
36 $this->assertEmpty($job1->result_array());
37 }
38
39 // ------------------------------------------------------------------------
40
41 /**
42 * @see ./mocks/schema/skeleton.php
43 */
44 public function test_delete_several_tables()
45 {
46 // Check initial record
Andrey Andreevc1862882012-06-09 23:16:58 +030047 $user4 = $this->db->where('id', 4)->get('user')->row();
48 $job4 = $this->db->where('id', 4)->get('job')->row();
Taufan Aditya6657cc12012-05-05 01:06:41 +070049
50 $this->assertEquals('Musician', $job4->name);
51 $this->assertEquals('Chris Martin', $user4->name);
52
53 // Do the delete
54 $this->db->delete(array('job', 'user'), array('id' => 4));
55
56 // Check the record
57 $job4 = $this->db->where('id', 4)->get('job');
58 $user4 = $this->db->where('id', 4)->get('user');
59
60 $this->assertEmpty($job4->result_array());
61 $this->assertEmpty($user4->result_array());
62 }
63
64}