Taufan Aditya | 6657cc1 | 2012-05-05 01:06:41 +0700 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class 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 Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 26 | $job1 = $this->db->where('id', 1)->get('job')->row(); |
Taufan Aditya | 6657cc1 | 2012-05-05 01:06:41 +0700 | [diff] [blame] | 27 | |
| 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 Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 34 | $job1 = $this->db->where('id', 1)->get('job'); |
Taufan Aditya | 6657cc1 | 2012-05-05 01:06:41 +0700 | [diff] [blame] | 35 | |
| 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 Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 47 | $user4 = $this->db->where('id', 4)->get('user')->row(); |
| 48 | $job4 = $this->db->where('id', 4)->get('job')->row(); |
Taufan Aditya | 6657cc1 | 2012-05-05 01:06:41 +0700 | [diff] [blame] | 49 | |
| 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 | } |