3 if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
5 if (isset($_GET['getOutputCompression'])) {
6 echo (int)ini_get('zlib.output_compression');
9 if (isset($_GET['hello'])) {
10 // try to disable (may not work)
11 ini_set('zlib.output_compression', '0');
17 require_once '_inc.php';
19 function test_environment()
24 $noSlash = assertTrue(
25 0 === preg_match('@[\\\\/]$@', $_SERVER['DOCUMENT_ROOT'])
26 ,'environment : DOCUMENT_ROOT should not end in trailing slash'
28 $isRealPath = assertTrue(false !== realpath($_SERVER['DOCUMENT_ROOT'])
29 ,'environment : DOCUMENT_ROOT should pass realpath()'
31 $containsThisFile = assertTrue(
32 0 === strpos(realpath(__FILE__), realpath($_SERVER['DOCUMENT_ROOT']))
33 ,'environment : DOCUMENT_ROOT should contain this test file'
35 if (! $noSlash || ! $isRealPath || ! $containsThisFile) {
36 echo "\nDOCUMENT_ROOT is set to: '{$_SERVER['DOCUMENT_ROOT']}'. If you "
37 . "cannot modify this, consider setting \$min_documentRoot in config.php\n\n";
39 if (isset($_SERVER['SUBDOMAIN_DOCUMENT_ROOT'])) {
40 echo "\n!NOTE: environment : \$_SERVER['SUBDOMAIN_DOCUMENT_ROOT'] is set. "
41 . "You may need to set \$min_documentRoot to this in config.php\n";
43 if (realpath(__FILE__) !== realpath($_SERVER['DOCUMENT_ROOT'] . '/min_unit_tests/test_environment.php')) {
44 echo "!NOTE: environment : /min_unit_tests/ is not directly inside DOCUMENT_ROOT\n";
48 . $_SERVER['HTTP_HOST'] // avoid redirects when SERVER_NAME doesn't match
49 . ('80' === $_SERVER['SERVER_PORT'] ? '' : ":{$_SERVER['SERVER_PORT']}")
50 . dirname($_SERVER['REQUEST_URI'])
51 . '/test_environment.php';
53 $oc = @file_get_contents($thisUrl . '?getOutputCompression=1');
55 if (false === $oc || ! preg_match('/^[01]$/', $oc)) {
56 echo "!WARN: environment : Local HTTP request failed. Testing cannot continue.\n";
60 echo "!WARN: environment : zlib.output_compression is enabled in php.ini"
64 $fp = fopen($thisUrl . '?hello=1', 'r', false, stream_context_create(array(
67 'header' => "Accept-Encoding: deflate, gzip\r\n"
71 $meta = stream_get_meta_data($fp);
74 foreach ($meta['wrapper_data'] as $i => $header) {
75 if ((preg_match('@^Content-Length: (\\d+)$@i', $header, $m) && $m[1] !== '6')
76 || preg_match('@^Content-Encoding:@i', $header, $m)
82 if ($passed && stream_get_contents($fp) !== 'World!') {
87 ,'environment : PHP/server does not auto-HTTP-encode content'
91 if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
93 echo "\nReturned content should be 6 bytes and not HTTP encoded.\n"
94 . "Headers returned by: {$thisUrl}?hello=1\n\n";
95 var_export($meta['wrapper_data']);