blob: 6d220d65dd6c724e91d9f2a33567d2c85219a348 [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');
26 $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';";
27 $res = $this->db->query($sql)->result_array();
28
29 // Check the result
30 $this->assertEquals(1, count($res));
31 }
32
33 // ------------------------------------------------------------------------
34
35 /**
36 * @see ./mocks/schema/skeleton.php
37 */
38 public function test_escape_like_backslash_sign()
39 {
40 $string = $this->db->escape_like_str('\\');
41 $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';";
42 $res = $this->db->query($sql)->result_array();
43
44 // Check the result
45 $this->assertEquals(2, count($res));
46 }
47}