Permalink
Browse files

fixes and added support for passing a compressor to collection constr…

…uctor via options COMPRESSOR field
  • Loading branch information...
1 parent e8bd348 commit 0eba67cb0e583ce2ba41ae79addee267b0608aff @kaviththiranga committed Dec 11, 2012
@@ -46,7 +46,7 @@ public function __construct($options = array())
}
/**
- * Method to combine a set of files and save to single file.
+ * Method to combine content of a set of files.
*
* @return Void
*
@@ -32,7 +32,7 @@ public function __construct($options = array())
}
/**
- * Method to combine a set of files and save to single file.
+ * Method to combine content of a set of css files
*
* @return Void
*
@@ -53,7 +53,18 @@ public function combine()
{
$this->options['COMPRESS_OPTIONS']['type'] = 'css';
- $this->combined .= JMediaCompressor::compressString(JFile::read($file), $this->options['COMPRESS_OPTIONS']) . "\n\n";
+ if ($this->options['COMPRESSOR'] != null && $this->options['COMPRESSOR']->isSupported($file))
+ {
+ $compressor = $this->options['COMPRESSOR'];
+ $compressor->setUncompressed(file_get_contents($file));
+ $compressor->compress();
+
+ $this->combined .= $compressor->getCompressed();
+ }
+ else
+ {
+ $this->combined .= JMediaCompressor::compressString(JFile::read($file), $this->options['COMPRESS_OPTIONS']) . "\n\n";
+ }
}
else
{
@@ -33,7 +33,7 @@ public function __construct($options = array())
}
/**
- * Method to combine a set of files and save to single file.
+ * Method to combine content of a set of js files
*
* @since 12.1
*
@@ -54,7 +54,18 @@ public function combine()
{
$this->options['COMPRESS_OPTIONS']['type'] = 'js';
- $this->combined .= JMediaCompressor::compressString(JFile::read($file), $this->options['COMPRESS_OPTIONS']) . "\n\n";
+ if ($this->options['COMPRESSOR'] != null && $this->options['COMPRESSOR']->isSupported($file))
+ {
+ $compressor = $this->options['COMPRESSOR'];
+ $compressor->setUncompressed(file_get_contents($file));
+ $compressor->compress();
+
+ $this->combined .= $compressor->getCompressed();
+ }
+ else
+ {
+ $this->combined .= JMediaCompressor::compressString(JFile::read($file), $this->options['COMPRESS_OPTIONS']) . "\n\n";
+ }
}
else
{
@@ -1,48 +1,48 @@
-<?php
-/**
- * @package Joomla.UnitTest
- * @subpackage Media
- *
- * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
- * @license GNU General Public License version 2 or later; see LICENSE
- */
-
-jimport('joomla.filesystem.file');
-jimport('joomla.filesystem.folder');
-
-/**
- * Test class for JMediaCompressor.
- */
-class JMediaCombinerCssTest extends TestCase
-{
- /**
- * @var JMediaCompressor
- */
- protected $object;
-
-
- /**
- * Sets up the fixture, for example, opens a network connection.
- * This method is called before a test is executed.
- */
- protected function setUp()
- {
- $this->object = JMediaCombiner::getInstance(array('type' => 'css'));
- }
-
-
- public function testCombine()
- {
- }
-
- public function loadCssFiles()
- {
- // Path to source css files
- $path = JPATH_BASE . '/test_files/css';
-
- $files = JFolder::files($path,'.',false,true, array(), array('.min.css', '.php', '.html','.combined.css'));//get full path
-
- return $files;
- }
-
+<?php
+/**
+ * @package Joomla.UnitTest
+ * @subpackage Media
+ *
+ * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+jimport('joomla.filesystem.file');
+jimport('joomla.filesystem.folder');
+
+/**
+ * Test class for JMediaCollectionCss.
+ */
+class JMediaCombinerCssTest extends TestCase
+{
+ /**
+ * @var JMediaCollectionCss
+ */
+ protected $object;
+
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ $this->object = JMediaCollection::getInstance(array('type' => 'css'));
+ }
+
+
+ public function testCombine()
+ {
+ }
+
+ public function loadCssFiles()
+ {
+ // Path to source css files
+ $path = JPATH_BASE . '/test_files/css';
+
+ $files = JFolder::files($path,'.',false,true, array(), array('.min.css', '.php', '.html','.combined.css'));//get full path
+
+ return $files;
+ }
+
}
@@ -16,7 +16,7 @@
class JMediaCombinerJsTest extends TestCase
{
/**
- * @var JMediaCompressor
+ * @var JMediaCollection
*/
protected $object;
@@ -27,13 +27,13 @@ class JMediaCombinerJsTest extends TestCase
*/
protected function setUp()
{
- $this->object = JMediaCombiner::getInstance(array('type' => 'js'));
+ $this->object = JMediaCollection::getInstance(array('type' => 'js'));
}
public function testCombine()
{
- $this->object->setSources($this->loadJsFiles());
+ $this->object->addFiles($this->loadJsFiles());
$this->object->combine();
Oops, something went wrong.

0 comments on commit 0eba67c

Please sign in to comment.