mirror of
https://github.com/mrclay/minify.git
synced 2025-08-08 15:16:56 +02:00
Fixed tests & classes in case of mbstring.func_overload & 2 (Issue 132)
Added ability to match multiple strings in URIs for debugging
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
/*!
|
||||||
|
* Minify URI Builder
|
||||||
|
*/
|
||||||
var MUB = {
|
var MUB = {
|
||||||
_uid : 0
|
_uid : 0
|
||||||
,_minRoot : '/min/?'
|
,_minRoot : '/min/?'
|
||||||
|
@@ -3,10 +3,11 @@ javascript:(function(){
|
|||||||
,c = d.cookie
|
,c = d.cookie
|
||||||
,m = c.match(/\bminDebug=([^; ]+)/)
|
,m = c.match(/\bminDebug=([^; ]+)/)
|
||||||
,v = m ? decodeURIComponent(m[1]) : ''
|
,v = m ? decodeURIComponent(m[1]) : ''
|
||||||
,p = prompt('Debug Minify URIs on "' + location.hostname + '" \ncontaining: (empty to disable)', v)
|
,p = prompt('Debug Minify URIs on ' + location.hostname + ' which contain:'
|
||||||
|
+ '\n(empty for none, space = OR)', v)
|
||||||
;
|
;
|
||||||
if (p === null) return;
|
if (p === null) return;
|
||||||
p = p.replace(/\s+/g, '');
|
p = p.replace(/^\s+|\s+$/, '');
|
||||||
v = (p === '')
|
v = (p === '')
|
||||||
? 'minDebug=; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/'
|
? 'minDebug=; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/'
|
||||||
: 'minDebug=' + encodeURIComponent(p) + '; path=/';
|
: 'minDebug=' + encodeURIComponent(p) + '; path=/';
|
||||||
|
@@ -36,9 +36,13 @@ foreach ($min_symlinks as $uri => $target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($min_allowDebugFlag) {
|
if ($min_allowDebugFlag) {
|
||||||
if (! empty($_COOKIE['minDebug'])
|
if (! empty($_COOKIE['minDebug'])) {
|
||||||
&& false !== strpos($_SERVER['REQUEST_URI'], $_COOKIE['minDebug'])) {
|
foreach (preg_split('/\\s+/', $_COOKIE['minDebug']) as $debugUri) {
|
||||||
$min_serveOptions['debug'] = true;
|
if (false !== strpos($_SERVER['REQUEST_URI'], $debugUri)) {
|
||||||
|
$min_serveOptions['debug'] = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// allow GET to override
|
// allow GET to override
|
||||||
if (isset($_GET['debug'])) {
|
if (isset($_GET['debug'])) {
|
||||||
|
@@ -90,8 +90,13 @@ class HTTP_Encoder {
|
|||||||
*/
|
*/
|
||||||
public function __construct($spec)
|
public function __construct($spec)
|
||||||
{
|
{
|
||||||
|
$this->_useMbStrlen = (function_exists('mb_strlen')
|
||||||
|
&& (ini_get('mbstring.func_overload') !== '')
|
||||||
|
&& ((int)ini_get('mbstring.func_overload') & 2));
|
||||||
$this->_content = $spec['content'];
|
$this->_content = $spec['content'];
|
||||||
$this->_headers['Content-Length'] = (string)strlen($this->_content);
|
$this->_headers['Content-Length'] = $this->_useMbStrlen
|
||||||
|
? (string)mb_strlen($this->_content, '8bit')
|
||||||
|
: (string)strlen($this->_content);
|
||||||
if (isset($spec['type'])) {
|
if (isset($spec['type'])) {
|
||||||
$this->_headers['Content-Type'] = $spec['type'];
|
$this->_headers['Content-Type'] = $spec['type'];
|
||||||
}
|
}
|
||||||
@@ -275,7 +280,9 @@ class HTTP_Encoder {
|
|||||||
if (false === $encoded) {
|
if (false === $encoded) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->_headers['Content-Length'] = strlen($encoded);
|
$this->_headers['Content-Length'] = $this->_useMbStrlen
|
||||||
|
? (string)mb_strlen($encoded, '8bit')
|
||||||
|
: (string)strlen($encoded);
|
||||||
$this->_headers['Content-Encoding'] = $this->_encodeMethod[1];
|
$this->_headers['Content-Encoding'] = $this->_encodeMethod[1];
|
||||||
$this->_content = $encoded;
|
$this->_content = $encoded;
|
||||||
return true;
|
return true;
|
||||||
@@ -327,4 +334,5 @@ class HTTP_Encoder {
|
|||||||
protected $_content = '';
|
protected $_content = '';
|
||||||
protected $_headers = array();
|
protected $_headers = array();
|
||||||
protected $_encodeMethod = array('', '');
|
protected $_encodeMethod = array('', '');
|
||||||
|
protected $_useMbStrlen = false;
|
||||||
}
|
}
|
||||||
|
@@ -84,16 +84,6 @@ class JSMin {
|
|||||||
// likely pre-minified and would be broken by JSMin
|
// likely pre-minified and would be broken by JSMin
|
||||||
return $js;
|
return $js;
|
||||||
}
|
}
|
||||||
if (function_exists('mb_strlen')
|
|
||||||
&& (ini_get('mbstring.func_overload') !== '')
|
|
||||||
&& ((int)ini_get('mbstring.func_overload') & 2)) {
|
|
||||||
$enc = mb_internal_encoding();
|
|
||||||
mb_internal_encoding('8bit');
|
|
||||||
$jsmin = new JSMin($js);
|
|
||||||
$ret = $jsmin->min();
|
|
||||||
mb_internal_encoding($enc);
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
$jsmin = new JSMin($js);
|
$jsmin = new JSMin($js);
|
||||||
return $jsmin->min();
|
return $jsmin->min();
|
||||||
}
|
}
|
||||||
@@ -107,8 +97,7 @@ class JSMin {
|
|||||||
*/
|
*/
|
||||||
public function __construct($input)
|
public function __construct($input)
|
||||||
{
|
{
|
||||||
$this->input = str_replace("\r\n", "\n", $input);
|
$this->input = $input;
|
||||||
$this->inputLength = strlen($this->input);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -119,6 +108,15 @@ class JSMin {
|
|||||||
if ($this->output !== '') { // min already run
|
if ($this->output !== '') { // min already run
|
||||||
return $this->output;
|
return $this->output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$mbIntEnc = null;
|
||||||
|
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
||||||
|
$mbIntEnc = mb_internal_encoding();
|
||||||
|
mb_internal_encoding('8bit');
|
||||||
|
}
|
||||||
|
$this->input = str_replace("\r\n", "\n", $this->input);
|
||||||
|
$this->inputLength = strlen($this->input);
|
||||||
|
|
||||||
$this->action(self::ACTION_DELETE_A_B);
|
$this->action(self::ACTION_DELETE_A_B);
|
||||||
|
|
||||||
while ($this->a !== null) {
|
while ($this->a !== null) {
|
||||||
@@ -131,8 +129,11 @@ class JSMin {
|
|||||||
} elseif ($this->a === "\n") {
|
} elseif ($this->a === "\n") {
|
||||||
if ($this->b === ' ') {
|
if ($this->b === ' ') {
|
||||||
$command = self::ACTION_DELETE_A_B;
|
$command = self::ACTION_DELETE_A_B;
|
||||||
} elseif (false === strpos('{[(+-', $this->b)
|
// in case of mbstring.func_overload & 2, must check for null b,
|
||||||
&& ! $this->isAlphaNum($this->b)) {
|
// otherwise mb_strpos will give WARNING
|
||||||
|
} elseif ($this->b === null
|
||||||
|
|| (false === strpos('{[(+-', $this->b)
|
||||||
|
&& ! $this->isAlphaNum($this->b))) {
|
||||||
$command = self::ACTION_DELETE_A;
|
$command = self::ACTION_DELETE_A;
|
||||||
}
|
}
|
||||||
} elseif (! $this->isAlphaNum($this->a)) {
|
} elseif (! $this->isAlphaNum($this->a)) {
|
||||||
@@ -145,6 +146,10 @@ class JSMin {
|
|||||||
$this->action($command);
|
$this->action($command);
|
||||||
}
|
}
|
||||||
$this->output = trim($this->output);
|
$this->output = trim($this->output);
|
||||||
|
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return $this->output;
|
return $this->output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,7 +29,7 @@ require_once 'Minify/Source.php';
|
|||||||
*/
|
*/
|
||||||
class Minify {
|
class Minify {
|
||||||
|
|
||||||
const VERSION = '2.1.3';
|
const VERSION = '2.1.4';
|
||||||
const TYPE_CSS = 'text/css';
|
const TYPE_CSS = 'text/css';
|
||||||
const TYPE_HTML = 'text/html';
|
const TYPE_HTML = 'text/html';
|
||||||
// there is some debate over the ideal JS Content-Type, but this is the
|
// there is some debate over the ideal JS Content-Type, but this is the
|
||||||
@@ -312,12 +312,9 @@ class Minify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add headers
|
// add headers
|
||||||
$hasMbOverload = (function_exists('mb_strlen')
|
|
||||||
&& (ini_get('mbstring.func_overload') !== '')
|
|
||||||
&& ((int)ini_get('mbstring.func_overload') & 2));
|
|
||||||
$headers['Content-Length'] = $cacheIsReady
|
$headers['Content-Length'] = $cacheIsReady
|
||||||
? $cacheContentLength
|
? $cacheContentLength
|
||||||
: ($hasMbOverload
|
: ((function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
||||||
? mb_strlen($content, '8bit')
|
? mb_strlen($content, '8bit')
|
||||||
: strlen($content)
|
: strlen($content)
|
||||||
);
|
);
|
||||||
|
@@ -54,9 +54,12 @@ class Minify_Cache_APC {
|
|||||||
*/
|
*/
|
||||||
public function getSize($id)
|
public function getSize($id)
|
||||||
{
|
{
|
||||||
return $this->_fetch($id)
|
if (! $this->_fetch($id)) {
|
||||||
? strlen($this->_data)
|
return false;
|
||||||
: false;
|
}
|
||||||
|
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
||||||
|
? mb_strlen($this->_data, '8bit')
|
||||||
|
: strlen($this->_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -60,9 +60,12 @@ class Minify_Cache_Memcache {
|
|||||||
*/
|
*/
|
||||||
public function getSize($id)
|
public function getSize($id)
|
||||||
{
|
{
|
||||||
return $this->_fetch($id)
|
if (! $this->_fetch($id)) {
|
||||||
? strlen($this->_data)
|
return false;
|
||||||
: false;
|
}
|
||||||
|
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
||||||
|
? mb_strlen($this->_data, '8bit')
|
||||||
|
: strlen($this->_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
require_once 'Minify/Controller/Base.php';
|
require_once 'Minify/Controller/Base.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller class for emulating version 1 of minify.php
|
* Controller class for emulating version 1 of minify.php (mostly a proof-of-concept)
|
||||||
*
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* Minify::serve('Version1');
|
* Minify::serve('Version1');
|
||||||
|
@@ -24,7 +24,7 @@ if ($min_errorLogger && true !== $min_errorLogger) { // custom logger
|
|||||||
error_reporting(E_ALL | E_STRICT);
|
error_reporting(E_ALL | E_STRICT);
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
|
|
||||||
header('Content-Type: text/plain');
|
header('Content-Type: text/plain;charset=utf-8');
|
||||||
|
|
||||||
$thisDir = dirname(__FILE__);
|
$thisDir = dirname(__FILE__);
|
||||||
|
|
||||||
@@ -47,4 +47,17 @@ function assertTrue($test, $message)
|
|||||||
return (bool)$test;
|
return (bool)$test;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get number of bytes in a string regardless of mbstring.func_overload
|
||||||
|
*
|
||||||
|
* @param string $str
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
function countBytes($str)
|
||||||
|
{
|
||||||
|
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
||||||
|
? mb_strlen($str, '8bit')
|
||||||
|
: strlen($str);
|
||||||
|
}
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
7
min_unit_tests/_test_files/js/issue132.js
Normal file
7
min_unit_tests/_test_files/js/issue132.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// from jQuery tablesorter
|
||||||
|
ts.addParser({
|
||||||
|
id: "currency",
|
||||||
|
is: function(s) {
|
||||||
|
return /^[£$€?.]/.test(s);
|
||||||
|
},
|
||||||
|
});
|
1
min_unit_tests/_test_files/js/issue132.min.js
vendored
Normal file
1
min_unit_tests/_test_files/js/issue132.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ts.addParser({id:"currency",is:function(s){return /^[£$€?.]/.test(s);},});
|
@@ -1,4 +1,4 @@
|
|||||||
var MrClay = window.MrClay || {};
|
var MrClay = window.MrClay || {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simplified access to/manipulation of the query string
|
* Simplified access to/manipulation of the query string
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// http://mrclay.org/
|
// http://mrclay.org/
|
||||||
(function(){
|
(function(){
|
||||||
var
|
var
|
||||||
reMailto = /^mailto:my_name_is_(\S+)_and_the_domain_is_(\S+)$/,
|
reMailto = /^mailto:my_name_is_(\S+)_and_the_domain_is_(\S+)$/,
|
||||||
|
@@ -94,10 +94,11 @@ function test_HTTP_Encoder()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test compression of varied content (HTML,JS, & CSS)
|
// test compression of varied content (HTML,JS, & CSS)
|
||||||
|
|
||||||
$variedContent = file_get_contents($thisDir . '/_test_files/html/before.html')
|
$variedContent = file_get_contents($thisDir . '/_test_files/html/before.html')
|
||||||
. file_get_contents($thisDir . '/_test_files/css/subsilver.css')
|
. file_get_contents($thisDir . '/_test_files/css/subsilver.css')
|
||||||
. file_get_contents($thisDir . '/_test_files/js/jquery-1.2.3.js');
|
. file_get_contents($thisDir . '/_test_files/js/jquery-1.2.3.js');
|
||||||
$variedLength = strlen($variedContent);
|
$variedLength = countBytes($variedContent);
|
||||||
|
|
||||||
$encodingTests = array(
|
$encodingTests = array(
|
||||||
array('method' => 'deflate', 'inv' => 'gzinflate', 'exp' => 32157)
|
array('method' => 'deflate', 'inv' => 'gzinflate', 'exp' => 32157)
|
||||||
@@ -111,7 +112,7 @@ function test_HTTP_Encoder()
|
|||||||
,'method' => $test['method']
|
,'method' => $test['method']
|
||||||
));
|
));
|
||||||
$e->encode(9);
|
$e->encode(9);
|
||||||
$ret = strlen($e->getContent());
|
$ret = countBytes($e->getContent());
|
||||||
|
|
||||||
// test uncompression
|
// test uncompression
|
||||||
$roundTrip = @call_user_func($test['inv'], $e->getContent());
|
$roundTrip = @call_user_func($test['inv'], $e->getContent());
|
||||||
@@ -154,15 +155,31 @@ function _gzdecode($data)
|
|||||||
// http://www.php.net/manual/en/function.gzdecode.php#82930
|
// http://www.php.net/manual/en/function.gzdecode.php#82930
|
||||||
function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
||||||
{
|
{
|
||||||
|
$mbIntEnc = null;
|
||||||
|
$hasMbOverload = (function_exists('mb_strlen')
|
||||||
|
&& (ini_get('mbstring.func_overload') !== '')
|
||||||
|
&& ((int)ini_get('mbstring.func_overload') & 2));
|
||||||
|
if ($hasMbOverload) {
|
||||||
|
$mbIntEnc = mb_internal_encoding();
|
||||||
|
mb_internal_encoding('8bit');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$len = strlen($data);
|
$len = strlen($data);
|
||||||
if ($len < 18 || strcmp(substr($data,0,2),"\x1f\x8b")) {
|
if ($len < 18 || strcmp(substr($data,0,2),"\x1f\x8b")) {
|
||||||
$error = "Not in GZIP format.";
|
$error = "Not in GZIP format.";
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return null; // Not GZIP format (See RFC 1952)
|
return null; // Not GZIP format (See RFC 1952)
|
||||||
}
|
}
|
||||||
$method = ord(substr($data,2,1)); // Compression method
|
$method = ord(substr($data,2,1)); // Compression method
|
||||||
$flags = ord(substr($data,3,1)); // Flags
|
$flags = ord(substr($data,3,1)); // Flags
|
||||||
if ($flags & 31 != $flags) {
|
if ($flags & 31 != $flags) {
|
||||||
$error = "Reserved bits not allowed.";
|
$error = "Reserved bits not allowed.";
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// NOTE: $mtime may be negative (PHP integer limitations)
|
// NOTE: $mtime may be negative (PHP integer limitations)
|
||||||
@@ -176,11 +193,17 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
if ($flags & 4) {
|
if ($flags & 4) {
|
||||||
// 2-byte length prefixed EXTRA data in header
|
// 2-byte length prefixed EXTRA data in header
|
||||||
if ($len - $headerlen - 2 < 8) {
|
if ($len - $headerlen - 2 < 8) {
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return false; // invalid
|
return false; // invalid
|
||||||
}
|
}
|
||||||
$extralen = unpack("v",substr($data,8,2));
|
$extralen = unpack("v",substr($data,8,2));
|
||||||
$extralen = $extralen[1];
|
$extralen = $extralen[1];
|
||||||
if ($len - $headerlen - 2 - $extralen < 8) {
|
if ($len - $headerlen - 2 - $extralen < 8) {
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return false; // invalid
|
return false; // invalid
|
||||||
}
|
}
|
||||||
$extra = substr($data,10,$extralen);
|
$extra = substr($data,10,$extralen);
|
||||||
@@ -191,10 +214,16 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
if ($flags & 8) {
|
if ($flags & 8) {
|
||||||
// C-style string
|
// C-style string
|
||||||
if ($len - $headerlen - 1 < 8) {
|
if ($len - $headerlen - 1 < 8) {
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return false; // invalid
|
return false; // invalid
|
||||||
}
|
}
|
||||||
$filenamelen = strpos(substr($data,$headerlen),chr(0));
|
$filenamelen = strpos(substr($data,$headerlen),chr(0));
|
||||||
if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) {
|
if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) {
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return false; // invalid
|
return false; // invalid
|
||||||
}
|
}
|
||||||
$filename = substr($data,$headerlen,$filenamelen);
|
$filename = substr($data,$headerlen,$filenamelen);
|
||||||
@@ -205,10 +234,16 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
if ($flags & 16) {
|
if ($flags & 16) {
|
||||||
// C-style string COMMENT data in header
|
// C-style string COMMENT data in header
|
||||||
if ($len - $headerlen - 1 < 8) {
|
if ($len - $headerlen - 1 < 8) {
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return false; // invalid
|
return false; // invalid
|
||||||
}
|
}
|
||||||
$commentlen = strpos(substr($data,$headerlen),chr(0));
|
$commentlen = strpos(substr($data,$headerlen),chr(0));
|
||||||
if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) {
|
if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) {
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return false; // Invalid header format
|
return false; // Invalid header format
|
||||||
}
|
}
|
||||||
$comment = substr($data,$headerlen,$commentlen);
|
$comment = substr($data,$headerlen,$commentlen);
|
||||||
@@ -218,6 +253,9 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
if ($flags & 2) {
|
if ($flags & 2) {
|
||||||
// 2-bytes (lowest order) of CRC32 on header present
|
// 2-bytes (lowest order) of CRC32 on header present
|
||||||
if ($len - $headerlen - 2 < 8) {
|
if ($len - $headerlen - 2 < 8) {
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return false; // invalid
|
return false; // invalid
|
||||||
}
|
}
|
||||||
$calccrc = crc32(substr($data,0,$headerlen)) & 0xffff;
|
$calccrc = crc32(substr($data,0,$headerlen)) & 0xffff;
|
||||||
@@ -225,6 +263,9 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
$headercrc = $headercrc[1];
|
$headercrc = $headercrc[1];
|
||||||
if ($headercrc != $calccrc) {
|
if ($headercrc != $calccrc) {
|
||||||
$error = "Header checksum failed.";
|
$error = "Header checksum failed.";
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return false; // Bad header CRC
|
return false; // Bad header CRC
|
||||||
}
|
}
|
||||||
$headerlen += 2;
|
$headerlen += 2;
|
||||||
@@ -238,6 +279,9 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
$bodylen = $len-$headerlen-8;
|
$bodylen = $len-$headerlen-8;
|
||||||
if ($bodylen < 1) {
|
if ($bodylen < 1) {
|
||||||
// IMPLEMENTATION BUG!
|
// IMPLEMENTATION BUG!
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$body = substr($data,$headerlen,$bodylen);
|
$body = substr($data,$headerlen,$bodylen);
|
||||||
@@ -250,6 +294,9 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$error = "Unknown compression method.";
|
$error = "Unknown compression method.";
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} // zero-byte body content is allowed
|
} // zero-byte body content is allowed
|
||||||
@@ -259,7 +306,11 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
$lenOK = $isize == strlen($data);
|
$lenOK = $isize == strlen($data);
|
||||||
if (!$lenOK || !$crcOK) {
|
if (!$lenOK || !$crcOK) {
|
||||||
$error = ( $lenOK ? '' : 'Length check FAILED. ') . ( $crcOK ? '' : 'Checksum FAILED.');
|
$error = ( $lenOK ? '' : 'Length check FAILED. ') . ( $crcOK ? '' : 'Checksum FAILED.');
|
||||||
return false;
|
$ret = false;
|
||||||
}
|
}
|
||||||
return $data;
|
$ret = $data;
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
}
|
}
|
@@ -10,45 +10,52 @@ function test_JSMin()
|
|||||||
$src = file_get_contents($thisDir . '/_test_files/js/before.js');
|
$src = file_get_contents($thisDir . '/_test_files/js/before.js');
|
||||||
$minExpected = file_get_contents($thisDir . '/_test_files/js/before.min.js');
|
$minExpected = file_get_contents($thisDir . '/_test_files/js/before.min.js');
|
||||||
$minOutput = JSMin::minify($src);
|
$minOutput = JSMin::minify($src);
|
||||||
|
|
||||||
$passed = assertTrue($minExpected == $minOutput, 'JSMin : Overall');
|
$passed = assertTrue($minExpected == $minOutput, 'JSMin : Overall');
|
||||||
|
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
|
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||||
echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
|
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||||
echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";
|
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$src = file_get_contents($thisDir . '/_test_files/js/issue144.js');
|
$src = file_get_contents($thisDir . '/_test_files/js/issue144.js');
|
||||||
$minExpected = file_get_contents($thisDir . '/_test_files/js/issue144.min.js');
|
$minExpected = file_get_contents($thisDir . '/_test_files/js/issue144.min.js');
|
||||||
$minOutput = JSMin::minify($src);
|
$minOutput = JSMin::minify($src);
|
||||||
|
|
||||||
$passed = assertTrue($minExpected == $minOutput, 'JSMin : Don\'t minify files with + ++ (Issue 144)');
|
$passed = assertTrue($minExpected == $minOutput, 'JSMin : Don\'t minify files with + ++ (Issue 144)');
|
||||||
|
|
||||||
|
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
||||||
|
$src = file_get_contents($thisDir . '/_test_files/js/issue132.js');
|
||||||
|
$minExpected = file_get_contents($thisDir . '/_test_files/js/issue132.min.js');
|
||||||
|
$minOutput = JSMin::minify($src);
|
||||||
|
$passed = assertTrue($minExpected == $minOutput, 'JSMin : mbstring.func_overload shouldn\'t cause failure (Issue 132)');
|
||||||
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
|
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||||
|
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||||
|
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$src = file_get_contents($thisDir . '/_test_files/js/issue74.js');
|
$src = file_get_contents($thisDir . '/_test_files/js/issue74.js');
|
||||||
$minExpected = file_get_contents($thisDir . '/_test_files/js/issue74.min.js');
|
$minExpected = file_get_contents($thisDir . '/_test_files/js/issue74.min.js');
|
||||||
$minOutput = JSMin::minify($src);
|
$minOutput = JSMin::minify($src);
|
||||||
|
|
||||||
$passed = assertTrue($minExpected == $minOutput, 'JSMin : Quotes in RegExp literals (Issue 74)');
|
$passed = assertTrue($minExpected == $minOutput, 'JSMin : Quotes in RegExp literals (Issue 74)');
|
||||||
|
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
|
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||||
echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
|
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||||
echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";
|
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||||
|
|
||||||
|
// only test exceptions on this page
|
||||||
test_JSMin_exception('"Hello'
|
test_JSMin_exception('"Hello'
|
||||||
,'Unterminated String'
|
,'Unterminated String'
|
||||||
,'JSMin_UnterminatedStringException'
|
,'JSMin_UnterminatedStringException'
|
||||||
,"Unterminated String: \"Hello");
|
,"JSMin: Unterminated String at byte 6: \"Hello");
|
||||||
test_JSMin_exception("return /regexp\n}"
|
test_JSMin_exception("return /regexp\n}"
|
||||||
,'Unterminated RegExp'
|
,'Unterminated RegExp'
|
||||||
,'JSMin_UnterminatedRegExpException'
|
,'JSMin_UnterminatedRegExpException'
|
||||||
,"Unterminated RegExp: /regexp\n");
|
,"JSMin: Unterminated RegExp at byte 15: /regexp\n");
|
||||||
test_JSMin_exception("/* Comment "
|
test_JSMin_exception("/* Comment "
|
||||||
,'Unterminated Comment'
|
,'Unterminated Comment'
|
||||||
,'JSMin_UnterminatedCommentException'
|
,'JSMin_UnterminatedCommentException'
|
||||||
,"Unterminated Comment: /* Comment ");
|
,"JSMin: Unterminated comment at byte 11: /* Comment ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,9 +15,9 @@ function test_JSMinPlus()
|
|||||||
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Conditional Comments');
|
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Conditional Comments');
|
||||||
|
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
|
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||||
echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
|
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||||
echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";
|
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -30,9 +30,9 @@ function test_JSMinPlus()
|
|||||||
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Overall');
|
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Overall');
|
||||||
|
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
|
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||||
echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
|
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||||
echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";
|
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$src = file_get_contents($thisDir . '/_test_files/js/issue74.js');
|
$src = file_get_contents($thisDir . '/_test_files/js/issue74.js');
|
||||||
@@ -42,39 +42,10 @@ function test_JSMinPlus()
|
|||||||
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Quotes in RegExp literals (Issue 74)');
|
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Quotes in RegExp literals (Issue 74)');
|
||||||
|
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
|
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||||
echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
|
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||||
echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";
|
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||||
/*
|
|
||||||
test_JSMin_exception('"Hello'
|
|
||||||
,'Unterminated String'
|
|
||||||
,'JSMin_UnterminatedStringException'
|
|
||||||
,"Unterminated String: '\"Hello'");
|
|
||||||
test_JSMin_exception("return /regexp\n}"
|
|
||||||
,'Unterminated RegExp'
|
|
||||||
,'JSMin_UnterminatedRegExpException'
|
|
||||||
,"Unterminated RegExp: '/regexp\n'");
|
|
||||||
test_JSMin_exception("/* Comment "
|
|
||||||
,'Unterminated Comment'
|
|
||||||
,'JSMin_UnterminatedCommentException'
|
|
||||||
,"Unterminated Comment: '/* Comment '");
|
|
||||||
//*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*function test_JSMin_exception($js, $label, $expClass, $expMessage) {
|
|
||||||
$eClass = $eMsg = '';
|
|
||||||
try {
|
|
||||||
JSMin::minify($js);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$eClass = get_class($e);
|
|
||||||
$eMsg = $e->getMessage();
|
|
||||||
}
|
|
||||||
$passed = assertTrue($eClass === $expClass && $eMsg === $expMessage,
|
|
||||||
'JSMin : throw on ' . $label);
|
|
||||||
if (! $passed && __FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
|
||||||
echo "\n ---" , $e, "\n\n";
|
|
||||||
}
|
|
||||||
}//*/
|
|
||||||
|
|
||||||
test_JSMinPlus();
|
test_JSMinPlus();
|
||||||
|
@@ -71,7 +71,7 @@ function test_Minify()
|
|||||||
'Last-Modified' => gmdate('D, d M Y H:i:s \G\M\T', $lastModified),
|
'Last-Modified' => gmdate('D, d M Y H:i:s \G\M\T', $lastModified),
|
||||||
'ETag' => "\"pub{$lastModified}\"",
|
'ETag' => "\"pub{$lastModified}\"",
|
||||||
'Cache-Control' => 'max-age=86400',
|
'Cache-Control' => 'max-age=86400',
|
||||||
'Content-Length' => strlen($content),
|
'Content-Length' => countBytes($content),
|
||||||
'Content-Type' => 'application/x-javascript; charset=utf-8',
|
'Content-Type' => 'application/x-javascript; charset=utf-8',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -170,9 +170,17 @@ function test_Minify()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test minifying CSS and responding with Etag/Last-Modified
|
// Test Issue 132
|
||||||
|
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
||||||
|
$output = Minify::serve('Files', array(
|
||||||
|
'files' => array(dirname(__FILE__) . '/_test_files/js/issue132.js')
|
||||||
|
,'quiet' => true
|
||||||
|
,'encodeOutput' => false
|
||||||
|
));
|
||||||
|
$passed = assertTrue($output['headers']['Content-Length'] == 77, 'Minify : Issue 132 : mbstring.func_overload shouldn\'t cause incorrect Content-Length');
|
||||||
|
}
|
||||||
|
|
||||||
Minify::setCache(null);
|
// Test minifying CSS and responding with Etag/Last-Modified
|
||||||
|
|
||||||
// don't allow conditional headers
|
// don't allow conditional headers
|
||||||
unset($_SERVER['HTTP_IF_NONE_MATCH'], $_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
unset($_SERVER['HTTP_IF_NONE_MATCH'], $_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
||||||
@@ -188,7 +196,7 @@ function test_Minify()
|
|||||||
'Last-Modified' => gmdate('D, d M Y H:i:s \G\M\T', $lastModified),
|
'Last-Modified' => gmdate('D, d M Y H:i:s \G\M\T', $lastModified),
|
||||||
'ETag' => "\"pub{$lastModified}\"",
|
'ETag' => "\"pub{$lastModified}\"",
|
||||||
'Cache-Control' => 'max-age=0',
|
'Cache-Control' => 'max-age=0',
|
||||||
'Content-Length' => strlen($expectedContent),
|
'Content-Length' => countBytes($expectedContent),
|
||||||
'Content-Type' => 'text/css; charset=utf-8',
|
'Content-Type' => 'text/css; charset=utf-8',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@@ -41,10 +41,10 @@ function test_CSS()
|
|||||||
$passed = assertTrue($minExpected === $minOutput, 'Minify_CSS : ' . $item);
|
$passed = assertTrue($minExpected === $minOutput, 'Minify_CSS : ' . $item);
|
||||||
|
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
|
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||||
if (!$passed) {
|
if (!$passed) {
|
||||||
echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
|
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||||
echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";
|
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,9 +20,9 @@ function test_Minify_CSS_UriRewriter()
|
|||||||
$passed = assertTrue($expected === $actual, 'Minify_CSS_UriRewriter');
|
$passed = assertTrue($expected === $actual, 'Minify_CSS_UriRewriter');
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
echo "\n---Input:\n\n{$in}\n";
|
echo "\n---Input:\n\n{$in}\n";
|
||||||
echo "\n---Output: " .strlen($actual). " bytes\n\n{$actual}\n\n";
|
echo "\n---Output: " .countBytes($actual). " bytes\n\n{$actual}\n\n";
|
||||||
if (!$passed) {
|
if (!$passed) {
|
||||||
echo "---Expected: " .strlen($expected). " bytes\n\n{$expected}\n\n\n";
|
echo "---Expected: " .countBytes($expected). " bytes\n\n{$expected}\n\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// show debugging only when test run directly
|
// show debugging only when test run directly
|
||||||
@@ -42,9 +42,9 @@ function test_Minify_CSS_UriRewriter()
|
|||||||
$passed = assertTrue($exp === $actual, 'Minify_CSS_UriRewriter : Issue 99');
|
$passed = assertTrue($exp === $actual, 'Minify_CSS_UriRewriter : Issue 99');
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
echo "\n---Input:\n\n{$in}\n";
|
echo "\n---Input:\n\n{$in}\n";
|
||||||
echo "\n---Output: " .strlen($actual). " bytes\n\n{$actual}\n\n";
|
echo "\n---Output: " .countBytes($actual). " bytes\n\n{$actual}\n\n";
|
||||||
if (!$passed) {
|
if (!$passed) {
|
||||||
echo "---Expected: " .strlen($exp). " bytes\n\n{$exp}\n\n\n";
|
echo "---Expected: " .countBytes($exp). " bytes\n\n{$exp}\n\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// show debugging only when test run directly
|
// show debugging only when test run directly
|
||||||
|
@@ -9,14 +9,14 @@ function test_Minify_Cache_APC()
|
|||||||
if (! function_exists('apc_store')) {
|
if (! function_exists('apc_store')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$data = str_repeat(md5('testing'), 160);
|
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||||
$id = 'Minify_test_cache';
|
$id = 'Minify_test_cache';
|
||||||
|
|
||||||
$cache = new Minify_Cache_APC();
|
$cache = new Minify_Cache_APC();
|
||||||
|
|
||||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
||||||
|
|
||||||
assertTrue(strlen($data) === $cache->getSize($id), $prefix . 'getSize');
|
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||||
|
|
||||||
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@ function test_Minify_Cache_File()
|
|||||||
{
|
{
|
||||||
global $minifyCachePath;
|
global $minifyCachePath;
|
||||||
|
|
||||||
$data = str_repeat(md5(time()), 160);
|
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||||
$id = 'Minify_test_cache_noLock';
|
$id = 'Minify_test_cache_noLock';
|
||||||
$prefix = 'Minify_Cache_File : ';
|
$prefix = 'Minify_Cache_File : ';
|
||||||
|
|
||||||
@@ -16,8 +16,8 @@ function test_Minify_Cache_File()
|
|||||||
echo "NOTE: Minify_Cache_File : path is set to: '" . $cache->getPath() . "'.\n";
|
echo "NOTE: Minify_Cache_File : path is set to: '" . $cache->getPath() . "'.\n";
|
||||||
|
|
||||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
||||||
|
|
||||||
assertTrue(strlen($data) === $cache->getSize($id), $prefix . 'getSize');
|
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||||
|
|
||||||
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
||||||
|
|
||||||
@@ -28,26 +28,26 @@ function test_Minify_Cache_File()
|
|||||||
|
|
||||||
assertTrue($data === $displayed, $prefix . 'display');
|
assertTrue($data === $displayed, $prefix . 'display');
|
||||||
|
|
||||||
assertTrue($data === $cache->fetch($id), $prefix . 'fetch');
|
assertTrue($data === $cache->fetch($id), $prefix . 'fetch');
|
||||||
|
|
||||||
// test with locks
|
// test with locks
|
||||||
|
|
||||||
$id = 'Minify_test_cache_withLock';
|
$id = 'Minify_test_cache_withLock';
|
||||||
$cache = new Minify_Cache_File($minifyCachePath, true);
|
$cache = new Minify_Cache_File($minifyCachePath, true);
|
||||||
|
|
||||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store w/ lock');
|
assertTrue(true === $cache->store($id, $data), $prefix . 'store w/ lock');
|
||||||
|
|
||||||
assertTrue(strlen($data) === $cache->getSize($id), $prefix . 'getSize');
|
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||||
|
|
||||||
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$cache->display($id);
|
$cache->display($id);
|
||||||
$displayed = ob_get_contents();
|
$displayed = ob_get_contents();
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
|
|
||||||
assertTrue($data === $displayed, $prefix . 'display w/ lock');
|
assertTrue($data === $displayed, $prefix . 'display w/ lock');
|
||||||
|
|
||||||
assertTrue($data === $cache->fetch($id), $prefix . 'fetch w/ lock');
|
assertTrue($data === $cache->fetch($id), $prefix . 'fetch w/ lock');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,14 +14,14 @@ function test_Minify_Cache_Memcache()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = str_repeat(md5('testing'), 160);
|
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||||
$id = 'Minify_test_cache';
|
$id = 'Minify_test_cache';
|
||||||
|
|
||||||
$cache = new Minify_Cache_Memcache($mc);
|
$cache = new Minify_Cache_Memcache($mc);
|
||||||
|
|
||||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
||||||
|
|
||||||
assertTrue(strlen($data) === $cache->getSize($id), $prefix . 'getSize');
|
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||||
|
|
||||||
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
||||||
|
|
||||||
|
@@ -19,9 +19,9 @@ function test_Minify_CommentPreserver()
|
|||||||
$actual = Minify_CommentPreserver::process($in, '_test_MCP_processor');
|
$actual = Minify_CommentPreserver::process($in, '_test_MCP_processor');
|
||||||
$passed = assertTrue($expected === $actual, 'Minify_CommentPreserver');
|
$passed = assertTrue($expected === $actual, 'Minify_CommentPreserver');
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
echo "\n---Output: " .strlen($actual). " bytes\n\n{$actual}\n\n";
|
echo "\n---Output: " .countBytes($actual). " bytes\n\n{$actual}\n\n";
|
||||||
if (!$passed) {
|
if (!$passed) {
|
||||||
echo "---Expected: " .strlen($expected). " bytes\n\n{$expected}\n\n\n";
|
echo "---Expected: " .countBytes($expected). " bytes\n\n{$expected}\n\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,12 +23,12 @@ function test_HTML()
|
|||||||
|
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
if ($passed) {
|
if ($passed) {
|
||||||
echo "\n---Source: ", strlen($src), " bytes\n"
|
echo "\n---Source: ", countBytes($src), " bytes\n"
|
||||||
, "---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n\n";
|
, "---Output: ", countBytes($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n\n";
|
||||||
} else {
|
} else {
|
||||||
echo "\n---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n"
|
echo "\n---Output: ", countBytes($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n"
|
||||||
, "---Expected: ", strlen($minExpected), " bytes\n\n{$minExpected}\n\n"
|
, "---Expected: ", countBytes($minExpected), " bytes\n\n{$minExpected}\n\n"
|
||||||
, "---Source: ", strlen($src), " bytes\n\n{$src}\n\n\n";
|
, "---Source: ", countBytes($src), " bytes\n\n{$src}\n\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,12 +46,12 @@ function test_HTML()
|
|||||||
|
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
if ($passed) {
|
if ($passed) {
|
||||||
echo "\n---Source: ", strlen($src), " bytes\n"
|
echo "\n---Source: ", countBytes($src), " bytes\n"
|
||||||
, "---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n\n";
|
, "---Output: ", countBytes($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n\n";
|
||||||
} else {
|
} else {
|
||||||
echo "\n---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n"
|
echo "\n---Output: ", countBytes($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n"
|
||||||
, "---Expected: ", strlen($minExpected), " bytes\n\n{$minExpected}\n\n"
|
, "---Expected: ", countBytes($minExpected), " bytes\n\n{$minExpected}\n\n"
|
||||||
, "---Source: ", strlen($src), " bytes\n\n{$src}\n\n\n";
|
, "---Source: ", countBytes($src), " bytes\n\n{$src}\n\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,18 +27,18 @@ function test_Minify_ImportProcessor()
|
|||||||
$passed = assertTrue($expected === $actual, 'ImportProcessor');
|
$passed = assertTrue($expected === $actual, 'ImportProcessor');
|
||||||
|
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
echo "\n---Output: " .strlen($actual). " bytes\n\n{$actual}\n\n";
|
echo "\n---Output: " .countBytes($actual). " bytes\n\n{$actual}\n\n";
|
||||||
if (!$passed) {
|
if (!$passed) {
|
||||||
echo "---Expected: " .strlen($expected). " bytes\n\n{$expected}\n\n\n";
|
echo "---Expected: " .countBytes($expected). " bytes\n\n{$expected}\n\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$expectedIncludes = array (
|
$expectedIncludes = array (
|
||||||
realpath($linDir . '/input.css')
|
realpath($linDir . '/input.css')
|
||||||
,realpath($linDir . '/adjacent.css')
|
,realpath($linDir . '/adjacent.css')
|
||||||
,realpath($linDir . '/../css/styles.css')
|
,realpath($linDir . '/../css/styles.css')
|
||||||
,realpath($linDir . '/1/tv.css')
|
,realpath($linDir . '/1/tv.css')
|
||||||
,realpath($linDir . '/1/adjacent.css')
|
,realpath($linDir . '/1/adjacent.css')
|
||||||
);
|
);
|
||||||
|
|
||||||
$passed = assertTrue($expectedIncludes === Minify_ImportProcessor::$filesIncluded
|
$passed = assertTrue($expectedIncludes === Minify_ImportProcessor::$filesIncluded
|
||||||
|
@@ -26,9 +26,9 @@ function test_Lines()
|
|||||||
$passed = assertTrue($exp === $ret['content'], 'Minify_Lines');
|
$passed = assertTrue($exp === $ret['content'], 'Minify_Lines');
|
||||||
|
|
||||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
echo "\n---Output: " .strlen($ret['content']). " bytes\n\n{$ret['content']}\n\n";
|
echo "\n---Output: " .countBytes($ret['content']). " bytes\n\n{$ret['content']}\n\n";
|
||||||
if (!$passed) {
|
if (!$passed) {
|
||||||
echo "---Expected: " .strlen($exp). " bytes\n\n{$exp}\n\n\n";
|
echo "---Expected: " .countBytes($exp). " bytes\n\n{$exp}\n\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user