xref: /dokuwiki/_test/bootstrap.php (revision b2fcc742e10e700a52cea2d2c4ebf8bb440e35bd)
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; str_replace is for WIN
24define('DOKU_INC', str_replace('\\', '/', dirname(dirname(__FILE__))) . '/');
25define('TMP_DIR', str_replace('\\', '/', 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 for initial setup
92DokuWikiTest::setupDataDir();
93DokuWikiTest::setupConfDir();
94
95// disable all non-default plugins by default
96$dh = dir(DOKU_INC.'lib/plugins/');
97while (false !== ($entry = $dh->read())) {
98    if ($entry == '.' || $entry == '..') {
99        continue;
100    }
101
102    if (!is_dir(DOKU_INC.'lib/plugins/'.$entry)) {
103        continue;
104    }
105
106    if (!in_array($entry, $default_plugins)) {
107        // disable this plugin
108        TestUtils::fappend(DOKU_CONF.'plugins.local.php', "\$plugins['$entry'] = 0;\n");
109    }
110}
111$dh->close();
112
113// load dw
114require_once(DOKU_INC.'inc/init.php');
115
116// load the parser so $PARSER_MODES is defined before the tests start
117// otherwise PHPUnit unsets $PARSER_MODES in some cases which breaks p_get_parsermodes()
118require_once(DOKU_INC.'inc/parser/parser.php');
119
120