]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/unit/test.php
include [all] Include and file path should be devided with single space. File path...
[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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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    echo "Traceback:\n";
150    printSimpleTrace(debug_backtrace());
151    exit;
152 }
153 $foo = assert_options( ASSERT_CALLBACK, 'assert_callback');
154
155 //
156 // Get error reporting to call back, too
157 //
158 // set the error reporting level for this script
159 if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
160     error_reporting(E_ALL & ~E_STRICT);         // exclude E_STRICT
161 else
162     error_reporting(E_ALL); // php4
163
164 // This is too strict, fails on every notice and warning.
165 /*
166 function myErrorHandler$errno, $errstr, $errfile, $errline) {
167    echo "$errfile: $errline: error# $errno: $errstr\n";
168    echo "Traceback:\n";
169    printSimpleTrace(debug_backtrace());
170 }
171 // The ErrorManager version
172 function _ErrorHandler_CB(&$error) {
173    echo "Traceback:\n";
174    printSimpleTrace(debug_backtrace());
175    if ($error->isFatal()) {
176         $error->errno = E_USER_WARNING;
177         return true; // ignore error
178    }
179    return true;
180 }
181 // set to the user defined error handler
182 // $old_error_handler = set_error_handler("myErrorHandler");
183 // This is already done via _DEBUG_TRACE
184 //$ErrorManager->pushErrorHandler(new WikiFunctionCb('_ErrorHandler_CB'));
185 */
186
187 function purge_dir($dir) {
188     static $finder;
189     if (!isset($finder)) {
190         $finder = new FileFinder;
191     }
192     $fileSet = new fileSet($dir);
193     assert(!empty($dir));
194     foreach ($fileSet->getFiles() as $f) {
195         unlink("$dir/$f");
196     }
197 }
198
199 function purge_testbox() {
200     global $DBParams;
201     if (isset($GLOBALS['request'])) {
202         $dbi = $GLOBALS['request']->getDbh();
203     }
204     $dir = $DBParams['directory'];
205     switch ($DBParams['dbtype']) {
206     case 'file':
207     case 'flatfile':
208         assert(!empty($dir));
209         foreach (array('latest_ver','links','page_data','ver_data') as $d) {
210             purge_dir("$dir/$d");
211         }
212         break;
213     case 'SQL':
214     case 'ADODB':
215     case 'PDO':
216         foreach (array_reverse($dbi->_backend->_table_names) as $table) {
217             $dbi->genericSqlQuery("DELETE FROM $table");
218         }
219         break;
220     case 'dba':
221         purge_dir($dir);
222         break;
223     }
224     if (isset($dbi)) {
225         $dbi->_cache->close();
226         $dbi->_backend->_latest_versions = array();
227     }
228 }
229
230 function printConstant($v) {
231     echo "$v=";
232     if (defined($v)) {
233         if (constant($v) or constant($v)===0 or constant($v)==='0') echo constant($v);
234         else echo "false";
235     } else echo "undefined";
236     echo "\n";
237 }
238 /**
239  * via the HTML sapi interface print a form to easily change the current cmdline settings.
240  */
241 function html_option_form() {
242     global $debug_level, $user_level, $start_debug;
243
244     $form = HTML();
245     $option = HTML::div(array('class' => 'option'),
246                         HTML::span(array('title' => 'doubleclick to (un)select all', 'style'=>'font-weight: bold; padding: 1px; border: 2px outset;','onDblClick'=>'flipAll(\'test[\')'),
247                                    ' test: '),
248                         HTML::br());
249     $i = 0;
250     foreach ($GLOBALS['alltests'] as $s) {
251         $id = preg_replace("/\W/", "", $s) . $i++;
252         $input = array('type' => 'checkbox', 'name' => 'test['.$s.']', 'value' => '1', 'id' => $id);
253         if (in_array($s,$GLOBALS['runtests'])) $input['checked'] = 'checked';
254         $option->pushContent(HTML::input($input), HTML::label(array('for' => $id), $s), HTML::br());
255     }
256     $form->pushContent(HTML::td($option));
257
258     $option = HTML::div(array('class' => 'option'),
259                         HTML::span(array('title' => 'doubleclick to (un)select all', 'style'=>'font-weight: bold; padding: 1px; border: 2px outset;', 'onDblClick'=>'flipAll(\'db[\')'),
260                                    ' db: '),
261                         HTML::br());
262     foreach ($GLOBALS['database_backends'] as $s) {
263         $id = preg_replace("/\W/", "", $s) . $i++;
264         $input = array('type' => 'checkbox', 'name' => 'db['.$s.']', 'value' => '1', 'id' => $id);
265         if (in_array($s,$GLOBALS['run_database_backends'])) $input['checked'] = 'checked';
266         $option->pushContent(HTML::input($input), HTML::label(array('for' => $id), $s), HTML::br());
267     }
268     $form->pushContent(HTML::td($option));
269
270     $js = JavaScript(
271 "function flipAll(formName) {
272   var isFirstSet = -1;
273   formObj = document.forms[0];
274   for (var i=0; i < formObj.length; i++) {
275       fldObj = formObj.elements[i];
276       if ((fldObj.type == 'checkbox') && (fldObj.name.substring(0,formName.length) == formName)) {
277          if (isFirstSet == -1)
278            isFirstSet = (fldObj.checked) ? true : false;
279          fldObj.checked = (isFirstSet) ? false : true;
280        }
281    }
282 }
283 function updateDebugEdit(formObj) {
284   val=0;
285   for (var i=0; i < formObj.length; i++) {
286       fldObj = formObj.elements[i];
287       if ((fldObj.type == 'checkbox') && (fldObj.name.substring(0,7) == '_debug[')) {
288          if (fldObj.checked) val = val + parseInt(fldObj.value);
289        }
290    }
291    formObj.debug.value = val;
292 }
293 function updateLevelEdit(formObj) {
294   for (var i=0; i < formObj.length; i++) {
295       fldObj = formObj.elements[i];
296       if ((fldObj.type == 'radio') && (fldObj.name.substring(0,7) == '_level[')) {
297          if (fldObj.checked) {
298             formObj.level.value = fldObj.value;
299             return;
300          }
301       }
302    }
303 }");
304     $option = HTML::div(array('class' => 'option'),
305                         HTML::span(array('title' => 'doubleclick to (un)select all', 'style'=>'font-weight: bold; padding: 1px; border: 2px outset;',
306                                          'onDblClick'=>'flipAll(\'_debug[\')'),
307                                    ' debug: '),' ',
308                         HTML::input(array('name'=>'debug','id'=>'debug',
309                                           'value'=>$debug_level,'size'=>5)),
310                         HTML::br());
311     foreach (array('VERBOSE'    => 1,
312                    'PAGELINKS'  => 2,
313                    'PARSER'     => 4,
314                    'TRACE'      => 8,
315                    'INFO'       => 16,
316                    'APD'        => 32,
317                    'LOGIN'      => 64,
318                    'SQL'        => 128,
319                    'REMOTE'     => 256,
320                    ) as $s => $v) {
321         $id = preg_replace("/\W/", "", $s) . $i++;
322         $input = array('type' => 'checkbox', 'name' => '_debug[]', 'value' => $v, 'id' => $id,
323                        'onClick' => 'updateDebugEdit(this.form)');
324         if ($debug_level & $v) $input['checked'] = 'checked';
325         $option->pushContent(HTML::input($input), HTML::label(array('for' => $id), "_DEBUG_".$s), HTML::br());
326     }
327     $form->pushContent(HTML::td($option));
328
329     $option = HTML::div(array('class' => 'option'),
330                         HTML::span(array('style'=>'font-weight: bold;'), "level: "),
331                         HTML::input(array('name'=>'level','id'=>'level',
332                                           'value'=>$user_level,'size'=>5)),
333                         HTML::br());
334     foreach (array('FORBIDDEN'  => -1,
335                    'ANON'       => 0,
336                    'BOGO'       => 1,
337                    'USER'       => 2,
338                    'ADMIN'      => 10,
339                    'UNOBTAINABLE'=> 100,
340                    ) as $s => $v) {
341         $id = preg_replace("/\W/", "", $s) . $i++;
342         $input = array('type' => 'radio', 'name' => '_level[]', 'value' => $v, 'id' => $id,
343                        'onClick' => 'updateLevelEdit(this.form)');
344         if ($user_level & $v) $input['checked'] = 'checked';
345         $option->pushContent(HTML::input($input), HTML::label(array('for' => $id), "WIKIAUTH_".$s), HTML::br());
346     }
347     $form->pushContent(HTML::td($option));
348
349     unset($input);
350     $option = HTML::div(array('class' => 'option'), 'defines: ', HTML::br());
351     if (!empty($GLOBALS['define']))
352       foreach ($GLOBALS['define'] as $s) {
353         if (defined($s)) {
354             $input = array('type' => 'edit', 'name' => $s, 'value' => constant($s));
355             $option->pushContent(HTML::input($input), HTML::label(array('for' => $id), $s), HTML::br());
356         }
357     }
358     if (!empty($input))
359         $form->pushContent(HTML::td($option));
360     $table = HTML::form(array('action' => $_SERVER['PHP_SELF'],
361                                           'method' => 'GET',
362                               'accept-charset' => $GLOBALS['charset']),
363                         $js,
364                         HTML::table(HTML::tr(array('valign'=>'top'), $form)),
365                         HTML::input(array('type' => 'submit')),
366                         HTML::input(array('type' => 'reset')));
367     if ($start_debug)
368         $table->pushContent(HiddenInputs(array('start_debug' => $start_debug)));
369     return $table->printXml();
370 }
371
372 //####################################################################
373 //
374 // End of preamble, run the test suite ..
375 //
376 //####################################################################
377
378 ob_start();
379
380 if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']))
381     echo "<pre>\n";
382 elseif (!empty($HTTP_SERVER_VARS['argv']))
383     $argv = $HTTP_SERVER_VARS['argv'];
384 elseif (!ini_get("register_argc_argv"))
385     echo "Could not read cmd args (register_argc_argv=Off?)\n";
386 // purge the testbox
387
388 $debug_level = 1; //was 9, _DEBUG_VERBOSE | _DEBUG_TRACE
389 //if (defined('E_STRICT')) $debug_level = 5; // add PARSER flag on php5
390 $user_level  = 1; // BOGO (conflicts with RateIt)
391 // use argv (from cli) or tests (from browser) params to run only certain tests
392 // avoid pear: Console::Getopt
393 $alltests = array(/* valid tests without clean virgin setup */
394                   'InlineParserTest','HtmlParserTest',
395                   'PageListTest','ListPagesTest','XmlRpcTest',
396                   /* virgin setup */
397                   'SetupWiki',
398                   /* valid tests only with clean virgin setup */
399                   'AllPagesTest','AllUsersTest','OrphanedPagesTest',
400                   'WantedPagesTest','TextSearchTest','IncludePageTest',
401                   'AtomParserTest','AtomFeedTest',
402                   /* final tests which require all valid pages and consumes > 32MB */
403                   'DumpHtml');
404 // support db=file db=dba test=SetupWiki test=DumpHtml debug=num -dconstant=value
405 // or  db=file,dba test=SetupWiki,DumpHtml debug=num -dconstant=value
406 if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
407     $argv = array();
408     foreach ($HTTP_GET_VARS as $key => $val) {
409         if (is_array($val))
410             foreach ($val as $k => $v) $argv[] = $key."=".$k;
411         elseif (strstr($val,",") and in_array($key, array("test","db")))
412             foreach (explode(",",$val) as $v) $argv[] = $key."=".$v;
413         else
414             $argv[] = $key."=".$val;
415     }
416 } elseif (!empty($argv) and preg_match("/test\.php$/", $argv[0])) {
417     array_shift($argv);
418 }
419 if (!empty($argv)) {
420     $runtests = array();
421     $define = array();
422     $run_database_backends = array();
423     $m = array();
424     foreach ($argv as $arg) {
425         if (preg_match("/^test=(.+)$/",$arg,$m) and in_array($m[1], $alltests))
426             $runtests[] = $m[1];
427         elseif (preg_match("/^db=(.+)$/",$arg,$m) and in_array($m[1], $database_backends))
428             $run_database_backends[] = $m[1];
429         elseif (preg_match("/^debug=(\d+)$/",$arg,$m))
430             $debug_level = $m[1];
431         elseif (preg_match("/^level=(\d+)$/",$arg,$m))
432             $user_level = $m[1];
433         elseif (preg_match("/^\-d(\w+)=(.+)$/",$arg,$m)) {
434             $define[$m[1]] = $m[2];
435             if ($m[2] == 'true') $m[2] = true;
436             elseif ($m[2] == 'false') $m[2] = false;
437             if (!defined($m[1])) define($m[1], $m[2]);
438         } elseif (in_array($arg, $alltests))
439             $runtests[] = $arg;
440         elseif ($debug_level & 1)
441             echo "ignored arg: ", $arg, "\n";
442     }
443 }
444
445 if (empty($run_database_backends))
446     $run_database_backends = $database_backends;
447 if (empty($runtests))
448     $runtests = $alltests;
449 if ($debug_level & 1) {
450     //echo "\n";
451     echo "PHP_SAPI=",php_sapi_name(), "\n";
452     echo "PHP_OS=",PHP_OS, "\n";
453     echo "PHP_VERSION=",PHP_VERSION, "\n";
454     echo "test=", join(",",$runtests),"\n";
455     echo "db=", join(",",$run_database_backends),"\n";
456     echo "debug=", $debug_level,"\n";
457     echo "level=", $user_level,"\n";
458     if (!empty($define)) {
459         foreach ($define as $k => $v) printConstant($k);
460     }
461     if ($debug_level & 8) {
462         echo "pid=",getmypid(),"\n";
463     }
464     echo "\n";
465 }
466 flush();
467
468 if (!defined('DEBUG'))
469     define('DEBUG', $debug_level);
470 // override defaults:
471 if (!defined('RATING_STORAGE'))
472    define('RATING_STORAGE', 'WIKIPAGE');
473 if (!defined('GROUP_METHOD'))
474     define('GROUP_METHOD', 'NONE');
475
476 if (DEBUG & 8)
477     printMemoryUsage("beforePEAR");
478
479 if (DEBUG & 8)
480     printMemoryUsage("beforePhpWiki");
481
482 define('PHPWIKI_NOMAIN', true);
483 // Other needed files
484 require_once $rootdir.'index.php';
485 require_once $rootdir.'lib/main.php';
486
487 // init filefinder for pear path fixup.
488 FindFile ('PHPUnit.php', 'missing_okay');
489 // PEAR library (requires version ??)
490 require_once 'PHPUnit.php';
491
492 ob_end_flush();
493
494 if ($debug_level & 1) {
495     //echo "\n";
496     echo "PHPWIKI_VERSION=",PHPWIKI_VERSION,
497         strstr(PHPWIKI_VERSION,"pre") ? strftime(" / %Y%m%d") : "","\n";
498     if ($debug_level & 9) {
499         // which constants affect memory?
500         foreach (explode(",","USECACHE,WIKIDB_NOCACHE_MARKUP,"
501                             ."ENABLE_USER_NEW,ENABLE_PAGEPERM") as $v) {
502             printConstant($v);
503         }
504     }
505     echo "\n";
506 }
507
508 global $ErrorManager;
509 $ErrorManager->setPostponedErrorMask(EM_FATAL_ERRORS|EM_WARNING_ERRORS|EM_NOTICE_ERRORS);
510 // FIXME: ignore cached requests (if-modified-since) from cli
511 class MockRequest extends WikiRequest {
512     function MockRequest($dbparams) {
513         $this->_dbi = WikiDB::open($dbparams);
514         $this->_user = new MockUser("a_user", $GLOBALS['user_level']);
515         $this->_group = new GroupNone();
516         $this->_args = array('pagename' => 'HomePage', 'action' => 'browse');
517         $this->Request();
518     }
519     function getGroup() {
520         if (is_object($this->_group))
521             return $this->_group;
522         else // FIXME: this is set to "/f:" somewhere.
523             return new GroupNone();
524     }
525 }
526
527 if (ENABLE_USER_NEW) {
528     class MockUser extends _WikiUser {
529         function MockUser($name, $level) {
530             $this->_userid = $name;
531             $this->_isSignedIn = $level > 1;
532             $this->_level = $level;
533         }
534         function isSignedIn() {
535             return $this->_isSignedIn;
536         }
537     }
538 } else {
539     class MockUser extends WikiUser {
540         function MockUser($name, $level) {
541             $this->_userid = $name;
542             $this->_isSignedIn = $level > 1;
543             $this->_level = $level;
544         }
545         function isSignedIn() {
546             return $this->_isSignedIn;
547         }
548     }
549 }
550
551 /*
552 if (ENABLE_USER_NEW)
553     $request->_user = WikiUser('AnonUser');
554 else {
555     $request->_user = new WikiUser($request, 'AnonUser');
556     $request->_prefs = $request->_user->getPreferences();
557 }
558 */
559 if (DEBUG & _DEBUG_TRACE)
560     printMemoryUsage("PhpWikiLoaded");
561
562 // provide a nice input form for all options
563 if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
564     echo html_option_form();
565     flush();
566 }
567
568 // save and restore all args for each test.
569 class phpwiki_TestCase extends PHPUnit_TestCase {
570     function setUp() {
571         global $request, $WikiTheme;
572     include_once 'themes/'. THEME . "/themeinfo.php";
573         $this->_savedargs = $request->_args;
574         $request->_args = array();
575         if (DEBUG & 1) {
576             echo $this->_name,"\n";
577             flush();
578         }
579     }
580     function tearDown() {
581         global $request;
582         $request->_args = $this->_savedargs;
583         if (DEBUG & _DEBUG_TRACE)
584             printMemoryUsage();
585     }
586 }
587
588 // Test all db backends.
589 foreach ($run_database_backends as $dbtype) {
590     global $request, $DBParams;
591     //    if (DEBUG & _DEBUG_TRACE)
592     //        printMemoryUsage("PHPUnitInitialized");
593     $DBParams['dbtype'] = $dbtype;
594     if (string_starts_with($dbtype, 'PearDB_')) {
595     $DBParams['dbtype'] = 'SQL';
596     $DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 7).":", $DBParams['dsn']);
597         echo "dsn: ",$DBParams['dsn'],"\n";
598     }
599     if (string_starts_with($dbtype, 'ADODB_')) {
600     $DBParams['dbtype'] = 'ADODB';
601     $DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 6).":", $DBParams['dsn']);
602         echo "dsn: ",$DBParams['dsn'],"\n";
603     }
604     if (string_starts_with($dbtype, 'PDO_')) {
605     $DBParams['dbtype'] = 'PDO';
606     $DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 4).":", $DBParams['dsn']);
607         echo "dsn: ",$DBParams['dsn'],"\n";
608     }
609     // sqlite fix:
610     if (preg_match('/sqlite$/', $dbtype)) {
611     $DBParams['dsn'] = preg_replace("/127\.0\.0\.1/", '', $DBParams['dsn']);
612         echo "dsn: ",$DBParams['dsn'],"\n";
613     }
614     $DBParams['directory']            = $cur_dir . '/.testbox';
615     if ($dbtype == 'flatfile')
616         $DBParams['directory']        = $cur_dir . '/.testbox/flatfile';
617     $DBParams['prefix']               = $database_prefix;
618     // from config.ini
619     //$DBParams['dba_handler']          = $database_dba_handler;
620
621     echo "Testing DB Backend \"$dbtype\" ...\n";
622     flush();
623     $request = new MockRequest($DBParams);
624     if ( ! ENABLE_USER_NEW ) {
625         $request->_user->_request =& $request;
626         $request->_user->_dbi =& $request->_dbi;
627     }
628     if (DEBUG & _DEBUG_TRACE)
629         printMemoryUsage("PhpWikiInitialized");
630
631     foreach ($runtests as $test) {
632         if (!@ob_get_level()) ob_start();
633         $suite  = new PHPUnit_TestSuite("phpwiki");
634         if (file_exists(dirname(__FILE__).'/lib/'.$test.'.php'))
635             require_once dirname(__FILE__).'/lib/'.$test.'.php';
636         else
637             require_once dirname(__FILE__).'/lib/plugin/'.$test.'.php';
638         $suite->addTest( new PHPUnit_TestSuite($test) );
639
640         @set_time_limit(240);
641         $result = PHPUnit::run($suite);
642         echo "ran " . $result->runCount() . " tests, " . $result->failureCount() . " failures.\n";
643         ob_end_flush();
644         if ($result->failureCount() > 0) {
645             echo "More detail:\n";
646             echo $result->toString();
647         }
648     }
649
650     $request->chunkOutput();
651     $request->_dbi->close();
652     unset($request->_user);
653     unset($request->_dbi);
654     unset($request);
655     unset($suite);
656     unset($result);
657 }
658
659 if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']))
660     echo "</pre>\n";
661
662 // Local Variables:
663 // mode: php
664 // tab-width: 8
665 // c-basic-offset: 4
666 // c-hanging-comment-ender-p: nil
667 // indent-tabs-mode: nil
668 // End:
669 ?>