Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

improvements to tests

  • Loading branch information...
commit fe98101fea8ab9975a45a55f4ce83ec0877f7fe6 1 parent 0e47352
@kaviththiranga authored
View
2  tests/suites/unit/joomla/media/JMediaCompressorTest.php
@@ -274,7 +274,6 @@ public function testGetInstance()
$this->assertInstanceOf('JMediaCompressorJs', $compressor2);
}
-
/**
* Test JMediaCompressor::isSupported Method
*
@@ -295,7 +294,6 @@ public function testIsSupported()
$this->assertFalse(JMediaCompressor::isSupported('index.php'));
}
-
/**
* test clear Method
*
View
76 tests/suites/unit/joomla/media/compressor/JMediaCompressorCssTest.php
@@ -12,6 +12,11 @@
/**
* Test class for JMediaCompressorCss.
+ *
+ * @package Joomla.UnitTest
+ * @subpackage Media
+ *
+ * @since 12.1
*/
class JMediaCompressorCssTest extends TestCase
{
@@ -20,16 +25,28 @@ class JMediaCompressorCssTest extends TestCase
*/
protected $object;
+ /**
+ * @var array files needed for tests
+ */
protected $files;
+ /**
+ * @var string path to test files
+ */
protected $pathToTestFiles;
+ /**
+ * @var string file extension suffix for compressed files
+ */
protected $suffix;
-
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
+ *
+ * @return void
+ *
+ * @since 12.1
*/
protected function setUp()
{
@@ -41,46 +58,38 @@ protected function setUp()
/**
* Loads Necessary files
+ *
+ * @return void
+ *
+ * @since 12.1
*/
protected function loadFiles()
{
- //
- $this->files = glob($this->pathToTestFiles . DIRECTORY_SEPARATOR . '*.css');
- }
-
- 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);
- $this->assertEquals($value, $test[$key]);
- }
- // Replace the existed options to avoid any harm to other tests
- $this->object->setOptions($existing_options);
+ // Load only non compressed css files in to array
+ // Skip other files
+ $this->files = JFolder::files(
+ $this->pathToTestFiles, '.', false, true, array(),
+ array('.min.css', '.php', '.html', '.combined.css')
+ );
}
+ /**
+ * Test compress Method
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
public function testCompress()
{
-
- // Put the path to test files for css compressor. (Include expected result in filename.min.css file)
- $path = JPATH_TESTS . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'css';
-
- $files = JFolder::files($path, '.', false, true, array(), array('.min.css', '.php', '.html', '.combined.css'));
+ $files = JFolder::files($this->pathToTestFiles, '.', false, true, array(), array('.min.css', '.php', '.html', '.combined.css'));
foreach ($files as $file)
{
$this->object->setUncompressed(file_get_contents($file));
- // Getting the expected result from filename.min.js file.
- $expected = file_get_contents(str_ireplace('.css', '.min.css', $file));
+ // Getting the expected result from filename.min.css file.
+ $expected = file_get_contents(str_ireplace('.css', '.' . $this->suffix . '.css', $file));
$this->object->compress();
@@ -93,9 +102,16 @@ public function testCompress()
}
+ /**
+ * test clear Method
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
public function testClear()
{
- $sourceCss = JPATH_TESTS . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'css/comments.css';
+ $sourceCss = $this->pathToTestFiles . DIRECTORY_SEPARATOR . 'comments.css';
$this->object->setUncompressed(file_get_contents($sourceCss));
$this->object->compress();
View
87 tests/suites/unit/joomla/media/compressor/JMediaCompressorJsTest.php
@@ -13,6 +13,11 @@
/**
* Test class for JMediaCompressor.
+ *
+ * @package Joomla.UnitTest
+ * @subpackage Media
+ *
+ * @since 12.1
*/
class JMediaCompressorJsTest extends TestCase
{
@@ -21,16 +26,28 @@ class JMediaCompressorJsTest extends TestCase
*/
protected $object;
+ /**
+ * @var array files needed for tests
+ */
protected $files;
+ /**
+ * @var string path to test files
+ */
protected $pathToTestFiles;
+ /**
+ * @var string file extension suffix for compressed files
+ */
protected $suffix;
-
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
+ *
+ * @return void
+ *
+ * @since 12.1
*/
protected function setUp()
{
@@ -42,47 +59,39 @@ protected function setUp()
/**
* Loads Necessary files
+ *
+ * @return void
+ *
+ * @since 12.1
*/
protected function loadFiles()
{
- //
- $this->files = glob($this->pathToTestFiles . DIRECTORY_SEPARATOR . '*.js');
- }
-
- 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);
-
+ // Load only non compressed css files in to array
+ // Skip other files
+ $this->files = JFolder::files(
+ $this->pathToTestFiles, '.', false, true, array(),
+ array('.min.js', '.php', '.html', '.combined.js')
+ );
}
+ /**
+ * Test compress Method
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
public function testCompress()
{
- // Put the path to test files for java script compressor.
- $path = JPATH_TESTS . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'js';
-
- $files = JFolder::files($path,'.',false,true, array(),array('.min.js','.php','.html','.combined.js'));
+ $files = JFolder::files($this->pathToTestFiles, '.', false, true, array(), array('.min.js', '.php', '.html', '.combined.js'));
foreach ($files as $file)
{
$this->object->setUncompressed(file_get_contents($file));
// Getting the expected result from filename.min.js file.
- $expected = file_get_contents(str_ireplace('.js', '.min.js', $file));
+ $expected = file_get_contents(str_ireplace('.js', '.' . $this->suffix . '.js', $file));
$this->object->compress();
@@ -95,6 +104,13 @@ public function testCompress()
}
+ /**
+ * Test _checkAlphaNum Method
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
public function test_checkAlphaNum()
{
$method = new ReflectionMethod('JMediaCompressorJs', '_checkAlphaNum');
@@ -106,12 +122,12 @@ public function test_checkAlphaNum()
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$";
$rand_letter = $chars[rand(0, 53)];
- // Check whether _checkAlphaNum() return true on alphabatical chars and '_' , '$'
+ // Check whether _checkAlphaNum() return true on alphabetical chars and '_' , '$'
$this->assertTrue($method->invoke($this->object, $rand_letter));
$rand_extended_char = chr(rand(127, 255));
- // Check whether _checkAlphaNum() return true on extended aschii chars
+ // Check whether _checkAlphaNum() return true on extended ascii chars
$this->assertTrue($method->invoke($this->object, $rand_extended_char));
@@ -122,11 +138,18 @@ public function test_checkAlphaNum()
$this->assertFalse($method->invoke($this->object, $rand_non_alpha_char));
}
+ /**
+ * test clear Method
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
public function testClear()
{
- $sourceJs = JPATH_TESTS . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'case1.js';
+ $sourceJs = $this->pathToTestFiles . DIRECTORY_SEPARATOR . 'case1.js';
- $this->object->setUncompressed(JFile::read($sourceJs));
+ $this->object->setUncompressed(file_get_contents($sourceJs));
$this->object->compress();
$this->object->clear();

0 comments on commit fe98101

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