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