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