diff options
author | Andrey Andreev <narf@devilix.net> | 2019-01-16 16:49:35 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2019-01-16 16:49:35 +0100 |
commit | c576995304fc3609cca0b7b92d1b2cd611ec82f5 (patch) | |
tree | c8b9121cb295b56bbabe3aeaad0a3eb1f2d390bb /tests/codeigniter/database/query_builder | |
parent | 4eaf80a6ec0b58a0adc95638153363e00ebf5378 (diff) |
[ci skip] 3.1.10 release
Diffstat (limited to 'tests/codeigniter/database/query_builder')
17 files changed, 0 insertions, 1145 deletions
diff --git a/tests/codeigniter/database/query_builder/count_test.php b/tests/codeigniter/database/query_builder/count_test.php deleted file mode 100644 index da312d866..000000000 --- a/tests/codeigniter/database/query_builder/count_test.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -class Count_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_count_all() - { - $this->assertEquals(4, $this->db->count_all('job')); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_count_all_results() - { - $this->assertEquals(2, $this->db->like('name', 'ian')->count_all_results('job')); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_count_all_results_limit() - { - $this->assertEquals(1, $this->db->like('name', 'ian')->limit(1)->count_all_results('job')); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/delete_test.php b/tests/codeigniter/database/query_builder/delete_test.php deleted file mode 100644 index ab9d97f56..000000000 --- a/tests/codeigniter/database/query_builder/delete_test.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php - -class Delete_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_delete() - { - // Check initial record - $job1 = $this->db->where('id', 1)->get('job')->row(); - - $this->assertEquals('Developer', $job1->name); - - // Do the delete - $this->db->delete('job', array('id' => 1)); - - // Check the record - $job1 = $this->db->where('id', 1)->get('job'); - - $this->assertEmpty($job1->result_array()); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_delete_several_tables() - { - // Check initial record - $user4 = $this->db->where('id', 4)->get('user')->row(); - $job4 = $this->db->where('id', 4)->get('job')->row(); - - $this->assertEquals('Musician', $job4->name); - $this->assertEquals('Chris Martin', $user4->name); - - // Do the delete - $this->db->delete(array('job', 'user'), array('id' => 4)); - - // Check the record - $job4 = $this->db->where('id', 4)->get('job'); - $user4 = $this->db->where('id', 4)->get('user'); - - $this->assertEmpty($job4->result_array()); - $this->assertEmpty($user4->result_array()); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php deleted file mode 100644 index 81fabe448..000000000 --- a/tests/codeigniter/database/query_builder/distinct_test.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -class Distinct_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_distinct() - { - $users = $this->db->select('country') - ->distinct() - ->get('user') - ->result_array(); - - $this->assertCount(3, $users); - } - -} diff --git a/tests/codeigniter/database/query_builder/empty_test.php b/tests/codeigniter/database/query_builder/empty_test.php deleted file mode 100644 index 3f63a60f5..000000000 --- a/tests/codeigniter/database/query_builder/empty_test.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php - -class Empty_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_empty_table() - { - // Check initial record - $jobs = $this->db->get('job')->result_array(); - - $this->assertCount(4, $jobs); - - // Do the empty - $this->db->empty_table('job'); - - // Check the record - $jobs = $this->db->get('job'); - - $this->assertEmpty($jobs->result_array()); - } - -} diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php deleted file mode 100644 index de6cd0a9d..000000000 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -class Escape_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_escape_like_percent_sign() - { - // Escape the like string - $string = $this->db->escape_like_str('\%foo'); - - if (strpos(DB_DRIVER, 'mysql') !== FALSE) - { - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';"; - } - else - { - $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';'; - } - - $res = $this->db->query($sql)->result_array(); - - // Check the result - $this->assertCount(1, $res); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_escape_like_backslash_sign() - { - // Escape the like string - $string = $this->db->escape_like_str('\\'); - - if (strpos(DB_DRIVER, 'mysql') !== FALSE) - { - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';"; - } - else - { - $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';'; - } - - $res = $this->db->query($sql)->result_array(); - - // Check the result - $this->assertCount(2, $res); - } - -} diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php deleted file mode 100644 index 5a4ac690d..000000000 --- a/tests/codeigniter/database/query_builder/from_test.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php - -class From_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_from_simple() - { - $jobs = $this->db->from('job') - ->get() - ->result_array(); - - $this->assertCount(4, $jobs); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_from_with_where() - { - $job1 = $this->db->from('job') - ->where('id', 1) - ->get() - ->row(); - - $this->assertEquals('1', $job1->id); - $this->assertEquals('Developer', $job1->name); - $this->assertEquals('Awesome job, but sometimes makes you bored', $job1->description); - } - -} diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php deleted file mode 100644 index 156027537..000000000 --- a/tests/codeigniter/database/query_builder/get_test.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php - -class Get_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_get_simple() - { - $jobs = $this->db->get('job')->result_array(); - - // Dummy jobs contain 4 rows - $this->assertCount(4, $jobs); - - // Check rows item - $this->assertEquals('Developer', $jobs[0]['name']); - $this->assertEquals('Politician', $jobs[1]['name']); - $this->assertEquals('Accountant', $jobs[2]['name']); - $this->assertEquals('Musician', $jobs[3]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_get_where() - { - $job1 = $this->db->get_where('job', array('id' => 1))->result_array(); - - // Dummy jobs contain 1 rows - $this->assertCount(1, $job1); - - // Check rows item - $this->assertEquals('Developer', $job1[0]['name']); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php deleted file mode 100644 index b40e5e507..000000000 --- a/tests/codeigniter/database/query_builder/group_test.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php - -class Group_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_group_by() - { - $jobs = $this->db->select('name') - ->from('job') - ->group_by('name') - ->get() - ->result_array(); - - $this->assertCount(4, $jobs); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_having_by() - { - $jobs = $this->db->select('name') - ->from('job') - ->group_by('name') - ->having('SUM(id) > 2') - ->get() - ->result_array(); - - $this->assertCount(2, $jobs); - } -} diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php deleted file mode 100644 index 30c055680..000000000 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ /dev/null @@ -1,66 +0,0 @@ -<?php - -class Insert_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - * @see ./mocks/schema/skeleton.php - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - - // Truncate the current datas - $this->db->truncate('job'); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_insert() - { - $job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!'); - - // Do normal insert - $this->assertTrue($this->db->insert('job', $job_data)); - - $job1 = $this->db->get('job')->row(); - - // Check the result - $this->assertEquals('Grocery Sales', $job1->name); - - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_insert_batch() - { - $job_datas = array( - array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), - array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'), - ); - - // Do insert batch except for sqlite driver - if (strpos(DB_DRIVER, 'sqlite') === FALSE) - { - $this->assertEquals(2, $this->db->insert_batch('job', $job_datas)); - - $job_2 = $this->db->where('id', 2)->get('job')->row(); - $job_3 = $this->db->where('id', 3)->get('job')->row(); - - // Check the result - $this->assertEquals('Commedian', $job_2->name); - $this->assertEquals('Cab Driver', $job_3->name); - } - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php deleted file mode 100644 index 54b2a4e18..000000000 --- a/tests/codeigniter/database/query_builder/join_test.php +++ /dev/null @@ -1,101 +0,0 @@ -<?php - -class Join_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_join_simple() - { - $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') - ->from('job') - ->join('user', 'user.id = job.id') - ->get() - ->result_array(); - - // Check the result - $this->assertEquals('1', $job_user[0]['job_id']); - $this->assertEquals('1', $job_user[0]['user_id']); - $this->assertEquals('Derek Jones', $job_user[0]['user_name']); - $this->assertEquals('Developer', $job_user[0]['job_name']); - } - - // ------------------------------------------------------------------------ - - public function test_join_escape_is_null() - { - $expected = 'SELECT '.$this->db->escape_identifiers('field') - ."\nFROM ".$this->db->escape_identifiers('table1') - ."\nJOIN ".$this->db->escape_identifiers('table2').' ON '.$this->db->escape_identifiers('field').' IS NULL'; - - $this->assertEquals( - $expected, - $this->db->select('field')->from('table1')->join('table2', 'field IS NULL')->get_compiled_select() - ); - - $expected = 'SELECT '.$this->db->escape_identifiers('field') - ."\nFROM ".$this->db->escape_identifiers('table1') - ."\nJOIN ".$this->db->escape_identifiers('table2').' ON '.$this->db->escape_identifiers('field').' IS NOT NULL'; - - $this->assertEquals( - $expected, - $this->db->select('field')->from('table1')->join('table2', 'field IS NOT NULL')->get_compiled_select() - ); - } - - // ------------------------------------------------------------------------ - - public function test_join_escape_multiple_conditions() - { - // We just need a valid query produced, not one that makes sense - $fields = array($this->db->protect_identifiers('table1.field1'), $this->db->protect_identifiers('table2.field2')); - - $expected = 'SELECT '.implode(', ', $fields) - ."\nFROM ".$this->db->escape_identifiers('table1') - ."\nLEFT JOIN ".$this->db->escape_identifiers('table2').' ON '.implode(' = ', $fields) - .' AND '.$fields[0]." = 'foo' AND ".$fields[1].' = 0'; - - $result = $this->db->select('table1.field1, table2.field2') - ->from('table1') - ->join('table2', "table1.field1 = table2.field2 AND table1.field1 = 'foo' AND table2.field2 = 0", 'LEFT') - ->get_compiled_select(); - - $this->assertEquals($expected, $result); - } - - // ------------------------------------------------------------------------ - - public function test_join_escape_multiple_conditions_with_parentheses() - { - // We just need a valid query produced, not one that makes sense - $fields = array($this->db->protect_identifiers('table1.field1'), $this->db->protect_identifiers('table2.field2')); - - $expected = 'SELECT '.implode(', ', $fields) - ."\nFROM ".$this->db->escape_identifiers('table1') - ."\nRIGHT JOIN ".$this->db->escape_identifiers('table2').' ON '.implode(' = ', $fields) - .' AND ('.$fields[0]." = 'foo' OR ".$fields[1].' IS NULL)'; - - $result = $this->db->select('table1.field1, table2.field2') - ->from('table1') - ->join('table2', "table1.field1 = table2.field2 AND (table1.field1 = 'foo' OR table2.field2 IS NULL)", 'RIGHT') - ->get_compiled_select(); - - $this->assertEquals($expected, $result); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php deleted file mode 100644 index 4d8673d99..000000000 --- a/tests/codeigniter/database/query_builder/like_test.php +++ /dev/null @@ -1,129 +0,0 @@ -<?php - -class Like_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_like() - { - $job1 = $this->db->like('name', 'veloper') - ->get('job') - ->row(); - - // Check the result - $this->assertEquals('1', $job1->id); - $this->assertEquals('Developer', $job1->name); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_or_like() - { - $jobs = $this->db->like('name', 'ian') - ->or_like('name', 'veloper') - ->get('job') - ->result_array(); - - // Check the result - $this->assertCount(3, $jobs); - $this->assertEquals('Developer', $jobs[0]['name']); - $this->assertEquals('Politician', $jobs[1]['name']); - $this->assertEquals('Musician', $jobs[2]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_not_like() - { - $jobs = $this->db->not_like('name', 'veloper') - ->get('job') - ->result_array(); - - // Check the result - $this->assertCount(3, $jobs); - $this->assertEquals('Politician', $jobs[0]['name']); - $this->assertEquals('Accountant', $jobs[1]['name']); - $this->assertEquals('Musician', $jobs[2]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_or_not_like() - { - $jobs = $this->db->like('name', 'an') - ->or_not_like('name', 'veloper') - ->get('job') - ->result_array(); - - // Check the result - $this->assertCount(3, $jobs); - $this->assertEquals('Politician', $jobs[0]['name']); - $this->assertEquals('Accountant', $jobs[1]['name']); - $this->assertEquals('Musician', $jobs[2]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * GitHub issue #273 - * - * @see ./mocks/schema/skeleton.php - */ - public function test_like_spaces_and_tabs() - { - $spaces = $this->db->like('value', ' ')->get('misc')->result_array(); - $tabs = $this->db->like('value', "\t")->get('misc')->result_array(); - - $this->assertCount(1, $spaces); - $this->assertCount(1, $tabs); - } - - /** - * GitHub issue #5462 - * - * @see ./mocks/schema/skeleton.php - * - * @dataProvider like_set_side_provider - */ - public function test_like_set_side($str, $side, $expected_name) - { - $actual = $this->db->like('name', $str, $side)->get('job')->result_array(); - $this->assertCount(1, $actual); - $this->assertEquals($expected_name, $actual[0]['name']); - } - - public function like_set_side_provider() - { - return array( - array('Developer', 'none', 'Developer'), - array('tician', 'before', 'Politician'), - array('Accou', 'after', 'Accountant'), - array('usicia', 'both', 'Musician'), - ); - } -} diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php deleted file mode 100644 index a1976d457..000000000 --- a/tests/codeigniter/database/query_builder/limit_test.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -class Limit_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_limit() - { - $jobs = $this->db->limit(2) - ->get('job') - ->result_array(); - - $this->assertCount(2, $jobs); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_limit_and_offset() - { - $jobs = $this->db->limit(2, 2) - ->get('job') - ->result_array(); - - $this->assertCount(2, $jobs); - $this->assertEquals('Accountant', $jobs[0]['name']); - $this->assertEquals('Musician', $jobs[1]['name']); - } - -} diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php deleted file mode 100644 index ff5bc543d..000000000 --- a/tests/codeigniter/database/query_builder/order_test.php +++ /dev/null @@ -1,55 +0,0 @@ -<?php - -class Order_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_order_ascending() - { - $jobs = $this->db->order_by('name', 'asc') - ->get('job') - ->result_array(); - - // Check the result - $this->assertCount(4, $jobs); - $this->assertEquals('Accountant', $jobs[0]['name']); - $this->assertEquals('Developer', $jobs[1]['name']); - $this->assertEquals('Musician', $jobs[2]['name']); - $this->assertEquals('Politician', $jobs[3]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_order_descending() - { - $jobs = $this->db->order_by('name', 'desc') - ->get('job') - ->result_array(); - - $this->assertCount(4, $jobs); - $this->assertEquals('Politician', $jobs[0]['name']); - $this->assertEquals('Musician', $jobs[1]['name']); - $this->assertEquals('Developer', $jobs[2]['name']); - $this->assertEquals('Accountant', $jobs[3]['name']); - } - -} diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php deleted file mode 100644 index 93b5c3d46..000000000 --- a/tests/codeigniter/database/query_builder/select_test.php +++ /dev/null @@ -1,95 +0,0 @@ -<?php - -class Select_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_select_only_one_collumn() - { - $jobs_name = $this->db->select('name') - ->get('job') - ->result_array(); - - // Check rows item - $this->assertArrayHasKey('name',$jobs_name[0]); - $this->assertArrayNotHasKey('id', $jobs_name[0]); - $this->assertArrayNotHasKey('description', $jobs_name[0]); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_select_min() - { - $job_min = $this->db->select_min('id') - ->get('job') - ->row(); - - // Minimum id was 1 - $this->assertEquals('1', $job_min->id); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_select_max() - { - $job_max = $this->db->select_max('id') - ->get('job') - ->row(); - - // Maximum id was 4 - $this->assertEquals('4', $job_max->id); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_select_avg() - { - $job_avg = $this->db->select_avg('id') - ->get('job') - ->row(); - - // Average should be 2.5 - $this->assertEquals('2.5', $job_avg->id); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_select_sum() - { - $job_sum = $this->db->select_sum('id') - ->get('job') - ->row(); - - // Sum of ids should be 10 - $this->assertEquals('10', $job_sum->id); - } - -} diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php deleted file mode 100644 index 64abe2872..000000000 --- a/tests/codeigniter/database/query_builder/truncate_test.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php - -class Truncate_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_truncate() - { - // Check initial record - $jobs = $this->db->get('job')->result_array(); - $this->assertCount(4, $jobs); - - // Do the empty - $this->db->truncate('job'); - - // Check the record - $jobs = $this->db->get('job'); - $this->assertEmpty($jobs->result_array()); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_truncate_with_from() - { - // Check initial record - $users = $this->db->get('user')->result_array(); - $this->assertCount(4, $users); - - // Do the empty - $this->db->from('user')->truncate(); - - // Check the record - $users = $this->db->get('user'); - $this->assertEmpty($users->result_array()); - } - -} diff --git a/tests/codeigniter/database/query_builder/update_test.php b/tests/codeigniter/database/query_builder/update_test.php deleted file mode 100644 index 27a647c45..000000000 --- a/tests/codeigniter/database/query_builder/update_test.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php - -class Update_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_update() - { - // Check initial record - $job1 = $this->db->where('id', 1)->get('job')->row(); - $this->assertEquals('Developer', $job1->name); - - // Do the update - $this->db->where('id', 1)->update('job', array('name' => 'Programmer')); - - // Check updated record - $job1 = $this->db->where('id', 1)->get('job')->row(); - $this->assertEquals('Programmer', $job1->name); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_update_with_set() - { - // Check initial record - $job1 = $this->db->where('id', 4)->get('job')->row(); - $this->assertEquals('Musician', $job1->name); - - // Do the update - $this->db->set('name', 'Vocalist'); - $this->db->update('job', NULL, 'id = 4'); - - // Check updated record - $job1 = $this->db->where('id', 4)->get('job')->row(); - $this->assertEquals('Vocalist', $job1->name); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php deleted file mode 100644 index 8a7a09ddb..000000000 --- a/tests/codeigniter/database/query_builder/where_test.php +++ /dev/null @@ -1,134 +0,0 @@ -<?php - -class Where_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_simple_key_value() - { - $job1 = $this->db->where('id', 1)->get('job')->row(); - - $this->assertEquals('1', $job1->id); - $this->assertEquals('Developer', $job1->name); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_custom_key_value() - { - $jobs = $this->db->where('id !=', 1)->get('job')->result_array(); - $this->assertCount(3, $jobs); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_associative_array() - { - $where = array('id >' => 2, 'name !=' => 'Accountant'); - $jobs = $this->db->where($where)->get('job')->result_array(); - - $this->assertCount(1, $jobs); - - // Should be Musician - $job = current($jobs); - $this->assertEquals('Musician', $job['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_custom_string() - { - $where = "id > 2 AND name != 'Accountant'"; - $jobs = $this->db->where($where)->get('job')->result_array(); - - $this->assertCount(1, $jobs); - - // Should be Musician - $job = current($jobs); - $this->assertEquals('Musician', $job['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_or() - { - $jobs = $this->db->where('name !=', 'Accountant') - ->or_where('id >', 3) - ->get('job') - ->result_array(); - - $this->assertCount(3, $jobs); - $this->assertEquals('Developer', $jobs[0]['name']); - $this->assertEquals('Politician', $jobs[1]['name']); - $this->assertEquals('Musician', $jobs[2]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_in() - { - $jobs = $this->db->where_in('name', array('Politician', 'Accountant')) - ->get('job') - ->result_array(); - - $this->assertCount(2, $jobs); - $this->assertEquals('Politician', $jobs[0]['name']); - $this->assertEquals('Accountant', $jobs[1]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_not_in() - { - $jobs = $this->db->where_not_in('name', array('Politician', 'Accountant')) - ->get('job') - ->result_array(); - - $this->assertCount(2, $jobs); - $this->assertEquals('Developer', $jobs[0]['name']); - $this->assertEquals('Musician', $jobs[1]['name']); - } - - // ------------------------------------------------------------------------ - - public function test_issue4093() - { - $input = 'bar and baz or qux'; - $sql = $this->db->where('foo', $input)->get_compiled_select('dummy'); - $this->assertEquals("'".$input."'", substr($sql, -20)); - } -} |