mirror of
https://github.com/mrclay/minify.git
synced 2025-08-16 02:54:33 +02:00
+ unit tests for sensing server/PHP auto-HTTP-encoding and zlib.output_compression
moved ini_set('zlib.output_compression', '0') to config.php so extras and ab tests should work when this is set in php.ini/.htaccess. builder/index.php : added escapes to JS strings for valid HTML
This commit is contained in:
@@ -117,7 +117,7 @@ src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function () {
|
$(function () {
|
||||||
// detection of double output encoding
|
// detection of double output encoding
|
||||||
var msg = '<p class=topWarning><strong>Warning:</strong> ';
|
var msg = '<\p class=topWarning><\strong>Warning:<\/strong> ';
|
||||||
var url = 'ocCheck.php?' + (new Date()).getTime();
|
var url = 'ocCheck.php?' + (new Date()).getTime();
|
||||||
$.get(url, function (ocStatus) {
|
$.get(url, function (ocStatus) {
|
||||||
$.get(url + '&hello=1', function (ocHello) {
|
$.get(url + '&hello=1', function (ocHello) {
|
||||||
@@ -131,13 +131,13 @@ $(function () {
|
|||||||
else
|
else
|
||||||
msg += 'The option "zlib.output_compression" is disabled in your PHP configuration '
|
msg += 'The option "zlib.output_compression" is disabled in your PHP configuration '
|
||||||
+ 'so this behavior is likely due to a server option.';
|
+ 'so this behavior is likely due to a server option.';
|
||||||
$(document.body).prepend(msg + '</p>');
|
$(document.body).prepend(msg + '<\/p>');
|
||||||
} else
|
} else
|
||||||
if (ocStatus == '1')
|
if (ocStatus == '1')
|
||||||
$(document.body).prepend('<p class=topNote><strong>Note:</strong> The option '
|
$(document.body).prepend('<\p class=topNote><\strong>Note:</\strong> The option '
|
||||||
+ '"zlib.output_compression" is enabled in your PHP configuration, but has been '
|
+ '"zlib.output_compression" is enabled in your PHP configuration, but has been '
|
||||||
+ 'successfully disabled via ini_set(). If you experience mangled output you '
|
+ 'successfully disabled via ini_set(). If you experience mangled output you '
|
||||||
+ 'may want to consider disabling this option in your PHP configuration.'
|
+ 'may want to consider disabling this option in your PHP configuration.<\/p>'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -5,6 +5,8 @@
|
|||||||
* @package Minify
|
* @package Minify
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$_oc = ini_get('zlib.output_compression');
|
||||||
|
|
||||||
// allow access only if builder is enabled
|
// allow access only if builder is enabled
|
||||||
require dirname(__FILE__) . '/../config.php';
|
require dirname(__FILE__) . '/../config.php';
|
||||||
if (! $min_enableBuilder) {
|
if (! $min_enableBuilder) {
|
||||||
@@ -30,5 +32,5 @@ if (isset($_GET['hello'])) {
|
|||||||
} else {
|
} else {
|
||||||
// echo status "0" or "1"
|
// echo status "0" or "1"
|
||||||
header('Content-Type: text/plain');
|
header('Content-Type: text/plain');
|
||||||
echo (int)ini_get('zlib.output_compression');
|
echo (int)$_oc;
|
||||||
}
|
}
|
||||||
|
@@ -94,3 +94,6 @@ $min_serveOptions['minApp']['maxFiles'] = 10;
|
|||||||
*/
|
*/
|
||||||
$min_uploaderHoursBehind = 0;
|
$min_uploaderHoursBehind = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// try to disable output_compression (may not have an effect)
|
||||||
|
ini_set('zlib.output_compression', '0');
|
||||||
|
@@ -9,9 +9,6 @@
|
|||||||
|
|
||||||
define('MINIFY_MIN_DIR', dirname(__FILE__));
|
define('MINIFY_MIN_DIR', dirname(__FILE__));
|
||||||
|
|
||||||
// try to disable output_compression (may not have an effect)
|
|
||||||
ini_set('zlib.output_compression', '0');
|
|
||||||
|
|
||||||
// load config
|
// load config
|
||||||
require MINIFY_MIN_DIR . '/config.php';
|
require MINIFY_MIN_DIR . '/config.php';
|
||||||
|
|
||||||
|
@@ -13,3 +13,4 @@ require 'test_Minify_Javascript.php';
|
|||||||
require 'test_Minify_Lines.php';
|
require 'test_Minify_Lines.php';
|
||||||
require 'test_HTTP_Encoder.php';
|
require 'test_HTTP_Encoder.php';
|
||||||
require 'test_HTTP_ConditionalGet.php';
|
require 'test_HTTP_ConditionalGet.php';
|
||||||
|
require 'test_environment.php';
|
||||||
|
63
min_unit_tests/test_environment.php
Normal file
63
min_unit_tests/test_environment.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
|
// called directly
|
||||||
|
if (isset($_GET['getOutputCompression'])) {
|
||||||
|
echo (int)ini_get('zlib.output_compression');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
if (isset($_GET['hello'])) {
|
||||||
|
// try to disable (may not work)
|
||||||
|
ini_set('zlib.output_compression', '0');
|
||||||
|
echo 'World!';
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once '_inc.php';
|
||||||
|
|
||||||
|
function test_environment()
|
||||||
|
{
|
||||||
|
global $thisDir;
|
||||||
|
|
||||||
|
$thisUrl = 'http://'
|
||||||
|
. $_SERVER['SERVER_NAME']
|
||||||
|
. ('80' === $_SERVER['SERVER_PORT'] ? '' : ":{$_SERVER['SERVER_PORT']}")
|
||||||
|
. dirname($_SERVER['REQUEST_URI'])
|
||||||
|
. '/test_environment.php';
|
||||||
|
|
||||||
|
$oc = @file_get_contents($thisUrl . '?getOutputCompression=1');
|
||||||
|
|
||||||
|
if (false === $oc || ! preg_match('/^[01]$/', $oc)) {
|
||||||
|
echo "!WARN: environment : Local HTTP request failed. Testing cannot continue.\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ('1' === $oc) {
|
||||||
|
echo "!WARN: environment : zlib.output_compression is enabled in php.ini or .htaccess.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$fp = fopen($thisUrl . '?hello=1', 'r', false, stream_context_create(array(
|
||||||
|
'http' => array(
|
||||||
|
'method' => "GET",
|
||||||
|
'header' => "Accept-Encoding: deflate, gzip\r\n"
|
||||||
|
)
|
||||||
|
)));
|
||||||
|
|
||||||
|
$meta = stream_get_meta_data($fp);
|
||||||
|
|
||||||
|
$passed = assertTrue(
|
||||||
|
false !== strpos(serialize($meta), '"Content-Length: 6"')
|
||||||
|
,'environment : PHP/server does not auto-HTTP-encode content'
|
||||||
|
);
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
|
if (! $passed) {
|
||||||
|
echo "\nReturned content should be 6 bytes and not HTTP encoded.\n"
|
||||||
|
. "Headers returned by: {$thisUrl}?hello=1\n\n";
|
||||||
|
var_export($meta['wrapper_data']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test_environment();
|
Reference in New Issue
Block a user