]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/unit/test.php
several new tests by DanFr
[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, 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  */
29
30 ####################################################################
31 #
32 # Preamble needed to get the tests to run.
33 #
34 ####################################################################
35
36
37 $cur_dir = getcwd();
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);
42
43 # This quiets a warning in config.php
44 $HTTP_SERVER_VARS['REMOTE_ADDR'] = '127.0.0.1';
45
46 # Other needed files
47 require_once $rootdir.'index.php';
48 require_once $rootdir.'lib/stdlib.php';
49
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," :";
53    echo "$message";
54    echo "Traceback:";
55    print_r(debug_backtrace());
56    exit;
57 }
58 $foo = assert_options( ASSERT_CALLBACK, 'assert_callback');
59
60 # This is the test DB backend
61 #require_once( 'lib/WikiDB/backend/cvs.php' );
62 $db_params                         = array();
63 $db_params['directory']            = $cur_dir . '/.testbox';
64 $db_params['dbtype']               = 'file';
65
66 # Mock objects to allow tests to run
67 require_once($rootdir.'lib/Request.php');
68 require_once($rootdir.'lib/WikiDB.php');
69 if (ENABLE_USER_NEW)
70     require_once($rootdir."lib/WikiUserNew.php");
71 else
72     require_once($rootdir."lib/WikiUser.php"); 
73 require_once($rootdir."lib/WikiGroup.php");
74 require_once($rootdir."lib/PagePerm.php");
75
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');
81         $this->Request();
82     }
83     function setArg($arg, $value) {
84         $this->_args[$arg] = $value;
85     }
86     function getArg($arg) {
87         return $this->_args[$arg];
88     }
89     function getDbh() {
90         return $this->_dbi;
91     }
92     function getUser () {
93         if (isset($this->_user))
94             return $this->_user;
95         else
96             return $GLOBALS['ForbiddenUser'];
97     }
98     function getPage ($pagename = false) {
99         if (!isset($this->_dbi))
100             $this->getDbh();
101         if (!$pagename) 
102             $pagename = $this->getArg('pagename');
103         return $this->_dbi->getPage($pagename);
104     }
105     function getPrefs () {
106         return $this->_prefs;
107     }
108     function getPref ($key) {
109         if (isset($this->_prefs))
110             return $this->_prefs->get($key);
111     }
112 }
113
114 $request = new MockRequest($db_params);
115
116 if (ENABLE_USER_NEW)
117     $request->_user = WikiUser('AnonUser');
118 else {
119     $request->_user = new WikiUser($request, 'AnonUser');
120     $request->_prefs = $request->_user->getPreferences();
121 }
122 include_once("themes/" . THEME . "/themeinfo.php");
123
124 ####################################################################
125 #
126 # End of preamble, run the test suite ..
127 #
128 ####################################################################
129
130 # Test files
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'; 
139
140 if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']))
141     echo "<pre>\n";
142 print "Run tests ..\n";
143
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); 
153
154 echo $result->toString();
155
156 if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']))
157     echo "</pre>\n";
158
159 // (c-file-style: "gnu")
160 // Local Variables:
161 // mode: php
162 // tab-width: 8
163 // c-basic-offset: 4
164 // c-hanging-comment-ender-p: nil
165 // indent-tabs-mode: nil
166 // End:   
167 ?>