Taufan Aditya | f78018e | 2012-05-04 15:53:55 +0700 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class Like_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_like() |
| 24 | { |
| 25 | $job1 = $this->db->like('name', 'veloper') |
| 26 | ->get('job') |
| 27 | ->row(); |
| 28 | |
| 29 | // Check the result |
| 30 | $this->assertEquals('1', $job1->id); |
| 31 | $this->assertEquals('Developer', $job1->name); |
| 32 | } |
| 33 | |
| 34 | // ------------------------------------------------------------------------ |
| 35 | |
| 36 | /** |
| 37 | * @see ./mocks/schema/skeleton.php |
| 38 | */ |
| 39 | public function test_or_like() |
| 40 | { |
| 41 | $jobs = $this->db->like('name', 'ian') |
| 42 | ->or_like('name', 'veloper') |
| 43 | ->get('job') |
| 44 | ->result_array(); |
| 45 | |
| 46 | // Check the result |
Andrey Andreev | 20d9b0a | 2017-12-20 19:57:39 +0200 | [diff] [blame^] | 47 | $this->assertCount(3, $jobs); |
Taufan Aditya | f78018e | 2012-05-04 15:53:55 +0700 | [diff] [blame] | 48 | $this->assertEquals('Developer', $jobs[0]['name']); |
| 49 | $this->assertEquals('Politician', $jobs[1]['name']); |
| 50 | $this->assertEquals('Musician', $jobs[2]['name']); |
| 51 | } |
| 52 | |
| 53 | // ------------------------------------------------------------------------ |
| 54 | |
| 55 | /** |
| 56 | * @see ./mocks/schema/skeleton.php |
| 57 | */ |
| 58 | public function test_not_like() |
| 59 | { |
| 60 | $jobs = $this->db->not_like('name', 'veloper') |
| 61 | ->get('job') |
| 62 | ->result_array(); |
| 63 | |
| 64 | // Check the result |
Andrey Andreev | 20d9b0a | 2017-12-20 19:57:39 +0200 | [diff] [blame^] | 65 | $this->assertCount(3, $jobs); |
Taufan Aditya | f78018e | 2012-05-04 15:53:55 +0700 | [diff] [blame] | 66 | $this->assertEquals('Politician', $jobs[0]['name']); |
| 67 | $this->assertEquals('Accountant', $jobs[1]['name']); |
| 68 | $this->assertEquals('Musician', $jobs[2]['name']); |
| 69 | } |
| 70 | |
| 71 | // ------------------------------------------------------------------------ |
| 72 | |
| 73 | /** |
| 74 | * @see ./mocks/schema/skeleton.php |
| 75 | */ |
| 76 | public function test_or_not_like() |
| 77 | { |
| 78 | $jobs = $this->db->like('name', 'an') |
| 79 | ->or_not_like('name', 'veloper') |
| 80 | ->get('job') |
| 81 | ->result_array(); |
| 82 | |
| 83 | // Check the result |
Andrey Andreev | 20d9b0a | 2017-12-20 19:57:39 +0200 | [diff] [blame^] | 84 | $this->assertCount(3, $jobs); |
Taufan Aditya | f78018e | 2012-05-04 15:53:55 +0700 | [diff] [blame] | 85 | $this->assertEquals('Politician', $jobs[0]['name']); |
| 86 | $this->assertEquals('Accountant', $jobs[1]['name']); |
| 87 | $this->assertEquals('Musician', $jobs[2]['name']); |
| 88 | } |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 89 | |
Andrey Andreev | 96a4ca6 | 2012-10-23 01:11:48 +0300 | [diff] [blame] | 90 | // ------------------------------------------------------------------------ |
| 91 | |
| 92 | /** |
| 93 | * GitHub issue #273 |
| 94 | * |
| 95 | * @see ./mocks/schema/skeleton.php |
| 96 | */ |
| 97 | public function test_like_spaces_and_tabs() |
| 98 | { |
Andrey Andreev | 348bd1e | 2012-10-23 01:24:11 +0300 | [diff] [blame] | 99 | $spaces = $this->db->like('value', ' ')->get('misc')->result_array(); |
| 100 | $tabs = $this->db->like('value', "\t")->get('misc')->result_array(); |
Andrey Andreev | 96a4ca6 | 2012-10-23 01:11:48 +0300 | [diff] [blame] | 101 | |
Andrey Andreev | 20d9b0a | 2017-12-20 19:57:39 +0200 | [diff] [blame^] | 102 | $this->assertCount(1, $spaces); |
| 103 | $this->assertCount(1, $tabs); |
Andrey Andreev | 96a4ca6 | 2012-10-23 01:11:48 +0300 | [diff] [blame] | 104 | } |
| 105 | |
Andrey Andreev | 20d9b0a | 2017-12-20 19:57:39 +0200 | [diff] [blame^] | 106 | } |