blob: 3672afae37228e6bc7c8212750e7059928d8835b [file] [log] [blame]
Taufan Adityaf78018e2012-05-04 15:53:55 +07001<?php
2
3class 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 Andreev20d9b0a2017-12-20 19:57:39 +020047 $this->assertCount(3, $jobs);
Taufan Adityaf78018e2012-05-04 15:53:55 +070048 $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 Andreev20d9b0a2017-12-20 19:57:39 +020065 $this->assertCount(3, $jobs);
Taufan Adityaf78018e2012-05-04 15:53:55 +070066 $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 Andreev20d9b0a2017-12-20 19:57:39 +020084 $this->assertCount(3, $jobs);
Taufan Adityaf78018e2012-05-04 15:53:55 +070085 $this->assertEquals('Politician', $jobs[0]['name']);
86 $this->assertEquals('Accountant', $jobs[1]['name']);
87 $this->assertEquals('Musician', $jobs[2]['name']);
88 }
Andrey Andreevc1862882012-06-09 23:16:58 +030089
Andrey Andreev96a4ca62012-10-23 01:11:48 +030090 // ------------------------------------------------------------------------
91
92 /**
93 * GitHub issue #273
94 *
95 * @see ./mocks/schema/skeleton.php
96 */
97 public function test_like_spaces_and_tabs()
98 {
Andrey Andreev348bd1e2012-10-23 01:24:11 +030099 $spaces = $this->db->like('value', ' ')->get('misc')->result_array();
100 $tabs = $this->db->like('value', "\t")->get('misc')->result_array();
Andrey Andreev96a4ca62012-10-23 01:11:48 +0300101
Andrey Andreev20d9b0a2017-12-20 19:57:39 +0200102 $this->assertCount(1, $spaces);
103 $this->assertCount(1, $tabs);
Andrey Andreev96a4ca62012-10-23 01:11:48 +0300104 }
105
Andrey Andreev20d9b0a2017-12-20 19:57:39 +0200106}