Taufan Aditya | 9ec507b | 2012-05-05 00:55:39 +0700 | [diff] [blame^] | 1 | <?php |
| 2 | |
| 3 | class Update_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_update() |
| 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 update |
| 33 | $job_data = array('name' => 'Programmer'); |
| 34 | |
| 35 | $this->db->where('id', 1) |
| 36 | ->update('job', $job_data); |
| 37 | |
| 38 | // Check updated record |
| 39 | $job1 = $this->db->where('id', 1) |
| 40 | ->get('job') |
| 41 | ->row(); |
| 42 | |
| 43 | $this->assertEquals('Programmer', $job1->name); |
| 44 | } |
| 45 | |
| 46 | // ------------------------------------------------------------------------ |
| 47 | |
| 48 | /** |
| 49 | * @see ./mocks/schema/skeleton.php |
| 50 | */ |
| 51 | public function test_update_with_set() |
| 52 | { |
| 53 | // Check initial record |
| 54 | $job1 = $this->db->where('id', 4) |
| 55 | ->get('job') |
| 56 | ->row(); |
| 57 | |
| 58 | $this->assertEquals('Musician', $job1->name); |
| 59 | |
| 60 | // Do the update |
| 61 | $this->db->set('name', 'Vocalist'); |
| 62 | $this->db->update('job', NULL, 'id = 4'); |
| 63 | |
| 64 | // Check updated record |
| 65 | $job1 = $this->db->where('id', 4) |
| 66 | ->get('job') |
| 67 | ->row(); |
| 68 | |
| 69 | $this->assertEquals('Vocalist', $job1->name); |
| 70 | } |
| 71 | } |