Permalink
Browse files

Compressor tests implemented

  • Loading branch information...
kaviththiranga committed Jul 29, 2012
1 parent 1edad0a commit 8b660579bb7425f4d1369cbcc94b3f42c57209d3
@@ -1,3 +1,4 @@
+
<?php
/**
* @package Joomla.UnitTest
@@ -30,12 +31,23 @@ protected function setUp()
$this->object = JMediaCompressor::getInstance(array('type' => 'css'));
}
+ public function testGetInstance()
+ {
+ $compressor1 = JMediaCompressor::getInstance(array('type'=>'css'));
+
+ $this->assertInstanceOf('JMediaCompressorCss', $compressor1);
+
+ $compressor2 = JMediaCompressor::getInstance(array('type'=>'js'));
+
+ $this->assertInstanceOf('JMediaCompressorJs', $compressor2);
+ }
public function testSetCompressed()
{
$random = rand();
$this->object->setCompressed($random);
$test = $this->object->getCompressed();
$this->assertEquals($random,$test);
+ $this->object->clear();
}
public function testSetUncompressed()
@@ -44,32 +56,36 @@ public function testSetUncompressed()
$this->object->setUncompressed($random);
$test = $this->object->getUncompressed();
$this->assertEquals($random,$test);
+ $this->object->clear();
}
-
- public function testCompress()
+
+ public function testGetRatio()
{
-
- echo 'Starting Media Compression Test';
-
- $path = dirname(JPATH_PLATFORM).'\media\system\css';
- $files = JFolder::files($path,'.',false,true);
- foreach($files as $file)
- {
- $start = microtime();
- echo ' File: ' . basename($file);
- $uncompressed= JFile::read($file);
- $uncompressed_size = strlen($uncompressed);
- echo ' Before: ' . $uncompressed_size . ' bytes';
- $this->object->setUncompressed($uncompressed);
- $this->object->compress();
- $compressed = $this->object->getCompressed();
- $compressed_size = strlen($compressed);
- echo ' After: ' . $compressed_size . ' bytes';
- echo ' Ratio: ' . round(($compressed_size / $uncompressed_size),2);
- echo ' Time: '. round((microtime()-$start),4). ' ms';
- echo '';
- }
-
-
+ $this->object->setUncompressed("TestUncompressed");
+ $this->object->setCompressed("TestCompressed");
+
+ $expected = round ((14/16)*100 , 2);
+ $test = $this->object->getRatio();
+
+ $this->assertEquals($expected, $test);
+
+ $this->object->clear();
}
+
+ public function testCompressString()
+ {
+
+ }
+
+ public function testIsSupported()
+ {
+ $file1 = JPATH_BASE . '/test_files/css/comments.css';
+
+ $this->assertTrue(JMediaCompressor::isSupported($file1));
+
+ $file2 = JPATH_BASE . '/test_files/js/case1.js';
+
+ $this->assertTrue(JMediaCompressor::isSupported($file2));
+ }
+
}
@@ -36,6 +36,7 @@ public function testSetCompressed()
$this->object->setCompressed($random);
$test = $this->object->getCompressed();
$this->assertEquals($random,$test);
+ $this->object->clear();
}
public function testSetUncompressed()
@@ -44,32 +45,32 @@ public function testSetUncompressed()
$this->object->setUncompressed($random);
$test = $this->object->getUncompressed();
$this->assertEquals($random,$test);
+ $this->object->clear();
}
- public function testCompress()
+ public function testCompress()
{
- echo 'Starting Media Compression Test';
-
- $path = dirname(JPATH_PLATFORM).'\media\system\css';
- $files = JFolder::files($path,'.',false,true);
- foreach($files as $file)
- {
- $start = microtime();
- echo ' File: ' . basename($file);
- $uncompressed= JFile::read($file);
- $uncompressed_size = strlen($uncompressed);
- echo ' Before: ' . $uncompressed_size . ' bytes';
- $this->object->setUncompressed($uncompressed);
- $this->object->compress();
- $compressed = $this->object->getCompressed();
- $compressed_size = strlen($compressed);
- echo ' After: ' . $compressed_size . ' bytes';
- echo ' Ratio: ' . round(($compressed_size / $uncompressed_size),2);
- echo ' Time: '. round((microtime()-$start),4). ' ms';
- echo '';
- }
-
+ //Put the path to test files for css compressor. (Include expected result in filename.min.css file)
+ $path = JPATH_BASE . '/test_files/css';
+
+ $files = JFolder::files($path,'.',false,true, array(),array('.min.css','.php','.html'));
+
+ foreach ($files as $file)
+ {
+ $this->object->setUncompressed(JFile::read($file));
+
+ // Getting the expected result from filename.min.js file.
+ $expected = JFile::read(str_ireplace('.css', '.min.css', $file));
+
+ $this->object->compress();
+
+ $result = $this->object->getCompressed();
+
+ $this->assertEquals($expected, $result);
+
+ $this->object->clear();
+ }
}
}
@@ -9,6 +9,7 @@
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
+jimport('joomla.filesystem.path');
/**
* Test class for JMediaCompressor.
@@ -27,7 +28,7 @@ class JMediaCompressorTest extends TestCase
*/
protected function setUp()
{
- $this->object = JMediaCompressor::getInstance(array('type' => 'css'));
+ $this->object = JMediaCompressor::getInstance(array('type' => 'js'));
}
public function testSetCompressed()
@@ -36,6 +37,7 @@ public function testSetCompressed()
$this->object->setCompressed($random);
$test = $this->object->getCompressed();
$this->assertEquals($random,$test);
+ $this->object->clear();
}
public function testSetUncompressed()
@@ -44,32 +46,41 @@ public function testSetUncompressed()
$this->object->setUncompressed($random);
$test = $this->object->getUncompressed();
$this->assertEquals($random,$test);
+ $this->object->clear();
+ }
+
+ public function testGetCompressed()
+ {
+ $random = rand();
+ $this->object->setCompressed($random);
+ $test = $this->object->getCompressed();
+ $this->assertEquals($random,$test);
+ $this->object->clear();
}
public function testCompress()
{
- echo 'Starting Media Compression Test';
-
- $path = dirname(JPATH_PLATFORM).'\media\system\css';
- $files = JFolder::files($path,'.',false,true);
- foreach($files as $file)
- {
- $start = microtime();
- echo ' File: ' . basename($file);
- $uncompressed= JFile::read($file);
- $uncompressed_size = strlen($uncompressed);
- echo ' Before: ' . $uncompressed_size . ' bytes';
- $this->object->setUncompressed($uncompressed);
- $this->object->compress();
- $compressed = $this->object->getCompressed();
- $compressed_size = strlen($compressed);
- echo ' After: ' . $compressed_size . ' bytes';
- echo ' Ratio: ' . round(($compressed_size / $uncompressed_size),2);
- echo ' Time: '. round((microtime()-$start),4). ' ms';
- echo '';
- }
-
+ //Put the path to test files for java script compressor.
+ $path = JPATH_BASE . '/test_files/js';
+
+ $files = JFolder::files($path,'.',false,true, array(),array('.min.js','.php','.html'));
+
+ foreach ($files as $file)
+ {
+ $this->object->setUncompressed(JFile::read($file));
+
+ // Getting the expected result from filename.min.js file.
+ $expected = JFile::read(str_ireplace('.js', '.min.js', $file));
+
+ $this->object->compress();
+
+ $result = $this->object->getCompressed();
+
+ $this->assertEquals($expected, $result);
+
+ $this->object->clear();
+ }
}
}

0 comments on commit 8b66057

Please sign in to comment.