public static function test(&$error) { try { Minify_ClosureCompiler::minify('alert("ok");'); $error = 'OK'; return true; } catch (Exception $exception) { $error = $exception->getMessage(); return false; } }
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 = "\n (function (window, undefined){\n function addOne(input) {\n return 1 + input;\n }\n window.addOne = addOne;\n window.undefined = undefined;\n })(window);\n "; $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"; } }
// //print_r($test); // list($before) = str_split($contents, $test[2][1]+1); // fetches all the text before the match // $line_number = strlen($before) - strlen(str_replace("\n", "", $before)) + 1; // $warnings[] = "Uncommented console output found building $core_name in: $filePath on line: $line_number"; //} //$core_files[$core_name] .= Minify_ClosureCompiler::minify(file_get_contents($filePath), array()); checkConsoleLog($contents, $warnings, "Console output found in: {$filePath} on line:"); } else { $errors[] = "Unable to find Javascript file for {$core_name}: {$filePath}"; } } if (!count($errors)) { // Strip console.xxx //$core_files[$core_name] = preg_replace('/(;|\s)*console\.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd|time|timeEnd|profile|profileEnd|count)\s*\(.*?\)\s*;/m',';',$core_files[$core_name]); // Compile $core_files[$core_name] = Minify_ClosureCompiler::minify($core_files[$core_name], array()); //$core_files[$core_name] = Minify_YUICompressor::minifyJs($core_files[$core_name], array()); } } $change_count = 0; if (!count($errors)) { // Create Core path if needed: if (!file_exists($pathToCore)) { if (!@mkdir($pathToCore)) { $errors[] = "Unable to access or create core script path: {$pathToCore}"; } } // Create Core CSS and JS files if (!count($errors)) { foreach ($core_files as $core_name => $core) { $file = $pathToCore . "/{$core_name}";