| 1 |
lars |
1 |
<?php
|
|
|
2 |
// +----------------------------------------------------------------------+
|
|
|
3 |
// | PHP versions 4 and 5 |
|
|
|
4 |
// +----------------------------------------------------------------------+
|
|
|
5 |
// | Copyright (c) 2007 m3 Media Services Ltd. |
|
|
|
6 |
// | All rights reserved. |
|
|
|
7 |
// +----------------------------------------------------------------------+
|
|
|
8 |
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
|
|
|
9 |
// | API as well as database abstraction for PHP applications. |
|
|
|
10 |
// | This LICENSE is in the BSD license style. |
|
|
|
11 |
// | |
|
|
|
12 |
// | Redistribution and use in source and binary forms, with or without |
|
|
|
13 |
// | modification, are permitted provided that the following conditions |
|
|
|
14 |
// | are met: |
|
|
|
15 |
// | |
|
|
|
16 |
// | Redistributions of source code must retain the above copyright |
|
|
|
17 |
// | notice, this list of conditions and the following disclaimer. |
|
|
|
18 |
// | |
|
|
|
19 |
// | Redistributions in binary form must reproduce the above copyright |
|
|
|
20 |
// | notice, this list of conditions and the following disclaimer in the |
|
|
|
21 |
// | documentation and/or other materials provided with the distribution. |
|
|
|
22 |
// | |
|
|
|
23 |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
|
|
|
24 |
// | Lukas Smith nor the names of his contributors may be used to endorse |
|
|
|
25 |
// | or promote products derived from this software without specific prior|
|
|
|
26 |
// | written permission. |
|
|
|
27 |
// | |
|
|
|
28 |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
|
|
29 |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
|
|
30 |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
|
|
31 |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
|
|
32 |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
|
|
33 |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
|
|
34 |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
|
|
|
35 |
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
|
|
36 |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
|
|
37 |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
|
|
|
38 |
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
|
|
39 |
// | POSSIBILITY OF SUCH DAMAGE. |
|
|
|
40 |
// +----------------------------------------------------------------------+
|
|
|
41 |
// | Author: Monique Szpak <monique.szpak@openads.org> |
|
|
|
42 |
// | Andrew Hill <andrew.hill@openads.org> |
|
|
|
43 |
// +----------------------------------------------------------------------+
|
|
|
44 |
//
|
|
|
45 |
// $Id: MDB2_internals_testcase.php,v 1.1 2007/03/02 16:39:22 quipo Exp $
|
|
|
46 |
|
|
|
47 |
require_once 'MDB2_testcase.php';
|
|
|
48 |
|
|
|
49 |
class MDB2_Internals_TestCase extends MDB2_TestCase {
|
|
|
50 |
|
|
|
51 |
var $clear_tables = false;
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Tests that the MDB2::apiVersion() method returns an API version number.
|
|
|
55 |
*/
|
|
|
56 |
function test_apiVersion()
|
|
|
57 |
{
|
|
|
58 |
$result = MDB2::apiVersion();
|
|
|
59 |
$this->assertNotNull($result, 'apiVersion');
|
|
|
60 |
$result = strtok($result, '.');
|
|
|
61 |
$this->assertTrue(is_numeric($result), 'apiVersion');
|
|
|
62 |
$result = strtok('.');
|
|
|
63 |
$this->assertTrue(is_numeric($result), 'apiVersion');
|
|
|
64 |
$result = strtok('.');
|
|
|
65 |
$this->assertTrue(is_numeric($result), 'apiVersion');
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* Tests that the MDB2::classExists() method correctly tests for
|
|
|
70 |
* existence of a class.
|
|
|
71 |
*/
|
|
|
72 |
function test_classExists()
|
|
|
73 |
{
|
|
|
74 |
$this->assertFalse(MDB2::classExists('null'), 'classExists');
|
|
|
75 |
$this->assertTrue(MDB2::classExists('MDB2'), 'classExists');
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Tests that the MDB2::loadClass() method correctly loads classes.
|
|
|
80 |
*/
|
|
|
81 |
function test_loadClass()
|
|
|
82 |
{
|
|
|
83 |
$this->assertTrue(MDB2::loadClass('MDB2', false), 'loadClass');
|
|
|
84 |
// Suppress handling of PEAR errors while testing next case
|
|
|
85 |
PEAR::pushErrorHandling(null);
|
|
|
86 |
$result = MDB2::loadClass('null', false);
|
|
|
87 |
$this->assertTrue(is_a($result, 'pear_error'), 'loadClass');
|
|
|
88 |
PEAR::popErrorHandling();
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Tests that the MDB2::factory() method correctly connects to a
|
|
|
93 |
* database.
|
|
|
94 |
*/
|
|
|
95 |
function test_factory()
|
|
|
96 |
{
|
|
|
97 |
$db =& MDB2::factory($this->dsn);
|
|
|
98 |
$this->assertTrue(MDB2::isConnection($db), 'factory');
|
|
|
99 |
// Suppress handling of PEAR errors while preparing the
|
|
|
100 |
// next test case database connection
|
|
|
101 |
PEAR::pushErrorHandling(null);
|
|
|
102 |
$db =& MDB2::factory(null);
|
|
|
103 |
PEAR::popErrorHandling();
|
|
|
104 |
$this->assertFalse(MDB2::isConnection($db), 'factory');
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* Tests that the MDB2::loadFile() method returns the expected
|
|
|
109 |
* filename.
|
|
|
110 |
*/
|
|
|
111 |
function test_loadFile()
|
|
|
112 |
{
|
|
|
113 |
$filename = 'Extended';
|
|
|
114 |
$this->assertEquals('MDB2'.DIRECTORY_SEPARATOR.$filename.'.php', MDB2::loadFile($filename), 'loadFile');
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
/**
|
|
|
118 |
* Tests that the MDB2::isConnection() method correctly reports
|
|
|
119 |
* connections.
|
|
|
120 |
*/
|
|
|
121 |
function test_isConnection()
|
|
|
122 |
{
|
|
|
123 |
$this->assertTrue(MDB2::isConnection($this->db), 'isConnection');
|
|
|
124 |
$this->assertFalse(MDB2::isConnection(null), 'isConnection');
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
/**
|
|
|
128 |
* Tests that the MDB2::isResult() method correctly identifies
|
|
|
129 |
* results.
|
|
|
130 |
*/
|
|
|
131 |
function test_isResult()
|
|
|
132 |
{
|
|
|
133 |
$obj = new MDB2_Result();
|
|
|
134 |
$this->assertTrue(MDB2::isResult($obj), 'isResult');
|
|
|
135 |
$obj = null;
|
|
|
136 |
$this->assertFalse(MDB2::isResult($obj), 'isResult');
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
/**
|
|
|
140 |
* Tests that the MDB2::isResultCommon() method correctly identifies
|
|
|
141 |
* common results.
|
|
|
142 |
*/
|
|
|
143 |
function test_isResultCommon()
|
|
|
144 |
{
|
|
|
145 |
$result = null;
|
|
|
146 |
$obj = new MDB2_Result_Common($this->db, $result);
|
|
|
147 |
$this->assertTrue(MDB2::isResultCommon($obj), 'isResultCommon');
|
|
|
148 |
$obj = null;
|
|
|
149 |
$this->assertFalse(MDB2::isResultCommon($obj), 'isResultCommon');
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
/**
|
|
|
153 |
* Tests that the MDB2::parseDSN() method works.
|
|
|
154 |
*/
|
|
|
155 |
function test_parseDSN()
|
|
|
156 |
{
|
|
|
157 |
$dsn = $this->dsn;
|
|
|
158 |
$result = MDB2::parseDSN($dsn);
|
|
|
159 |
$this->assertEquals($dsn['phptype'],$result['dbsyntax'],'parseDSN');
|
|
|
160 |
|
|
|
161 |
$dsn = "mydbms://myname:mypassword@localhost";
|
|
|
162 |
$result = MDB2::parseDSN($dsn);
|
|
|
163 |
$this->assertEquals('mydbms', $result['phptype'],'parseDSN');
|
|
|
164 |
$this->assertEquals('mydbms',$result['dbsyntax'],'parseDSN');
|
|
|
165 |
$this->assertEquals('tcp',$result['protocol'],'parseDSN');
|
|
|
166 |
$this->assertEquals('localhost',$result['hostspec'],'parseDSN');
|
|
|
167 |
$this->assertEquals(false,$result['port'],'parseDSN');
|
|
|
168 |
$this->assertEquals(false,$result['socket'],'parseDSN');
|
|
|
169 |
$this->assertEquals('myname',$result['username'],'parseDSN');
|
|
|
170 |
$this->assertEquals('mypassword',$result['password'],'parseDSN');
|
|
|
171 |
$this->assertEquals(false,$result['database'],'parseDSN');
|
|
|
172 |
|
|
|
173 |
$dsn = "somesql://myname:mypassword@localhost:1234/mydb";
|
|
|
174 |
$result = MDB2::parseDSN($dsn);
|
|
|
175 |
$this->assertEquals('somesql',$result['phptype'],'parseDSN');
|
|
|
176 |
$this->assertEquals('somesql',$result['dbsyntax'],'parseDSN');
|
|
|
177 |
$this->assertEquals('tcp',$result['protocol'],'parseDSN');
|
|
|
178 |
$this->assertEquals('localhost',$result['hostspec'],'parseDSN');
|
|
|
179 |
$this->assertEquals('1234',$result['port'],'parseDSN');
|
|
|
180 |
$this->assertEquals(false,$result['socket'],'parseDSN');
|
|
|
181 |
$this->assertEquals('myname',$result['username'],'parseDSN');
|
|
|
182 |
$this->assertEquals('mypassword',$result['password'],'parseDSN');
|
|
|
183 |
$this->assertEquals('mydb',$result['database'],'parseDSN');
|
|
|
184 |
|
|
|
185 |
$dsn = "dbms1://myname@unix(opts)/mydb?param1=value1";
|
|
|
186 |
$result = MDB2::parseDSN($dsn);
|
|
|
187 |
$this->assertEquals('dbms1',$result['phptype'],'parseDSN');
|
|
|
188 |
$this->assertEquals('dbms1',$result['dbsyntax'],'parseDSN');
|
|
|
189 |
$this->assertEquals('unix',$result['protocol'],'parseDSN');
|
|
|
190 |
$this->assertEquals(false,$result['hostspec'],'parseDSN');
|
|
|
191 |
$this->assertEquals(false,$result['port'],'parseDSN');
|
|
|
192 |
$this->assertEquals('opts',$result['socket'],'parseDSN');
|
|
|
193 |
$this->assertEquals('myname',$result['username'],'parseDSN');
|
|
|
194 |
$this->assertEquals(false,$result['password'],'parseDSN');
|
|
|
195 |
$this->assertEquals('mydb',$result['database'],'parseDSN');
|
|
|
196 |
$this->assertEquals('value1',$result['param1'],'parseDSN');
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
/**
|
|
|
200 |
* Tests that the MDB2::fileExists() method correctly identifies
|
|
|
201 |
* existing/non-existing files.
|
|
|
202 |
*/
|
|
|
203 |
function test_fileExists()
|
|
|
204 |
{
|
|
|
205 |
$this->assertTrue(MDB2::fileExists('PEAR.php'), 'fileExists');
|
|
|
206 |
$this->assertFalse(MDB2::fileExists('itIsHopedThatNoOneHasAFileWithThisName.php'), 'fileExists');
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
/**
|
|
|
210 |
* Tests that the MDB2::__toString() method returns the expected
|
|
|
211 |
* string result.
|
|
|
212 |
*/
|
|
|
213 |
function test__toString()
|
|
|
214 |
{
|
|
|
215 |
$expected = "MDB2_Driver_{$this->dsn['phptype']}: (phptype = {$this->dsn['phptype']}, dbsyntax = {$this->db->dbsyntax})";
|
|
|
216 |
if (version_compare(PHP_VERSION, "5.0.0", "<")) {
|
|
|
217 |
$expected = strtolower($expected);
|
|
|
218 |
}
|
|
|
219 |
$this->assertEquals($expected ,$this->db->__toString(), '__toString');
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
/**
|
|
|
223 |
* Tests that the MDB2::setFetchMode() method correctly sets the
|
|
|
224 |
* fetch mode.
|
|
|
225 |
*/
|
|
|
226 |
function test_setFetchMode()
|
|
|
227 |
{
|
|
|
228 |
$tmp = $this->db->fetchmode;
|
|
|
229 |
$this->db->setFetchMode(MDB2_FETCHMODE_OBJECT);
|
|
|
230 |
$this->assertEquals('stdClass', $this->db->options['fetch_class'], 'setFetchMode');
|
|
|
231 |
$this->db->setFetchMode(MDB2_FETCHMODE_ORDERED);
|
|
|
232 |
$this->assertEquals(MDB2_FETCHMODE_ORDERED, $this->db->fetchmode, 'setFetchMode');
|
|
|
233 |
$this->db->setFetchMode(MDB2_FETCHMODE_ASSOC);
|
|
|
234 |
$this->assertEquals(MDB2_FETCHMODE_ASSOC, $this->db->fetchmode, 'setFetchMode');
|
|
|
235 |
$this->db->fetchmode = $tmp;
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
/**
|
|
|
239 |
* Tests that the MDB2::escape() method correctly escapes strings.
|
|
|
240 |
*/
|
|
|
241 |
function test_escape()
|
|
|
242 |
{
|
|
|
243 |
$tmp = $this->db->string_quoting;
|
|
|
244 |
$this->string_quoting['escape'] = '\\';
|
|
|
245 |
$this->string_quoting['end'] = '"';
|
|
|
246 |
$text = 'xxx"z"xxx';
|
|
|
247 |
$this->assertEquals('xxx\"z\"xxx', MDB2_Driver_Common::escape($text), 'escape');
|
|
|
248 |
$this->db->string_quoting = $tmp;
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
/**
|
|
|
252 |
* Tests that the MDB2::quoteIdentifier() method correctly quotes strings.
|
|
|
253 |
*/
|
|
|
254 |
function test_quoteIdentifier()
|
|
|
255 |
{
|
|
|
256 |
if ($this->db->phptype == 'ibase') {
|
|
|
257 |
return;
|
|
|
258 |
}
|
|
|
259 |
$tmp = $this->db->identifier_quoting;
|
|
|
260 |
$this->db->identifier_quoting['start'] = '"';
|
|
|
261 |
$this->db->identifier_quoting['end'] = '`';
|
|
|
262 |
$this->db->identifier_quoting['escape'] = '/';
|
|
|
263 |
$text = 'my`identifier';
|
|
|
264 |
$this->assertEquals('"my/`identifier`', $this->db->quoteIdentifier($text), 'quoteIdentifier');
|
|
|
265 |
$this->db->identifier_quoting = $tmp;
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
/**
|
|
|
269 |
* Tests that the MDB2::getAsKeyword() method correctly returns
|
|
|
270 |
* the set "as" keyword.
|
|
|
271 |
*/
|
|
|
272 |
function test_getAsKeyword()
|
|
|
273 |
{
|
|
|
274 |
$tmp = $this->db->as_keyword;
|
|
|
275 |
$this->db->as_keyword = 'ALIAS';
|
|
|
276 |
$this->assertEquals('ALIAS', $this->db->getAsKeyword(), 'getAsKeyword');
|
|
|
277 |
$this->db->as_keyword = $tmp;
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
/**
|
|
|
281 |
* Tests that the MDB2::getConnection() method correctly returns
|
|
|
282 |
* a database resource.
|
|
|
283 |
*/
|
|
|
284 |
function test_getConnection()
|
|
|
285 |
{
|
|
|
286 |
$result = $this->db->getConnection();
|
|
|
287 |
$this->assertTrue(is_resource($result), 'getConnection');
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
/**
|
|
|
291 |
* A private method to return a defined "row" of data for use
|
|
|
292 |
* in the next set of tests.
|
|
|
293 |
*
|
|
|
294 |
* @access private
|
|
|
295 |
* @return array The array of "row" data.
|
|
|
296 |
*/
|
|
|
297 |
function _fetchRowData()
|
|
|
298 |
{
|
|
|
299 |
return array(
|
|
|
300 |
|
|
|
301 |
1 => 'notnull',
|
|
|
302 |
2 => 'length7 ',
|
|
|
303 |
'1?2:3.4' => 'assoc'
|
|
|
304 |
);
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
/**
|
|
|
308 |
* A private method to test results from the MDB2::_fixResultArrayValues()
|
|
|
309 |
* method when the $mode parameter was set to MDB2_PORTABILITY_EMPTY_TO_NULL.
|
|
|
310 |
*
|
|
|
311 |
* @access private
|
|
|
312 |
* @param array $row The result of the call to MDB2::_fixResultArrayValues().
|
|
|
313 |
*/
|
|
|
314 |
function _fixResultArrayValues_Test_EmptyToNull($row)
|
|
|
315 |
{
|
|
|
316 |
$this->assertNull($row[0], '_fixResultArrayValues');
|
|
|
317 |
$this->assertNotNull($row[1], '_fixResultArrayValues');
|
|
|
318 |
$this->assertNotNull($row[2], '_fixResultArrayValues');
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
/**
|
|
|
322 |
* A private method to test results from the MDB2::_fixResultArrayValues()
|
|
|
323 |
* method when the $mode parameter was set to MDB2_PORTABILITY_RTRIM.
|
|
|
324 |
*
|
|
|
325 |
* @access private
|
|
|
326 |
* @param array $row The result of the call to MDB2::_fixResultArrayValues().
|
|
|
327 |
*/
|
|
|
328 |
function _fixResultArrayValues_Test_Rtrim($row)
|
|
|
329 |
{
|
|
|
330 |
$this->assertEquals(strlen($row[0]), 0, '_fixResultArrayValues');
|
|
|
331 |
$this->assertEquals(strlen($row[1]), 7, '_fixResultArrayValues');
|
|
|
332 |
$this->assertEquals(strlen($row[2]), 7, '_fixResultArrayValues');
|
|
|
333 |
}
|
|
|
334 |
|
|
|
335 |
/**
|
|
|
336 |
* A private method to test results from the MDB2::_fixResultArrayValues()
|
|
|
337 |
* method when the $mode parameter was set to MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES.
|
|
|
338 |
*
|
|
|
339 |
* @access private
|
|
|
340 |
* @param array $row The result of the call to MDB2::_fixResultArrayValues().
|
|
|
341 |
*/
|
|
|
342 |
function _fixResultArrayValues_Test_FixAssocFieldNames($row)
|
|
|
343 |
{
|
|
|
344 |
$this->assertTrue(array_key_exists(4, $row), '_fixResultArrayValues');
|
|
|
345 |
$this->assertTrue($row[4] == 'assoc', '_fixResultArrayValues');
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
/**
|
|
|
349 |
* Tests that the MDB2::_fixResultArrayValues() method fixes array
|
|
|
350 |
* values when used with various $mode parameters.
|
|
|
351 |
*/
|
|
|
352 |
function test__fixResultArrayValues()
|
|
|
353 |
{
|
|
|
354 |
$mode = MDB2_PORTABILITY_EMPTY_TO_NULL;
|
|
|
355 |
$row = $this->_fetchRowData();
|
|
|
356 |
$this->db->_fixResultArrayValues($row, $mode);
|
|
|
357 |
$this->_fixResultArrayValues_Test_EmptyToNull($row);
|
|
|
358 |
|
|
|
359 |
$mode = MDB2_PORTABILITY_RTRIM;
|
|
|
360 |
$row = $this->_fetchRowData();
|
|
|
361 |
$this->db->_fixResultArrayValues($row, $mode);
|
|
|
362 |
$this->_fixResultArrayValues_Test_Rtrim($row);
|
|
|
363 |
|
|
|
364 |
$mode = MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES;
|
|
|
365 |
$row = $this->_fetchRowData();
|
|
|
366 |
$this->db->_fixResultArrayValues($row, $mode);
|
|
|
367 |
$this->_fixResultArrayValues_Test_FixAssocFieldNames($row);
|
|
|
368 |
|
|
|
369 |
$mode = MDB2_PORTABILITY_EMPTY_TO_NULL + MDB2_PORTABILITY_RTRIM;
|
|
|
370 |
$row = $this->_fetchRowData();
|
|
|
371 |
$this->db->_fixResultArrayValues($row, $mode);
|
|
|
372 |
$this->_fixResultArrayValues_Test_EmptyToNull($row);
|
|
|
373 |
$this->_fixResultArrayValues_Test_Rtrim($row);
|
|
|
374 |
|
|
|
375 |
$mode = MDB2_PORTABILITY_EMPTY_TO_NULL + MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES;
|
|
|
376 |
$row = $this->_fetchRowData();
|
|
|
377 |
$this->db->_fixResultArrayValues($row, $mode);
|
|
|
378 |
$this->_fixResultArrayValues_Test_EmptyToNull($row);
|
|
|
379 |
$this->_fixResultArrayValues_Test_FixAssocFieldNames($row);
|
|
|
380 |
|
|
|
381 |
$mode = MDB2_PORTABILITY_RTRIM + MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES;
|
|
|
382 |
$row = $this->_fetchRowData();
|
|
|
383 |
$this->db->_fixResultArrayValues($row, $mode);
|
|
|
384 |
$this->_fixResultArrayValues_Test_Rtrim($row);
|
|
|
385 |
$this->_fixResultArrayValues_Test_FixAssocFieldNames($row);
|
|
|
386 |
|
|
|
387 |
$mode = MDB2_PORTABILITY_EMPTY_TO_NULL + MDB2_PORTABILITY_RTRIM + MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES;
|
|
|
388 |
$row = $this->_fetchRowData();
|
|
|
389 |
$this->db->_fixResultArrayValues($row, $mode);
|
|
|
390 |
$this->_fixResultArrayValues_Test_EmptyToNull($row);
|
|
|
391 |
$this->_fixResultArrayValues_Test_Rtrim($row);
|
|
|
392 |
$this->_fixResultArrayValues_Test_FixAssocFieldNames($row);
|
|
|
393 |
}
|
|
|
394 |
|
|
|
395 |
/**
|
|
|
396 |
* Tests that the MDB2::transaction() method returns expected values
|
|
|
397 |
* when starting or rolling back a transaction, and for testing if
|
|
|
398 |
* the connection is in a transaction.
|
|
|
399 |
*/
|
|
|
400 |
function test_transaction()
|
|
|
401 |
{
|
|
|
402 |
if (!$this->db->supports('transactions'))
|
|
|
403 |
{
|
|
|
404 |
$this->assertTrue($this->db->beginTransaction(), 'transaction');
|
|
|
405 |
$this->assertTrue($this->db->in_transaction, 'transaction');
|
|
|
406 |
$this->assertTrue($this->db->rollback(), 'transaction');
|
|
|
407 |
$this->assertFalse($this->db->in_transaction, 'transaction');
|
|
|
408 |
|
|
|
409 |
$this->assertTrue($this->db->beginTransaction(), 'transaction');
|
|
|
410 |
$this->assertTrue($this->db->in_transaction, 'transaction');
|
|
|
411 |
$this->assertTrue($this->db->commit(), 'transaction');
|
|
|
412 |
$this->assertFalse($this->db->in_transaction, 'transaction');
|
|
|
413 |
}
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
// Nested transactions are not yet tested, due to a MySQL 5 problem with
|
|
|
417 |
// savepoints causing netsted transactions to fail.
|
|
|
418 |
//
|
|
|
419 |
// See http://bugs.mysql.com/bug.php?id=26288
|
|
|
420 |
|
|
|
421 |
/**
|
|
|
422 |
* Tests that the MDB2::setDatabase() and MDB2::getDatabase() methods
|
|
|
423 |
* correctly set and get the database name.
|
|
|
424 |
*/
|
|
|
425 |
function test_setGetDatabase()
|
|
|
426 |
{
|
|
|
427 |
$old_name = $this->db->database_name;
|
|
|
428 |
$this->assertEquals($old_name, $this->db->setDatabase('test_database'), 'setDatabase');
|
|
|
429 |
$this->assertEquals('test_database', $this->db->database_name, 'setDatabase');
|
|
|
430 |
$this->assertEquals('test_database', $this->db->getDatabase(), 'getDatabase');
|
|
|
431 |
$this->db->database_name = $old_name;
|
|
|
432 |
}
|
|
|
433 |
|
|
|
434 |
/**
|
|
|
435 |
* Tests that the MDB2::setDSN() method correctly sets
|
|
|
436 |
* the DSN.
|
|
|
437 |
*/
|
|
|
438 |
function test_setDSN()
|
|
|
439 |
{
|
|
|
440 |
$dsn = "mydbms://myname:mypassword@localhost";
|
|
|
441 |
$result = $this->db->setDSN($dsn);
|
|
|
442 |
$dsn_set = $this->db->dsn;
|
|
|
443 |
|
|
|
444 |
$this->assertEquals('mydbms', $dsn_set['phptype'],'setDSN');
|
|
|
445 |
$this->assertEquals('mydbms',$dsn_set['dbsyntax'],'setDSN');
|
|
|
446 |
$this->assertEquals('tcp',$dsn_set['protocol'],'setDSN');
|
|
|
447 |
$this->assertEquals('localhost',$dsn_set['hostspec'],'setDSN');
|
|
|
448 |
$this->assertEquals(false,$dsn_set['port'],'setDSN');
|
|
|
449 |
$this->assertEquals(false,$dsn_set['socket'],'setDSN');
|
|
|
450 |
$this->assertEquals('myname',$dsn_set['username'],'setDSN');
|
|
|
451 |
$this->assertEquals('mypassword',$dsn_set['password'],'setDSN');
|
|
|
452 |
$this->assertEquals(false,$dsn_set['database'],'setDSN');
|
|
|
453 |
}
|
|
|
454 |
|
|
|
455 |
/**
|
|
|
456 |
* Tests that the MDB2::getDSN() method correctly gets
|
|
|
457 |
* the DSN.
|
|
|
458 |
*/
|
|
|
459 |
function test_getDSN()
|
|
|
460 |
{
|
|
|
461 |
$dsn_set = "mydbms://myname:mypassword@localhost";
|
|
|
462 |
$result = $this->db->setDSN($dsn_set);
|
|
|
463 |
$dsn_get = $this->db->getDSN();
|
|
|
464 |
$dsn_rex = "/(([\w]+)\(mydbms\):\/\/myname:mypassword@localhost\/)/";
|
|
|
465 |
//preg_match($dsn_rex, $dsn_get, $matches);
|
|
|
466 |
$this->assertRegExp($dsn_rex, $dsn_get, 'testGetDSN');
|
|
|
467 |
$dsn_rex = "/{$this->dsn['phptype']}[\w\W]+/";
|
|
|
468 |
$this->assertRegExp($dsn_rex, $dsn_get, 'testGetDSN');
|
|
|
469 |
|
|
|
470 |
$dsn_set = "mydbms://myname:mypassword@localhost";
|
|
|
471 |
$result = $this->db->setDSN($dsn_set);
|
|
|
472 |
$dsn_get = $this->db->getDSN('string', true);
|
|
|
473 |
$dsn_rex = "/(([\w]+)\(mydbms\):\/\/myname:1@localhost\/)/";
|
|
|
474 |
$this->assertRegExp($dsn_rex, $dsn_get, 'testGetDSN');
|
|
|
475 |
$dsn_rex = "/{$this->dsn['phptype']}[\w\W]+/";
|
|
|
476 |
$this->assertRegExp($dsn_rex, $dsn_get, 'testGetDSN');
|
|
|
477 |
|
|
|
478 |
}
|
|
|
479 |
|
|
|
480 |
/**
|
|
|
481 |
* Tests that the MDB2::setLimit() method correctly sets the limit
|
|
|
482 |
* and offset values.
|
|
|
483 |
*/
|
|
|
484 |
function test_setLimit()
|
|
|
485 |
{
|
|
|
486 |
if (!$this->db->supports('limit_queries'))
|
|
|
487 |
{
|
|
|
488 |
$this->db->limit = null;
|
|
|
489 |
$this->db->offset = null;
|
|
|
490 |
$this->db->setLimit(100, 50);
|
|
|
491 |
$this->assertEquals(100, $this->db->limit , 'setLimit');
|
|
|
492 |
$this->assertEquals( 50, $this->db->offset, 'setLimit');
|
|
|
493 |
}
|
|
|
494 |
}
|
|
|
495 |
|
|
|
496 |
/**
|
|
|
497 |
* Tests that the MDB2::supports() method correctly finds keys
|
|
|
498 |
* in the "supports" array.
|
|
|
499 |
*/
|
|
|
500 |
function test_supports()
|
|
|
501 |
{
|
|
|
502 |
$this->db->supports['testkey'] = true;
|
|
|
503 |
$this->assertTrue($this->db->supports('testkey'), 'supports');
|
|
|
504 |
unset($this->db->supports['testkey']);
|
|
|
505 |
}
|
|
|
506 |
|
|
|
507 |
/**
|
|
|
508 |
* Tests that the MDB2::getSequenceName() method correctly gets
|
|
|
509 |
* sequence names.
|
|
|
510 |
*/
|
|
|
511 |
function test_getSequenceName()
|
|
|
512 |
{
|
|
|
513 |
$tmp = $this->db->options['seqname_format'];
|
|
|
514 |
$this->db->options['seqname_format'] = '%s_seq';
|
|
|
515 |
$this->assertEquals('test_seq', strtolower($this->db->getSequenceName('test')), 'getSequenceName');
|
|
|
516 |
$this->db->options['seqname_format'] = $tmp;
|
|
|
517 |
}
|
|
|
518 |
|
|
|
519 |
/**
|
|
|
520 |
* Tests that the MDB2::getIndexName() method correctly gets
|
|
|
521 |
* index names.
|
|
|
522 |
*/
|
|
|
523 |
function test_getIndexName()
|
|
|
524 |
{
|
|
|
525 |
$tmp = $this->db->options['idxname_format'];
|
|
|
526 |
$this->db->options['idxname_format'] = 'idx_%s';
|
|
|
527 |
$this->assertEquals('idx_test', $this->db->getIndexName('test'), 'getIndexName');
|
|
|
528 |
$this->db->options['idxname_format'] = $tmp;
|
|
|
529 |
}
|
|
|
530 |
|
|
|
531 |
/**
|
|
|
532 |
* Tests that the MDB2::disconnect() method correctly disconnects.
|
|
|
533 |
*/
|
|
|
534 |
function test_disconnect()
|
|
|
535 |
{
|
|
|
536 |
$this->assertTrue($this->db->disconnect(), 'disconnect');
|
|
|
537 |
$this->assertEquals(0, $this->db->connection, 'disconnect');
|
|
|
538 |
$this->assertEquals(array(), $this->db->connected_dsn, 'disconnect');
|
|
|
539 |
$this->assertEquals('', $this->db->connected_database_name, 'disconnect');
|
|
|
540 |
$this->assertNull($this->db->opened_persistent, 'disconnect');
|
|
|
541 |
$this->assertEquals('', $this->db->connected_server_info, 'disconnect');
|
|
|
542 |
$this->assertNull($this->db->in_transaction, 'disconnect');
|
|
|
543 |
$this->assertNull($this->db->nested_transaction_counter, 'disconnect');
|
|
|
544 |
}
|
|
|
545 |
|
|
|
546 |
}
|
|
|
547 |
|
|
|
548 |
?>
|