blob: 27a647c451076eeea650d2840c08ab6a1fcea14b [file] [log] [blame]
Taufan Aditya9ec507b2012-05-05 00:55:39 +07001<?php
2
3class 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 Andreevc1862882012-06-09 23:16:58 +030026 $job1 = $this->db->where('id', 1)->get('job')->row();
Taufan Aditya9ec507b2012-05-05 00:55:39 +070027 $this->assertEquals('Developer', $job1->name);
28
29 // Do the update
Andrey Andreevc1862882012-06-09 23:16:58 +030030 $this->db->where('id', 1)->update('job', array('name' => 'Programmer'));
Taufan Aditya9ec507b2012-05-05 00:55:39 +070031
32 // Check updated record
Andrey Andreevc1862882012-06-09 23:16:58 +030033 $job1 = $this->db->where('id', 1)->get('job')->row();
Taufan Aditya9ec507b2012-05-05 00:55:39 +070034 $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 Andreevc1862882012-06-09 23:16:58 +030045 $job1 = $this->db->where('id', 4)->get('job')->row();
Taufan Aditya9ec507b2012-05-05 00:55:39 +070046 $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 Andreevc1862882012-06-09 23:16:58 +030053 $job1 = $this->db->where('id', 4)->get('job')->row();
Taufan Aditya9ec507b2012-05-05 00:55:39 +070054 $this->assertEquals('Vocalist', $job1->name);
55 }
Andrey Andreevc1862882012-06-09 23:16:58 +030056
Taufan Aditya9ec507b2012-05-05 00:55:39 +070057}