Taufan Aditya | 39f35fd | 2012-05-05 01:29:13 +0700 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class Truncate_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_truncate() |
| 24 | { |
| 25 | // Check initial record |
| 26 | $jobs = $this->db->get('job')->result_array(); |
Andrey Andreev | 20d9b0a | 2017-12-20 19:57:39 +0200 | [diff] [blame^] | 27 | $this->assertCount(4, $jobs); |
Taufan Aditya | 39f35fd | 2012-05-05 01:29:13 +0700 | [diff] [blame] | 28 | |
| 29 | // Do the empty |
| 30 | $this->db->truncate('job'); |
| 31 | |
| 32 | // Check the record |
| 33 | $jobs = $this->db->get('job'); |
Taufan Aditya | 39f35fd | 2012-05-05 01:29:13 +0700 | [diff] [blame] | 34 | $this->assertEmpty($jobs->result_array()); |
| 35 | } |
| 36 | |
| 37 | // ------------------------------------------------------------------------ |
| 38 | |
| 39 | /** |
| 40 | * @see ./mocks/schema/skeleton.php |
| 41 | */ |
| 42 | public function test_truncate_with_from() |
| 43 | { |
| 44 | // Check initial record |
| 45 | $users = $this->db->get('user')->result_array(); |
Andrey Andreev | 20d9b0a | 2017-12-20 19:57:39 +0200 | [diff] [blame^] | 46 | $this->assertCount(4, $users); |
Taufan Aditya | 39f35fd | 2012-05-05 01:29:13 +0700 | [diff] [blame] | 47 | |
| 48 | // Do the empty |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 49 | $this->db->from('user')->truncate(); |
Taufan Aditya | 39f35fd | 2012-05-05 01:29:13 +0700 | [diff] [blame] | 50 | |
| 51 | // Check the record |
| 52 | $users = $this->db->get('user'); |
Taufan Aditya | 39f35fd | 2012-05-05 01:29:13 +0700 | [diff] [blame] | 53 | $this->assertEmpty($users->result_array()); |
| 54 | } |
| 55 | |
Andrey Andreev | 20d9b0a | 2017-12-20 19:57:39 +0200 | [diff] [blame^] | 56 | } |