1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-06 06:07:24 +02:00

Collapse "min" into project root and get unit tests working.

Fixes #472
This commit is contained in:
Steve Clay
2015-09-28 15:36:52 -04:00
parent 2720239c8c
commit e596b35fc4
89 changed files with 133 additions and 94 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,4 @@
/test /test
/docs
/.idea/ /.idea/
.DS_Store .DS_Store
/vendor/ /vendor/

View File

@@ -145,7 +145,7 @@ Then create a new file, for example "min.php" in your site root. The contents of
this file could look like this: this file could look like this:
<?php <?php
$customConfigDirectory = dirname(__FILE__) . '/min-configs'; $customConfigDirectory = __DIR__ . '/min-configs';
$min_customConfigPaths = array( $min_customConfigPaths = array(
'base' => $customConfigDirectory . '/config.php', 'base' => $customConfigDirectory . '/config.php',
'test' => $customConfigDirectory . '/config-test.php', 'test' => $customConfigDirectory . '/config-test.php',

View File

@@ -24,15 +24,29 @@ Unfortunately we can't support the WordPress plugins here.
Installation Installation
------------ ------------
Place the `/min/` directory as a child of your DOCUMENT_ROOT Installation requires PHP 5.3+, SSH access, and access to tools like `git` and `composer` or the privileges to install them.
directory: i.e. you will have: `/home/example/www/min`
You can see verify that it is working by visiting these two URLs: ```bash
- http://example.org/min/?f=min/quick-test.js cd /path/to/public_html
- http://example.org/min/?f=min/quick-test.css git clone https://github.com/mrclay/minify.git min
cd min
composer install
```
What this does:
1. Inside your DOCUMENT_ROOT directory, we clone this repo. Otherwise you may [download](https://github.com/mrclay/minify/archive/master.zip) and extract the zip file.
1. We rename this directory `min`. E.g. You will have something like: `/home/example/public_html/min`
1. We `cd` into it and run `composer install` to install the dependencies.
You can verify that it is working by visiting these two URLs:
* http://example.org/min/?f=min/quick-test.js
* http://example.org/min/?f=min/quick-test.css
If your server supports mod_rewrite, this URL should also work: If your server supports mod_rewrite, this URL should also work:
- http://example.org/min/f=min/quick-test.js
* http://example.org/min/f=min/quick-test.js
Configuration & Usage Configuration & Usage
--------------------- ---------------------
@@ -54,22 +68,17 @@ Support
Unit Testing Unit Testing
------------ ------------
1. Place the /min_unit_tests/ directory as a child of your DOCUMENT_ROOT 1. Open the file `min_unit_tests/_inc.php`.
directory: i.e. you will have: /home/example/www/min_unit_tests 1. Enable the file by commenting out the `die()` statement.
1. Access: http://example.org/min/min_unit_tests/test_all.php (If you wish, the other test_*.php files can be run to test individual components with more verbose output.)
2. To run unit tests, access: http://example.org/min_unit_tests/test_all.php 1. Re-disable the `_inc.php` file when you are done.
(If you wish, the other test_*.php files can be run to test individual
components with more verbose output.)
3. Remove /min_unit_tests/ from your DOCUMENT_ROOT when you are done.
Warnings Warnings
-------- --------
* Minify is designed for efficiency, but, for very high traffic sites, it will probably serve files slower than your HTTPd due to the CGI overhead of PHP. See the [FAQ](https://github.com/mrclay/minify/blob/master/docs/FAQ.wiki.md#how-fast-is-it) and [CookBook](https://github.com/mrclay/minify/blob/master/docs/CookBook.wiki.md) for more info. * Minify is designed for efficiency, but, for very high traffic sites, it will probably serve files slower than your HTTPd due to the CGI overhead of PHP. See the [FAQ](https://github.com/mrclay/minify/blob/master/docs/FAQ.wiki.md#how-fast-is-it) and [CookBook](https://github.com/mrclay/minify/blob/master/docs/CookBook.wiki.md) for more info.
* If you combine a lot of CSS, watch out for [IE's 4096 selectors-per-file limit](http://stackoverflow.com/a/9906889/3779), affects IE 6 through 9. * If you combine a lot of CSS, watch out for [IE's 4096 selectors-per-file limit](http://stackoverflow.com/a/9906889/3779), affects IE 6 through 9.
* Minify *should* work fine with files encoded in UTF-8 or other 8-bit encodings like ISO 8859/Windows-1252. By default Minify appends ";charset=utf-8" to the Content-Type headers it sends. * Minify *should* work fine with files encoded in UTF-8 or other 8-bit encodings like ISO 8859/Windows-1252. By default Minify appends ";charset=utf-8" to the Content-Type headers it sends.
Acknowledgments Acknowledgments
--------------- ---------------

View File

@@ -12,13 +12,13 @@ if (0 === strpos($_SERVER["SERVER_SOFTWARE"], 'Apache/')
$userDir = DIRECTORY_SEPARATOR . $m[1] . DIRECTORY_SEPARATOR; $userDir = DIRECTORY_SEPARATOR . $m[1] . DIRECTORY_SEPARATOR;
if (false !== strpos(__FILE__, $userDir)) { if (false !== strpos(__FILE__, $userDir)) {
$sm = array(); $sm = array();
$sm["//~{$m[1]}"] = dirname(dirname(__FILE__)); $sm["//~{$m[1]}"] = dirname(__DIR__);
$array = str_replace('array (', 'array(', var_export($sm, 1)); $array = str_replace('array (', 'array(', var_export($sm, 1));
$symlinkOption = "\$min_symlinks = $array;"; $symlinkOption = "\$min_symlinks = $array;";
} }
} }
require __DIR__ . '/../../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
require __DIR__ . '/../config.php'; require __DIR__ . '/../config.php';
if (! $min_enableBuilder) { if (! $min_enableBuilder) {
@@ -159,7 +159,7 @@ by Minify. E.g. <code>@import "<span class=minRoot>/min/?</span>g=css2";</code><
</div><!-- #app --> </div><!-- #app -->
<hr> <hr>
<p>Need help? Check the <a href="http://code.google.com/p/minify/w/list?can=3">wiki</a>, <p>Need help? Check the <a href="https://github.com/mrclay/minify/tree/master/docs">wiki</a>,
or post to the <a class=ext href="http://groups.google.com/group/minify">discussion or post to the <a class=ext href="http://groups.google.com/group/minify">discussion
list</a>.</p> list</a>.</p>
<p><small>Powered by Minify <?php echo Minify::VERSION; ?></small></p> <p><small>Powered by Minify <?php echo Minify::VERSION; ?></small></p>
@@ -239,8 +239,8 @@ $server->serve($controller, array(
'lastModifiedTime' => max( 'lastModifiedTime' => max(
// regenerate cache if any of these change // regenerate cache if any of these change
filemtime(__FILE__), filemtime(__FILE__),
filemtime(dirname(__FILE__) . '/../config.php'), filemtime(__DIR__ . '/../config.php'),
filemtime(dirname(__FILE__) . '/../lib/Minify.php') filemtime(__DIR__ . '/../lib/Minify.php')
), ),
'minifyAll' => true, 'minifyAll' => true,
'encodeOutput' => $encodeOutput, 'encodeOutput' => $encodeOutput,

View File

@@ -5,12 +5,12 @@
* @package Minify * @package Minify
*/ */
require __DIR__ . '/../../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
$_oc = ini_get('zlib.output_compression'); $_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 __DIR__ . '/../config.php';
if (! $min_enableBuilder) { if (! $min_enableBuilder) {
header('Location: /'); header('Location: /');
exit; exit;

View File

@@ -6,7 +6,7 @@ exit;
$_oc = ini_get('zlib.output_compression'); $_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 __DIR__ . '/../config.php';
if (! $min_enableBuilder) { if (! $min_enableBuilder) {
exit; exit;
} }

View File

@@ -17,7 +17,7 @@
"wiki": "https://github.com/mrclay/minify/blob/master/docs" "wiki": "https://github.com/mrclay/minify/blob/master/docs"
}, },
"autoload": { "autoload": {
"classmap": ["min/lib/"] "classmap": ["lib/"]
}, },
"require": { "require": {
"ext-pcre": "*", "ext-pcre": "*",

2
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "523e463e2f705e3389708dffaeeda859", "hash": "de48bc346ef046cc11ddc45358b1887b",
"packages": [ "packages": [
{ {
"name": "firephp/firephp-core", "name": "firephp/firephp-core",

View File

@@ -10,7 +10,7 @@
/** /**
* Allow use of the Minify URI Builder app. Only set this to true while you need it. * Allow use of the Minify URI Builder app. Only set this to true while you need it.
*/ */
$min_enableBuilder = false; $min_enableBuilder = true;
/** /**
@@ -78,7 +78,7 @@ $min_allowDebugFlag = false;
* second line. The third line might work on some Apache servers. * second line. The third line might work on some Apache servers.
*/ */
$min_documentRoot = ''; $min_documentRoot = '';
//$min_documentRoot = dirname(dirname(dirname(__FILE__))); //$min_documentRoot = dirname(dirname(__DIR__));
//$min_documentRoot = substr(__FILE__, 0, -15); //$min_documentRoot = substr(__FILE__, 0, -15);
//$min_documentRoot = $_SERVER['SUBDOMAIN_DOCUMENT_ROOT']; //$min_documentRoot = $_SERVER['SUBDOMAIN_DOCUMENT_ROOT'];

View File

@@ -7,15 +7,13 @@
* @package Minify * @package Minify
*/ */
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/bootstrap.php';
define('MINIFY_MIN_DIR', dirname(__FILE__));
// set config path defaults // set config path defaults
$min_configPaths = array( $min_configPaths = array(
'base' => MINIFY_MIN_DIR . '/config.php', 'base' => __DIR__ . '/config.php',
'test' => MINIFY_MIN_DIR . '/config-test.php', 'test' => __DIR__ . '/config-test.php',
'groups' => MINIFY_MIN_DIR . '/groupsConfig.php', 'groups' => __DIR__ . '/groupsConfig.php',
); );
// check for custom config paths // check for custom config paths

View File

@@ -84,7 +84,7 @@ class Minify {
'encodeLevel' => 9, 'encodeLevel' => 9,
'minifiers' => array( 'minifiers' => array(
Minify::TYPE_JS => array('JSMin', 'minify'), Minify::TYPE_JS => array('JSMin\\JSMin', 'minify'),
Minify::TYPE_CSS => array('Minify_CSS', 'minify'), Minify::TYPE_CSS => array('Minify_CSS', 'minify'),
Minify::TYPE_HTML => array('Minify_HTML', 'minify'), Minify::TYPE_HTML => array('Minify_HTML', 'minify'),
), ),

View File

@@ -53,7 +53,7 @@ class Minify_Controller_Page extends Minify_Controller_Base {
// this will be the 2nd argument passed to Minify_HTML::minify() // this will be the 2nd argument passed to Minify_HTML::minify()
$sourceSpec['minifyOptions'] = array( $sourceSpec['minifyOptions'] = array(
'cssMinifier' => array('Minify_CSS', 'minify') 'cssMinifier' => array('Minify_CSS', 'minify')
,'jsMinifier' => array('JSMin', 'minify') ,'jsMinifier' => array('JSMin\\JSMin', 'minify')
); );
unset($options['minifyAll']); unset($options['minifyAll']);
} }

View File

@@ -115,7 +115,7 @@ class Minify_HTML_Helper {
$this->_groupKey = $key; $this->_groupKey = $key;
if ($checkLastModified) { if ($checkLastModified) {
if (! $this->groupsConfigFile) { if (! $this->groupsConfigFile) {
$this->groupsConfigFile = dirname(dirname(dirname(dirname(__FILE__)))) . '/groupsConfig.php'; $this->groupsConfigFile = dirname(dirname(dirname(__DIR__))) . '/groupsConfig.php';
} }
if (is_file($this->groupsConfigFile)) { if (is_file($this->groupsConfigFile)) {
$gc = (require $this->groupsConfigFile); $gc = (require $this->groupsConfigFile);

View File

@@ -68,7 +68,7 @@ class Minify_JS_ClosureCompiler {
/** /**
* @var callable Function to minify JS if service fails. Default is JSMin * @var callable Function to minify JS if service fails. Default is JSMin
*/ */
protected $fallbackMinifier = array('JSMin', 'minify'); protected $fallbackMinifier = array('JSMin\\JSMin', 'minify');
/** /**
* Minify JavaScript code via HTTP request to a Closure Compiler API * Minify JavaScript code via HTTP request to a Closure Compiler API

View File

@@ -13,7 +13,7 @@
class Minify_Loader { class Minify_Loader {
public function loadClass($class) public function loadClass($class)
{ {
$file = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR; $file = dirname(__DIR__) . DIRECTORY_SEPARATOR;
$file .= strtr($class, "\\_", DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . '.php'; $file .= strtr($class, "\\_", DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . '.php';
if (is_readable($file)) { if (is_readable($file)) {
require $file; require $file;

View File

@@ -1,6 +1,8 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
die('Must be rewritten for new API');
require __DIR__ . '/../../bootstrap.php'; require __DIR__ . '/../../bootstrap.php';
$cli = new MrClay\Cli; $cli = new MrClay\Cli;

View File

@@ -1,6 +1,8 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
die('Must be rewritten for new API');
require __DIR__ . '/../../bootstrap.php'; require __DIR__ . '/../../bootstrap.php';
$cli = new MrClay\Cli; $cli = new MrClay\Cli;

View File

@@ -2,7 +2,7 @@
// using same lib path and cache path specified in /min/config.php // using same lib path and cache path specified in /min/config.php
require dirname(__FILE__) . '/../min/config.php'; require __DIR__ . '/../config.php';
$minifyCachePath = isset($min_cachePath) $minifyCachePath = isset($min_cachePath)
? $min_cachePath ? $min_cachePath

View File

@@ -31,7 +31,7 @@ if (isset($_POST['method']) && $_POST['method'] === 'Minify and serve') {
$sourceSpec['content'] = $textIn; $sourceSpec['content'] = $textIn;
$sourceSpec['id'] = 'foo'; $sourceSpec['id'] = 'foo';
if (isset($_POST['minJs'])) { if (isset($_POST['minJs'])) {
$sourceSpec['minifyOptions']['jsMinifier'] = array('JSMin', 'minify'); $sourceSpec['minifyOptions']['jsMinifier'] = array('JSMin\\JSMin', 'minify');
} }
if (isset($_POST['minCss'])) { if (isset($_POST['minCss'])) {
$sourceSpec['minifyOptions']['cssMinifier'] = array('Minify_CSS', 'minify'); $sourceSpec['minifyOptions']['cssMinifier'] = array('Minify_CSS', 'minify');
@@ -50,7 +50,7 @@ if (isset($_POST['method']) && $_POST['method'] === 'Minify and serve') {
} }
$tpl = array(); $tpl = array();
$tpl['classes'] = array('Minify_HTML', 'JSMin', 'Minify_CSS', 'Minify_CSSmin', 'JSMinPlus'); $tpl['classes'] = array('Minify_HTML', 'JSMin\\JSMin', 'Minify_CSS', 'Minify_CSSmin', 'JSMinPlus');
if (isset($_POST['method']) && in_array($_POST['method'], $tpl['classes'])) { if (isset($_POST['method']) && in_array($_POST['method'], $tpl['classes'])) {
@@ -58,7 +58,7 @@ if (isset($_POST['method']) && in_array($_POST['method'], $tpl['classes'])) {
if ($_POST['method'] === 'Minify_HTML') { if ($_POST['method'] === 'Minify_HTML') {
$args[] = array( $args[] = array(
'cssMinifier' => array('Minify_CSS', 'minify') 'cssMinifier' => array('Minify_CSS', 'minify')
,'jsMinifier' => array('JSMin', 'minify') ,'jsMinifier' => array('JSMin\\JSMin', 'minify')
); );
} }
$func = array($_POST['method'], 'minify'); $func = array($_POST['method'], 'minify');

View File

@@ -96,7 +96,7 @@ if (isset($_POST['url'])) {
if ($type['minify'] === 'text/html') { if ($type['minify'] === 'text/html') {
if (isset($_POST['minJs'])) { if (isset($_POST['minJs'])) {
$sourceSpec['minifyOptions']['jsMinifier'] = array('JSMin', 'minify'); $sourceSpec['minifyOptions']['jsMinifier'] = array('JSMin\\JSMin', 'minify');
} }
if (isset($_POST['minCss'])) { if (isset($_POST['minCss'])) {
$sourceSpec['minifyOptions']['cssMinifier'] = array('Minify_CSS', 'minify'); $sourceSpec['minifyOptions']['cssMinifier'] = array('Minify_CSS', 'minify');

View File

@@ -26,7 +26,7 @@ if (! empty($_POST)) {
} }
} }
$defaultCurrentDir = dirname(__FILE__); $defaultCurrentDir = __DIR__;
$defaultDocRoot = realpath($_SERVER['DOCUMENT_ROOT']); $defaultDocRoot = realpath($_SERVER['DOCUMENT_ROOT']);
$defaultSymLink = '//symlinkPath'; $defaultSymLink = '//symlinkPath';
$defaultSymTarget = ($defaultCurrentDir[0] === '/') ? '/tmp' : 'C:\\WINDOWS\\Temp'; $defaultSymTarget = ($defaultCurrentDir[0] === '/') ? '/tmp' : 'C:\\WINDOWS\\Temp';

View File

@@ -28,7 +28,7 @@ property is false, you echo the content.</p>
require '_include.php'; require '_include.php';
echo send_slowly(get_content(array( send_slowly(get_content(array(
'title' => $title 'title' => $title
,'explain' => $explain ,'explain' => $explain
))); )));

View File

@@ -33,7 +33,7 @@ p span {padding:0 .5em;}
ob_end_clean(); ob_end_clean();
} elseif ($_GET['test'] == '1') { } elseif ($_GET['test'] == '1') {
$content = file_get_contents(dirname(__FILE__) . '/green.png'); $content = file_get_contents(__DIR__ . '/green.png');
$type = 'image/png'; $type = 'image/png';
} elseif ($_GET['test'] == '2') { } elseif ($_GET['test'] == '2') {

View File

@@ -1,7 +1,9 @@
<?php <?php
// comment this out to run tests
die('This script is disabled.');
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
require __DIR__ . '/../min/config.php'; require __DIR__ . '/../config.php';
// set cache path and doc root if configured // set cache path and doc root if configured
$minifyCachePath = isset($min_cachePath) $minifyCachePath = isset($min_cachePath)
@@ -23,7 +25,7 @@ ini_set('display_errors', 1);
header('Content-Type: text/plain;charset=utf-8'); header('Content-Type: text/plain;charset=utf-8');
$thisDir = dirname(__FILE__); $thisDir = __DIR__;
/** /**
* pTest - PHP Unit Tester * pTest - PHP Unit Tester

View File

@@ -1,3 +1,2 @@
function testIssue74(){return /'/;} function testIssue74(){return/'/;}
!function(s){return /^[£$€?.]/.test(s);}();typeof !function(s){return/^[£$€?.]/.test(s);}();typeof/ ' /;x=/ [/] /;1/foo;(2)/foo;function(){return/foo/};function(){return typeof/foo/};
/ ' /;x=/ [/] /;1/foo;(2)/foo;function(){return/foo/};function(){return typeof/foo/};

View File

@@ -1,6 +1,8 @@
<?php <?php
require_once '_inc.php'; require_once '_inc.php';
use JSMin\JSMin;
function test_JSMin() function test_JSMin()
{ {
global $thisDir; global $thisDir;
@@ -59,34 +61,34 @@ function test_JSMin()
test_JSMin_exception('"Hello' test_JSMin_exception('"Hello'
,'Unterminated String' ,'Unterminated String'
,'JSMin_UnterminatedStringException' ,'JSMin\UnterminatedStringException'
,"JSMin: Unterminated String at byte 5: \"Hello"); ,"JSMin: Unterminated String at byte 5: \"Hello");
test_JSMin_exception("return /regexp\n}" test_JSMin_exception("return /regexp\n}"
,'Unterminated RegExp' ,'Unterminated RegExp'
,'JSMin_UnterminatedRegExpException' ,'JSMin\UnterminatedRegExpException'
,"JSMin: Unterminated RegExp at byte 14: /regexp\n"); ,"JSMin: Unterminated RegExp at byte 14: /regexp\n");
test_JSMin_exception("return/regexp\n}" test_JSMin_exception("return/regexp\n}"
,'Unterminated RegExp' ,'Unterminated RegExp'
,'JSMin_UnterminatedRegExpException' ,'JSMin\UnterminatedRegExpException'
,"JSMin: Unterminated RegExp at byte 13: /regexp\n"); ,"JSMin: Unterminated RegExp at byte 13: /regexp\n");
test_JSMin_exception(";return/regexp\n}" test_JSMin_exception(";return/regexp\n}"
,'Unterminated RegExp' ,'Unterminated RegExp'
,'JSMin_UnterminatedRegExpException' ,'JSMin\UnterminatedRegExpException'
,"JSMin: Unterminated RegExp at byte 14: /regexp\n"); ,"JSMin: Unterminated RegExp at byte 14: /regexp\n");
test_JSMin_exception(";return /regexp\n}" test_JSMin_exception(";return /regexp\n}"
,'Unterminated RegExp' ,'Unterminated RegExp'
,'JSMin_UnterminatedRegExpException' ,'JSMin\UnterminatedRegExpException'
,"JSMin: Unterminated RegExp at byte 15: /regexp\n"); ,"JSMin: Unterminated RegExp at byte 15: /regexp\n");
test_JSMin_exception("typeof/regexp\n}" test_JSMin_exception("typeof/regexp\n}"
,'Unterminated RegExp' ,'Unterminated RegExp'
,'JSMin_UnterminatedRegExpException' ,'JSMin\UnterminatedRegExpException'
,"JSMin: Unterminated RegExp at byte 13: /regexp\n"); ,"JSMin: Unterminated RegExp at byte 13: /regexp\n");
test_JSMin_exception("/* Comment " test_JSMin_exception("/* Comment "
,'Unterminated Comment' ,'Unterminated Comment'
,'JSMin_UnterminatedCommentException' ,'JSMin\UnterminatedCommentException'
,"JSMin: Unterminated comment at byte 11: /* Comment "); ,"JSMin: Unterminated comment at byte 11: /* Comment ");
} }

View File

@@ -8,7 +8,7 @@ function test_Minify()
{ {
global $thisDir; global $thisDir;
$minifyTestPath = dirname(__FILE__) . '/_test_files/minify'; $minifyTestPath = __DIR__ . '/_test_files/minify';
$thisFileActive = (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])); $thisFileActive = (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME']));
$tomorrow = $_SERVER['REQUEST_TIME'] + 86400; $tomorrow = $_SERVER['REQUEST_TIME'] + 86400;
$lastModified = $_SERVER['REQUEST_TIME'] - 86400; $lastModified = $_SERVER['REQUEST_TIME'] - 86400;
@@ -19,6 +19,20 @@ function test_Minify()
$_SERVER['HTTP_IF_NONE_MATCH'] = "\"{$lastModified}pub\""; $_SERVER['HTTP_IF_NONE_MATCH'] = "\"{$lastModified}pub\"";
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s \G\M\T', $lastModified); $_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s \G\M\T', $lastModified);
$minify = new Minify(new Minify_Cache_Null());
$env = new Minify_Env(array(
'server' => $_SERVER,
));
$sourceFactory = new Minify_Source_Factory($env, array(), new Minify_Cache_Null());
$controller = new Minify_Controller_Files($env, $sourceFactory);
$output = $minify->serve($controller, array(
'files' => $thisDir . '/_test_files/css/styles.css' // controller casts to array
,'quiet' => true
,'lastModifiedTime' => $lastModified
,'encodeOutput' => false
));
$expected = array ( $expected = array (
'success' => true 'success' => true
,'statusCode' => 304 ,'statusCode' => 304
@@ -32,12 +46,7 @@ function test_Minify()
'_responseCode' => 'HTTP/1.0 304 Not Modified', '_responseCode' => 'HTTP/1.0 304 Not Modified',
) )
); );
$output = Minify::serve('Files', array(
'files' => $thisDir . '/_test_files/css/styles.css' // controller casts to array
,'quiet' => true
,'lastModifiedTime' => $lastModified
,'encodeOutput' => false
));
$passed = assertTrue($expected === $output, 'Minify : 304 response'); $passed = assertTrue($expected === $output, 'Minify : 304 response');
if ($thisFileActive) { if ($thisFileActive) {
echo "\nOutput: " .var_export($output, 1). "\n\n"; echo "\nOutput: " .var_export($output, 1). "\n\n";
@@ -48,8 +57,7 @@ function test_Minify()
assertTrue( assertTrue(
! class_exists('Minify_CSS', false) ! class_exists('Minify_CSS', false)
&& ! class_exists('Minify_Cache_File', false) ,'Minify : minifier classes aren\'t loaded for 304s'
,'Minify : cache, and minifier classes aren\'t loaded for 304s'
); );
// Test JS and Expires // Test JS and Expires
@@ -74,9 +82,16 @@ function test_Minify()
'Content-Type' => 'application/x-javascript; charset=utf-8', 'Content-Type' => 'application/x-javascript; charset=utf-8',
) )
); );
unset($_SERVER['HTTP_IF_NONE_MATCH']); unset($_SERVER['HTTP_IF_NONE_MATCH']);
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']); unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
$output = Minify::serve('Files', array(
$env = new Minify_Env(array(
'server' => $_SERVER,
));
$sourceFactory = new Minify_Source_Factory($env, array(), new Minify_Cache_Null());
$controller = new Minify_Controller_Files($env, $sourceFactory);
$output = $minify->serve($controller, array(
'files' => array( 'files' => array(
$minifyTestPath . '/email.js' $minifyTestPath . '/email.js'
,$minifyTestPath . '/QueryString.js' ,$minifyTestPath . '/QueryString.js'
@@ -95,10 +110,8 @@ function test_Minify()
} }
// test for Issue 73 // test for Issue 73
Minify::setCache(null);
$expected = ";function h(){}"; $expected = ";function h(){}";
$output = Minify::serve('Files', array( $output = $minify->serve($controller, array(
'files' => array( 'files' => array(
$minifyTestPath . '/issue73_1.js' $minifyTestPath . '/issue73_1.js'
,$minifyTestPath . '/issue73_2.js' ,$minifyTestPath . '/issue73_2.js'
@@ -118,7 +131,7 @@ function test_Minify()
// test for Issue 89 // test for Issue 89
$expected = file_get_contents($minifyTestPath . '/issue89_out.min.css'); $expected = file_get_contents($minifyTestPath . '/issue89_out.min.css');
$output = Minify::serve('Files', array( $output = $minify->serve($controller, array(
'files' => array( 'files' => array(
$minifyTestPath . '/issue89_1.css' $minifyTestPath . '/issue89_1.css'
,$minifyTestPath . '/issue89_2.css' ,$minifyTestPath . '/issue89_2.css'
@@ -136,7 +149,7 @@ function test_Minify()
} }
} }
$output = Minify::serve('Files', array( $output = $minify->serve($controller, array(
'files' => array( 'files' => array(
$minifyTestPath . '/issue89_1.css' $minifyTestPath . '/issue89_1.css'
,$minifyTestPath . '/issue89_2.css' ,$minifyTestPath . '/issue89_2.css'
@@ -145,7 +158,10 @@ function test_Minify()
,'encodeOutput' => false ,'encodeOutput' => false
)); ));
$output = $output['content']; $output = $output['content'];
$passed = assertTrue(0 === strpos($output, Minify::$importWarning), 'Minify : Issue 89 : detect invalid imports');
$defaultOptions = $minify->getDefaultOptions();
$passed = assertTrue(0 === strpos($output, $defaultOptions['importWarning']), 'Minify : Issue 89 : detect invalid imports');
if ($thisFileActive) { if ($thisFileActive) {
if (! $passed) { if (! $passed) {
echo "\n---Output : " .var_export($output, 1). "\n"; echo "\n---Output : " .var_export($output, 1). "\n";
@@ -153,7 +169,7 @@ function test_Minify()
} }
} }
$output = Minify::serve('Files', array( $output = $minify->serve($controller, array(
'files' => array( 'files' => array(
$minifyTestPath . '/issue89_1.css' $minifyTestPath . '/issue89_1.css'
) )
@@ -161,7 +177,7 @@ function test_Minify()
,'encodeOutput' => false ,'encodeOutput' => false
)); ));
$output = $output['content']; $output = $output['content'];
$passed = assertTrue(false === strpos($output, Minify::$importWarning), 'Minify : Issue 89 : don\'t warn about valid imports'); $passed = assertTrue(false === strpos($output, $defaultOptions['importWarning']), 'Minify : Issue 89 : don\'t warn about valid imports');
if ($thisFileActive) { if ($thisFileActive) {
if (! $passed) { if (! $passed) {
echo "\n---Output : " .var_export($output, 1). "\n"; echo "\n---Output : " .var_export($output, 1). "\n";
@@ -171,8 +187,8 @@ function test_Minify()
// Test Issue 132 // Test Issue 132
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) { if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
$output = Minify::serve('Files', array( $output = $minify->serve($controller, array(
'files' => array(dirname(__FILE__) . '/_test_files/js/issue132.js') 'files' => array(__DIR__ . '/_test_files/js/issue132.js')
,'quiet' => true ,'quiet' => true
,'encodeOutput' => false ,'encodeOutput' => false
)); ));
@@ -199,7 +215,14 @@ function test_Minify()
'Content-Type' => 'text/css; charset=utf-8', 'Content-Type' => 'text/css; charset=utf-8',
) )
); );
$output = Minify::serve('Files', array(
$env = new Minify_Env(array(
'server' => $_SERVER,
));
$sourceFactory = new Minify_Source_Factory($env, array(), new Minify_Cache_Null());
$controller = new Minify_Controller_Files($env, $sourceFactory);
$output = $minify->serve($controller, array(
'files' => array( 'files' => array(
$thisDir . '/_test_files/css/styles.css' $thisDir . '/_test_files/css/styles.css'
,$thisDir . '/_test_files/css/comments.css' ,$thisDir . '/_test_files/css/comments.css'

View File

@@ -5,7 +5,7 @@ function test_CSS()
{ {
global $thisDir; global $thisDir;
$cssPath = dirname(__FILE__) . '/_test_files/css'; $cssPath = __DIR__ . '/_test_files/css';
// build test file list // build test file list
$d = dir($cssPath); $d = dir($cssPath);

View File

@@ -11,7 +11,7 @@ function test_HTML()
$time = microtime(true); $time = microtime(true);
$minOutput = Minify_HTML::minify($src, array( $minOutput = Minify_HTML::minify($src, array(
'cssMinifier' => array('Minify_CSS', 'minify') 'cssMinifier' => array('Minify_CSS', 'minify')
,'jsMinifier' => array('JSMin', 'minify') ,'jsMinifier' => array('JSMin\\JSMin', 'minify')
)); ));
$time = microtime(true) - $time; $time = microtime(true) - $time;
@@ -34,7 +34,7 @@ function test_HTML()
$time = microtime(true); $time = microtime(true);
$minOutput = Minify_HTML::minify($src, array( $minOutput = Minify_HTML::minify($src, array(
'cssMinifier' => array('Minify_CSS', 'minify') 'cssMinifier' => array('Minify_CSS', 'minify')
,'jsMinifier' => array('JSMin', 'minify') ,'jsMinifier' => array('JSMin\\JSMin', 'minify')
)); ));
$time = microtime(true) - $time; $time = microtime(true) - $time;

View File

@@ -35,7 +35,7 @@ function test_Minify_HTML_Helper()
)); ));
$passed = assertTrue($actual === $expected, 'Minify_HTML_Helper : existing group'); $passed = assertTrue($actual === $expected, 'Minify_HTML_Helper : existing group');
$utilsFile = dirname(dirname(__FILE__)) . '/min/utils.php'; $utilsFile = dirname(__DIR__) . '/min/utils.php';
if (is_file($utilsFile)) { if (is_file($utilsFile)) {
require_once $utilsFile; require_once $utilsFile;

View File

@@ -8,9 +8,12 @@ function test_Lines()
$exp = file_get_contents("{$thisDir}/_test_files/minify/lines_output.js"); $exp = file_get_contents("{$thisDir}/_test_files/minify/lines_output.js");
Minify::setCache(null); // no cache $env = new Minify_Env();
$sourceFactory = new Minify_Source_Factory($env, array(), new Minify_Cache_Null());
$ret = Minify::serve('Files', array( $controller = new Minify_Controller_Files($env, $sourceFactory);
$minify = new Minify(new Minify_Cache_Null());
$ret = $minify->serve($controller, array(
'debug' => true 'debug' => true
,'quiet' => true ,'quiet' => true
,'encodeOutput' => false ,'encodeOutput' => false

View File

@@ -4,13 +4,13 @@
* *
* @warning These functions execute min/groupsConfig.php, sometimes multiple times. * @warning These functions execute min/groupsConfig.php, sometimes multiple times.
* You must make sure that functions are not redefined, and if your use custom sources, * You must make sure that functions are not redefined, and if your use custom sources,
* you must require_once dirname(__FILE__) . '/lib/Minify/Source.php' so that * you must require_once __DIR__ . '/lib/Minify/Source.php' so that
* class is available. * class is available.
* *
* @package Minify * @package Minify
*/ */
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/bootstrap.php';
/* /*
* Get an HTML-escaped Minify URI for a group or set of files. By default, URIs * Get an HTML-escaped Minify URI for a group or set of files. By default, URIs
@@ -56,7 +56,7 @@ function Minify_mtime($keysAndFiles, $groupsConfigFile = null)
{ {
$gc = null; $gc = null;
if (! $groupsConfigFile) { if (! $groupsConfigFile) {
$groupsConfigFile = dirname(__FILE__) . '/groupsConfig.php'; $groupsConfigFile = __DIR__ . '/groupsConfig.php';
} }
$sources = array(); $sources = array();
foreach ($keysAndFiles as $keyOrFile) { foreach ($keysAndFiles as $keyOrFile) {