diff --git a/tests/MinifyClosureCompilerTest.php b/tests/MinifyClosureCompilerTest.php index ea93eea..13c88d0 100644 --- a/tests/MinifyClosureCompilerTest.php +++ b/tests/MinifyClosureCompilerTest.php @@ -80,12 +80,22 @@ class MinifyClosureCompilerTest extends TestCase { $this->assertHasJar(); - $src = file_get_contents(self::$test_files . '/bug-513.js'); + $src = $this->getDataFile('bug-513.js'); $minExpected = 'var a=4;'; $minOutput = Minify_ClosureCompiler::minify($src); $this->assertSame($minExpected, $minOutput, 'advanced optimizations'); } + public function testOptions() + { + $this->assertHasJar(); + + $src = $this->getDataFile('js/jscomp.polyfill.js'); + $exp = $this->getDataFile('js/jscomp.polyfill.min.js'); + $res = Minify_ClosureCompiler::minify($src); + $this->assertSame($exp, $res); + } + protected function assertHasJar() { $this->assertNotEmpty(Minify_ClosureCompiler::$jarFile); diff --git a/tests/TestCase.php b/tests/TestCase.php index a871461..f763412 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -47,4 +47,23 @@ class TestCase extends PHPUnit_Framework_TestCase $this->assertSame($data, $displayed, "$id display"); $this->assertEquals($data, $cache->fetch($id), "$id fetch"); } + + /** + * Read data file, assert that it exists and is not empty. + * As a side effect calls trim() to fight against different Editors that insert or strip final newline. + * + * @param string $filename + * @return string + */ + protected function getDataFile($filename) + { + $path = self::$test_files . '/' . $filename; + $this->assertFileExists($path); + $contents = file_get_contents($path); + $this->assertNotEmpty($contents); + $contents = trim($contents); + $this->assertNotEmpty($contents); + + return $contents; + } } \ No newline at end of file diff --git a/tests/_test_files/js/jscomp.polyfill.js b/tests/_test_files/js/jscomp.polyfill.js new file mode 100644 index 0000000..f1da735 --- /dev/null +++ b/tests/_test_files/js/jscomp.polyfill.js @@ -0,0 +1,7 @@ +(function() { + /** + * @type {string} + */ + var $array = jQuery.find('#div'); + print($array.find('a')); +})(); \ No newline at end of file diff --git a/tests/_test_files/js/jscomp.polyfill.min.js b/tests/_test_files/js/jscomp.polyfill.min.js new file mode 100644 index 0000000..6146151 --- /dev/null +++ b/tests/_test_files/js/jscomp.polyfill.min.js @@ -0,0 +1 @@ +(function(){var a=jQuery.find("#div");print(a.find("a"))})(); \ No newline at end of file