xref: /dokuwiki/_test/bootstrap.php (revision 682adb32603ee80c53e533a0c0dbde18ade4a8fc)
1<?php
2/**
3 * Test Suite bootstrapping for DokuWiki
4 */
5
6if(!defined('DOKU_UNITTEST')) define('DOKU_UNITTEST',dirname(__FILE__).'/');
7require_once DOKU_UNITTEST.'core/phpQuery-onefile.php';
8require_once DOKU_UNITTEST.'core/DokuWikiTest.php';
9require_once DOKU_UNITTEST.'core/TestResponse.php';
10require_once DOKU_UNITTEST.'core/TestRequest.php';
11require_once DOKU_UNITTEST.'core/TestUtils.php';
12
13
14// backward compatibility to old test suite
15define('SIMPLE_TEST', true);
16
17// basic behaviours
18define('DOKU_E_LEVEL',E_ALL ^ E_NOTICE);
19error_reporting(DOKU_E_LEVEL);
20set_time_limit(0);
21ini_set('memory_limit','2048M');
22
23// prepare temporary directories
24define('DOKU_INC', dirname(dirname(__FILE__)).'/');
25define('TMP_DIR', sys_get_temp_dir().'/dwtests-'.microtime(true));
26define('DOKU_CONF', TMP_DIR.'/conf/');
27define('DOKU_TMP_DATA', TMP_DIR.'/data/');
28
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'
40);
41
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(),
70);
71
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() ]
75if (php_sapi_name() == 'cli') {
76  $_SERVER = array_merge($default_server_vars, $_SERVER);
77}
78
79// create temp directories
80mkdir(TMP_DIR);
81
82// cleanup dir after exit
83if (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";
89}
90
91// populate default dirs
92TestUtils::rcopy(TMP_DIR, DOKU_INC.'/conf');
93TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/conf');
94mkdir(DOKU_TMP_DATA);
95foreach(array(
96    'attic', 'cache', 'index', 'locks', 'media',
97    'media_attic', 'media_meta', 'meta', 'pages', 'tmp') as $dir){
98    mkdir(DOKU_TMP_DATA.'/'.$dir);
99}
100
101// disable all non-default plugins by default
102$dh = dir(DOKU_INC.'lib/plugins/');
103while (false !== ($entry = $dh->read())) {
104    if ($entry == '.' || $entry == '..') {
105        continue;
106    }
107
108    if (!is_dir(DOKU_INC.'lib/plugins/'.$entry)) {
109        continue;
110    }
111
112    if (!in_array($entry, $default_plugins)) {
113        // disable this plugin
114        TestUtils::fappend(DOKU_CONF.'plugins.local.php', "\$plugins['$entry'] = 0;\n");
115    }
116}
117$dh->close();
118
119// load dw
120require_once(DOKU_INC.'inc/init.php');
121
122// load the parser so $PARSER_MODES is defined before the tests start
123// otherwise PHPUnit unsets $PARSER_MODES in some cases which breaks p_get_parsermodes()
124require_once(DOKU_INC.'inc/parser/parser.php');
125
126