Permalink
Browse files

refactored tests

  • Loading branch information...
1 parent d6bc851 commit a888977b374419d8509f8d50c3537ebea4c3c1bd @kaviththiranga committed Dec 15, 2012
@@ -96,15 +96,15 @@ public function testCombineFiles()
$this->object->addFiles($files);
// Path to expected combined file without compression turned on
- $expected = JFile::read($path . '/all.combined.css');
+ $expected = file_get_contents($path . '/all.combined.css');
$this->object->combine();
$this->assertEquals($expected, $this->object->getCombined());
// Path to expected combined file with compression turned on
- $expectedCompressed = JFile::read($path . '/all.combined.min.css');
+ $expectedCompressed = file_get_contents($path . '/all.combined.min.css');
$this->object->setOptions(array('COMPRESS' => true));
@@ -1,5 +1,5 @@
-
<?php
+
/**
* @package Joomla.UnitTest
* @subpackage Media
@@ -52,7 +52,6 @@ protected function loadFiles()
{
//
$this->files = glob($this->pathToTestFiles . DIRECTORY_SEPARATOR . '*.css');
- var_dump($this->files);
}
/**
@@ -150,16 +149,16 @@ public function testSetOptions()
public function testCompressString()
{
$sourceCss = JPATH_BASE . '/test_files/css/comments.css';
- $expectedCss = JFile::read(str_ireplace('.css', '.min.css', $sourceCss));
+ $expectedCss = file_get_contents(str_ireplace('.css', '.min.css', $sourceCss));
- $testCss = JMediaCompressor::compressString(JFile::read($sourceCss), array('type' => 'css'));
+ $testCss = JMediaCompressor::compressString(file_get_contents($sourceCss), array('type' => 'css'));
$this->assertEquals($expectedCss, $testCss);
$sourceJs = JPATH_BASE . '/test_files/js/case1.js';
- $expectedJs = JFile::read(str_ireplace('.js', '.min.js', $sourceJs));
+ $expectedJs = file_get_contents(str_ireplace('.js', '.min.js', $sourceJs));
- $testJs = JMediaCompressor::compressString(JFile::read($sourceJs), array('type' => 'js'));
+ $testJs = JMediaCompressor::compressString(file_get_contents($sourceJs), array('type' => 'js'));
$this->assertEquals($expectedJs, $testJs);
}
@@ -195,4 +194,4 @@ public function testClear()
$this->assertAttributeEquals(null, 'uncompressedSize', $this->object);
}
-}
+}
@@ -39,9 +39,8 @@ 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;
}
@@ -34,22 +34,19 @@ protected function setUp()
public function testCombine()
{
$this->object->addFiles($this->loadJsFiles());
-
+
$this->object->combine();
-
-
-
-
+
}
public function loadJsFiles()
{
// Path to source css files
$path = JPATH_BASE . '/test_files/js';
-
+
$files = JFolder::files($path,'.',false,true, array(), array('.min.js', '.php', '.html','.combined.js'));//get full path
-
+
return $files;
}
-}
+}
@@ -30,34 +30,16 @@ 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 testSetOptions()
{
$existing_options = $this->object->getOptions();
$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);
@@ -73,14 +55,14 @@ 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','.combined.css'));
+ $files = JFolder::files($path, '.', false, true, array(), array('.min.css', '.php', '.html', '.combined.css'));
foreach ($files as $file)
{
- $this->object->setUncompressed(JFile::read($file));
+ $this->object->setUncompressed(file_get_contents($file));
// Getting the expected result from filename.min.js file.
- $expected = JFile::read(str_ireplace('.css', '.min.css', $file));
+ $expected = file_get_contents(str_ireplace('.css', '.min.css', $file));
$this->object->compress();
@@ -97,7 +79,7 @@ public function testClear()
{
$sourceCss = JPATH_BASE . '/test_files/css/comments.css';
- $this->object->setUncompressed(JFile::read($sourceCss));
+ $this->object->setUncompressed(file_get_contents($sourceCss));
$this->object->compress();
$this->object->clear();
@@ -31,67 +31,40 @@ protected function setUp()
$this->object = JMediaCompressor::getInstance(array('type' => 'js'));
}
- 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 testGetCompressed()
- {
- $random = rand();
- $this->object->setCompressed($random);
- $test = $this->object->getCompressed();
- $this->assertEquals($random,$test);
- $this->object->clear();
- }
-
public function testSetOptions()
{
$existing_options = $this->object->getOptions();
$expected = array('REMOVE_COMMENTS' => false, 'CHANGE_ENCODING' => false);
-
+
$this->object->setOptions($expected);
-
+
$test = $this->object->getOptions();
-
+
foreach ($expected as $key => $value)
{
$this->arrayHasKey($key, $test);
$this->assertEquals($value, $test[$key]);
}
// Replace the existed options to avoid any harm to other tests
$this->object->setOptions($existing_options);
-
+
}
public function testCompress()
{
- //Put the path to test files for java script compressor.
+ // 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','.combined.js'));
foreach ($files as $file)
{
- $this->object->setUncompressed(JFile::read($file));
+ $this->object->setUncompressed(file_get_contents($file));
// Getting the expected result from filename.min.js file.
- $expected = JFile::read(str_ireplace('.js', '.min.js', $file));
+ $expected = file_get_contents(str_ireplace('.js', '.min.js', $file));
$this->object->compress();
@@ -108,12 +81,12 @@ public function test_checkAlphaNum()
{
$method = new ReflectionMethod('JMediaCompressorJs', '_checkAlphaNum');
$method->setAccessible(true);
-
+
// Check whether _checkAlphaNum() return true on numbers
- $this->assertTrue($method->invoke($this->object, rand(0,9)));
+ $this->assertTrue($method->invoke($this->object, rand(0, 9)));
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$";
- $rand_letter = $chars[rand(0,53)];
+ $rand_letter = $chars[rand(0, 53)];
// Check whether _checkAlphaNum() return true on alphabatical chars and '_' , '$'
$this->assertTrue($method->invoke($this->object, $rand_letter));
@@ -123,8 +96,8 @@ public function test_checkAlphaNum()
// Check whether _checkAlphaNum() return true on extended aschii chars
$this->assertTrue($method->invoke($this->object, $rand_extended_char));
-
- $non_alpha_chars = '~`{}[]|\/-()&*%^#@!,.<>?=+"' . "'" ;
+
+ $non_alpha_chars = '~`{}[]|\/-()&*%^#@!,.<>?=+"' . "'";
$rand_non_alpha_char = $non_alpha_chars[rand(0, 27)];
// Check whether _checkAlphaNum() return false on non alpha numeric chars
@@ -134,7 +107,7 @@ public function test_checkAlphaNum()
public function testClear()
{
$sourceJs = JPATH_BASE . '/test_files/js/case1.js';
-
+
$this->object->setUncompressed(JFile::read($sourceJs));
$this->object->compress();
$this->object->clear();
@@ -159,4 +132,5 @@ public function testClear()
$this->assertAttributeEquals('', '_previousChar', $this->object);
}
-}
+
+}

0 comments on commit a888977

Please sign in to comment.