File: test.php

package info (click to toggle)
phpwiki 1.3.12p3-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 16,956 kB
  • ctags: 21,608
  • sloc: php: 82,335; xml: 3,840; sh: 1,522; sql: 1,198; perl: 625; makefile: 562; awk: 28
file content (650 lines) | stat: -rwxr-xr-x 22,916 bytes parent folder | download | duplicates (3)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
<?php // #!/usr/local/bin/php -Cq
/* Copyright (C) 2004 Dan Frankowski <dfrankow@cs.umn.edu>
 * Copyright (C) 2004,2005,2006 Reini Urban <rurban@x-ray.at>
 *
 * This file is part of PhpWiki.
 * 
 * PhpWiki is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * PhpWiki is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with PhpWiki; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/**
 * Unit tests for PhpWiki. 
 *
 * You must have PEAR's PHPUnit package <http://pear.php.net/package/PHPUnit>. 
 * These tests are unrelated to test/maketest.pl, which do not use PHPUnit.
 * These tests run from the command-line as well as from the browser.
 * Use the argv (from cli) or tests (from browser) params to run only certain tests.
 *
 * $ tests.php test=<testname1> test=<testname2> ... db=dba debug=9 level=10
 */
/****************************************************************
   User definable options
*****************************************************************/
// common cfg options are taken from config/config.ini

//TODO: let the user decide which constants to use: define="x=y"
//define('USE_DB_SESSION', false);
//define('ENABLE_USER_NEW', false);

// memory usage: (8MB limit on certain servers)
// setupwiki
// cli:  Mem16712 => Mem16928
// web:  Mem21216 => Mem26332 (5MB)

// dumphtml:
// cli: Mem20696 => Mem31240  (with USECACHE)    (10MB)
// cli: Mem20240 => Mem30212  (without USECACHE) (10MB)
// web: Mem29424 => Mem35400  (without USECACHE) (6MB)
//define('USECACHE', false);

//##################################################################
//
// Preamble needed to get the tests to run.
//
//##################################################################

$cur_dir = getcwd();
// Add root dir to the path
if (substr(PHP_OS,0,3) == 'WIN')
    $cur_dir = str_replace("\\","/", $cur_dir);
$rootdir = $cur_dir . '/../../';
$ini_sep = substr(PHP_OS,0,3) == 'WIN' ? ';' : ':';
$include_path = ini_get('include_path') . $ini_sep 
              . $rootdir . $ini_sep . $rootdir . "lib/pear";
ini_set('include_path', $include_path);
define('DEFAULT_LANGUAGE','en'); // don't use browser detection
$LANG='en';
if (!isset($HTTP_SERVER_VARS)) {
   $HTTP_SERVER_VARS =& $_SERVER;
   $HTTP_GET_VARS    =& $_GET;
   $HTTP_POST_VARS   =& $_POST;
}

if (!empty($HTTP_SERVER_VARS) and $HTTP_SERVER_VARS["SERVER_NAME"] == 'phpwiki.sourceforge.net') {
    ini_set('include_path', ini_get('include_path') . ":/usr/share/pear");
    //define('ENABLE_PAGEPERM',false); // costs nothing
    define('USECACHE',false); // really?
    //define('WIKIDB_NOCACHE_MARKUP',1);
}

// available database backends to test:
$database_backends = array(
                           'file',
                           'dba',
                           'SQL',   // default backend defined in the config.ini DSN
                           'ADODB', // same backend as defined in the config.ini DSN
			   // specific backends (need to be setup as db=test_phpwiki)
			   'PearDB_pgsql', 'PearDB_sqlite', 'PearDB_mysql',
			   //'PearDB_oci8','PearDB_mssql', 
			   'ADODB_postgres7', 'ADODB_sqlite', 'ADODB_mysql', 
			   //'ADODB_oci8', 'ADODB_mssql', 
                           // 'cvs'
                           );
if ((int)substr(phpversion(), 1) >= 5)
    array_push($database_backends, 'PDO_pqsql', 'PDO_sqlite', 'PDO_mysql');
                                   //'PDO_oci', 'PDO_odbc'

//TODO: convert cvs test                           
// For "cvs" see the seperate tests/unit_test_backend_cvs.php (cvs is experimental)
//TODO: read some database values from config.ini, just use the "test_" prefix
// "flatfile" testing occurs in "tests/unit/.testbox/"
// "dba" needs the DATABASE_DBA_HANDLER, also in the .textbox directory
//$database_dba_handler = (substr(PHP_OS,0,3) == 'WIN') ? "db3" : "gdbm";
// "SQL" and "ADODB" need delete permissions to the test db
//  You have to create that database beforehand with our schema
//$database_dsn = "mysql://wikiuser:@localhost/phpwiki";
$database_prefix = "test_";

// Quiet warnings in IniConfig.php
$HTTP_SERVER_VARS['REMOTE_ADDR'] = '127.0.0.1';
$HTTP_SERVER_VARS['HTTP_USER_AGENT'] = "PHPUnit";

function printMemoryUsage($msg = '') {
    static $mem = 0;
    static $initmem = 0;
    if ($msg) echo $msg,"\n";
    if ((defined('DEBUG') and (DEBUG & 8)) or !defined('DEBUG')) {
        require_once("lib/stdlib.php");
        echo "-- MEMORY USAGE: ";
        $oldmem = $mem;
        $mem = getMemoryUsage();
        if (!$initmem) $initmem = $mem;
        // old libc on sf.net server doesn't understand "%+4d"
        echo sprintf("%8d\t[%s%4d]\t[+%4d]\n", $mem, $mem > $oldmem ? "+" : ($mem == $oldmem ? " " : ""), 
                     $mem - $oldmem, $mem - $initmem);
        // TODO: print time
        flush();
    }
}
/* // now in stdlib.php
function printSimpleTrace($bt) {
    //print_r($bt);
    echo "Traceback:\n";
    foreach ($bt as $i => $elem) {
        if (!array_key_exists('file', $elem)) {
            continue;
        }
        print "  " . $elem['file'] . ':' . $elem['line'] . "\n";
    }
}
*/
// Show lots of detail when an assert() in the code fails
function assert_callback( $script, $line, $message ) {
   echo "assert failed: script ", $script," line ", $line," :";
   echo "$message";
   if (function_exists('debug_backtrace')) { // >= 4.3.0
       echo "Traceback:\n";
       printSimpleTrace(debug_backtrace());
   }
   exit;
}
$foo = assert_options( ASSERT_CALLBACK, 'assert_callback');

//
// Get error reporting to call back, too
//
// set the error reporting level for this script
if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
    error_reporting(E_ALL & ~E_STRICT); 	// exclude E_STRICT
else
    error_reporting(E_ALL); // php4

// This is too strict, fails on every notice and warning. 
/*
function myErrorHandler$errno, $errstr, $errfile, $errline) {
   echo "$errfile: $errline: error# $errno: $errstr\n";
   echo "Traceback:\n";
   printSimpleTrace(debug_backtrace());
}
// The ErrorManager version
function _ErrorHandler_CB(&$error) {
   echo "Traceback:\n";
   printSimpleTrace(debug_backtrace());
   if ($error->isFatal()) {
        $error->errno = E_USER_WARNING;
        return true; // ignore error
   }
   return true;
}
// set to the user defined error handler
// $old_error_handler = set_error_handler("myErrorHandler");
// This is already done via _DEBUG_TRACE
//$ErrorManager->pushErrorHandler(new WikiFunctionCb('_ErrorHandler_CB'));
*/

function purge_dir($dir) {
    static $finder;
    if (!isset($finder)) {
        $finder = new FileFinder;
    }
    $fileSet = new fileSet($dir);
    assert(!empty($dir));
    foreach ($fileSet->getFiles() as $f) {
    	unlink("$dir/$f");
    }
}

function purge_testbox() {
    global $DBParams;	
    if (isset($GLOBALS['request'])) {
        $dbi = $GLOBALS['request']->getDbh();
    }
    $dir = $DBParams['directory'];
    switch ($DBParams['dbtype']) {
    case 'file':
        assert(!empty($dir));
        foreach (array('latest_ver','links','page_data','ver_data') as $d) {
            purge_dir("$dir/$d");
        }
        break;
    case 'SQL':
    case 'ADODB':
    case 'PDO':
        foreach ($dbi->_backend->_table_names as $table) {
            $dbi->genericSqlQuery("DELETE FROM $table");
        }
        break;
    case 'dba':
        purge_dir($dir);
        break;
    }
    if (isset($dbi)) {
        $dbi->_cache->close();
        $dbi->_backend->_latest_versions = array();
    }
}

function printConstant($v) {
    echo "$v=";
    if (defined($v)) {
        if (constant($v) or constant($v)===0 or constant($v)==='0') echo constant($v);
        else echo "false";
    } else echo "undefined";
    echo "\n";
}
/**
 * via the HTML sapi interface print a form to easily change the current cmdline settings.
 */
function html_option_form() {
    global $debug_level, $user_level, $start_debug;

    $form = HTML();
    $option = HTML::div(array('class' => 'option'), 
                        HTML::span(array('style'=>'font-weight: bold','onDblClick'=>'flipAll(\'test[\')'), 'test: '),
                        HTML::br());
    foreach ($GLOBALS['alltests'] as $s) {
        $input = array('type' => 'checkbox', 'name' => 'test['.$s.']', 'value' => '1');
        if (in_array($s,$GLOBALS['runtests'])) $input['checked'] = 'checked';
        $option->pushContent(HTML::input($input), $s, HTML::br());
    }
    $form->pushContent(HTML::td($option));

    $option = HTML::div(array('class' => 'option'), 
                        HTML::span(array('style'=>'font-weight: bold','onDblClick'=>'flipAll(\'db[\')'), 'db: '),
                        HTML::br());
    foreach ($GLOBALS['database_backends'] as $s) {
        $input = array('type' => 'checkbox', 'name' => 'db['.$s.']', 'value' => '1');
        if (in_array($s,$GLOBALS['run_database_backends'])) $input['checked'] = 'checked';
        $option->pushContent(HTML::input($input), $s, HTML::br());
    }
    $form->pushContent(HTML::td($option));

    $js = JavaScript(
"function flipAll(formName) {
  var isFirstSet = -1;
  formObj = document.forms[0];
  for (var i=0; i < formObj.length; i++) {
      fldObj = formObj.elements[i];
      if ((fldObj.type == 'checkbox') && (fldObj.name.substring(0,formName.length) == formName)) { 
         if (isFirstSet == -1)
           isFirstSet = (fldObj.checked) ? true : false;
         fldObj.checked = (isFirstSet) ? false : true;
       }
   }
}
function updateDebugEdit(formObj) {
  val=0;
  for (var i=0; i < formObj.length; i++) {
      fldObj = formObj.elements[i];
      if ((fldObj.type == 'checkbox') && (fldObj.name.substring(0,7) == '_debug[')) { 
         if (fldObj.checked) val = val + parseInt(fldObj.value);
       }
   }
   formObj.debug.value = val;
}
function updateLevelEdit(formObj) {
  for (var i=0; i < formObj.length; i++) {
      fldObj = formObj.elements[i];
      if ((fldObj.type == 'radio') && (fldObj.name.substring(0,7) == '_level[')) {
         if (fldObj.checked) {
            formObj.level.value = fldObj.value;
            return;
         }
      }
   }
}");
    $option = HTML::div(array('class' => 'option'),
                        HTML::span(array('style'=>'font-weight: bold',
                                         'onDblClick'=>'flipAll(\'_debug[\')'), 
                                   'debug: '),
                        HTML::input(array('name'=>'debug','id'=>'debug',
                                          'value'=>$debug_level,'size'=>5)),
                        HTML::br());
    foreach (array('VERBOSE' 	=> 1,
                   'PAGELINKS' 	=> 2,
                   'PARSER' 	=> 4,
                   'TRACE' 	=> 8,
                   'INFO' 	=> 16,
                   'APD' 	=> 32,
                   'LOGIN' 	=> 64,
                   'SQL' 	=> 128,
                   ) as $s => $v) {
        $input = array('type' => 'checkbox', 'name' => '_debug[]', 'value' => $v, 
                       'onClick' => 'updateDebugEdit(this.form)');
        if ($debug_level & $v) $input['checked'] = 'checked';
        $option->pushContent(HTML::input($input), "_DEBUG_".$s, HTML::br());
    }
    $form->pushContent(HTML::td($option));

    $option = HTML::div(array('class' => 'option'), 
                        HTML::span(array('style'=>'font-weight: bold'), "level: "),
                        HTML::input(array('name'=>'level','id'=>'level',
                                          'value'=>$user_level,'size'=>5)),
                        HTML::br());
    foreach (array('FORBIDDEN' 	=> -1,
                   'ANON' 	=> 0,
                   'BOGO' 	=> 1,
                   'USER' 	=> 2,
                   'ADMIN' 	=> 10,
                   'UNOBTAINABLE'=> 100,
                   ) as $s => $v) {
        $input = array('type' => 'radio', 'name' => '_level[]', 'value' => $v,
                       'onClick' => 'updateLevelEdit(this.form)');
        if ($user_level & $v) $input['checked'] = 'checked';
        $option->pushContent(HTML::input($input), "WIKIAUTH_".$s, HTML::br());
    }
    $form->pushContent(HTML::td($option));

    unset($input);
    $option = HTML::div(array('class' => 'option'), 'defines: ', HTML::br());
    if (!empty($GLOBALS['define']))
      foreach ($GLOBALS['define'] as $s) {
        if (defined($s)) {
            $input = array('type' => 'edit', 'name' => $s, 'value' => constant($s));
            $option->pushContent(HTML::input($input), $s, HTML::br());
        }
    }
    if (!empty($input))
        $form->pushContent(HTML::td($option));
    $table = HTML::form(array('action' => $_SERVER['PHP_SELF'],
                                          'method' => 'GET',
                              'accept-charset' => $GLOBALS['charset']),
                        $js,
                        HTML::table(HTML::tr(array('valign'=>'top'), $form)),
                        HTML::input(array('type' => 'submit')),
                        HTML::input(array('type' => 'reset')));
    if ($start_debug)
        $table->pushContent(HiddenInputs(array('start_debug' => $start_debug)));
    return $table->printXml();
}

//####################################################################
//
// End of preamble, run the test suite ..
//
//####################################################################

ob_start();

if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']))
    echo "<pre>\n";
elseif (!empty($HTTP_SERVER_VARS['argv']))
    $argv = $HTTP_SERVER_VARS['argv'];
elseif (!ini_get("register_argc_argv"))
    echo "Could not read cmd args (register_argc_argv=Off?)\n";
// purge the testbox
    
$debug_level = 1; //was 9, _DEBUG_VERBOSE | _DEBUG_TRACE
//if (defined('E_STRICT')) $debug_level = 5; // add PARSER flag on php5
$user_level  = 1; // BOGO (conflicts with RateIt)
// use argv (from cli) or tests (from browser) params to run only certain tests
// avoid pear: Console::Getopt
$alltests = array('InlineParserTest','HtmlParserTest',
                  'PageListTest','ListPagesTest',
                  'SetupWiki',
                  'AllPagesTest','AllUsersTest','OrphanedPagesTest',
                  'WantedPagesTest',
                  'TextSearchTest','IncludePageTest',
                  'DumpHtml');
// support db=file db=dba test=SetupWiki test=DumpHtml debug=num -dconstant=value
// or  db=file,dba test=SetupWiki,DumpHtml debug=num -dconstant=value
if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
    $argv = array();
    foreach ($HTTP_GET_VARS as $key => $val) {
    	if (is_array($val))
    	    foreach ($val as $k => $v) $argv[] = $key."=".$k;
    	elseif (strstr($val,",") and in_array($key, array("test","db")))
    	    foreach (explode(",",$val) as $v) $argv[] = $key."=".$v;
    	else
            $argv[] = $key."=".$val;
    }
} elseif (!empty($argv) and preg_match("/test\.php$/", $argv[0])) {
    array_shift($argv);
}    
if (!empty($argv)) {
    $runtests = array();
    $define = array();
    $run_database_backends = array();
    $m = array();
    foreach ($argv as $arg) {
        if (preg_match("/^test=(.+)$/",$arg,$m) and in_array($m[1], $alltests))
            $runtests[] = $m[1];
        elseif (preg_match("/^db=(.+)$/",$arg,$m) and in_array($m[1], $database_backends))
            $run_database_backends[] = $m[1];
        elseif (preg_match("/^debug=(\d+)$/",$arg,$m))
            $debug_level = $m[1];
        elseif (preg_match("/^level=(\d+)$/",$arg,$m))
            $user_level = $m[1];
        elseif (preg_match("/^\-d(\w+)=(.+)$/",$arg,$m)) {
            $define[$m[1]] = $m[2];
            if ($m[2] == 'true') $m[2] = true;
            elseif ($m[2] == 'false') $m[2] = false;
            if (!defined($m[1])) define($m[1], $m[2]);
        } elseif (in_array($arg, $alltests))
            $runtests[] = $arg;
        elseif ($debug_level & 1)
            echo "ignored arg: ", $arg, "\n";
    }
}

if (empty($run_database_backends))
    $run_database_backends = $database_backends;
if (empty($runtests))
    $runtests = $alltests;
if ($debug_level & 1) {
    //echo "\n";
    echo "PHP_SAPI=",php_sapi_name(), "\n";
    echo "PHP_OS=",PHP_OS, "\n";
    echo "PHP_VERSION=",PHP_VERSION, "\n";
    echo "test=", join(",",$runtests),"\n";
    echo "db=", join(",",$run_database_backends),"\n";
    echo "debug=", $debug_level,"\n";
    echo "level=", $user_level,"\n";
    if (!empty($define)) {
    	foreach ($define as $k => $v) printConstant($k);
    }
    if ($debug_level & 8) {
    	echo "pid=",getmypid(),"\n";
    }
    echo "\n";
}
flush();

if (!defined('DEBUG'))
    define('DEBUG', $debug_level);
// override defaults:
if (!defined('RATING_STORAGE')) 
   define('RATING_STORAGE', 'WIKIPAGE');
if (!defined('GROUP_METHOD'))
    define('GROUP_METHOD', 'NONE');

if (DEBUG & 8)
    printMemoryUsage("beforePEAR");

if (DEBUG & 8)
    printMemoryUsage("beforePhpWiki");

define('PHPWIKI_NOMAIN', true);
// Other needed files
require_once $rootdir.'index.php';
require_once $rootdir.'lib/main.php';

// init filefinder for pear path fixup.
FindFile ('PHPUnit.php', 'missing_okay');
// PEAR library (requires version ??)
require_once 'PHPUnit.php';

ob_end_flush();

if ($debug_level & 1) {
    //echo "\n";
    echo "PHPWIKI_VERSION=",PHPWIKI_VERSION, 
        strstr(PHPWIKI_VERSION,"pre") ? strftime(" / %Y%m%d") : "","\n";
    if ($debug_level & 9) {
        // which constants affect memory?
        foreach (explode(",","USECACHE,WIKIDB_NOCACHE_MARKUP,"
                            ."ENABLE_USER_NEW,ENABLE_PAGEPERM") as $v) {
            printConstant($v);
        }
    }
    echo "\n";
}

global $ErrorManager;
$ErrorManager->setPostponedErrorMask(EM_FATAL_ERRORS|EM_WARNING_ERRORS|EM_NOTICE_ERRORS);
// FIXME: ignore cached requests (if-modified-since) from cli
class MockRequest extends WikiRequest {
    function MockRequest($dbparams) {
        $this->_dbi = WikiDB::open($dbparams);
        $this->_user = new MockUser("a_user", $GLOBALS['user_level']);
        $this->_group = new GroupNone();
        $this->_args = array('pagename' => 'HomePage', 'action' => 'browse');
        $this->Request();
    }
    function getGroup() {
    	if (is_object($this->_group))
            return $this->_group;
        else // FIXME: this is set to "/f:" somewhere.
            return new GroupNone();
    }
}

if (ENABLE_USER_NEW) {
    class MockUser extends _WikiUser {
        function MockUser($name, $level) {
            $this->_userid = $name;
            $this->_isSignedIn = $level > 1;
            $this->_level = $level;
        }
        function isSignedIn() {
            return $this->_isSignedIn;
        }
    }
} else {
    class MockUser extends WikiUser {
        function MockUser($name, $level) {
            $this->_userid = $name;
            $this->_isSignedIn = $level > 1;
            $this->_level = $level;
        }
        function isSignedIn() {
            return $this->_isSignedIn;
        }
    }
}

/*
if (ENABLE_USER_NEW)
    $request->_user = WikiUser('AnonUser');
else {
    $request->_user = new WikiUser($request, 'AnonUser');
    $request->_prefs = $request->_user->getPreferences();
}
*/
if (DEBUG & _DEBUG_TRACE)
    printMemoryUsage("PhpWikiLoaded");

// provide a nice input form for all options
if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
    echo html_option_form();
    flush();
}

// save and restore all args for each test.
class phpwiki_TestCase extends PHPUnit_TestCase {
    function setUp() { 
        global $request, $WikiTheme;
	include_once("themes/" . THEME . "/themeinfo.php");
        $this->_savedargs = $request->_args;
        $request->_args = array();
        if (DEBUG & 1) {
            echo $this->_name,"\n";
            flush();
        }
    }
    function tearDown() {
        global $request;
        $request->_args = $this->_savedargs;
        if (DEBUG & _DEBUG_TRACE)
            printMemoryUsage();
    }
}

// Test all db backends.
foreach ($run_database_backends as $dbtype) {
    global $request, $DBParams;
    //    if (DEBUG & _DEBUG_TRACE)
    //        printMemoryUsage("PHPUnitInitialized");
    $DBParams['dbtype'] = $dbtype;
    if (string_starts_with($dbtype, 'PearDB_')) {
	$DBParams['dbtype'] = 'SQL';
	$DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 7).":", $DBParams['dsn']);
        echo "dsn: ",$DBParams['dsn'],"\n";
    }
    if (string_starts_with($dbtype, 'ADODB_')) {
	$DBParams['dbtype'] = 'ADODB';
	$DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 6).":", $DBParams['dsn']);
        echo "dsn: ",$DBParams['dsn'],"\n";
    }
    if (string_starts_with($dbtype, 'PDO_')) {
	$DBParams['dbtype'] = 'PDO';
	$DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 4).":", $DBParams['dsn']);
        echo "dsn: ",$DBParams['dsn'],"\n";
    }
    $DBParams['directory']            = $cur_dir . '/.testbox';
    $DBParams['prefix']               = $database_prefix;
    // from config.ini
    //$DBParams['dba_handler']          = $database_dba_handler;

    echo "Testing DB Backend \"$dbtype\" ...\n";
    flush();
    $request = new MockRequest($DBParams);
    if ( ! ENABLE_USER_NEW ) {
        $request->_user->_request =& $request;
        $request->_user->_dbi =& $request->_dbi;
    }
    if (DEBUG & _DEBUG_TRACE)
        printMemoryUsage("PhpWikiInitialized");

    foreach ($runtests as $test) {
    	if (!@ob_get_level()) ob_start();
        $suite  = new PHPUnit_TestSuite("phpwiki");
        if (file_exists(dirname(__FILE__).'/lib/'.$test.'.php'))
            require_once dirname(__FILE__).'/lib/'.$test.'.php';
        else    
            require_once dirname(__FILE__).'/lib/plugin/'.$test.'.php';
        $suite->addTest( new PHPUnit_TestSuite($test) );

        @set_time_limit(240); 
        $result = PHPUnit::run($suite); 
        echo "ran " . $result->runCount() . " tests, " . $result->failureCount() . " failures.\n";
        ob_end_flush();
        if ($result->failureCount() > 0) {
            echo "More detail:\n";
            echo $result->toString();
        }
    }

    $request->chunkOutput();
    $request->_dbi->close();
    unset($request->_user);
    unset($request->_dbi);
    unset($request);
    unset($suite);
    unset($result);
}

if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']))
    echo "</pre>\n";

// (c-file-style: "gnu")
// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:   
?>