1 <?php // #! /usr/local/bin/php -Cq
2 /* Copyright (C) 2004, Dan Frankowski <dfrankow@cs.umn.edu>
3 * Copyright (C) 2004, Reini Urban <rurban@x-ray.at>
5 * This file is part of PhpWiki.
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.
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.
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
23 * Unit tests for PhpWiki.
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.
30 ####################################################################
32 # Preamble needed to get the tests to run.
34 ####################################################################
38 # Add root dir to the path
39 $rootdir = $cur_dir . '/../../';
40 $ini_sep = substr(PHP_OS,0,3) == 'WIN' ? ';' : ':';
41 ini_set('include_path', ini_get('include_path') . $ini_sep . $rootdir);
43 # This quiets a warning in config.php
44 $HTTP_SERVER_VARS['REMOTE_ADDR'] = '127.0.0.1';
47 require_once $rootdir.'index.php';
48 require_once $rootdir.'lib/stdlib.php';
50 # Show lots of detail when an assert() in the code fails
51 function assert_callback( $script, $line, $message ) {
52 echo "assert failed: script ", $script," line ", $line," :";
55 print_r(debug_backtrace());
58 $foo = assert_options( ASSERT_CALLBACK, 'assert_callback');
60 # This is the test DB backend
61 #require_once( 'lib/WikiDB/backend/cvs.php' );
63 $db_params['directory'] = $cur_dir . '/.testbox';
64 $db_params['dbtype'] = 'file';
66 # Mock objects to allow tests to run
67 require_once($rootdir.'lib/Request.php');
68 require_once($rootdir.'lib/WikiDB.php');
70 require_once($rootdir."lib/WikiUserNew.php");
72 require_once($rootdir."lib/WikiUser.php");
73 require_once($rootdir."lib/WikiGroup.php");
74 require_once($rootdir."lib/PagePerm.php");
76 class MockRequest extends Request {
77 function MockRequest(&$dbparams) {
78 global $Theme, $request;
79 $this->_dbi = WikiDB::open(&$dbparams);
80 $this->_args = array('pagename' => 'HomePage', 'action' => 'browse');
83 function setArg($arg, $value) {
84 $this->_args[$arg] = $value;
86 function getArg($arg) {
87 return $this->_args[$arg];
93 if (isset($this->_user))
96 return $GLOBALS['ForbiddenUser'];
98 function getPage ($pagename = false) {
99 if (!isset($this->_dbi))
102 $pagename = $this->getArg('pagename');
103 return $this->_dbi->getPage($pagename);
105 function getPrefs () {
106 return $this->_prefs;
108 function getPref ($key) {
109 if (isset($this->_prefs))
110 return $this->_prefs->get($key);
114 $request = new MockRequest($db_params);
117 $request->_user = WikiUser('AnonUser');
119 $request->_user = new WikiUser($request, 'AnonUser');
120 $request->_prefs = $request->_user->getPreferences();
122 include_once("themes/" . THEME . "/themeinfo.php");
124 ####################################################################
126 # End of preamble, run the test suite ..
128 ####################################################################
131 require_once 'PHPUnit.php';
132 # lib/config.php might do a cwd()
133 require_once dirname(__FILE__).'/lib/InlineParserTest.php';
134 require_once dirname(__FILE__).'/lib/PageListTest.php';
135 require_once dirname(__FILE__).'/lib/plugin/ListPagesTest.php';
136 require_once dirname(__FILE__).'/lib/plugin/AllPagesTest.php';
137 require_once dirname(__FILE__).'/lib/plugin/AllUsersTest.php';
138 require_once dirname(__FILE__).'/lib/plugin/OrphanedPagesTest.php';
140 if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']))
142 print "Run tests ..\n";
144 $suite = new PHPUnit_TestSuite("phpwiki");
145 $suite->addTest( new PHPUnit_TestSuite("InlineParserTest") );
146 $suite->addTest( new PHPUnit_TestSuite("HtmlParserTest") );
147 $suite->addTest( new PHPUnit_TestSuite("PageListTest") );
148 $suite->addTest( new PHPUnit_TestSuite("ListPagesTest") );
149 $suite->addTest( new PHPUnit_TestSuite("AllPagesTest") );
150 $suite->addTest( new PHPUnit_TestSuite("AllUsersTest") );
151 $suite->addTest( new PHPUnit_TestSuite("OrphanedPagesTest") );
152 $result = PHPUnit::run($suite);
154 echo $result->toString();
156 if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']))
159 // (c-file-style: "gnu")
164 // c-hanging-comment-ender-p: nil
165 // indent-tabs-mode: nil