forked from lox/pheasant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBindingTest.php
138 lines (118 loc) · 3.48 KB
/
BindingTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
namespace Pheasant\Tests;
use \Pheasant\Database\Binder;
class BindingTest extends \Pheasant\Tests\MysqlTestCase
{
public function testBasicStringBinding()
{
$binder = new Binder();
$this->assertEquals(
$binder->bind('SELECT * FROM table WHERE column=?', array('test')),
"SELECT * FROM table WHERE column='test'"
);
}
public function testIntBinding()
{
$binder = new Binder();
$this->assertEquals(
$binder->bind('column=?', array(24)),
"column='24'"
);
}
public function testNullBinding()
{
$binder = new Binder();
$this->assertEquals(
$binder->magicBind('column=?', array(null)),
'column IS NULL'
);
}
public function testMultipleBinding()
{
$binder = new Binder();
$this->assertEquals(
$binder->magicBind('a=? and b=?', array(24, 'test')),
"a='24' and b='test'"
);
}
public function testArrayBinding()
{
$binder = new Binder();
$this->assertEquals(
$binder->magicBind('a=? and b=?', array(24, array(1, 2, "llama's"))),
"a='24' and b IN ('1','2','llama\'s')"
);
}
public function testEmptyArrayBinding()
{
$binder = new Binder();
$this->assertEquals(
$binder->magicBind('x=?', array(array())),
'x IN (null)'
);
}
public function testInjectingStatements()
{
$binder = new Binder();
$this->assertEquals(
$binder->bind('x=?', array('10\'; DROP TABLE --')),
"x='10\'; DROP TABLE --'"
);
}
/**
* @expectedException InvalidArgumentException
*/
public function testBindMissingParameters()
{
$binder = new Binder();
$binder->bind('x=? and y=?', array(24));
}
public function testBoolBinding()
{
$binder = new Binder();
$this->assertEquals(
$binder->bind('column1=? and column2=?', array(false, true)),
"column1='' and column2=1"
);
}
public function testBindIntoAQueryWithQuestionMarksInQuotes()
{
$binder = new Binder();
$this->assertEquals(
$binder->bind("name='???' and llamas=?", array(24)),
"name='???' and llamas='24'"
);
}
public function testBindIntoAQueryWithEscapedQuotesInStrings()
{
$binder = new Binder();
$this->assertEquals(
$binder->bind("name='\'7r' and llamas=?", array(24)),
"name='\'7r' and llamas='24'"
);
$this->assertEquals(
$binder->bind("name='\'7r\\\\' and another='test question?' and llamas=?", array(24)),
"name='\'7r\\\\' and another='test question?' and llamas='24'"
);
$this->assertEquals(
$binder->bind("name='\'7r\\\\' and x='\'7r' and llamas=?", array(24)),
"name='\'7r\\\\' and x='\'7r' and llamas='24'"
);
}
public function testBindIntoAQueryWithQuotesInQuotes()
{
$binder = new Binder();
$this->assertEquals(
$binder->bind("name='\"' and llamas=?", array(24)),
"name='\"' and llamas='24'"
);
}
public function testBindWithBackquote()
{
$binder = new Binder();
$this->assertEquals(
$binder->magicBind('`id`=?', array(1)),
"`id`='1'"
);
}
}