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 |
| 26 | $job1 = $this->db->where('id', 1) |
| 27 | ->get('job') |
| 28 | ->row(); |
| 29 | |
| 30 | $this->assertEquals('Developer', $job1->name); |
| 31 | |
| 32 | // Do the delete |
| 33 | $this->db->delete('job', array('id' => 1)); |
| 34 | |
| 35 | // Check the record |
| 36 | $job1 = $this->db->where('id', 1) |
| 37 | ->get('job'); |
| 38 | |
| 39 | $this->assertEmpty($job1->result_array()); |
| 40 | } |
| 41 | |
| 42 | // ------------------------------------------------------------------------ |
| 43 | |
| 44 | /** |
| 45 | * @see ./mocks/schema/skeleton.php |
| 46 | */ |
| 47 | public function test_delete_several_tables() |
| 48 | { |
| 49 | // Check initial record |
| 50 | $user4 = $this->db->where('id', 4) |
| 51 | ->get('user') |
| 52 | ->row(); |
| 53 | |
| 54 | $job4 = $this->db->where('id', 4) |
| 55 | ->get('job') |
| 56 | ->row(); |
| 57 | |
| 58 | $this->assertEquals('Musician', $job4->name); |
| 59 | $this->assertEquals('Chris Martin', $user4->name); |
| 60 | |
| 61 | // Do the delete |
| 62 | $this->db->delete(array('job', 'user'), array('id' => 4)); |
| 63 | |
| 64 | // Check the record |
| 65 | $job4 = $this->db->where('id', 4)->get('job'); |
| 66 | $user4 = $this->db->where('id', 4)->get('user'); |
| 67 | |
| 68 | $this->assertEmpty($job4->result_array()); |
| 69 | $this->assertEmpty($user4->result_array()); |
| 70 | } |
| 71 | |
| 72 | } |