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 |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 26 | $job1 = $this->db->where('id', 1)->get('job')->row(); |
Taufan Aditya | 9ec507b | 2012-05-05 00:55:39 +0700 | [diff] [blame] | 27 | $this->assertEquals('Developer', $job1->name); |
| 28 | |
| 29 | // Do the update |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 30 | $this->db->where('id', 1)->update('job', array('name' => 'Programmer')); |
Taufan Aditya | 9ec507b | 2012-05-05 00:55:39 +0700 | [diff] [blame] | 31 | |
| 32 | // Check updated record |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 33 | $job1 = $this->db->where('id', 1)->get('job')->row(); |
Taufan Aditya | 9ec507b | 2012-05-05 00:55:39 +0700 | [diff] [blame] | 34 | $this->assertEquals('Programmer', $job1->name); |
| 35 | } |
| 36 | |
| 37 | // ------------------------------------------------------------------------ |
| 38 | |
| 39 | /** |
| 40 | * @see ./mocks/schema/skeleton.php |
| 41 | */ |
| 42 | public function test_update_with_set() |
| 43 | { |
| 44 | // Check initial record |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 45 | $job1 = $this->db->where('id', 4)->get('job')->row(); |
Taufan Aditya | 9ec507b | 2012-05-05 00:55:39 +0700 | [diff] [blame] | 46 | $this->assertEquals('Musician', $job1->name); |
| 47 | |
| 48 | // Do the update |
| 49 | $this->db->set('name', 'Vocalist'); |
| 50 | $this->db->update('job', NULL, 'id = 4'); |
| 51 | |
| 52 | // Check updated record |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 53 | $job1 = $this->db->where('id', 4)->get('job')->row(); |
Taufan Aditya | 9ec507b | 2012-05-05 00:55:39 +0700 | [diff] [blame] | 54 | $this->assertEquals('Vocalist', $job1->name); |
| 55 | } |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 56 | |
Taufan Aditya | 9ec507b | 2012-05-05 00:55:39 +0700 | [diff] [blame] | 57 | } |