Taufan Aditya | d6b41bb | 2012-05-04 15:05:22 +0700 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class Join_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_join_simple() |
| 24 | { |
| 25 | $job_user = $this->db->select('job.id as job_id, job.name as job_name, user.id as user_id, user.name as user_name') |
| 26 | ->from('job') |
| 27 | ->join('user', 'user.id = job.id') |
| 28 | ->get() |
| 29 | ->result_array(); |
| 30 | |
| 31 | // Check the result |
| 32 | $this->assertEquals('1', $job_user[0]['job_id']); |
| 33 | $this->assertEquals('1', $job_user[0]['user_id']); |
| 34 | $this->assertEquals('Derek Jones', $job_user[0]['user_name']); |
| 35 | $this->assertEquals('Developer', $job_user[0]['job_name']); |
| 36 | } |
| 37 | |
| 38 | } |