forked from koala-framework/koala-framework
/
Test.php
107 lines (100 loc) · 3.24 KB
/
Test.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
<?php
/**
* @group Model
* @group Model_Db
* @group Model_DbWithConnection
*/
class Kwf_Model_DbWithConnection_Test extends Kwf_Test_TestCase
{
protected $backupStaticAttributes = false;
private $_tableName;
public function setUp()
{
$this->_tableName = 'test'.uniqid();
$sql = "CREATE TABLE $this->_tableName (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`test1` VARCHAR( 200 ) character set utf8 NOT NULL,
`test2` VARCHAR( 200 ) character set utf8 NOT NULL
) ENGINE = INNODB DEFAULT CHARSET=utf8";
Kwf_Registry::get('db')->query($sql);
$m = new Kwf_Model_Db(array(
'table' => $this->_tableName
));
$r = $m->createRow();
$r->test1 = '1x1';
$r->test2 = '1';
$r->save();
}
public function tearDown()
{
Kwf_Registry::get('db')->query("DROP TABLE {$this->_tableName}");
}
public function testIt()
{
$model = new Kwf_Model_Db(array(
'table' => $this->_tableName
));
$this->assertEquals('1x1', $model->getRow(1)->test1);
}
/*
AUSKOMMENTIERT WEIL:
- dieser blöder bug eh nur lokal auftritt
- weiter oben eh ein test ist der das eingentliche problem testet
- mich der blöde test jetzt schon langsam anzipft!
public function testEscaping()
{
$values = array(
array(0x2c, 0x8a, 0x3e, 0x43, 0xb3, 0x9, 0x3d, 0x97, 0x4a, 0x27),
array(0xfb, 0xc4, 0x4a, 0xde, 0x9d, 0x63, 0x9e, 0x5d, 0x27, 0xa9),
':a\\\'', 'a\'b', '\'?', '?', 'a?b', 'a"b', 'a\\b', 'a\\\'b'
);
$model = new Kwf_Model_Db(array(
'table' => $this->_tableName
));
$this->expectOutputString(str_repeat("WARNING: (? or :) and a single quote are used together in an sql query value. This is a problem because of an Php bug. The single quote is ignored.\n", 4));
foreach ($values as $v) {
if (is_array($v)) {
$vn = '';
foreach ($v as $i) {
$vn .= chr($i);
}
$v = $vn;
}
$s = $model->select()->whereEquals('test1', $v);
$model->getRow($s);
$s = $model->select()->where(new Kwf_Model_Select_Expr_Equal('test1', $v));
$model->getRow($s);
}
}
*/
/**
* @group slow
*
AUSKOMMENTIERT WEIL:
- dieser blöder bug eh nur lokal auftritt
- weiter oben eh ein test ist der das eingentliche problem testet
- mich der blöde test jetzt schon langsam anzipft!
public function testEscapingBruteForce()
{
$model = new Kwf_Model_Db(array(
'table' => $this->_tableName
));
for($i=0;$i<1000;$i++) {
$v = '';
$hex = '';
for($j=0;$j<10;$j++) {
$chr = rand(0, 255);
$v .= chr($chr);
$hex .= "0x".dechex($chr).", ";
}
//echo "\n";
$s = $model->select()->whereEquals('test1', $v);
try {
$model->getRow($s);
} catch (Zend_Db_Statement_Exception $e) {
$this->fail("value: '$v' ($hex); ".$e->getMessage());
}
}
}
*/
}