blob: aaba8c80339a9db69a5737cc18387fc6c3ec539d (
plain)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
<?php
Prado::using('System.Data.TDbConnection');
if(!defined('SQLMAP_TESTS'))
define('SQLMAP_TESTS', realpath(dirname(__FILE__)));
if(!class_exists('Account', false))
{
include(SQLMAP_TESTS.'/domain/A.php');
include(SQLMAP_TESTS.'/domain/Account.php');
include(SQLMAP_TESTS.'/domain/AccountBis.php');
include(SQLMAP_TESTS.'/domain/AccountCollection.php');
include(SQLMAP_TESTS.'/domain/B.php');
include(SQLMAP_TESTS.'/domain/Document.php');
include(SQLMAP_TESTS.'/domain/Book.php');
include(SQLMAP_TESTS.'/domain/C.php');
include(SQLMAP_TESTS.'/domain/Category.php');
include(SQLMAP_TESTS.'/domain/Complex.php');
include(SQLMAP_TESTS.'/domain/D.php');
include(SQLMAP_TESTS.'/domain/DocumentCollection.php');
include(SQLMAP_TESTS.'/domain/E.php');
include(SQLMAP_TESTS.'/domain/F.php');
include(SQLMAP_TESTS.'/domain/LineItem.php');
include(SQLMAP_TESTS.'/domain/LineItemCollection.php');
include(SQLMAP_TESTS.'/domain/Newspaper.php');
include(SQLMAP_TESTS.'/domain/Order.php');
include(SQLMAP_TESTS.'/domain/Other.php');
include(SQLMAP_TESTS.'/domain/Sample.php');
include(SQLMAP_TESTS.'/domain/Search.php');
include(SQLMAP_TESTS.'/domain/User.php');
}
class DefaultScriptRunner
{
function runScript($connection, $script)
{
$sql = file_get_contents($script);
$lines = explode(';', $sql);
foreach($lines as $line)
{
$line = trim($line);
if(strlen($line) > 0)
$connection->createCommand($line)->execute();
}
}
}
class CopyFileScriptRunner
{
protected $baseFile;
protected $targetFile;
public function __construct($base, $target)
{
$this->baseFile = $base;
$this->targetFile = $target;
}
function runScript($connection, $script)
{
copy($this->baseFile, $this->targetFile);
}
}
class SQLiteBaseTestConfig extends BaseTestConfig
{
protected $baseFile;
protected $targetFile;
public function __construct()
{
$this->_sqlmapConfigFile = SQLMAP_TESTS.'/sqlite.xml';
$this->_scriptDir = SQLMAP_TESTS.'/scripts/sqlite/';
$this->targetFile = realpath(SQLMAP_TESTS.'/sqlite/tests.db');
$this->baseFile = realpath(SQLMAP_TESTS.'/sqlite/backup.db');
$file = realpath($this->targetFile);
$this->_connection = new TDbConnection("sqlite:{$file}");
}
public function getScriptRunner()
{
return new CopyFileScriptRunner($this->baseFile, $this->targetFile);
}
}
class MySQLBaseTestConfig extends BaseTestConfig
{
public function __construct()
{
$this->_sqlmapConfigFile = SQLMAP_TESTS.'/mysql.xml';
$this->_scriptDir = SQLMAP_TESTS.'/scripts/mysql/';
$this->_features = array('insert_id');
$dsn = 'mysql:host=localhost;dbname=sqlmap_test;port=3307';
$this->_connection = new TDbConnection($dsn, 'test5', 'test5');
}
}
class MSSQLBaseTestConfig extends BaseTestConfig
{
public function __construct()
{
$this->_sqlmap = SQLMAP_TESTS.'/mssql.xml';
$this->_connectionString = 'odbc_mssql://sqlmap_tests';
$this->_scriptDir = SQLMAP_TESTS.'/scripts/mssql/';
$this->_features = array('insert_id');
}
}
class BaseTestConfig
{
protected $_scriptDir;
protected $_connection;
protected $_sqlmapConfigFile;
public function hasFeature($type)
{
return false;
}
public function getScriptDir()
{
return $this->_scriptDir;
}
public function getConnection()
{
return $this->_connection;
}
public function getSqlMapConfigFile()
{
return $this->_sqlmapConfigFile;
}
public function getScriptRunner()
{
return new DefaultScriptRunner();
}
public static function createConfigInstance()
{
//change this to connection to a different database
//return new MySQLBaseTestConfig();
return new SQLiteBaseTestConfig();
//return new MSSQLBaseTestConfig();
}
}
?>
|