| 1 |
<?php |
| 2 |
|
| 3 |
namespace Minify\Test; |
| 4 |
|
| 5 |
use Exception; |
| 6 |
use Minify_ClosureCompiler; |
| 7 |
use Minify_NailgunClosureCompiler; |
| 8 |
|
| 9 |
class MinifyNailgunClosureCompilerTest extends TestCase |
| 10 |
{ |
| 11 |
public static function setupBeforeClass() |
| 12 |
{ |
| 13 |
parent::setupBeforeClass(); |
| 14 |
Minify_ClosureCompiler::$isDebug = true; |
| 15 |
|
| 16 |
// To test more functionality, download a compiler.jar from |
| 17 |
// https://github.com/google/closure-compiler#getting-started, |
| 18 |
// put it under tests dir as 'compiler.jar' |
| 19 |
|
| 20 |
// set minimum necessary settings |
| 21 |
Minify_ClosureCompiler::$jarFile = __DIR__ . DIRECTORY_SEPARATOR . 'compiler.jar'; |
| 22 |
Minify_ClosureCompiler::$tempDir = sys_get_temp_dir(); |
| 23 |
Minify_NailgunClosureCompiler::$ngJarFile = __DIR__ . DIRECTORY_SEPARATOR . 'nailgun.jar'; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Test minimisation with the minimum necessary settings |
| 28 |
*/ |
| 29 |
public function test1() |
| 30 |
{ |
| 31 |
$this->assertHasJar(); |
| 32 |
$src = " |
| 33 |
(function (window, undefined){ |
| 34 |
function addOne(input) { |
| 35 |
return 1 + input; |
| 36 |
} |
| 37 |
window.addOne = addOne; |
| 38 |
window.undefined = undefined; |
| 39 |
})(window); |
| 40 |
"; |
| 41 |
$minExpected = "(function(a,b){a.addOne=function(a){return 1+a};a.undefined=b})(window);"; |
| 42 |
$minOutput = Minify_NailgunClosureCompiler::minify($src); |
| 43 |
$this->assertSame($minExpected, $minOutput, 'minimum necessary settings'); |
| 44 |
} |
| 45 |
|
| 46 |
protected function assertHasJar() |
| 47 |
{ |
| 48 |
$this->assertNotEmpty(Minify_ClosureCompiler::$jarFile); |
| 49 |
$this->assertNotEmpty(Minify_NailgunClosureCompiler::$ngJarFile); |
| 50 |
try { |
| 51 |
$this->assertFileExists(Minify_ClosureCompiler::$jarFile, "Have closure compiler compiler.jar"); |
| 52 |
$this->assertFileExists(Minify_NailgunClosureCompiler::$ngJarFile, "Have nailgun.jar"); |
| 53 |
} catch (Exception $e) { |
| 54 |
$this->markTestSkipped($e->getMessage()); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|