Merge pull request #3343 from splitbrain/bug3271
[dokuwiki.git] / _test / bootstrap.php
blob2813d0b7da2019d1d475d4d0ba60ee478281b393
1 <?php
2 /**
3 * Test Suite bootstrapping for DokuWiki
4 */
6 if(!defined('DOKU_UNITTEST')) define('DOKU_UNITTEST',dirname(__FILE__).'/');
7 require_once DOKU_UNITTEST.'core/phpQuery-onefile.php';
8 require_once DOKU_UNITTEST.'core/DokuWikiTest.php';
9 require_once DOKU_UNITTEST.'core/TestResponse.php';
10 require_once DOKU_UNITTEST.'core/TestRequest.php';
11 require_once DOKU_UNITTEST.'core/TestUtils.php';
14 // backward compatibility to old test suite
15 define('SIMPLE_TEST', true);
17 // basic behaviours
18 define('DOKU_E_LEVEL',E_ALL ^ E_NOTICE);
19 error_reporting(DOKU_E_LEVEL);
20 set_time_limit(0);
21 ini_set('memory_limit','2048M');
23 // prepare temporary directories; str_replace is for WIN
24 define('DOKU_INC', str_replace('\\', '/', dirname(dirname(__FILE__))) . '/');
25 define('TMP_DIR', str_replace('\\', '/', sys_get_temp_dir()) . '/dwtests-'.microtime(true));
26 define('DOKU_CONF', TMP_DIR.'/conf/');
27 define('DOKU_TMP_DATA', TMP_DIR.'/data/');
29 // default plugins
30 $default_plugins = array(
31 'authplain',
32 'acl',
33 'config',
34 'info',
35 'plugin',
36 'popularity',
37 'revert',
38 'safefnrecode',
39 'usermanager'
42 // default server variables
43 $default_server_vars = array(
44 'QUERY_STRING' => '?id=',
45 'REQUEST_METHOD' => 'GET',
46 'CONTENT_TYPE' => '',
47 'CONTENT_LENGTH' => '',
48 'SCRIPT_NAME' => '/doku.php',
49 'REQUEST_URI' => '/doku.php?id=',
50 'DOCUMENT_URI' => '/doku.php',
51 'DOCUMENT_ROOT' => DOKU_INC,
52 'SERVER_PROTOCOL' => 'HTTP/1.1',
53 'SERVER_SOFTWARE' => 'nginx/0.7.67',
54 'REMOTE_ADDR' => '87.142.120.6',
55 'REMOTE_PORT' => '21418',
56 'SERVER_ADDR' => '46.38.241.24',
57 'SERVER_PORT' => '443',
58 'SERVER_NAME' => 'wiki.example.com',
59 'REDIRECT_STATUS' => '200',
60 'SCRIPT_FILENAME' => DOKU_INC.'doku.php',
61 'HTTP_HOST' => 'wiki.example.com',
62 'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; OpenBSD amd64; rv:11.0) Gecko/20100101 Firefox/11.0',
63 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
64 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
65 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
66 'HTTP_CONNECTION' => 'keep-alive',
67 'HTTP_CACHE_CONTROL' => 'max-age=0',
68 'PHP_SELF' => '/doku.php',
69 'REQUEST_TIME' => time(),
72 // fixup for $_SERVER when run from CLI,
73 // some values should be mocked for use by inc/init.php which is called here
74 // [ $_SERVER is also mocked in TestRequest::execute() ]
75 if (php_sapi_name() == 'cli') {
76 $_SERVER = array_merge($default_server_vars, $_SERVER);
79 // create temp directories
80 mkdir(TMP_DIR);
82 // cleanup dir after exit
83 if (getenv('PRESERVE_TMP') != 'true') {
84 register_shutdown_function(function() {
85 TestUtils::rdelete(TMP_DIR);
86 });
87 } else {
88 echo ">>>> Preserving temporary directory: ".TMP_DIR."\n";
91 // populate default dirs for initial setup
92 DokuWikiTest::setupDataDir();
93 DokuWikiTest::setupConfDir();
95 // disable all non-default plugins by default
96 $dh = dir(DOKU_INC.'lib/plugins/');
97 while (false !== ($entry = $dh->read())) {
98 if ($entry == '.' || $entry == '..') {
99 continue;
102 if (!is_dir(DOKU_INC.'lib/plugins/'.$entry)) {
103 continue;
106 if (!in_array($entry, $default_plugins)) {
107 // disable this plugin
108 TestUtils::fappend(DOKU_CONF.'plugins.local.php', "\$plugins['$entry'] = 0;\n");
111 $dh->close();
113 // use no mbstring help during tests
114 if (!defined('UTF8_NOMBSTRING')) define('UTF8_NOMBSTRING', 1);
116 // load dw
117 require_once(DOKU_INC.'inc/init.php');
119 // load the parser so $PARSER_MODES is defined before the tests start
120 // otherwise PHPUnit unsets $PARSER_MODES in some cases which breaks p_get_parsermodes()
121 require_once(DOKU_INC.'inc/parser/parser.php');