diff --git a/min/config.php b/min/config.php index b6465e8..76199a0 100644 --- a/min/config.php +++ b/min/config.php @@ -66,6 +66,17 @@ $min_documentRoot = ''; $min_cacheFileLocking = true; +/** + * Combining multiple CSS files can place @import declarations after rules, which + * is invalid. Minify will attempt to detect when this happens and place a + * warning comment at the top of the CSS output. To resolve this you can either + * move the @imports within your CSS files, or enable this option, which will + * move all @imports to the top of the output. Note that moving @imports could + * affect CSS values (which is why this option is disabled by default). + */ +$min_serveOptions['bubbleCssImports'] = false; + + /** * Maximum age of browser cache in seconds. After this period, the browser * will send another conditional GET. Use a longer period for lower traffic diff --git a/min_unit_tests/_test_files/minify/issue89_1.css b/min_unit_tests/_test_files/minify/issue89_1.css new file mode 100644 index 0000000..99f0069 --- /dev/null +++ b/min_unit_tests/_test_files/minify/issue89_1.css @@ -0,0 +1,7 @@ +/* this { is a } comment */ + +@import "/1.css"; + +selector { + property: value; +} diff --git a/min_unit_tests/_test_files/minify/issue89_2.css b/min_unit_tests/_test_files/minify/issue89_2.css new file mode 100644 index 0000000..2de44aa --- /dev/null +++ b/min_unit_tests/_test_files/minify/issue89_2.css @@ -0,0 +1,7 @@ +/* this { is a } comment */ + +@import "/2.css"; + +selector2 { + property: value; +} diff --git a/min_unit_tests/_test_files/minify/issue89_out.min.css b/min_unit_tests/_test_files/minify/issue89_out.min.css new file mode 100644 index 0000000..5fb03c4 --- /dev/null +++ b/min_unit_tests/_test_files/minify/issue89_out.min.css @@ -0,0 +1 @@ +@import "/1.css";@import "/2.css";selector{property:value}selector2{property:value} \ No newline at end of file diff --git a/min_unit_tests/test_Minify.php b/min_unit_tests/test_Minify.php index 7581fba..b377dd1 100644 --- a/min_unit_tests/test_Minify.php +++ b/min_unit_tests/test_Minify.php @@ -10,6 +10,7 @@ function test_Minify() global $thisDir; $minifyTestPath = dirname(__FILE__) . '/_test_files/minify'; + $thisFileActive = (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])); $tomorrow = $_SERVER['REQUEST_TIME'] + 86400; $lastModified = $_SERVER['REQUEST_TIME'] - 86400; @@ -38,7 +39,7 @@ function test_Minify() ,'encodeOutput' => false )); $passed = assertTrue($expected === $output, 'Minify : 304 response'); - if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { + if ($thisFileActive) { echo "\nOutput: " .var_export($output, 1). "\n\n"; if (! $passed) { echo "\n\n\n\n---Expected: " .var_export($expected, 1). "\n\n"; @@ -84,7 +85,7 @@ function test_Minify() )); $passed = assertTrue($expected === $output, 'Minify : JS and Expires'); - if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { + if ($thisFileActive) { echo "\nOutput: " .var_export($output, 1). "\n\n"; if (! $passed) { echo "\n\n\n\n---Expected: " .var_export($expected, 1). "\n\n"; @@ -106,7 +107,60 @@ function test_Minify() $output = $output['content']; $passed = assertTrue($expected === $output, 'Minify : Issue 73'); - if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { + if ($thisFileActive) { + if (! $passed) { + echo "\n---Output : " .var_export($output, 1). "\n"; + echo "---Expected: " .var_export($expected, 1). "\n\n"; + } + } + + // test for Issue 89 + $expected = file_get_contents($minifyTestPath . '/issue89_out.min.css'); + $output = Minify::serve('Files', array( + 'files' => array( + $minifyTestPath . '/issue89_1.css' + ,$minifyTestPath . '/issue89_2.css' + ) + ,'quiet' => true + ,'encodeOutput' => false + ,'bubbleCssImports' => true + )); + $output = $output['content']; + $passed = assertTrue($expected === $output, 'Minify : Issue 89 : bubbleCssImports'); + if ($thisFileActive) { + if (! $passed) { + echo "\n---Output : " .var_export($output, 1). "\n"; + echo "---Expected: " .var_export($expected, 1). "\n\n"; + } + } + + $output = Minify::serve('Files', array( + 'files' => array( + $minifyTestPath . '/issue89_1.css' + ,$minifyTestPath . '/issue89_2.css' + ) + ,'quiet' => true + ,'encodeOutput' => false + )); + $output = $output['content']; + $passed = assertTrue(0 === strpos($output, Minify::$importWarning), 'Minify : Issue 89 : detect invalid imports'); + if ($thisFileActive) { + if (! $passed) { + echo "\n---Output : " .var_export($output, 1). "\n"; + echo "---Expected: " .var_export($expected, 1). "\n\n"; + } + } + + $output = Minify::serve('Files', array( + 'files' => array( + $minifyTestPath . '/issue89_1.css' + ) + ,'quiet' => true + ,'encodeOutput' => false + )); + $output = $output['content']; + $passed = assertTrue(false === strpos($output, Minify::$importWarning), 'Minify : Issue 89 : don\'t warn about valid imports'); + if ($thisFileActive) { if (! $passed) { echo "\n---Output : " .var_export($output, 1). "\n"; echo "---Expected: " .var_export($expected, 1). "\n\n"; @@ -146,7 +200,7 @@ function test_Minify() )); $passed = assertTrue($expected === $output, 'Minify : CSS and Etag/Last-Modified'); - if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { + if ($thisFileActive) { echo "\nOutput: " .var_export($output, 1). "\n\n"; if (! $passed) { echo "\n\n\n\n---Expected: " .var_export($expected, 1). "\n\n";