<?php

require dirname(__FILE__) . '/../bootstrap/unit.php';
require dirname(__FILE__) . '/../../lib/compressor/sfAssetsManagerPacker.class.php';
$fileDir = dirname(__FILE__) . '/../fixtures/js';
$t = new lime_test(2, new lime_output_color());
$packer = new sfAssetsManagerPacker();
$file = $packer->execute(array($fileDir . '/file1.js', $fileDir . '/file2.js'));
$t->ok(file_exists($file), '->execute() creates a temporary file');
$t->is(file_get_contents($file), "var file1 = 'file1 content';\nvar file2 = 'file2 content';\n", '->execute() packs multiple files content into 1 file');
 /**
  * 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
     if ($type == 'js') {
         $minifier = new sfAssetsManagerJSMinifier();
     } elseif ($type == 'css') {
         $cdnImg = sfConfig::get('app_sf_assets_manager_plugin_cdn_img', '');
         $strCss = str_replace("url('/", "url('" . $cdnImg . '/', file_get_contents($packed));
         file_put_contents($packed, $strCss);
         $minifier = new sfAssetsManagerCSSMinifier();
     }
     $minified = $minifier->execute($packed);
     $outputUri = $this->getFileUri($name, $type);
     $outputPath = sfConfig::get('sf_web_dir') . $outputUri;
     // create file
     rename($minified, $outputPath);
     return $outputUri;
 }
 /**
  * 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;
 }