]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/unit/test.php
Add svn:keywords
[SourceForge/phpwiki.git] / tests / unit / test.php
1 <?php // #!/usr/local/bin/php -Cq
2 /* Copyright (C) 2004 Dan Frankowski <dfrankow@cs.umn.edu>
3  * Copyright (C) 2004,2005,2006 Reini Urban <rurban@x-ray.at>
4  * $Id$
5  *
6  * This file is part of PhpWiki.
7  * 
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with PhpWiki; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  * Unit tests for PhpWiki. 
25  *
26  * You must have PEAR's PHPUnit package <http://pear.php.net/package/PHPUnit>. 
27  * These tests are unrelated to test/maketest.pl, which do not use PHPUnit.
28  * These tests run from the command-line as well as from the browser.
29  * Use the argv (from cli) or tests (from browser) params to run only certain tests.
30  *
31  * $ tests.php test=<testname1> test=<testname2> ... db=dba debug=9 level=10
32  */
33 /****************************************************************
34    User definable options
35 *****************************************************************/
36 // common cfg options are taken from config/config.ini
37
38 //TODO: let the user decide which constants to use: define="x=y"
39 //define('USE_DB_SESSION', false);
40 //define('ENABLE_USER_NEW', false);
41
42 // memory usage: (8MB limit on certain servers)
43 // setupwiki
44 // cli:  Mem16712 => Mem16928
45 // web:  Mem21216 => Mem26332 (5MB)
46
47 // dumphtml:
48 // cli: Mem20696 => Mem31240  (with USECACHE)    (10MB)
49 // cli: Mem20240 => Mem30212  (without USECACHE) (10MB)
50 // web: Mem29424 => Mem35400  (without USECACHE) (6MB)
51 //define('USECACHE', false);
52
53 //##################################################################
54 //
55 // Preamble needed to get the tests to run.
56 //
57 //##################################################################
58
59 $cur_dir = getcwd();
60 // Add root dir to the path
61 if (substr(PHP_OS,0,3) == 'WIN')
62     $cur_dir = str_replace("\\","/", $cur_dir);
63 $rootdir = $cur_dir . '/../../';
64 $ini_sep = substr(PHP_OS,0,3) == 'WIN' ? ';' : ':';
65 $include_path = ini_get('include_path') . $ini_sep 
66               . $rootdir . $ini_sep . $rootdir . "lib/pear";
67 ini_set('include_path', $include_path);
68 define('DEFAULT_LANGUAGE','en'); // don't use browser detection
69 $LANG='en';
70 if (!isset($HTTP_SERVER_VARS)) {
71    $HTTP_SERVER_VARS =& $_SERVER;
72    $HTTP_GET_VARS    =& $_GET;
73    $HTTP_POST_VARS   =& $_POST;
74 }
75
76 if (!empty($HTTP_SERVER_VARS) and $HTTP_SERVER_VARS["SERVER_NAME"] == 'phpwiki.sourceforge.net') {
77     ini_set('include_path', ini_get('include_path') . ":/usr/share/pear");
78     //define('ENABLE_PAGEPERM',false); // costs nothing
79     define('USECACHE',false); // really?
80     //define('WIKIDB_NOCACHE_MARKUP',1);
81 }
82
83 // available database backends to test:
84 $database_backends = array(
85                            'file',
86                            'flatfile', // not yet committed
87                            'dba',
88                            'SQL',   // default backend defined in the config.ini DSN
89                            'ADODB', // same backend as defined in the config.ini DSN
90                            // specific backends (need to be setup as db=test_phpwiki)
91                            'PearDB_pgsql', 'PearDB_sqlite', 'PearDB_mysql',
92                            //'PearDB_oci8','PearDB_mssql', 
93                            'ADODB_postgres7', 'ADODB_sqlite', 'ADODB_mysql', 
94                            //'ADODB_oci8', 'ADODB_mssql', 
95                            // 'cvs'
96                            );
97 if ((int)substr(phpversion(), 1) >= 5)
98     array_push($database_backends, 'PDO_pqsql', 'PDO_sqlite', 'PDO_mysql');
99                                    //'PDO_oci', 'PDO_odbc'
100
101 //TODO: convert cvs test                           
102 // For "cvs" see the seperate tests/unit_test_backend_cvs.php (cvs is experimental)
103 //TODO: read some database values from config.ini, just use the "test_" prefix
104 // "flatfile" testing occurs in "tests/unit/.testbox/flatfile"
105 // "dba" needs the DATABASE_DBA_HANDLER, also in the .textbox directory
106 //$database_dba_handler = (substr(PHP_OS,0,3) == 'WIN') ? "db3" : "gdbm";
107 // "SQL" and "ADODB" need delete permissions to the test db
108 //  You have to create that database beforehand with our schema
109 //$database_dsn = "mysql://wikiuser:@localhost/phpwiki";
110 $database_prefix = "test_";
111
112 // Quiet warnings in IniConfig.php
113 $HTTP_SERVER_VARS['REMOTE_ADDR'] = '127.0.0.1';
114 $HTTP_SERVER_VARS['HTTP_USER_AGENT'] = "PHPUnit";
115
116 function printMemoryUsage($msg = '') {
117     static $mem = 0;
118     static $initmem = 0;
119     if ($msg) echo $msg,"\n";
120     if ((defined('DEBUG') and (DEBUG & 8)) or !defined('DEBUG')) {
121         require_once("lib/stdlib.php");
122         echo "-- MEMORY USAGE: ";
123         $oldmem = $mem;
124         $mem = getMemoryUsage();
125         if (!$initmem) $initmem = $mem;
126         // old libc on sf.net server doesn't understand "%+4d"
127         echo sprintf("%8d\t[%s%4d]\t[+%4d]\n", $mem, $mem > $oldmem ? "+" : ($mem == $oldmem ? " " : ""), 
128                      $mem - $oldmem, $mem - $initmem);
129         // TODO: print time
130         flush();
131     }
132 }
133 /* // now in stdlib.php
134 function printSimpleTrace($bt) {
135     //print_r($bt);
136     echo "Traceback:\n";
137     foreach ($bt as $i => $elem) {
138         if (!array_key_exists('file', $elem)) {
139             continue;
140         }
141         print "  " . $elem['file'] . ':' . $elem['line'] . "\n";
142     }
143 }
144 */
145 // Show lots of detail when an assert() in the code fails
146 function assert_callback( $script, $line, $message ) {
147    echo "assert failed: script ", $script," line ", $line," :";
148    echo "$message";
149    if (function_exists('debug_backtrace')) { // >= 4.3.0
150        echo "Traceback:\n";
151        printSimpleTrace(debug_backtrace());
152    }
153    exit;
154 }
155 $foo = assert_options( ASSERT_CALLBACK, 'assert_callback');
156
157 //
158 // Get error reporting to call back, too
159 //
160 // set the error reporting level for this script
161 if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
162     error_reporting(E_ALL & ~E_STRICT);         // exclude E_STRICT
163 else
164     error_reporting(E_ALL); // php4
165
166 // This is too strict, fails on every notice and warning. 
167 /*
168 function myErrorHandler$errno, $errstr, $errfile, $errline) {
169    echo "$errfile: $errline: error# $errno: $errstr\n";
170    echo "Traceback:\n";
171    printSimpleTrace(debug_backtrace());
172 }
173 // The ErrorManager version
174 function _ErrorHandler_CB(&$error) {
175    echo "Traceback:\n";
176    printSimpleTrace(debug_backtrace());
177    if ($error->isFatal()) {
178         $error->errno = E_USER_WARNING;
179         return true; // ignore error
180    }
181    return true;
182 }
183 // set to the user defined error handler
184 // $old_error_handler = set_error_handler("myErrorHandler");
185 // This is already done via _DEBUG_TRACE
186 //$ErrorManager->pushErrorHandler(new WikiFunctionCb('_ErrorHandler_CB'));
187 */
188
189 function purge_dir($dir) {
190     static $finder;
191     if (!isset($finder)) {
192         $finder = new FileFinder;
193     }
194     $fileSet = new fileSet($dir);
195     assert(!empty($dir));
196     foreach ($fileSet->getFiles() as $f) {
197         unlink("$dir/$f");
198     }
199 }
200
201 function purge_testbox() {
202     global $DBParams;   
203     if (isset($GLOBALS['request'])) {
204         $dbi = $GLOBALS['request']->getDbh();
205     }
206     $dir = $DBParams['directory'];
207     switch ($DBParams['dbtype']) {
208     case 'file':
209     case 'flatfile':
210         assert(!empty($dir));
211         foreach (array('latest_ver','links','page_data','ver_data') as $d) {
212             purge_dir("$dir/$d");
213         }
214         break;
215     case 'SQL':
216     case 'ADODB':
217     case 'PDO':
218         foreach (array_reverse($dbi->_backend->_table_names) as $table) {
219             $dbi->genericSqlQuery("DELETE FROM $table");
220         }
221         break;
222     case 'dba':
223         purge_dir($dir);
224         break;
225     }
226     if (isset($dbi)) {
227         $dbi->_cache->close();
228         $dbi->_backend->_latest_versions = array();
229     }
230 }
231
232 function printConstant($v) {
233     echo "$v=";
234     if (defined($v)) {
235         if (constant($v) or constant($v)===0 or constant($v)==='0') echo constant($v);
236         else echo "false";
237     } else echo "undefined";
238     echo "\n";
239 }
240 /**
241  * via the HTML sapi interface print a form to easily change the current cmdline settings.
242  */
243 function html_option_form() {
244     global $debug_level, $user_level, $start_debug;
245
246     $form = HTML();
247     $option = HTML::div(array('class' => 'option'), 
248                         HTML::span(array('title' => 'doubleclick to (un)select all', 'style'=>'font-weight: bold; padding: 1px; border: 2px outset;','onDblClick'=>'flipAll(\'test[\')'), 
249                                    ' test: '),
250                         HTML::br());
251     $i = 0;
252     foreach ($GLOBALS['alltests'] as $s) {
253         $id = preg_replace("/\W/", "", $s) . $i++;
254         $input = array('type' => 'checkbox', 'name' => 'test['.$s.']', 'value' => '1', 'id' => $id);
255         if (in_array($s,$GLOBALS['runtests'])) $input['checked'] = 'checked';
256         $option->pushContent(HTML::input($input), HTML::label(array('for' => $id), $s), HTML::br());
257     }
258     $form->pushContent(HTML::td($option));
259
260     $option = HTML::div(array('class' => 'option'), 
261                         HTML::span(array('title' => 'doubleclick to (un)select all', 'style'=>'font-weight: bold; padding: 1px; border: 2px outset;', 'onDblClick'=>'flipAll(\'db[\')'), 
262                                    ' db: '),
263                         HTML::br());
264     foreach ($GLOBALS['database_backends'] as $s) {
265         $id = preg_replace("/\W/", "", $s) . $i++;
266         $input = array('type' => 'checkbox', 'name' => 'db['.$s.']', 'value' => '1', 'id' => $id);
267         if (in_array($s,$GLOBALS['run_database_backends'])) $input['checked'] = 'checked';
268         $option->pushContent(HTML::input($input), HTML::label(array('for' => $id), $s), HTML::br());
269     }
270     $form->pushContent(HTML::td($option));
271
272     $js = JavaScript(
273 "function flipAll(formName) {
274   var isFirstSet = -1;
275   formObj = document.forms[0];
276   for (var i=0; i < formObj.length; i++) {
277       fldObj = formObj.elements[i];
278       if ((fldObj.type == 'checkbox') && (fldObj.name.substring(0,formName.length) == formName)) { 
279          if (isFirstSet == -1)
280            isFirstSet = (fldObj.checked) ? true : false;
281          fldObj.checked = (isFirstSet) ? false : true;
282        }
283    }
284 }
285 function updateDebugEdit(formObj) {
286   val=0;
287   for (var i=0; i < formObj.length; i++) {
288       fldObj = formObj.elements[i];
289       if ((fldObj.type == 'checkbox') && (fldObj.name.substring(0,7) == '_debug[')) { 
290          if (fldObj.checked) val = val + parseInt(fldObj.value);
291        }
292    }
293    formObj.debug.value = val;
294 }
295 function updateLevelEdit(formObj) {
296   for (var i=0; i < formObj.length; i++) {
297       fldObj = formObj.elements[i];
298       if ((fldObj.type == 'radio') && (fldObj.name.substring(0,7) == '_level[')) {
299          if (fldObj.checked) {
300             formObj.level.value = fldObj.value;
301             return;
302          }
303       }
304    }
305 }");
306     $option = HTML::div(array('class' => 'option'),
307                         HTML::span(array('title' => 'doubleclick to (un)select all', 'style'=>'font-weight: bold; padding: 1px; border: 2px outset;',
308                                          'onDblClick'=>'flipAll(\'_debug[\')'), 
309                                    ' debug: '),' ',
310                         HTML::input(array('name'=>'debug','id'=>'debug',
311                                           'value'=>$debug_level,'size'=>5)),
312                         HTML::br());
313     foreach (array('VERBOSE'    => 1,
314                    'PAGELINKS'  => 2,
315                    'PARSER'     => 4,
316                    'TRACE'      => 8,
317                    'INFO'       => 16,
318                    'APD'        => 32,
319                    'LOGIN'      => 64,
320                    'SQL'        => 128,
321                    'REMOTE'     => 256,
322                    ) as $s => $v) {
323         $id = preg_replace("/\W/", "", $s) . $i++;
324         $input = array('type' => 'checkbox', 'name' => '_debug[]', 'value' => $v, 'id' => $id,
325                        'onClick' => 'updateDebugEdit(this.form)');
326         if ($debug_level & $v) $input['checked'] = 'checked';
327         $option->pushContent(HTML::input($input), HTML::label(array('for' => $id), "_DEBUG_".$s), HTML::br());
328     }
329     $form->pushContent(HTML::td($option));
330
331     $option = HTML::div(array('class' => 'option'), 
332                         HTML::span(array('style'=>'font-weight: bold;'), "level: "),
333                         HTML::input(array('name'=>'level','id'=>'level',
334                                           'value'=>$user_level,'size'=>5)),
335                         HTML::br());
336     foreach (array('FORBIDDEN'  => -1,
337                    'ANON'       => 0,
338                    'BOGO'       => 1,
339                    'USER'       => 2,
340                    'ADMIN'      => 10,
341                    'UNOBTAINABLE'=> 100,
342                    ) as $s => $v) {
343         $id = preg_replace("/\W/", "", $s) . $i++;
344         $input = array('type' => 'radio', 'name' => '_level[]', 'value' => $v, 'id' => $id,
345                        'onClick' => 'updateLevelEdit(this.form)');
346         if ($user_level & $v) $input['checked'] = 'checked';
347         $option->pushContent(HTML::input($input), HTML::label(array('for' => $id), "WIKIAUTH_".$s), HTML::br());
348     }
349     $form->pushContent(HTML::td($option));
350
351     unset($input);
352     $option = HTML::div(array('class' => 'option'), 'defines: ', HTML::br());
353     if (!empty($GLOBALS['define']))
354       foreach ($GLOBALS['define'] as $s) {
355         if (defined($s)) {
356             $input = array('type' => 'edit', 'name' => $s, 'value' => constant($s));
357             $option->pushContent(HTML::input($input), HTML::label(array('for' => $id), $s), HTML::br());
358         }
359     }
360     if (!empty($input))
361         $form->pushContent(HTML::td($option));
362     $table = HTML::form(array('action' => $_SERVER['PHP_SELF'],
363                                           'method' => 'GET',
364                               'accept-charset' => $GLOBALS['charset']),
365                         $js,
366                         HTML::table(HTML::tr(array('valign'=>'top'), $form)),
367                         HTML::input(array('type' => 'submit')),
368                         HTML::input(array('type' => 'reset')));
369     if ($start_debug)
370         $table->pushContent(HiddenInputs(array('start_debug' => $start_debug)));
371     return $table->printXml();
372 }
373
374 //####################################################################
375 //
376 // End of preamble, run the test suite ..
377 //
378 //####################################################################
379
380 ob_start();
381
382 if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']))
383     echo "<pre>\n";
384 elseif (!empty($HTTP_SERVER_VARS['argv']))
385     $argv = $HTTP_SERVER_VARS['argv'];
386 elseif (!ini_get("register_argc_argv"))
387     echo "Could not read cmd args (register_argc_argv=Off?)\n";
388 // purge the testbox
389     
390 $debug_level = 1; //was 9, _DEBUG_VERBOSE | _DEBUG_TRACE
391 //if (defined('E_STRICT')) $debug_level = 5; // add PARSER flag on php5
392 $user_level  = 1; // BOGO (conflicts with RateIt)
393 // use argv (from cli) or tests (from browser) params to run only certain tests
394 // avoid pear: Console::Getopt
395 $alltests = array(/* valid tests without clean virgin setup */
396                   'InlineParserTest','HtmlParserTest',
397                   'PageListTest','ListPagesTest','XmlRpcTest',
398                   /* virgin setup */
399                   'SetupWiki',
400                   /* valid tests only with clean virgin setup */
401                   'AllPagesTest','AllUsersTest','OrphanedPagesTest',
402                   'WantedPagesTest','TextSearchTest','IncludePageTest',
403                   /* final tests which require all valid pages and consumes > 32MB */
404                   'DumpHtml');
405 // support db=file db=dba test=SetupWiki test=DumpHtml debug=num -dconstant=value
406 // or  db=file,dba test=SetupWiki,DumpHtml debug=num -dconstant=value
407 if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
408     $argv = array();
409     foreach ($HTTP_GET_VARS as $key => $val) {
410         if (is_array($val))
411             foreach ($val as $k => $v) $argv[] = $key."=".$k;
412         elseif (strstr($val,",") and in_array($key, array("test","db")))
413             foreach (explode(",",$val) as $v) $argv[] = $key."=".$v;
414         else
415             $argv[] = $key."=".$val;
416     }
417 } elseif (!empty($argv) and preg_match("/test\.php$/", $argv[0])) {
418     array_shift($argv);
419 }    
420 if (!empty($argv)) {
421     $runtests = array();
422     $define = array();
423     $run_database_backends = array();
424     $m = array();
425     foreach ($argv as $arg) {
426         if (preg_match("/^test=(.+)$/",$arg,$m) and in_array($m[1], $alltests))
427             $runtests[] = $m[1];
428         elseif (preg_match("/^db=(.+)$/",$arg,$m) and in_array($m[1], $database_backends))
429             $run_database_backends[] = $m[1];
430         elseif (preg_match("/^debug=(\d+)$/",$arg,$m))
431             $debug_level = $m[1];
432         elseif (preg_match("/^level=(\d+)$/",$arg,$m))
433             $user_level = $m[1];
434         elseif (preg_match("/^\-d(\w+)=(.+)$/",$arg,$m)) {
435             $define[$m[1]] = $m[2];
436             if ($m[2] == 'true') $m[2] = true;
437             elseif ($m[2] == 'false') $m[2] = false;
438             if (!defined($m[1])) define($m[1], $m[2]);
439         } elseif (in_array($arg, $alltests))
440             $runtests[] = $arg;
441         elseif ($debug_level & 1)
442             echo "ignored arg: ", $arg, "\n";
443     }
444 }
445
446 if (empty($run_database_backends))
447     $run_database_backends = $database_backends;
448 if (empty($runtests))
449     $runtests = $alltests;
450 if ($debug_level & 1) {
451     //echo "\n";
452     echo "PHP_SAPI=",php_sapi_name(), "\n";
453     echo "PHP_OS=",PHP_OS, "\n";
454     echo "PHP_VERSION=",PHP_VERSION, "\n";
455     echo "test=", join(",",$runtests),"\n";
456     echo "db=", join(",",$run_database_backends),"\n";
457     echo "debug=", $debug_level,"\n";
458     echo "level=", $user_level,"\n";
459     if (!empty($define)) {
460         foreach ($define as $k => $v) printConstant($k);
461     }
462     if ($debug_level & 8) {
463         echo "pid=",getmypid(),"\n";
464     }
465     echo "\n";
466 }
467 flush();
468
469 if (!defined('DEBUG'))
470     define('DEBUG', $debug_level);
471 // override defaults:
472 if (!defined('RATING_STORAGE')) 
473    define('RATING_STORAGE', 'WIKIPAGE');
474 if (!defined('GROUP_METHOD'))
475     define('GROUP_METHOD', 'NONE');
476
477 if (DEBUG & 8)
478     printMemoryUsage("beforePEAR");
479
480 if (DEBUG & 8)
481     printMemoryUsage("beforePhpWiki");
482
483 define('PHPWIKI_NOMAIN', true);
484 // Other needed files
485 require_once $rootdir.'index.php';
486 require_once $rootdir.'lib/main.php';
487
488 // init filefinder for pear path fixup.
489 FindFile ('PHPUnit.php', 'missing_okay');
490 // PEAR library (requires version ??)
491 require_once 'PHPUnit.php';
492
493 ob_end_flush();
494
495 if ($debug_level & 1) {
496     //echo "\n";
497     echo "PHPWIKI_VERSION=",PHPWIKI_VERSION, 
498         strstr(PHPWIKI_VERSION,"pre") ? strftime(" / %Y%m%d") : "","\n";
499     if ($debug_level & 9) {
500         // which constants affect memory?
501         foreach (explode(",","USECACHE,WIKIDB_NOCACHE_MARKUP,"
502                             ."ENABLE_USER_NEW,ENABLE_PAGEPERM") as $v) {
503             printConstant($v);
504         }
505     }
506     echo "\n";
507 }
508
509 global $ErrorManager;
510 $ErrorManager->setPostponedErrorMask(EM_FATAL_ERRORS|EM_WARNING_ERRORS|EM_NOTICE_ERRORS);
511 // FIXME: ignore cached requests (if-modified-since) from cli
512 class MockRequest extends WikiRequest {
513     function MockRequest($dbparams) {
514         $this->_dbi = WikiDB::open($dbparams);
515         $this->_user = new MockUser("a_user", $GLOBALS['user_level']);
516         $this->_group = new GroupNone();
517         $this->_args = array('pagename' => 'HomePage', 'action' => 'browse');
518         $this->Request();
519     }
520     function getGroup() {
521         if (is_object($this->_group))
522             return $this->_group;
523         else // FIXME: this is set to "/f:" somewhere.
524             return new GroupNone();
525     }
526 }
527
528 if (ENABLE_USER_NEW) {
529     class MockUser extends _WikiUser {
530         function MockUser($name, $level) {
531             $this->_userid = $name;
532             $this->_isSignedIn = $level > 1;
533             $this->_level = $level;
534         }
535         function isSignedIn() {
536             return $this->_isSignedIn;
537         }
538     }
539 } else {
540     class MockUser extends WikiUser {
541         function MockUser($name, $level) {
542             $this->_userid = $name;
543             $this->_isSignedIn = $level > 1;
544             $this->_level = $level;
545         }
546         function isSignedIn() {
547             return $this->_isSignedIn;
548         }
549     }
550 }
551
552 /*
553 if (ENABLE_USER_NEW)
554     $request->_user = WikiUser('AnonUser');
555 else {
556     $request->_user = new WikiUser($request, 'AnonUser');
557     $request->_prefs = $request->_user->getPreferences();
558 }
559 */
560 if (DEBUG & _DEBUG_TRACE)
561     printMemoryUsage("PhpWikiLoaded");
562
563 // provide a nice input form for all options
564 if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
565     echo html_option_form();
566     flush();
567 }
568
569 // save and restore all args for each test.
570 class phpwiki_TestCase extends PHPUnit_TestCase {
571     function setUp() { 
572         global $request, $WikiTheme;
573         include_once("themes/" . THEME . "/themeinfo.php");
574         $this->_savedargs = $request->_args;
575         $request->_args = array();
576         if (DEBUG & 1) {
577             echo $this->_name,"\n";
578             flush();
579         }
580     }
581     function tearDown() {
582         global $request;
583         $request->_args = $this->_savedargs;
584         if (DEBUG & _DEBUG_TRACE)
585             printMemoryUsage();
586     }
587 }
588
589 // Test all db backends.
590 foreach ($run_database_backends as $dbtype) {
591     global $request, $DBParams;
592     //    if (DEBUG & _DEBUG_TRACE)
593     //        printMemoryUsage("PHPUnitInitialized");
594     $DBParams['dbtype'] = $dbtype;
595     if (string_starts_with($dbtype, 'PearDB_')) {
596         $DBParams['dbtype'] = 'SQL';
597         $DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 7).":", $DBParams['dsn']);
598         echo "dsn: ",$DBParams['dsn'],"\n";
599     }
600     if (string_starts_with($dbtype, 'ADODB_')) {
601         $DBParams['dbtype'] = 'ADODB';
602         $DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 6).":", $DBParams['dsn']);
603         echo "dsn: ",$DBParams['dsn'],"\n";
604     }
605     if (string_starts_with($dbtype, 'PDO_')) {
606         $DBParams['dbtype'] = 'PDO';
607         $DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 4).":", $DBParams['dsn']);
608         echo "dsn: ",$DBParams['dsn'],"\n";
609     }
610     // sqlite fix: 
611     if (preg_match('/sqlite$/', $dbtype)) {
612         $DBParams['dsn'] = preg_replace("/127\.0\.0\.1/", '', $DBParams['dsn']);
613         echo "dsn: ",$DBParams['dsn'],"\n";
614     }
615     $DBParams['directory']            = $cur_dir . '/.testbox';
616     if ($dbtype == 'flatfile')
617         $DBParams['directory']        = $cur_dir . '/.testbox/flatfile';
618     $DBParams['prefix']               = $database_prefix;
619     // from config.ini
620     //$DBParams['dba_handler']          = $database_dba_handler;
621
622     echo "Testing DB Backend \"$dbtype\" ...\n";
623     flush();
624     $request = new MockRequest($DBParams);
625     if ( ! ENABLE_USER_NEW ) {
626         $request->_user->_request =& $request;
627         $request->_user->_dbi =& $request->_dbi;
628     }
629     if (DEBUG & _DEBUG_TRACE)
630         printMemoryUsage("PhpWikiInitialized");
631
632     foreach ($runtests as $test) {
633         if (!@ob_get_level()) ob_start();
634         $suite  = new PHPUnit_TestSuite("phpwiki");
635         if (file_exists(dirname(__FILE__).'/lib/'.$test.'.php'))
636             require_once dirname(__FILE__).'/lib/'.$test.'.php';
637         else    
638             require_once dirname(__FILE__).'/lib/plugin/'.$test.'.php';
639         $suite->addTest( new PHPUnit_TestSuite($test) );
640
641         @set_time_limit(240); 
642         $result = PHPUnit::run($suite); 
643         echo "ran " . $result->runCount() . " tests, " . $result->failureCount() . " failures.\n";
644         ob_end_flush();
645         if ($result->failureCount() > 0) {
646             echo "More detail:\n";
647             echo $result->toString();
648         }
649     }
650
651     $request->chunkOutput();
652     $request->_dbi->close();
653     unset($request->_user);
654     unset($request->_dbi);
655     unset($request);
656     unset($suite);
657     unset($result);
658 }
659
660 if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']))
661     echo "</pre>\n";
662
663 // (c-file-style: "gnu")
664 // Local Variables:
665 // mode: php
666 // tab-width: 8
667 // c-basic-offset: 4
668 // c-hanging-comment-ender-p: nil
669 // indent-tabs-mode: nil
670 // End:   
671 ?>