]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/unit/test.php
PHPUnit tests by Dan Frankowski
[SourceForge/phpwiki.git] / tests / unit / test.php
1 #! /usr/local/bin/php -Cq
2 <?php
3 /* Copyright (C) 2004, Dan Frankowski <dfrankow@cs.umn.edu>
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  */
28
29 ####################################################################
30 #
31 # Preamble needed to get the tests to run.
32 #
33 ####################################################################
34
35
36 # Add root dir to the path
37 $rootdir = getcwd() . '/../../';
38 ini_set('include_path', ini_get('include_path') . (substr(PHP_OS,0,3) == 'WIN' ? ';' : ':') . $rootdir);
39
40 # This quiets a warning in config.php
41 $HTTP_SERVER_VARS['REMOTE_ADDR'] = '127.0.0.1';
42
43 # Other needed files
44 require_once 'index.php';
45 require_once 'lib/stdlib.php';
46 require_once 'lib/config.php';  // Needed for $WikiNameRegExp
47
48 # Show lots of detail when an assert() in the code fails
49 function assert_callback( $script, $line, $message ) {
50    echo "assert failed: script ", $script," line ", $line," :";
51    echo "$message";
52    echo "Traceback:";
53    print_r(debug_backtrace());
54    exit;
55 }
56 $foo = assert_options( ASSERT_CALLBACK, 'assert_callback');
57
58 # This is the test DB backend
59 #require_once( 'lib/WikiDB/backend/cvs.php' );
60 $db_params                         = array();
61 $db_params['directory']            = getcwd() . '/testbox';
62 $db_params['dbtype']               = 'file';
63
64 # Mock objects to allow tests to run
65 require_once( 'lib/WikiDB.php' );
66 class MockRequest {
67     function MockRequest(&$dbparams) {
68         $this->_dbi = WikiDB::open(&$dbparams);
69     }
70     function addArg($arg, $value) {
71         $this->args[$arg] = $value;
72     }
73     function getArg($arg) {
74         return $this->args[$arg];
75     }
76
77     function getDbh() {
78         return $this->_dbi;
79     }
80 }
81
82 $request = new MockRequest($db_params);
83
84 ####################################################################
85 #
86 # End of preamble, run the test suite ..
87 #
88 ####################################################################
89
90 # Test files
91 require_once ('PHPUnit.php');
92 # lib/config.php might do a cwd()
93 require_once (dirname(__FILE__).'/lib/InlineParserTest.php');
94
95 print "Run tests ..\n";
96 $suite  = new PHPUnit_TestSuite("InlineParserTest");
97 $result = PHPUnit::run($suite);
98
99 echo $result -> toString();
100
101 // (c-file-style: "gnu")
102 // Local Variables:
103 // mode: php
104 // tab-width: 8
105 // c-basic-offset: 4
106 // c-hanging-comment-ender-p: nil
107 // indent-tabs-mode: nil
108 // End:   
109 ?>