diff --git a/min/config.php b/min/config.php index 040908e..cbb9fa9 100644 --- a/min/config.php +++ b/min/config.php @@ -45,9 +45,10 @@ $min_enableBuilder = true; /** - * On most servers, this can be left empty. On others, $_SERVER['DOCUMENT_ROOT'] - * may be misconfigured or missing. If so, set this to your full document - * root path with no trailing slash. + * Leave an empty string to use PHP's $_SERVER['DOCUMENT_ROOT']. + * + * On some servers, this value may be misconfigured or missing. If so, set this + * to your full document root path with no trailing slash. * E.g. '/home/accountname/public_html' or 'c:\\xampp\\htdocs' * * If /min/ is directly inside your document root, just uncomment the diff --git a/min_unit_tests/_inc.php b/min_unit_tests/_inc.php index 1f99017..6c82808 100644 --- a/min_unit_tests/_inc.php +++ b/min_unit_tests/_inc.php @@ -4,9 +4,13 @@ require dirname(__FILE__) . '/../min/config.php'; set_include_path($min_libPath . PATH_SEPARATOR . get_include_path()); +// set cache path and doc root if configured $minifyCachePath = isset($min_cachePath) ? $min_cachePath : ''; +if ($min_documentRoot) { + $_SERVER['DOCUMENT_ROOT'] = $min_documentRoot; +} error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); diff --git a/min_unit_tests/_test_files/css/paths.css b/min_unit_tests/_test_files/css/paths_prepend.css similarity index 100% rename from min_unit_tests/_test_files/css/paths.css rename to min_unit_tests/_test_files/css/paths_prepend.css diff --git a/min_unit_tests/_test_files/css/paths.min.css b/min_unit_tests/_test_files/css/paths_prepend.min.css similarity index 100% rename from min_unit_tests/_test_files/css/paths.min.css rename to min_unit_tests/_test_files/css/paths_prepend.min.css diff --git a/min_unit_tests/_test_files/css/paths_rewrite.css b/min_unit_tests/_test_files/css/paths_rewrite.css new file mode 100644 index 0000000..aa41d0a --- /dev/null +++ b/min_unit_tests/_test_files/css/paths_rewrite.css @@ -0,0 +1,14 @@ +@import "foo.css"; +@import 'bar/foo.css' print; +@import '../bar/foo.css' print; +@import '../../foo.css' print; +@import '/css/foo.css'; /* abs, should not alter */ +@import 'http://foo.com/css/foo.css'; /* abs, should not alter */ +@import url(../foo.css) tv, projection; +@import url("/css/foo.css"); /* abs, should not alter */ +@import url(/css2/foo.css); /* abs, should not alter */ +@import url(data:image/gif;base64,AAAA); /* data, should not alter */ +foo {background:url('bar/foo.png')} +foo {background:url('http://foo.com/css/foo.css');} /* abs, should not alter */ +foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */ +foo {background:url(data:image/gif;base64,AAAA);} /* data, should not alter */ \ No newline at end of file diff --git a/min_unit_tests/_test_files/css/paths_rewrite.min.css b/min_unit_tests/_test_files/css/paths_rewrite.min.css new file mode 100644 index 0000000..3493615 --- /dev/null +++ b/min_unit_tests/_test_files/css/paths_rewrite.min.css @@ -0,0 +1 @@ +@import "/_test_files/css/foo.css";@import '/_test_files/css/bar/foo.css' print;@import '/_test_files/bar/foo.css' print;@import '/foo.css' print;@import '/css/foo.css';@import 'http://foo.com/css/foo.css';@import url(/_test_files/foo.css) tv, projection;@import url("/css/foo.css");@import url(/css2/foo.css);@import url(data:image/gif;base64,AAAA);foo{background:url('/_test_files/css/bar/foo.png')}foo{background:url('http://foo.com/css/foo.css')}foo{background:url("//foo.com/css/foo.css")}foo{background:url(data:image/gif;base64,AAAA)} \ No newline at end of file diff --git a/min_unit_tests/_test_files/css/styles.css b/min_unit_tests/_test_files/css/styles.css index 32d4b7f..bf46c0a 100644 --- a/min_unit_tests/_test_files/css/styles.css +++ b/min_unit_tests/_test_files/css/styles.css @@ -1,6 +1,6 @@ /* some CSS to try to exercise things in general */ -@import url( more.css ); +@import url( /more.css ); body, td, th { font-family: Verdana , "Bitstream Vera Sans" , sans-serif ; diff --git a/min_unit_tests/_test_files/css/styles.min.css b/min_unit_tests/_test_files/css/styles.min.css index e29908d..a823b05 100644 --- a/min_unit_tests/_test_files/css/styles.min.css +++ b/min_unit_tests/_test_files/css/styles.min.css @@ -1,3 +1,3 @@ -@import url(more.css);body,td,th{font-family:Verdana,"Bitstream Vera Sans",sans-serif;font-size:12px}.nav{margin-left:20%}#main-nav{background-color:red;border:1px +@import url(/more.css);body,td,th{font-family:Verdana,"Bitstream Vera Sans",sans-serif;font-size:12px}.nav{margin-left:20%}#main-nav{background-color:red;border:1px solid #0f7}div#content h1+p{padding-top:0;margin-top:0}@media all and (min-width: 640px){#media-queries-1{background-color:#0f0}}@media screen and (max-width: 2000px){#media-queries-2{background-color:#0f0}} \ No newline at end of file diff --git a/min_unit_tests/_test_files/importProcessor/output.css b/min_unit_tests/_test_files/importProcessor/output.css index c2b1095..1e4358c 100644 --- a/min_unit_tests/_test_files/importProcessor/output.css +++ b/min_unit_tests/_test_files/importProcessor/output.css @@ -1,7 +1,7 @@ @media screen { /* some CSS to try to exercise things in general */ -@import url(%TEST_FILES_URI%/css/more.css); +@import url(/more.css); body, td, th { font-family: Verdana , "Bitstream Vera Sans" , sans-serif ; diff --git a/min_unit_tests/_test_files/minify/minified.css b/min_unit_tests/_test_files/minify/minified.css index dc3a23e..0c36a5a 100644 --- a/min_unit_tests/_test_files/minify/minified.css +++ b/min_unit_tests/_test_files/minify/minified.css @@ -1,20 +1,4 @@ -@import url(%PATH_TO_WEB_TEST%/_test_files/css/more.css);body,td,th{font-family:Verdana,"Bitstream Vera Sans",sans-serif;font-size:12px}.nav{margin-left:20%}#main-nav{background-color:red;border:1px +@import url(/more.css);body,td,th{font-family:Verdana,"Bitstream Vera Sans",sans-serif;font-size:12px}.nav{margin-left:20%}#main-nav{background-color:red;border:1px solid #0f7}div#content -h1+p{padding-top:0;margin-top:0}@media all and (min-width: 640px){#media-queries-1{background-color:#0f0}}@media screen and (max-width: 2000px){#media-queries-2{background-color:#0f0}}.float-l{float:left}.form-suggest{height:200px;background:#DEE2D0;vertical-align:top}.form-input -input{font-size:10px}.hide{display:none}.form-input -textarea{font-size:11px;width:350px}.form-label{font-size:10px;font-weight:bold;line-height:25px;padding-right:10px;text-align:right;width:100px;color:#39738F}.font-9{font-size:9px}.form-topic{font-weight:bold}.form-error{color:red}.inline{display:inline}.space-10{clear:both;font-size:10px;height:10px;line-height:10px}.suggest-success{color:green;padding-left:10px;font-size:11px;font-weight:bold}.top{vertical-align:top}table -td{padding:3px}a:link,a:active,a:visited,a.postlink{color:#069;text-decoration:none}a:hover{color:#DD6900}a.admin:hover,a.mod:hover{color:#DD6900}a.but,a.but:hover,a.but:visited{color:#000;text-decoration:none}a.topictitle:visited{color:#5493B4}a.topictitle:hover{color:#DD6900}body{color:#000;font:11px Verdana,Arial,Helvetica,sans-serif;margin:0 -10px 10px 10px;padding:0;overflow:auto}font,th,td,p{font:12px Verdana,Arial,Helvetica,sans-serif}form{display:inline}hr{border:0px -solid #FFF;border-top-width:1px;height:0px}img{border:0 -solid}input{font:11px Verdana,Arial,Helvetica,sans-serif}input.button,input.liteoption,.fakebut{background:#FAFAFA;border:1px -solid #000;font-size:11px}input.catbutton{background:#FAFAFA;border:1px -solid #000;font-size:10px}input.mainoption{background:#FAFAFA;border:1px -solid #000;font-size:11px;font-weight:bold}input.post,textarea.post{background:#FFF;border:1px -solid #000;font:11px Verdana,Arial,Helvetica,sans-serif;padding-bottom:2px;padding-left:2px}select{background:#FFF;font:11px Verdana,Arial,Helvetica,sans-serif}table{text-align:left}td{vertical-align:middle}td.cat{background-color:#C2C6BA;font-weight:bold;height:20px;letter-spacing:1px;text-indent:4px}td.genmed,.genmed{font-size:11px}td.rowpic{background:#C2C6BA}td.spacerow{background:#E5E6E2}th{background-color:#FADD31;background-image:url(%PATH_TO_WEB_TEST%/_test_files/css/images/cellpic3.gif);background-repeat:repeat-x;color:#68685E;font-size:11px;font-weight:bold;line-height:16px;height:16px;padding-left:8px;padding-right:8px;text-align:center;white-space:nowrap}.admin,.mod{font-size:11px;font-weight:bold}.admin,a.admin,a.admin:visited{color:#FFA34F}.bodyline{background:#FFF;border:1px -solid #98AAB1}.center{text-align:center}.code{background:#FAFAFA;border:1px -solid #D1D7DC;color:#060;font:12px Courier,"Courier New",sans-serif;padding:5px}.errorline{background:#E5E6E2;border:1px -solid #8F8B8B;color:#D92A2A}.explaintitle{color:#5C81B1;font-size:11px;font-weight:bold}.forumline{background:#FFF}.gensmall{font-size:10px}.h1-font{color:#069;display:inline;font:bold 13px Verdana,Arial,Helvetica,sans-serif;margin:0;text-decoration:none}.h2-font{display:inline;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11px}.height1{height:1px}.height22{height:22px}.height25{height:25px}.height28{height:28px}.height30{height:30px}.height40{height:40px}.helpline{border:0 -solid;font-size:10px}.imgfolder{margin:1px -4px 1px 4px}.imgspace{margin-left:1px;margin-right:2px}.imgtopic,.imgicon{margin-left:3px}.left{text-align:left}.maintitle,h1,h2{color:#5C81B1;font:bold 20px/120% "Trebuchet MS",Verdana,Arial,Helvetica,sans-serif;text-decoration:none}.maxwidth{width:100%}.mod,a.mod,a.mod:visited{color:#060}.name{font-size:11px;font-weight:bold}.nav{font-size:11px;font-weight:bold}.nowrap{white-space:nowrap}.postbody{font-size:12px;line-height:125%}.postbody -a{text-decoration:underline}.postdetails{color:#00396A;font-size:10px}.quote{background:#F3F3EF;border:1px -solid #C2C6BA;color:#069;font-size:11px;line-height:125%}.right{text-align:right}.row1{background:#F0F0EB}.row2,.helpline{background:#E5E6E2}.row3{background:#DBDBD4}.subtitle,h2{font:bold 18px/180% "Trebuchet MS",Verdana,Arial,Helvetica,sans-serif;text-decoration:none}.topictitle{color:#000;font-size:11px;font-weight:bold}.underline{text-decoration:underline}.top{vertical-align:top}.image-hspace{margin-right:3px}.clear{clear:both} \ No newline at end of file +h1+p{padding-top:0;margin-top:0}@media all and (min-width: 640px){#media-queries-1{background-color:#0f0}}@media screen and (max-width: 2000px){#media-queries-2{background-color:#0f0}} +/* YUI Compressor style comments are preserved */ diff --git a/min_unit_tests/test_Minify.php b/min_unit_tests/test_Minify.php index 5c6429c..8b5184f 100644 --- a/min_unit_tests/test_Minify.php +++ b/min_unit_tests/test_Minify.php @@ -120,16 +120,7 @@ function test_Minify() // don't allow conditional headers unset($_SERVER['HTTP_IF_NONE_MATCH'], $_SERVER['HTTP_IF_MODIFIED_SINCE']); - $pathToWebTest = str_replace( - DIRECTORY_SEPARATOR - ,'/' - ,substr(dirname(__FILE__), strlen(realpath($_SERVER['DOCUMENT_ROOT']))) - ); - $expectedContent = str_replace( - '%PATH_TO_WEB_TEST%' - ,$pathToWebTest - ,file_get_contents($minifyTestPath . '/minified.css') - ); + $expectedContent = file_get_contents($minifyTestPath . '/minified.css'); $expected = array( 'success' => true @@ -146,7 +137,7 @@ function test_Minify() $output = Minify::serve('Files', array( 'files' => array( $thisDir . '/_test_files/css/styles.css' - ,$thisDir . '/_test_files/css/subsilver.css' + ,$thisDir . '/_test_files/css/comments.css' ) ,'quiet' => true ,'lastModifiedTime' => $lastModified diff --git a/min_unit_tests/test_Minify_Build.php b/min_unit_tests/test_Minify_Build.php index b4e3677..f68f519 100644 --- a/min_unit_tests/test_Minify_Build.php +++ b/min_unit_tests/test_Minify_Build.php @@ -7,7 +7,7 @@ function test_Minify_Build() { global $thisDir; - $file1 = $thisDir . '/_test_files/css/paths.css'; + $file1 = $thisDir . '/_test_files/css/paths_prepend.css'; $file2 = $thisDir . '/_test_files/css/styles.css'; $maxTime = max(filemtime($file1), filemtime($file2)); diff --git a/min_unit_tests/test_Minify_CSS.php b/min_unit_tests/test_Minify_CSS.php index 1b4841e..96e1875 100644 --- a/min_unit_tests/test_Minify_CSS.php +++ b/min_unit_tests/test_Minify_CSS.php @@ -20,13 +20,24 @@ function test_CSS() foreach ($list as $item) { - $options = ($item === 'paths') - ? array('prependRelativePath' => '../') - : array(); + $options = array(); + if ($item === 'paths_prepend') { + $options = array('prependRelativePath' => '../'); + } elseif ($item === 'paths_rewrite') { + $options = array('currentDir' => $thisDir . '/_test_files/css'); + $tempDocRoot = $_SERVER['DOCUMENT_ROOT']; + $_SERVER['DOCUMENT_ROOT'] = $thisDir; + } $src = file_get_contents($cssPath . "/{$item}.css"); $minExpected = file_get_contents($cssPath . "/{$item}.min.css"); $minOutput = Minify_CSS::minify($src, $options); + + // reset doc root as configured + if ($item === 'paths_rewrite') { + $_SERVER['DOCUMENT_ROOT'] = $tempDocRoot; + } + $passed = assertTrue($minExpected === $minOutput, 'Minify_CSS : ' . $item); if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { diff --git a/min_unit_tests/test_Minify_CSS_UriRewriter.php b/min_unit_tests/test_Minify_CSS_UriRewriter.php index 5259f16..704ab01 100644 --- a/min_unit_tests/test_Minify_CSS_UriRewriter.php +++ b/min_unit_tests/test_Minify_CSS_UriRewriter.php @@ -13,8 +13,8 @@ function test_Minify_CSS_UriRewriter() $actual = Minify_CSS_UriRewriter::rewrite( $in - ,$thisDir . '/_test_files/css_uriRewriter' - ,$thisDir + ,$thisDir . '/_test_files/css_uriRewriter' // currentDir + ,$thisDir // use DOCUMENT_ROOT = '/full/path/to/min_unit_tests' ); $passed = assertTrue($expected === $actual, 'Minify_CSS_UriRewriter'); diff --git a/min_unit_tests/test_environment.php b/min_unit_tests/test_environment.php index 94b3af3..f801569 100644 --- a/min_unit_tests/test_environment.php +++ b/min_unit_tests/test_environment.php @@ -25,18 +25,24 @@ function test_environment() 0 === preg_match('@[\\\\/]$@', $_SERVER['DOCUMENT_ROOT']) ,'environment : DOCUMENT_ROOT should not end in trailing slash' ); - $goodRoot = assertTrue( - 0 === strpos(realpath(__FILE__), realpath($_SERVER['DOCUMENT_ROOT'])) - ,'environment : DOCUMENT_ROOT should be real path and contain this test file' + $isRealPath = assertTrue(false !== realpath($_SERVER['DOCUMENT_ROOT']) + ,'environment : DOCUMENT_ROOT should pass realpath()' ); - if (! $noSlash || ! $goodRoot) { - echo "!NOTE: environment : If you cannot modify DOCUMENT_ROOT, consider " - . "setting \$min_documentRoot in config.php\n"; + $containsThisFile = assertTrue( + 0 === strpos(realpath(__FILE__), realpath($_SERVER['DOCUMENT_ROOT'])) + ,'environment : DOCUMENT_ROOT should contain this test file' + ); + if (! $noSlash || ! $isRealPath || ! $containsThisFile) { + echo "\nDOCUMENT_ROOT is set to: '{$_SERVER['DOCUMENT_ROOT']}'. If you " + . "cannot modify this, consider setting \$min_documentRoot in config.php\n\n"; } if (isset($_SERVER['SUBDOMAIN_DOCUMENT_ROOT'])) { - echo "!NOTE: environment : \$_SERVER['SUBDOMAIN_DOCUMENT_ROOT'] is set. " + echo "\n!NOTE: 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"; + } $thisUrl = 'http://' . $_SERVER['HTTP_HOST'] // avoid redirects when SERVER_NAME doesn't match