From 4f344b5d2196715c0f90bfcaaf0943b9b62c0089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 18 Nov 2015 17:33:01 +0200 Subject: [PATCH] port MinifyClosureCompilerTest to phpunit --- .../test_Minify_ClosureCompiler.php | 75 ------------------- min_unit_tests/test_all.php | 1 - tests/MinifyClosureCompilerTest.php | 72 ++++++++++++++++++ 3 files changed, 72 insertions(+), 76 deletions(-) delete mode 100644 min_unit_tests/test_Minify_ClosureCompiler.php create mode 100644 tests/MinifyClosureCompilerTest.php diff --git a/min_unit_tests/test_Minify_ClosureCompiler.php b/min_unit_tests/test_Minify_ClosureCompiler.php deleted file mode 100644 index 0ffe761..0000000 --- a/min_unit_tests/test_Minify_ClosureCompiler.php +++ /dev/null @@ -1,75 +0,0 @@ -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(); diff --git a/min_unit_tests/test_all.php b/min_unit_tests/test_all.php index bc473d7..d586af1 100644 --- a/min_unit_tests/test_all.php +++ b/min_unit_tests/test_all.php @@ -9,7 +9,6 @@ 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_YuiCSS.php'; require 'test_Minify_HTML.php'; require 'test_Minify_ImportProcessor.php'; diff --git a/tests/MinifyClosureCompilerTest.php b/tests/MinifyClosureCompilerTest.php new file mode 100644 index 0000000..3aace70 --- /dev/null +++ b/tests/MinifyClosureCompilerTest.php @@ -0,0 +1,72 @@ +fail(); + } catch (Exception $e) { + $this->assertInstanceOf('Minify_ClosureCompiler_Exception', $e); + } + } + + /** + * Test minification with the minimum necessary settings + */ + public function test2() + { + $this->assertHasCompilerJar(); + $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); + $this->assertSame($minExpected, $minOutput, 'minimum necessary settings'); + } + + /** + * Test minification with advanced compilation level + */ + public function test3() + { + $this->assertHasCompilerJar(); + $src = "function unused() {};"; + $minExpected = ''; + $minOutput = Minify_ClosureCompiler::minify($src, array( + Minify_ClosureCompiler::OPTION_COMPILATION_LEVEL => 'ADVANCED_OPTIMIZATIONS' + )); + $this->assertSame($minExpected, $minOutput, 'advanced optimizations'); + } + + protected function assertHasCompilerJar() + { + $this->assertFileExists(Minify_ClosureCompiler::$jarFile, "Have closure compiler compiler.jar"); + } +} \ No newline at end of file