blob: 96fbd078b7589c2420a2a814e3c822e7c89e8ea4 [file] [log] [blame]
Taufan Aditya2d574452012-05-25 04:03:56 +07001<?php
2
3class Escape_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_escape_like_percent_sign()
24 {
25 $string = $this->db->escape_like_str('\%foo');
Andrey Andreev59d6b4f2012-05-25 02:08:00 +030026 $res = $this->db->select('value')->from('misc')->like('key', $string, 'after')->get();
Taufan Aditya98dcac72012-05-25 05:07:51 +070027
Taufan Aditya2d574452012-05-25 04:03:56 +070028 // Check the result
Andrey Andreev59d6b4f2012-05-25 02:08:00 +030029 $this->assertEquals(1, count($res->result_array()));
Taufan Aditya2d574452012-05-25 04:03:56 +070030 }
31
32 // ------------------------------------------------------------------------
33
34 /**
35 * @see ./mocks/schema/skeleton.php
36 */
37 public function test_escape_like_backslash_sign()
38 {
39 $string = $this->db->escape_like_str('\\');
Andrey Andreev59d6b4f2012-05-25 02:08:00 +030040 $res = $this->db->select('value')->from('misc')->like('key', $string, 'after')->get();
41
Taufan Aditya2d574452012-05-25 04:03:56 +070042 // Check the result
Andrey Andreev59d6b4f2012-05-25 02:08:00 +030043 $this->assertEquals(2, count($res->result_array()));
Taufan Aditya2d574452012-05-25 04:03:56 +070044 }
Andrey Andreev59d6b4f2012-05-25 02:08:00 +030045
Taufan Aditya2d574452012-05-25 04:03:56 +070046}