xref: /dokuwiki/_test/bootstrap.php (revision 5a0eec47d375f076d810160503bdd303f8cf62a0)
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
18error_reporting(E_ALL);
19set_time_limit(0);
20ini_set('memory_limit','2048M');
21
22// prepare temporary directories
23define('DOKU_INC', dirname(dirname(__FILE__)).'/');
24define('TMP_DIR', sys_get_temp_dir().'/dwtests-'.microtime(true));
25define('DOKU_CONF', TMP_DIR.'/conf/');
26define('DOKU_TMP_DATA', TMP_DIR.'/data/');
27
28// default plugins
29$default_plugins = array(
30    'acl',
31    'config',
32    'info',
33    'plugin',
34    'popularity',
35    'revert',
36    'safefnrecode',
37    'usermanager'
38);
39
40// default server variables
41$default_server_vars = array(
42    'QUERY_STRING' => '?id=',
43    'REQUEST_METHOD' => 'GET',
44    'CONTENT_TYPE' => '',
45    'CONTENT_LENGTH' => '',
46    'SCRIPT_NAME' => '/doku.php',
47    'REQUEST_URI' => '/doku.php?id=',
48    'DOCUMENT_URI' => '/doku.php',
49    'DOCUMENT_ROOT' => DOKU_INC,
50    'SERVER_PROTOCOL' => 'HTTP/1.1',
51    'SERVER_SOFTWARE' => 'nginx/0.7.67',
52    'REMOTE_ADDR' => '87.142.120.6',
53    'REMOTE_PORT' => '21418',
54    'SERVER_ADDR' => '46.38.241.24',
55    'SERVER_PORT' => '443',
56    'SERVER_NAME' => 'wiki.example.com',
57    'REDIRECT_STATUS' => '200',
58    'SCRIPT_FILENAME' => DOKU_INC.'doku.php',
59    'HTTP_HOST' => 'wiki.example.com',
60    'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; OpenBSD amd64; rv:11.0) Gecko/20100101 Firefox/11.0',
61    'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
62    'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
63    'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
64    'HTTP_CONNECTION' => 'keep-alive',
65    'HTTP_CACHE_CONTROL' => 'max-age=0',
66    'PHP_SELF' => '/doku.php',
67    'REQUEST_TIME' => time(),
68);
69
70// create temp directories
71mkdir(TMP_DIR);
72
73// cleanup dir after exit
74register_shutdown_function(function() {
75    TestUtils::rdelete(TMP_DIR);
76});
77
78// populate default dirs
79TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/conf');
80TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/data');
81
82// disable all non-default plugins by default
83$dh = dir(DOKU_INC.'lib/plugins/');
84while (false !== ($entry = $dh->read())) {
85    if ($entry == '.' || $entry == '..') {
86        continue;
87    }
88
89    if (!is_dir(DOKU_INC.'lib/plugins/'.$entry)) {
90        continue;
91    }
92
93    if (!in_array($entry, $default_plugins)) {
94        // disable this plugin
95        TestUtils::fappend(DOKU_CONF.'plugins.local.php', "\$plugins['$entry'] = 0;\n");
96    }
97}
98$dh->close();
99
100// load dw
101require_once(DOKU_INC.'inc/init.php');
102
103