<?php require dirname(__FILE__) . '/../bootstrap/unit.php'; require dirname(__FILE__) . '/../../lib/compressor/sfAssetsManagerJSMinifier.class.php'; $fileDir = dirname(__FILE__) . '/../fixtures/js'; $minifier = new sfAssetsManagerJSMinifier(); $file = $minifier->execute($fileDir . '/expanded.js'); $t = new lime_test(2, new lime_output_color()); $t->ok(file_exists($file), '->execute() returns a file path'); $t->is(file_get_contents($file), "\nvar uncompressed='';var uncompressed2=2", '->execute() compresses the js file content');
/** * Pack files, minify contents and save result into a file. * @param array $files * @param sting $type "js" or "css" * @param string $name * @return string The web path of the created compressed file */ protected function compress(array $files, $type, $name) { if (empty($files)) { return; } // Abslotute files path $sources = array(); foreach ($files as $file) { $sources[] = $this->getAbsoluteDir($file, $type); } // merge files $packer = new sfAssetsManagerPacker(); $packed = $packer->execute($sources); // minify file $minifier = new sfAssetsManagerJSMinifier(); $minified = $minifier->execute($packed); $outputUri = $this->getFileUri($name, $type); $outputPath = sfConfig::get('sf_web_dir') . $outputUri; // create file rename($minified, $outputPath); return $outputUri; }