1
0
mirror of https://github.com/mrclay/minify.git synced 2025-09-19 10:21:31 +02:00

23 Commits
2.2.0 ... 2.2.1

Author SHA1 Message Date
Steve Clay
3c11ba8232 Merge pull request #128 from fisharebest/gitattributes
Exclude build/development tools from releases using .gitattributes
2014-10-30 18:58:02 -04:00
Greg Roach
ecbb5ae376 Exclude build/development tools from releases using .gitattributes 2014-10-24 09:29:20 +01:00
Elan Ruusamäe
bd9a450694 update cssmin to v2.4.8-4. fixes #123 2014-09-25 14:40:53 +03:00
Elan Ruusamäe
bceffd5afb remove duplicate $keys assignment 2014-09-21 14:31:30 +03:00
acidvertigo
153e08b5a0 Code clean 2014-09-20 14:21:31 +03:00
Elan Ruusamäe
ce109925aa remove two DOS EOL 2014-09-20 10:34:23 +03:00
Elan Ruusamäe
a0c5ecb514 Merge pull request #102 from greensolid-technologies/master
Add support for Wincache
2014-09-19 16:43:51 +03:00
Matthias Fax
6b469640a7 Add Wincache
Updated comments

Check for Wincache existence in constructor

Normalized markup

Add Wincache test

Tie Wincache test to test index
2014-06-12 15:14:47 +02:00
Steve Clay
fb3931f8cd Fixes #97: URIs with spaces are correctly rewritten 2014-04-03 19:53:48 -04:00
Steve Clay
50488ce207 Merge pull request #96 from glensc/patch-2
insert_final_newline to true
2014-03-20 06:47:05 -04:00
Elan Ruusamäe
ebc91b5d33 insert_final_newline to true 2014-03-20 09:17:56 +02:00
Steve Clay
e7728405f5 Merge pull request #95 from glensc/patch-1
.editorconfig: skip style apply in vendor/ (composer stuff)
2014-03-19 12:31:26 -04:00
Elan Ruusamäe
537b4b314a skip style apply in vendor/ (composer stuff) 2014-03-19 17:19:57 +02:00
Steve Clay
4a884a381f Merge pull request #94 from glensc/issue-51
Handle faiure to open cache file for writing
2014-03-19 10:34:30 -04:00
Steve Clay
b018c834da Created .editorconfig 2014-03-19 10:33:07 -04:00
Elan Ruusamäe
27b4f758bc fix passing invalid parametrs to flock. #51 2014-03-19 15:07:57 +02:00
Steve Clay
9231aed49f Adds Bootstrap styling to builder app 2014-03-12 10:35:14 -04:00
Steve Clay
ea7fe90554 Merge branch 'Jimdo-add-tests-closure-compiler' 2014-03-12 09:52:21 -04:00
Steve Clay
5ceada8a22 YUIC unit test updates
bail if jar not found, make test more obviously customizable, don't
fail test if YUIC correctly handles input it used to choke on.
2014-03-12 09:51:53 -04:00
Steve Clay
66f2622705 Clean up unit test messages 2014-03-12 09:49:16 -04:00
Steve Clay
f3a408fd74 Remove unused var, add @throws 2014-03-12 09:48:36 -04:00
Joscha Feth
c60b6a2984 fix typo 2014-03-05 19:29:22 +01:00
Joscha Feth
54a53c9c19 Adds tests for the command line based Closure Compiler 2014-03-05 19:20:52 +01:00
30 changed files with 380 additions and 65 deletions

19
.editorconfig Normal file
View File

@@ -0,0 +1,19 @@
# top-most EditorConfig file
root = true
[*]
charset = utf-8
end_of_line = lf
; temporary
trim_trailing_whitespace = false
[*.php]
indent_style = space
indent_size = 4
insert_final_newline = true
[vendor/**]
; Use editor default (possible autodetection).
indent_style =
indent_size =

5
.gitattributes vendored Normal file
View File

@@ -0,0 +1,5 @@
/.editorconfig export-ignore
/.gitignore export-ignore
/.gitattributes export-ignore
/min_extras export-ignore
/min_unit_tests export-ignore

View File

@@ -1,5 +1,8 @@
Minify Release History
(master)
* Builder styled with Bootstrap (thanks to help from acidvertigo)
Version 2.2.0
* Fix handling of RegEx in certain situations in JSMin
* Thanks to Vovan-VE for reporting this

View File

@@ -16,11 +16,17 @@
"issues": "http://code.google.com/p/minify/issues/list",
"wiki": "http://code.google.com/p/minify/w/list"
},
"autoload": {
"classmap": ["min/lib/"]
},
"require": {
"php": ">=5.2.1",
"ext-pcre": "*"
},
"autoload": {
"classmap": ["min/lib/"]
"require-dev": {
"tubalmartin/cssmin": "~2.4.8"
},
"suggest": {
"tubalmartin/cssmin": "Support minify with CSSMin (YUI PHP port)"
}
}

View File

@@ -26,8 +26,8 @@ var MUB = {
*/
newLi : function () {
return '<li id="li' + MUB._uid + '">http://' + location.host + '/<input type=text size=20>' +
' <button title="Remove">x</button> <button title="Include Earlier">&uarr;</button>' +
' <button title="Include Later">&darr;</button> <span></span></li>';
' <button class="btn btn-danger btn-sm" title="Remove">x</button> <button class="btn btn-default btn-sm" title="Include Earlier">&uarr;</button>' +
' <button class="btn btn-default btn-sm" title="Include Later">&darr;</button> <span></span></li>';
},
/**
* Add new empty source LI and attach handlers to buttons
@@ -36,13 +36,13 @@ var MUB = {
$('#sources').append(MUB.newLi());
var li = $('#li' + MUB._uid)[0];
$('button[title=Remove]', li).click(function () {
$('#results').hide();
$('#results').addClass('hide');
var hadValue = !!$('input', li)[0].value;
$(li).remove();
});
$('button[title$=Earlier]', li).click(function () {
$(li).prev('li').find('input').each(function () {
$('#results').hide();
$('#results').addClass('hide');
// this = previous li input
var tmp = this.value;
this.value = $('input', li).val();
@@ -52,7 +52,7 @@ var MUB = {
});
$('button[title$=Later]', li).click(function () {
$(li).next('li').find('input').each(function () {
$('#results').hide();
$('#results').addClass('hide');
// this = next li input
var tmp = this.value;
this.value = $('input', li).val();
@@ -77,9 +77,9 @@ var MUB = {
url : url,
complete : function (xhr, stat) {
if ('success' === stat)
$('span', li).html('&#x2713;');
$('span', li).html('<a href="#" class="btn btn-success btn-sm disabled">&#x2713;</a>');
else {
$('span', li).html('<button><b>404! </b> recheck</button>')
$('span', li).html('<button class="btn btn-warning btn-sm"><b>404! </b> recheck</button>')
.find('button').click(function () {
MUB.liUpdateTestLink.call(li);
});
@@ -184,16 +184,16 @@ var MUB = {
markup = '<link type="text/css" rel="stylesheet" href="' + uriH + '" />';
}
$('#uriHtml').val(markup);
$('#results').show();
$('#results').removeClass('hide');
},
/**
* Handler for the "Add file +" button
*/
addButtonClick : function () {
$('#results').hide();
$('#results').addClass('hide');
MUB.addLi();
MUB.updateAllTestLinks();
$('#update').show().click(MUB.update);
$('#update').removeClass('hide').click(MUB.update);
$('#sources li:last input')[0].focus();
},
/**
@@ -201,7 +201,7 @@ var MUB = {
*/
init : function () {
$('#jsDidntLoad').remove();
$('#app').show();
$('#app').removeClass('hide');
$('#sources').html('');
$('#add button').click(MUB.addButtonClick);
// make easier to copy text out of
@@ -213,7 +213,7 @@ var MUB = {
$('a.ext').attr({target:'_blank'});
if (location.hash) {
// make links out of URIs from bookmarklet
$('#getBm').hide();
$('#getBm').addClass('hide');
var i = 0, found = location.hash.substr(1).split(','), l = found.length;
$('#bmUris').html('<p><strong>Found by bookmarklet:</strong> /</p>');
var $p = $('#bmUris p');
@@ -227,7 +227,7 @@ var MUB = {
MUB.addButtonClick();
$('#sources li:last input').val(this.innerHTML);
MUB.liUpdateTestLink.call($('#sources li:last')[0]);
$('#results').hide();
$('#results').addClass('hide');
return false;
}).attr({title:'Add file +'});
} else {

View File

@@ -49,6 +49,7 @@ ob_start();
<!DOCTYPE html>
<title>Minify URI Builder</title>
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<style>
body {margin:1em 60px;}
h1, h2, h3 {margin-left:-25px; position:relative;}
@@ -111,7 +112,7 @@ and click [Update].</p>
<div id=bmUris></div>
<p><button id=update class=hide>Update</button></p>
<p><button class="btn btn-primary" id=update class=hide>Update</button></p>
<div id=results class=hide>

View File

@@ -1,4 +1,4 @@
<?php
<?php
/**
* AJAX checks for zlib.output_compression
*
@@ -11,7 +11,7 @@ $_oc = ini_get('zlib.output_compression');
require dirname(__FILE__) . '/../config.php';
if (! $min_enableBuilder) {
header('Location: /');
exit();
exit;
}
if (isset($_GET['hello'])) {
@@ -26,8 +26,8 @@ if (isset($_GET['hello'])) {
'content' => 'World!'
,'method' => 'deflate'
));
$he->encode();
$he->sendAll();
$he->encode();
$he->sendAll();
} else {
// echo status "0" or "1"

View File

@@ -1,5 +1,5 @@
<?php
exit();
exit;
/* currently unused.
// capture PHP's default setting (may get overridden in config
@@ -8,7 +8,7 @@ $_oc = ini_get('zlib.output_compression');
// allow access only if builder is enabled
require dirname(__FILE__) . '/../config.php';
if (! $min_enableBuilder) {
exit();
exit;
}
if (isset($_GET['oc'])) {

View File

@@ -52,6 +52,7 @@ $min_allowDebugFlag = false;
//$min_cachePath = 'c:\\WINDOWS\\Temp';
//$min_cachePath = '/tmp';
//$min_cachePath = preg_replace('/^\\d+;/', '', session_save_path());
/**
* To use APC/Memcache/ZendPlatform for cache storage, require the class and
* set $min_cachePath to an instance. Example below:

View File

@@ -79,8 +79,8 @@ if (isset($_GET['f']) || isset($_GET['g'])) {
} elseif ($min_enableBuilder) {
header('Location: builder/');
exit();
exit;
} else {
header("Location: /");
exit();
header('Location: /');
exit;
}

View File

@@ -1,7 +1,7 @@
<?php
/*!
* cssmin.php 2.4.8-2
* cssmin.php v2.4.8-4
* Author: Tubal Martin - http://tubalmartin.me/
* Repo: https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port
*
@@ -107,7 +107,7 @@ class CSSmin
$l = strlen($css);
// if the number of characters is 25000 or less, do not chunk
// if the number of characters is 5000 or less, do not chunk
if ($l <= $css_chunk_length) {
$css_chunks[] = $css;
} else {
@@ -291,7 +291,7 @@ class CSSmin
// Remove the spaces before the things that should not have spaces before them.
// But, be careful not to turn "p :link {...}" into "p:link{...}"
// Swap out any pseudo-class colons with the token, and then swap back.
$css = preg_replace_callback('/(?:^|\})(?:(?:[^\{\:])+\:)+(?:[^\{]*\{)/', array($this, 'replace_colon'), $css);
$css = preg_replace_callback('/(?:^|\})[^\{]*\s+\:/', array($this, 'replace_colon'), $css);
// Remove spaces before the things that should not have spaces before them.
$css = preg_replace('/\s+([\!\{\}\;\:\>\+\(\)\]\~\=,])/', '$1', $css);
@@ -336,11 +336,13 @@ class CSSmin
// to avoid issues on Symbian S60 3.x browsers.
$css = preg_replace('/(\*[a-z0-9\-]+\s*\:[^;\}]+)(\})/', '$1;$2', $css);
// Replace 0 length units 0(px,em,%) with 0.
$css = preg_replace('/(^|[^0-9])(?:0?\.)?0(?:em|ex|ch|rem|vw|vh|vm|vmin|cm|mm|in|px|pt|pc|%|deg|g?rad|m?s|k?hz)/iS', '${1}0', $css);
// Replace 0 <length> and 0 <percentage> values with 0.
// <length> data type: https://developer.mozilla.org/en-US/docs/Web/CSS/length
// <percentage> data type: https://developer.mozilla.org/en-US/docs/Web/CSS/percentage
$css = preg_replace('/([^\\\\]\:|\s)0(?:em|ex|ch|rem|vw|vh|vm|vmin|cm|mm|in|px|pt|pc|%)/iS', '${1}0', $css);
// 0% step in a keyframe? restore the % unit
$css = preg_replace_callback('/(@[a-z\-]*?keyframes[^\{]*?\{)(.*?\}\s*\})/iS', array($this, 'replace_keyframe_zero'), $css);
$css = preg_replace_callback('/(@[a-z\-]*?keyframes[^\{]+\{)(.*?)(\}\})/iS', array($this, 'replace_keyframe_zero'), $css);
// Replace 0 0; or 0 0 0; or 0 0 0 0; with 0.
$css = preg_replace('/\:0(?: 0){1,3}(;|\}| \!)/', ':0$1', $css);
@@ -596,7 +598,7 @@ class CSSmin
private function replace_keyframe_zero($matches)
{
return $matches[1] . preg_replace('/0\s*,/', '0%,', preg_replace('/\s*0\s*\{/', '0%{', $matches[2]));
return $matches[1] . preg_replace('/0(\{|,[^\)\{]+\{)/', '0%$1', $matches[2]) . $matches[3];
}
private function rgb_to_hex($matches)

View File

@@ -435,7 +435,7 @@ class Minify {
header('Content-Type: text/html; charset=utf-8');
echo "<h1>$h1</h1>";
echo "<p>Please see <a href='$url'>$url</a>.</p>";
exit();
exit;
}
/**

View File

@@ -70,7 +70,7 @@ class Minify_CSS_UriRewriter {
// rewrite
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
,array(self::$className, '_processUriCB'), $css);
$css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
$css = preg_replace_callback('/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/'
,array(self::$className, '_processUriCB'), $css);
return $css;
@@ -94,7 +94,7 @@ class Minify_CSS_UriRewriter {
// append
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
,array(self::$className, '_processUriCB'), $css);
$css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
$css = preg_replace_callback('/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/'
,array(self::$className, '_processUriCB'), $css);
self::$_prependPath = null;

View File

@@ -98,6 +98,9 @@ class Minify_Cache_File {
{
if ($this->_locking) {
$fp = fopen($this->_path . '/' . $id, 'rb');
if (!$fp) {
return false;
}
flock($fp, LOCK_SH);
$ret = stream_get_contents($fp);
flock($fp, LOCK_UN);

View File

@@ -0,0 +1,130 @@
<?php
/**
* Class Minify_Cache_Wincache
* @package Minify
*/
/**
* WinCache-based cache class for Minify
*
* <code>
* Minify::setCache(new Minify_Cache_WinCache());
* </code>
*
* @package Minify
* @author Matthias Fax
**/
class Minify_Cache_WinCache
{
/**
* Create a Minify_Cache_Wincache object, to be passed to
* Minify::setCache().
*
*
* @param int $expire seconds until expiration (default = 0
* meaning the item will not get an expiration date)
*/
public function __construct($expire = 0)
{
if (!function_exists('wincache_ucache_info')) {
throw new Exception("WinCache for PHP is not installed to be able to use Minify_Cache_WinCache!");
}
$this->_exp = $expire;
}
/**
* Write data to cache.
*
* @param string $id cache id
*
* @param string $data
*
* @return bool success
*/
public function store($id, $data)
{
return wincache_ucache_set($id, "{$_SERVER['REQUEST_TIME']}|{$data}", $this->_exp);
}
/**
* Get the size of a cache entry
*
* @param string $id cache id
*
* @return int size in bytes
*/
public function getSize($id)
{
if (!$this->_fetch($id)) {
return false;
}
return (function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload') & 2)) ? mb_strlen($this->_data, '8bit') : strlen($this->_data);
}
/**
* Does a valid cache entry exist?
*
* @param string $id cache id
*
* @param int $srcMtime mtime of the original source file(s)
*
* @return bool exists
*/
public function isValid($id, $srcMtime)
{
return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
}
/**
* Send the cached content to output
*
* @param string $id cache id
*/
public function display($id)
{
echo $this->_fetch($id) ? $this->_data : '';
}
/**
* Fetch the cached content
*
* @param string $id cache id
*
* @return string
*/
public function fetch($id)
{
return $this->_fetch($id) ? $this->_data : '';
}
private $_exp = NULL;
// cache of most recently fetched id
private $_lm = NULL;
private $_data = NULL;
private $_id = NULL;
/**
* Fetch data and timestamp from WinCache, store in instance
*
* @param string $id
*
* @return bool success
*/
private function _fetch($id)
{
if ($this->_id === $id) {
return true;
}
$suc = false;
$ret = wincache_ucache_get($id, $suc);
if (!$suc) {
$this->_id = NULL;
return false;
}
list($this->_lm, $this->_data) = explode('|', $ret, 2);
$this->_id = $id;
return true;
}
}

View File

@@ -33,6 +33,11 @@
*/
class Minify_ClosureCompiler {
const OPTION_CHARSET = 'charset';
const OPTION_COMPILATION_LEVEL = 'compilation_level';
public static $isDebug = false;
/**
* Filepath of the Closure Compiler jar file. This must be set before
* calling minifyJs().
@@ -65,18 +70,28 @@ class Minify_ClosureCompiler {
* @see https://code.google.com/p/closure-compiler/source/browse/trunk/README
*
* @return string
*
* @throws Minify_ClosureCompiler_Exception
*/
public static function minify($js, $options = array())
{
self::_prepare();
if (! ($tmpFile = tempnam(self::$tempDir, 'cc_'))) {
throw new Exception('Minify_ClosureCompiler : could not create temp file in "'.self::$tempDir.'".');
throw new Minify_ClosureCompiler_Exception('Minify_ClosureCompiler : could not create temp file in "'.self::$tempDir.'".');
}
file_put_contents($tmpFile, $js);
exec(self::_getCmd($options, $tmpFile), $output, $result_code);
$cmd = self::_getCmd($options, $tmpFile);
exec($cmd, $output, $result_code);
unlink($tmpFile);
if ($result_code != 0) {
throw new Exception('Minify_ClosureCompiler : Closure Compiler execution failed.');
$message = 'Minify_ClosureCompiler : Closure Compiler execution failed.';
if (self::$isDebug) {
exec($cmd . ' 2>&1', $error);
if ($error) {
$message .= "\nReason:\n" . join("\n", $error);
}
}
throw new Minify_ClosureCompiler_Exception($message);
}
return implode("\n", $output);
}
@@ -85,17 +100,18 @@ class Minify_ClosureCompiler {
{
$o = array_merge(
array(
'charset' => 'utf-8',
'compilation_level' => 'SIMPLE_OPTIMIZATIONS',
self::OPTION_CHARSET => 'utf-8',
self::OPTION_COMPILATION_LEVEL => 'SIMPLE_OPTIMIZATIONS',
),
$userOptions
);
$charsetOption = $o[self::OPTION_CHARSET];
$cmd = self::$javaExecutable . ' -jar ' . escapeshellarg(self::$jarFile)
. (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $o['charset'])
? " --charset {$o['charset']}"
. (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $charsetOption)
? " --charset {$charsetOption}"
: '');
foreach (array('compilation_level') as $opt) {
foreach (array(self::OPTION_COMPILATION_LEVEL) as $opt) {
if ($o[$opt]) {
$cmd .= " --{$opt} ". escapeshellarg($o[$opt]);
}
@@ -106,18 +122,18 @@ class Minify_ClosureCompiler {
private static function _prepare()
{
if (! is_file(self::$jarFile)) {
throw new Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not a valid file.');
throw new Minify_ClosureCompiler_Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not a valid file.');
}
if (! is_readable(self::$jarFile)) {
throw new Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not readable.');
throw new Minify_ClosureCompiler_Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not readable.');
}
if (! is_dir(self::$tempDir)) {
throw new Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not a valid direcotry.');
throw new Minify_ClosureCompiler_Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not a valid direcotry.');
}
if (! is_writable(self::$tempDir)) {
throw new Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not writable.');
throw new Minify_ClosureCompiler_Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not writable.');
}
}
}
/* vim:ts=4:sw=4:et */
class Minify_ClosureCompiler_Exception extends Exception {}

View File

@@ -49,7 +49,6 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
$this->log("Duplicate group key found.");
return $options;
}
$keys = explode(',', $_GET['g']);
foreach ($keys as $key) {
if (! isset($cOptions['groups'][$key])) {
$this->log("A group configuration for \"{$key}\" was not found");

View File

@@ -44,7 +44,7 @@ if (isset($_POST['method']) && $_POST['method'] === 'Minify and serve') {
} catch (Exception $e) {
echo h($e->getMessage());
}
exit();
exit;
}
$tpl = array();

View File

@@ -12,3 +12,6 @@ foo {background:url('/_test_files/css_uriRewriter/bar/foo.png')}
foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter */
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
foo {background:url(foo:bar);} /* scheme, should not alter */
foo {background:url("/_test_files/css_uriRewriter/foo bar.jpg");}
@import url('/_test_files/css_uriRewriter/foo bar.css');
@import "/_test_files/css_uriRewriter/foo bar.css";

View File

@@ -12,3 +12,6 @@ foo {background:url('http://cnd.com/A/B/bar/foo.png')}
foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter */
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
foo {background:url(foo:bar);} /* scheme, should not alter */
foo {background:url("http://cnd.com/A/B/foo bar.jpg");}
@import url('http://cnd.com/A/B/foo bar.css');
@import "http://cnd.com/A/B/foo bar.css";

View File

@@ -12,3 +12,6 @@ foo {background:url('//cnd.com/A/B/bar/foo.png')}
foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter */
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
foo {background:url(foo:bar);} /* scheme, should not alter */
foo {background:url("//cnd.com/A/B/foo bar.jpg");}
@import url('//cnd.com/A/B/foo bar.css');
@import "//cnd.com/A/B/foo bar.css";

View File

@@ -12,3 +12,6 @@ foo {background:url('bar/foo.png')}
foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter */
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
foo {background:url(foo:bar);} /* scheme, should not alter */
foo {background:url("foo bar.jpg");}
@import url('foo bar.css');
@import "foo bar.css";

View File

@@ -9,7 +9,7 @@ function test_Minify_Cache_File()
$cache = new Minify_Cache_File();
echo "NOTE: Minify_Cache_File : path is set to: '" . $cache->getPath() . "'.\n";
echo " Minify_Cache_File : path is set to: '" . $cache->getPath() . "'.\n";
assertTrue(true === $cache->store($id, $data), $prefix . 'store');

View File

@@ -8,14 +8,14 @@ function test_Minify_Cache_Memcache()
if (! function_exists('memcache_set')) {
if ($thisFileActive) {
echo "NOTE: {$prefix}PHP lacks memcache support\n";
echo " {$prefix}To test this component, install memcache in PHP\n";
}
return;
}
$mc = new Memcache;
if (! @$mc->connect('localhost', 11211)) {
if ($thisFileActive) {
echo "NOTE: {$prefix}Could not connect to localhost:11211\n";
echo " {$prefix}Memcache server not found on localhost:11211\n";
}
return;
}

View File

@@ -0,0 +1,31 @@
<?php
require_once '_inc.php';
function test_Minify_Cache_WinCache()
{
$prefix = 'Minify_Cache_WinCache : ';
if (! function_exists('wincache_ucache_info')) {
return;
}
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
$id = 'Minify_test_cache';
$cache = new Minify_Cache_WinCache();
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
ob_start();
$cache->display($id);
$displayed = ob_get_contents();
ob_end_clean();
assertTrue($data === $displayed, $prefix . 'display');
assertTrue($data === $cache->fetch($id), $prefix . 'fetch');
}
test_Minify_Cache_WinCache();

View File

@@ -0,0 +1,75 @@
<?php
require_once '_inc.php';
function test_Minify_ClosureCompiler()
{
global $thisDir;
Minify_ClosureCompiler::$isDebug = true;
// --- Test minification w/o setting the necessary settings ---
try {
Minify_ClosureCompiler::minify('');
} catch (Exception $e) {
$exc = $e;
}
$passed = assertTrue(
$exc instanceof Minify_ClosureCompiler_Exception
, 'Minify_ClosureCompiler : Throws Minify_ClosureCompiler_Exception');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Message: " . var_export($exc->getMessage(), 1) . "\n\n\n";
}
$compiler_jar_path = __DIR__ . DIRECTORY_SEPARATOR . 'compiler.jar';
if (is_file($compiler_jar_path)) {
// set minimum necessary settings
Minify_ClosureCompiler::$jarFile = $compiler_jar_path;
Minify_ClosureCompiler::$tempDir = sys_get_temp_dir();
// --- Test minification with the minimum necessary settings ---
$src = "
(function (window, undefined){
function addOne(input) {
return 1 + input;
}
window.addOne = addOne;
window.undefined = undefined;
})(window);
";
$minExpected = "(function(a,b){a.addOne=function(a){return 1+a};a.undefined=b})(window);";
$minOutput = Minify_ClosureCompiler::minify($src);
$passed = assertTrue($minExpected == $minOutput, 'Minify_ClosureCompiler : minimum necessary settings');
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";
}
// --- Test minification with advanced compilation level ---
$src = "function unused() {};";
$minExpected = '';
$minOutput = Minify_ClosureCompiler::minify($src, array(
Minify_ClosureCompiler::OPTION_COMPILATION_LEVEL => 'ADVANCED_OPTIMIZATIONS'
));
$passed = assertTrue($minExpected == $minOutput, 'Minify_ClosureCompiler : advanced optimizations');
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";
}
} else {
echo " Minify_ClosureCompiler : To test more functionality, download a compiler.jar from\n";
echo " https://code.google.com/p/closure-compiler/wiki/BinaryDownloads,\n";
echo " put it under '${compiler_jar_path}',\n";
echo " and make it readable by your webserver\n";
}
}
test_Minify_ClosureCompiler();

View File

@@ -17,7 +17,7 @@ function test_Minify_JS_ClosureCompiler()
$minExpected = "(function(a,b){a.addOne=function(a){return 1+a};a.undefined=b})(window);";
$minOutput = Minify_JS_ClosureCompiler::minify($src);
if (false !== strpos($minOutput, 'Error(22): Too many compiles')) {
echo "!NOTE: Too many recent calls to Closure Compiler API to test.\n";
echo "!---: Minify_JS_ClosureCompiler : Too many recent calls to Closure Compiler API to test.\n";
return;
}

View File

@@ -1,10 +1,20 @@
<?php
require_once '_inc.php';
// customize this as needed
define('MINIFY_TESTS_YUICOMPRESSOR_JAR_FILE', '/usr/share/java/yuicompressor.jar');
function test_Minify_YuiCSS()
{
// XXX this may need customizing
Minify_YUICompressor::$jarFile = '/usr/share/java/yuicompressor.jar';
if (!is_file(MINIFY_TESTS_YUICOMPRESSOR_JAR_FILE)) {
echo " Minify_YUICompressor : To test this, install the .jar file and customize the constant in:\n";
echo " " . __FILE__ . "\n";
return;
}
Minify_YUICompressor::$jarFile = MINIFY_TESTS_YUICOMPRESSOR_JAR_FILE;
Minify_YUICompressor::$tempDir = sys_get_temp_dir();
$src = "/* stack overflow test */
@@ -20,9 +30,9 @@ function test_Minify_YuiCSS()
// unfortunately error output is not caught from yui, so have to guess
try {
$minOutput = Minify_YUICompressor::minifyCss($src);
assertTrue(false, "Expected exception Not thrown");
echo " Minify_YUICompressor : Correctly handles input which caused stack overflow in 2.4.6\n";
} catch (Exception $e) {
assertTrue($e->getMessage() == 'Minify_YUICompressor : YUI compressor execution failed.', 'got expected Exception');
assertTrue($e->getMessage() == 'Minify_YUICompressor : YUI compressor execution failed.', 'Minify_YUICompressor : got expected Exception');
}
try {

View File

@@ -6,9 +6,11 @@ require 'test_Minify_HTML_Helper.php';
require 'test_Minify_Cache_APC.php';
require 'test_Minify_Cache_File.php';
require 'test_Minify_Cache_Memcache.php';
require 'test_Minify_Cache_WinCache.php';
require 'test_Minify_Cache_ZendPlatform.php';
require 'test_Minify_CSS.php';
require 'test_Minify_CSS_UriRewriter.php';
require 'test_Minify_ClosureCompiler.php';
require 'test_Minify_JS_ClosureCompiler.php';
require 'test_Minify_YuiCSS.php';
require 'test_Minify_CommentPreserver.php';

View File

@@ -43,11 +43,11 @@ function test_environment()
. "cannot modify this, consider setting \$min_documentRoot in config.php\n\n";
}
if (isset($_SERVER['SUBDOMAIN_DOCUMENT_ROOT'])) {
echo "\n!NOTE: environment : \$_SERVER['SUBDOMAIN_DOCUMENT_ROOT'] is set. "
echo "\n environment : \$_SERVER['SUBDOMAIN_DOCUMENT_ROOT'] is set. "
. "You may need to set \$min_documentRoot to this in config.php\n";
}
if (realpath(__FILE__) !== realpath($_SERVER['DOCUMENT_ROOT'] . '/min_unit_tests/test_environment.php')) {
echo "!NOTE: environment : /min_unit_tests/ is not directly inside DOCUMENT_ROOT\n";
echo " environment : /min_unit_tests/ is not directly inside DOCUMENT_ROOT\n";
}
$thisUrl = 'http://'
@@ -59,11 +59,11 @@ function test_environment()
$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";
echo "!---: environment : Local HTTP request failed. Testing cannot continue.\n";
return;
}
if ('1' === $oc) {
echo "!WARN: environment : zlib.output_compression is enabled in php.ini"
echo "!---: environment : zlib.output_compression is enabled in php.ini"
. " or .htaccess.\n";
}
@@ -88,9 +88,9 @@ function test_environment()
if (! $passed) {
$testFake = _test_environment_getHello($thisUrl . '?hello=faketype');
if ($testFake['length'] == 6) {
echo "!NOTE: environment : Server does not auto-encode arbitrary types. This\n"
. " may indicate that the auto-encoding is caused by Apache's \n"
. " AddOutputFilterByType.";
echo " environment : Server does not auto-encode arbitrary types. This\n"
. " may indicate that the auto-encoding is caused by Apache's\n"
. " AddOutputFilterByType.";
}
}
}