1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-10 08:04:14 +02:00

Minify.php : fix for Issue 73 and test

This commit is contained in:
Steve Clay
2009-01-06 16:32:28 +00:00
parent 34349dfe02
commit 039a25fc7c
4 changed files with 67 additions and 40 deletions

View File

@@ -56,7 +56,7 @@ class Minify {
* need to recombine files, minify and encode the output.
*
* @param mixed $cache object with identical interface as Minify_Cache_File or
* a directory path. (default = '')
* a directory path, or null to disable caching. (default = '')
*
* @param bool $fileLocking (default = true) This only applies if the first
* parameter is a string.
@@ -186,7 +186,7 @@ class Minify {
// check client cache
require_once 'HTTP/ConditionalGet.php';
$cgOptions = array(
'lastModifiedTime' => self::$_options['lastModifiedTime']
'lastModifiedTime' => self::$_options['lastModifiedTime']
,'isPublic' => self::$_options['isPublic']
);
if (self::$_options['maxAge'] > 0) {
@@ -402,9 +402,10 @@ class Minify {
protected static function _combineMinify() {
$type = self::$_options['contentType']; // ease readability
// when combining scripts, make sure all statements separated
// when combining scripts, make sure all statements separated and
// trailing single line comment is terminated
$implodeSeparator = ($type === self::TYPE_JS)
? ';'
? "\n;"
: '';
// allow the user to pass a particular array of options to each
// minifier (designated by type). source objects may still override

View File

@@ -0,0 +1,2 @@
// end in comment

View File

@@ -0,0 +1,3 @@
function h() {
}

View File

@@ -20,15 +20,15 @@ function test_Minify()
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s \G\M\T', $lastModified);
$expected = array (
'success' => true
'success' => true
,'statusCode' => 304
,'content' => '',
'headers' => array(
'Expires' => gmdate('D, d M Y H:i:s \G\M\T', $_SERVER['REQUEST_TIME'] + 1800),
'Last-Modified' => gmdate('D, d M Y H:i:s \G\M\T', $lastModified),
'ETag' => "\"{$lastModified}pub\"",
'Cache-Control' => 'max-age=1800, public, must-revalidate',
'_responseCode' => 'HTTP/1.0 304 Not Modified',
'Cache-Control' => 'max-age=1800, public, must-revalidate',
'_responseCode' => 'HTTP/1.0 304 Not Modified',
)
);
$output = Minify::serve('Files', array(
@@ -38,7 +38,7 @@ function test_Minify()
,'encodeOutput' => false
));
$passed = assertTrue($expected === $output, 'Minify : 304 response');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\nOutput: " .var_export($output, 1). "\n\n";
if (! $passed) {
echo "\n\n\n\n---Expected: " .var_export($expected, 1). "\n\n";
@@ -46,7 +46,6 @@ function test_Minify()
}
assertTrue(
//! class_exists('Cache_Lite_File', false)
! class_exists('HTTP_Encoder', false)
&& ! class_exists('Minify_CSS', false)
&& ! class_exists('Minify_Cache', false)
@@ -61,15 +60,15 @@ function test_Minify()
,filemtime($minifyTestPath . '/QueryString.js')
);
$expected = array(
'success' => true
'success' => true
,'statusCode' => 200
// Minify_Javascript always converts to \n line endings
,'content' => $content
,'headers' => array (
'Expires' => gmdate('D, d M Y H:i:s \G\M\T', $tomorrow),
'Last-Modified' => gmdate('D, d M Y H:i:s \G\M\T', $lastModified),
'ETag' => "\"{$lastModified}pub\"",
'Cache-Control' => 'max-age=86400, public, must-revalidate',
'Expires' => gmdate('D, d M Y H:i:s \G\M\T', $tomorrow),
'Last-Modified' => gmdate('D, d M Y H:i:s \G\M\T', $lastModified),
'ETag' => "\"{$lastModified}pub\"",
'Cache-Control' => 'max-age=86400, public, must-revalidate',
'Content-Length' => strlen($content),
'Content-Type' => 'application/x-javascript; charset=UTF-8',
)
@@ -83,15 +82,37 @@ function test_Minify()
,'maxAge' => 86400
,'encodeOutput' => false
));
$passed = assertTrue($expected === $output, 'Minify : JS and Expires');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
$passed = assertTrue($expected === $output, 'Minify : JS and Expires');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\nOutput: " .var_export($output, 1). "\n\n";
if (! $passed) {
echo "\n\n\n\n---Expected: " .var_export($expected, 1). "\n\n";
}
}
// test for Issue 73
Minify::setCache(null);
$expected = ";function h(){}";
$output = Minify::serve('Files', array(
'files' => array(
$minifyTestPath . '/issue73_1.js'
,$minifyTestPath . '/issue73_2.js'
)
,'quiet' => true
,'encodeOutput' => false
));
$output = $output['content'];
$passed = assertTrue($expected === $output, 'Minify : Issue 73');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
if (! $passed) {
echo "\n---Output : " .var_export($output, 1). "\n";
echo "---Expected: " .var_export($expected, 1). "\n\n";
}
}
// Test minifying CSS and responding with Etag/Last-Modified
Minify::setCache();
@@ -105,17 +126,17 @@ function test_Minify()
,substr(dirname(__FILE__), strlen(realpath($_SERVER['DOCUMENT_ROOT'])))
);
$expectedContent = str_replace(
'%PATH_TO_WEB_TEST%'
'%PATH_TO_WEB_TEST%'
,$pathToWebTest
,file_get_contents($minifyTestPath . '/minified.css')
);
$expected = array(
'success' => true
'success' => true
,'statusCode' => 200
,'content' => $expectedContent
,'content' => $expectedContent
,'headers' => array (
'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' => "\"{$lastModified}pub\"",
'Cache-Control' => 'max-age=0, public, must-revalidate',
'Content-Length' => strlen($expectedContent),