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 'authplain', 31 'acl', 32 'config', 33 'info', 34 'plugin', 35 'popularity', 36 'revert', 37 'safefnrecode', 38 'usermanager' 39); 40 41// default server variables 42$default_server_vars = array( 43 'QUERY_STRING' => '?id=', 44 'REQUEST_METHOD' => 'GET', 45 'CONTENT_TYPE' => '', 46 'CONTENT_LENGTH' => '', 47 'SCRIPT_NAME' => '/doku.php', 48 'REQUEST_URI' => '/doku.php?id=', 49 'DOCUMENT_URI' => '/doku.php', 50 'DOCUMENT_ROOT' => DOKU_INC, 51 'SERVER_PROTOCOL' => 'HTTP/1.1', 52 'SERVER_SOFTWARE' => 'nginx/0.7.67', 53 'REMOTE_ADDR' => '87.142.120.6', 54 'REMOTE_PORT' => '21418', 55 'SERVER_ADDR' => '46.38.241.24', 56 'SERVER_PORT' => '443', 57 'SERVER_NAME' => 'wiki.example.com', 58 'REDIRECT_STATUS' => '200', 59 'SCRIPT_FILENAME' => DOKU_INC.'doku.php', 60 'HTTP_HOST' => 'wiki.example.com', 61 'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; OpenBSD amd64; rv:11.0) Gecko/20100101 Firefox/11.0', 62 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 63 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5', 64 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 65 'HTTP_CONNECTION' => 'keep-alive', 66 'HTTP_CACHE_CONTROL' => 'max-age=0', 67 'PHP_SELF' => '/doku.php', 68 'REQUEST_TIME' => time(), 69); 70 71// fixup for $_SERVER when run from CLI, 72// some values should be mocked for use by inc/init.php which is called here 73// [ $_SERVER is also mocked in TestRequest::execute() ] 74if (php_sapi_name() == 'cli') { 75 $_SERVER = array_merge($default_server_vars, $_SERVER); 76} 77 78// create temp directories 79mkdir(TMP_DIR); 80 81// cleanup dir after exit 82if (getenv('PRESERVE_TMP') != 'true') { 83 register_shutdown_function(function() { 84 TestUtils::rdelete(TMP_DIR); 85 }); 86} else { 87 echo ">>>> Preserving temporary directory: ".TMP_DIR."\n"; 88} 89 90// populate default dirs 91TestUtils::rcopy(TMP_DIR, DOKU_INC.'/conf'); 92TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/conf'); 93mkdir(DOKU_TMP_DATA); 94foreach(array( 95 'attic', 'cache', 'index', 'locks', 'media', 96 'media_attic', 'media_meta', 'meta', 'pages', 'tmp') as $dir){ 97 mkdir(DOKU_TMP_DATA.'/'.$dir); 98} 99 100// disable all non-default plugins by default 101$dh = dir(DOKU_INC.'lib/plugins/'); 102while (false !== ($entry = $dh->read())) { 103 if ($entry == '.' || $entry == '..') { 104 continue; 105 } 106 107 if (!is_dir(DOKU_INC.'lib/plugins/'.$entry)) { 108 continue; 109 } 110 111 if (!in_array($entry, $default_plugins)) { 112 // disable this plugin 113 TestUtils::fappend(DOKU_CONF.'plugins.local.php', "\$plugins['$entry'] = 0;\n"); 114 } 115} 116$dh->close(); 117 118// load dw 119require_once(DOKU_INC.'inc/init.php'); 120 121// load the parser so $PARSER_MODES is defined before the tests start 122// otherwise PHPUnit unsets $PARSER_MODES in some cases which breaks p_get_parsermodes() 123require_once(DOKU_INC.'inc/parser/parser.php'); 124 125