2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Bootstrap for phpMyAdmin tests
6 * @package PhpMyAdmin-test
9 // Let PHP complain about all errors
10 error_reporting(E_ALL
);
12 // Ensure PHP has set timezone
13 date_default_timezone_set('UTC');
15 // Adding phpMyAdmin sources to include path
17 get_include_path() . PATH_SEPARATOR
. dirname(realpath("../index.php"))
20 // Setting constants for testing
21 define('PHPMYADMIN', 1);
22 define('TESTSUITE', 1);
23 define('PMA_MYSQL_INT_VERSION', 55000);
24 define('PMA_MYSQL_STR_VERSION', '5.50.00');
25 define('PMA_MYSQL_VERSION_COMMENT', 'MySQL Community Server (GPL)');
27 // Selenium tests setup
28 $test_defaults = array(
29 'TESTSUITE_SERVER' => 'localhost',
30 'TESTSUITE_USER' => 'root',
31 'TESTSUITE_PASSWORD' => '',
32 'TESTSUITE_DATABASE' => 'test',
33 'TESTSUITE_URL' => 'http://localhost/phpmyadmin/',
34 'TESTSUITE_SELENIUM_HOST' => '',
35 'TESTSUITE_SELENIUM_PORT' => '4444',
36 'TESTSUITE_SELENIUM_BROWSER' => 'firefox',
37 'TESTSUITE_SELENIUM_COVERAGE' => '',
38 'TESTSUITE_BROWSERSTACK_USER' => '',
39 'TESTSUITE_BROWSERSTACK_KEY' => '',
40 'TESTSUITE_FULL' => '',
42 foreach ($test_defaults as $varname => $defvalue) {
43 $envvar = getenv($varname);
45 $GLOBALS[$varname] = $envvar;
47 $GLOBALS[$varname] = $defvalue;
51 require_once 'libraries/vendor_config.php';
52 require_once 'libraries/autoloader.php';
53 require_once 'libraries/core.lib.php';
54 $CFG = new PMA\libraries\
Config();
55 // Initialize PMA_VERSION variable
56 define('PMA_VERSION', $CFG->get('PMA_VERSION'));
58 require_once 'libraries/sql-parser/autoload.php';
60 /* Ensure default langauge is active */
61 require_once 'libraries/php-gettext/gettext.inc';
62 PMA\libraries\LanguageManager
::getInstance()->getLanguage('en')->activate();
64 // Set proxy information from env, if available
65 $http_proxy = getenv('http_proxy');
66 if ($http_proxy && ($url_info = parse_url($http_proxy))) {
67 define('PROXY_URL', $url_info['host'] . ':' . $url_info['port']);
68 define('PROXY_USER', empty($url_info['user']) ?
'' : $url_info['user']);
69 define('PROXY_PASS', empty($url_info['pass']) ?
'' : $url_info['pass']);
71 define('PROXY_URL', '');
72 define('PROXY_USER', '');
73 define('PROXY_PASS', '');
76 // Ensure we have session started
79 // Standard environment for tests
80 $_SESSION[' PMA_token '] = 'token';
81 $_SESSION['tmpval']['pftext'] = 'F';
82 $GLOBALS['lang'] = 'en';
83 $GLOBALS['is_ajax_request'] = false;
84 $GLOBALS['cell_align_left'] = 'left';
86 // Check whether we have runkit extension
87 define('PMA_HAS_RUNKIT', function_exists('runkit_constant_redefine'));
88 $GLOBALS['runkit_internal_override'] = ini_get('runkit.internal_override');
92 * Function to emulate headers() function by storing headers in GLOBAL array
94 * @param string $string header string
95 * @param boolean $replace .
96 * @param integer $http_response_code .
100 function test_header($string, $replace = true, $http_response_code = 200)
102 if (! isset($GLOBALS['header'])) {
103 $GLOBALS['header'] = array();
106 $GLOBALS['header'][] = $string;
110 * Function to emulate headers_send.
112 * @return boolean false
114 function test_headers_sent()
120 * Function to emulate date() function
122 * @param string $date_format arg
124 * @return string dummy date
126 function test_date($date_format)
128 return '0000-00-00 00:00:00';
131 if (PMA_HAS_RUNKIT
&& $GLOBALS['runkit_internal_override']) {
132 echo "Enabling headers testing using runkit...\n";
133 runkit_function_rename('header', 'test_header_override');
134 runkit_function_rename('headers_sent', 'test_headers_sent_override');
135 runkit_function_rename('test_header', 'header');
136 runkit_function_rename('test_headers_sent', 'headers_sent');
137 define('PMA_TEST_HEADERS', true);
139 echo "No headers testing.\n";
140 echo "Please install runkit and enable runkit.internal_override!\n";
144 * Overrides date function
146 * @return boolean whether function was overridden or not
148 function setupForTestsUsingDate()
150 if (PMA_HAS_RUNKIT
&& $GLOBALS['runkit_internal_override']) {
151 runkit_function_rename('date', 'test_date_override');
152 runkit_function_rename('test_date', 'date');
160 * Restores date function
164 function tearDownForTestsUsingDate()
166 if (PMA_HAS_RUNKIT
&& $GLOBALS['runkit_internal_override']) {
167 runkit_function_rename('date', 'test_date');
168 runkit_function_rename('test_date_override', 'date');