Skip to content
Browse files

Unit tests further implemented

  • Loading branch information...
1 parent b5b5950 commit 7100c757e768afcd09dc7493ae5676447f2d5fd2 @kaviththiranga committed
View
56 tests/suites/unit/joomla/media/JMediaCombinerTest.php
@@ -15,20 +15,44 @@
*/
class JMediaCombinerTest 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'));
- }
-
-
+ /**
+ * @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 testGetInstance()
+ {
+ $compressor1 = JMediaCompressor::getInstance(array('type'=>'css'));
+
+ $this->assertInstanceOf('JMediaCompressorCss', $compressor1);
+
+ $compressor2 = JMediaCompressor::getInstance(array('type'=>'js'));
+
+ $this->assertInstanceOf('JMediaCompressorJs', $compressor2);
+ }
+
+ public function testCombineFiles()
+ {
+ }
+
+ public function testIsSupported()
+ {
+ $file1 = JPATH_BASE . '/test_files/css/comments.css';
+
+ $this->assertTrue(JMediaCombiner::isSupported($file1));
+
+ $file2 = JPATH_BASE . '/test_files/js/case2.js';
+
+ $this->assertTrue(JMediaCombiner::isSupported($file2));
+ }
}
View
203 tests/suites/unit/joomla/media/JMediaCompressorTest.php
@@ -13,95 +13,124 @@
/**
* Test class for JMediaCompressor.
+ *
+ * @package Joomla.UnitTest
+ * @subpackage Media
+ *
+ * @since 12.1
*/
class JMediaCompressorTest 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 = 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()
- {
- $random = rand();
- $this->object->setUncompressed($random);
- $test = $this->object->getUncompressed();
- $this->assertEquals($random,$test);
- $this->object->clear();
- }
-
- public function testGetRatio()
- {
- $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 testGetCompressors()
- {
- $expected = array('css','js');
-
- $test = JMediaCompressor::getCompressors();
-
- $this->assertEquals($expected, $test);
-
- }
-
- public function testCompressString()
- {
- $source = JPATH_BASE . '/test_files/css/comments.css';
- $expected = JFile::read(str_ireplace('.css', '.min.css', $source));
-
- $test = JMediaCompressor::compressString(JFile::read($source), array('type'=>'css'));
-
-
- $this->assertEquals($expected, $test);
- }
-
- public function testIsSupported()
- {
- $file1 = JPATH_BASE . '/test_files/css/comments.css';
-
- $this->assertTrue(JMediaCompressor::isSupported($file1));
-
- $file2 = JPATH_BASE . '/test_files/js/case2.js';
-
- $this->assertTrue(JMediaCompressor::isSupported($file2));
- }
+ /**
+ * @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 = 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()
+ {
+ $random = rand();
+ $this->object->setUncompressed($random);
+ $test = $this->object->getUncompressed();
+ $this->assertEquals($random,$test);
+ }
+
+ public function testGetRatio()
+ {
+ $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 testGetCompressors()
+ {
+ $expected = array('css','js');
+
+ $test = JMediaCompressor::getCompressors();
+
+ $this->assertEquals($expected, $test);
+
+ }
+
+ public function testSetOptions()
+ {
+ $expected = array('REMOVE_COMMENTS' => false, 'MIN_COLOR_CODES' => false, 'LIMIT_LINE_LENGTH' => false);
+
+ $this->object->setOptions($expected);
+
+ $test = $this->object->getOptions();
+
+ foreach ($expected as $key => $value)
+ {
+ $this->arrayHasKey($key, $test);
+ $this->assertEquals($value, $test[$key]);
+ }
+
+ }
+
+ public function testCompressString()
+ {
+ $source = JPATH_BASE . '/test_files/css/comments.css';
+ $expected = JFile::read(str_ireplace('.css', '.min.css', $source));
+
+ $test = JMediaCompressor::compressString(JFile::read($source), array('type' => 'css'));
+
+ $this->assertEquals($expected, $test);
+ }
+
+ public function testIsSupported()
+ {
+ $file1 = JPATH_BASE . '/test_files/css/comments.css';
+
+ $this->assertTrue(JMediaCompressor::isSupported($file1));
+
+ $file2 = JPATH_BASE . '/test_files/js/case2.js';
+
+ $this->assertTrue(JMediaCompressor::isSupported($file2));
+ }
+
+ public function testClear()
+ {
+ $this->object->setUncompressed(rand());
+ $this->object->compress();
+ $this->object->clear();
+ $this->assertEquals(null, $this->object->getUncompressed());
+ $this->assertEquals(null, $this->object->getcompressed());
+ $this->assertAttributeEquals(null, '_compressedSize', $this->object);
+ $this->assertAttributeEquals(null, '_uncompressedSize', $this->object);
+ }
}
View
116 tests/suites/unit/joomla/media/compressor/JMediaCompressorCssTest.php
@@ -15,62 +15,62 @@
*/
class JMediaCompressorTest 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 = JMediaCompressor::getInstance(array('type' => 'css'));
- }
-
- public function testSetCompressed()
- {
- $random = rand();
- $this->object->setCompressed($random);
- $test = $this->object->getCompressed();
- $this->assertEquals($random,$test);
- $this->object->clear();
- }
-
- public function testSetUncompressed()
- {
- $random = rand();
- $this->object->setUncompressed($random);
- $test = $this->object->getUncompressed();
- $this->assertEquals($random,$test);
- $this->object->clear();
- }
-
- public function testCompress()
- {
-
- //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();
- }
-
- }
+ /**
+ * @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 = JMediaCompressor::getInstance(array('type' => 'css'));
+ }
+
+ public function testSetCompressed()
+ {
+ $random = rand();
+ $this->object->setCompressed($random);
+ $test = $this->object->getCompressed();
+ $this->assertEquals($random,$test);
+ $this->object->clear();
+ }
+
+ public function testSetUncompressed()
+ {
+ $random = rand();
+ $this->object->setUncompressed($random);
+ $test = $this->object->getUncompressed();
+ $this->assertEquals($random,$test);
+ $this->object->clear();
+ }
+
+ public function testCompress()
+ {
+
+ // 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();
+ }
+
+ }
}

0 comments on commit 7100c75

Please sign in to comment.
Something went wrong with that request. Please try again.