Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Improvements to unit tests

  • Loading branch information...
commit 019853b9fe8328e80b0218e0b7e81e040ffd6b3b 1 parent dc14d7b
Kavith Thiranga Lokuhewage authored
8 tests/suites/unit/joomla/media/JMediaCombinerTest.php
@@ -32,13 +32,13 @@ protected function setUp()
32 32
33 33 public function testGetInstance()
34 34 {
35   - $compressor1 = JMediaCompressor::getInstance(array('type'=>'css'));
  35 + $Combiner1 = JMediaCombiner::getInstance(array('type'=>'css'));
36 36
37   - $this->assertInstanceOf('JMediaCompressorCss', $compressor1);
  37 + $this->assertInstanceOf('JMediaCombinerCss', $Combiner1);
38 38
39   - $compressor2 = JMediaCompressor::getInstance(array('type'=>'js'));
  39 + $Combiner2 = JMediaCombiner::getInstance(array('type'=>'js'));
40 40
41   - $this->assertInstanceOf('JMediaCompressorJs', $compressor2);
  41 + $this->assertInstanceOf('JMediaCombinerJs', $Combiner2);
42 42 }
43 43
44 44 public function testCombineFiles()
15 tests/suites/unit/joomla/media/JMediaCompressorTest.php
@@ -103,12 +103,19 @@ public function testSetOptions()
103 103
104 104 public function testCompressString()
105 105 {
106   - $source = JPATH_BASE . '/test_files/css/comments.css';
107   - $expected = JFile::read(str_ireplace('.css', '.min.css', $source));
  106 + $sourceCss = JPATH_BASE . '/test_files/css/comments.css';
  107 + $expectedCss = JFile::read(str_ireplace('.css', '.min.css', $sourceCss));
108 108
109   - $test = JMediaCompressor::compressString(JFile::read($source), array('type' => 'css'));
  109 + $testCss = JMediaCompressor::compressString(JFile::read($sourceCss), array('type' => 'css'));
110 110
111   - $this->assertEquals($expected, $test);
  111 + $this->assertEquals($expectedCss, $testCss);
  112 +
  113 + $sourceJs = JPATH_BASE . '/test_files/js/case1.js';
  114 + $expectedJs = JFile::read(str_ireplace('.js', '.min.js', $sourceJs));
  115 +
  116 + $testJs = JMediaCompressor::compressString(JFile::read($sourceJs), array('type' => 'js'));
  117 +
  118 + $this->assertEquals($expectedJs, $testJs);
112 119 }
113 120
114 121 public function testIsSupported()
38 tests/suites/unit/joomla/media/combiner/JMediaCombinerCssTest.php
... ... @@ -0,0 +1,38 @@
  1 +<?php
  2 +/**
  3 + * @package Joomla.UnitTest
  4 + * @subpackage Media
  5 + *
  6 + * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
  7 + * @license GNU General Public License version 2 or later; see LICENSE
  8 + */
  9 +
  10 +jimport('joomla.filesystem.file');
  11 +jimport('joomla.filesystem.folder');
  12 +
  13 +/**
  14 + * Test class for JMediaCompressor.
  15 + */
  16 +class JMediaCombinerTest extends TestCase
  17 +{
  18 + /**
  19 + * @var JMediaCompressor
  20 + */
  21 + protected $object;
  22 +
  23 +
  24 + /**
  25 + * Sets up the fixture, for example, opens a network connection.
  26 + * This method is called before a test is executed.
  27 + */
  28 + protected function setUp()
  29 + {
  30 + $this->object = JMediaCombiner::getInstance(array('type' => 'css'));
  31 + }
  32 +
  33 +
  34 + public function testCombineFiles()
  35 + {
  36 + }
  37 +
  38 +}
17 tests/suites/unit/joomla/media/compressor/JMediaCompressorCssTest.php
@@ -48,7 +48,7 @@ public function testSetUncompressed()
48 48 $this->object->clear();
49 49 }
50 50
51   - public function testCompress()
  51 + /*public function testCompress()
52 52 {
53 53
54 54 // Put the path to test files for css compressor. (Include expected result in filename.min.css file)
@@ -72,5 +72,20 @@ public function testCompress()
72 72 $this->object->clear();
73 73 }
74 74
  75 + }*/
  76 +
  77 + public function testClear()
  78 + {
  79 + $sourceCss = JPATH_BASE . '/test_files/css/comments.css';
  80 +
  81 + $this->object->setUncompressed(JFile::read($sourceCss));
  82 + $this->object->compress();
  83 + $this->object->clear();
  84 +
  85 + $this->assertEquals(null, $this->object->getUncompressed());
  86 + $this->assertEquals(null, $this->object->getcompressed());
  87 + $this->assertAttributeEquals(null, '_compressedSize', $this->object);
  88 + $this->assertAttributeEquals(null, '_uncompressedSize', $this->object);
  89 + $this->assertAttributeEquals(false, '_inHack', $this->object);
75 90 }
76 91 }
190 tests/suites/unit/joomla/media/compressor/JMediaCompressorJsTest.php
@@ -16,71 +16,127 @@
16 16 */
17 17 class JMediaCompressorTest extends TestCase
18 18 {
19   - /**
20   - * @var JMediaCompressor
21   - */
22   - protected $object;
23   -
24   -
25   - /**
26   - * Sets up the fixture, for example, opens a network connection.
27   - * This method is called before a test is executed.
28   - */
29   - protected function setUp()
30   - {
31   - $this->object = JMediaCompressor::getInstance(array('type' => 'js'));
32   - }
33   -
34   - public function testSetCompressed()
35   - {
36   - $random = rand();
37   - $this->object->setCompressed($random);
38   - $test = $this->object->getCompressed();
39   - $this->assertEquals($random,$test);
40   - $this->object->clear();
41   - }
42   -
43   - public function testSetUncompressed()
44   - {
45   - $random = rand();
46   - $this->object->setUncompressed($random);
47   - $test = $this->object->getUncompressed();
48   - $this->assertEquals($random,$test);
49   - $this->object->clear();
50   - }
51   -
52   - public function testGetCompressed()
53   - {
54   - $random = rand();
55   - $this->object->setCompressed($random);
56   - $test = $this->object->getCompressed();
57   - $this->assertEquals($random,$test);
58   - $this->object->clear();
59   - }
60   -
61   - public function testCompress()
62   - {
63   -
64   - //Put the path to test files for java script compressor.
65   - $path = JPATH_BASE . '/test_files/js';
66   -
67   - $files = JFolder::files($path,'.',false,true, array(),array('.min.js','.php','.html'));
68   -
69   - foreach ($files as $file)
70   - {
71   - $this->object->setUncompressed(JFile::read($file));
72   -
73   - // Getting the expected result from filename.min.js file.
74   - $expected = JFile::read(str_ireplace('.js', '.min.js', $file));
75   -
76   - $this->object->compress();
77   -
78   - $result = $this->object->getCompressed();
79   -
80   - $this->assertEquals($expected, $result);
81   -
82   - $this->object->clear();
83   - }
84   -
85   - }
  19 + /**
  20 + * @var JMediaCompressor
  21 + */
  22 + protected $object;
  23 +
  24 +
  25 + /**
  26 + * Sets up the fixture, for example, opens a network connection.
  27 + * This method is called before a test is executed.
  28 + */
  29 + protected function setUp()
  30 + {
  31 + $this->object = JMediaCompressor::getInstance(array('type' => 'js'));
  32 + }
  33 +
  34 + public function testSetCompressed()
  35 + {
  36 + $random = rand();
  37 + $this->object->setCompressed($random);
  38 + $test = $this->object->getCompressed();
  39 + $this->assertEquals($random,$test);
  40 + $this->object->clear();
  41 + }
  42 +
  43 + public function testSetUncompressed()
  44 + {
  45 + $random = rand();
  46 + $this->object->setUncompressed($random);
  47 + $test = $this->object->getUncompressed();
  48 + $this->assertEquals($random,$test);
  49 + $this->object->clear();
  50 + }
  51 +
  52 + public function testGetCompressed()
  53 + {
  54 + $random = rand();
  55 + $this->object->setCompressed($random);
  56 + $test = $this->object->getCompressed();
  57 + $this->assertEquals($random,$test);
  58 + $this->object->clear();
  59 + }
  60 +
  61 + /*public function testCompress()
  62 + {
  63 +
  64 + //Put the path to test files for java script compressor.
  65 + $path = JPATH_BASE . '/test_files/js';
  66 +
  67 + $files = JFolder::files($path,'.',false,true, array(),array('.min.js','.php','.html'));
  68 +
  69 + foreach ($files as $file)
  70 + {
  71 + $this->object->setUncompressed(JFile::read($file));
  72 +
  73 + // Getting the expected result from filename.min.js file.
  74 + $expected = JFile::read(str_ireplace('.js', '.min.js', $file));
  75 +
  76 + $this->object->compress();
  77 +
  78 + $result = $this->object->getCompressed();
  79 +
  80 + $this->assertEquals($expected, $result);
  81 +
  82 + $this->object->clear();
  83 + }
  84 +
  85 + }*/
  86 +
  87 + public function test_checkAlphaNum()
  88 + {
  89 + $method = new ReflectionMethod('JMediaCompressorJs', '_checkAlphaNum');
  90 + $method->setAccessible(true);
  91 +
  92 + // Check whether _checkAlphaNum() return true on numbers
  93 + $this->assertTrue($method->invoke($this->object, rand(0,9)));
  94 +
  95 + $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$";
  96 + $rand_letter = $chars[rand(0,53)];
  97 +
  98 + // Check whether _checkAlphaNum() return true on alphabatical chars and '_' , '$'
  99 + $this->assertTrue($method->invoke($this->object, $rand_letter));
  100 +
  101 + $rand_extended_char = chr(rand(127, 255));
  102 +
  103 + // Check whether _checkAlphaNum() return true on extended aschii chars
  104 + $this->assertTrue($method->invoke($this->object, $rand_extended_char));
  105 +
  106 +
  107 + $non_alpha_chars = '~`{}[]|\/-()&*%^#@!,.<>?=+"' . "'" ;
  108 + $rand_non_alpha_char = $non_alpha_chars[rand(0, 27)];
  109 +
  110 + // Check whether _checkAlphaNum() return false on non alpha numeric chars
  111 + $this->assertFalse($method->invoke($this->object, $rand_non_alpha_char));
  112 + }
  113 +
  114 + public function testClear()
  115 + {
  116 + $sourceJs = JPATH_BASE . '/test_files/js/case1.js';
  117 +
  118 + $this->object->setUncompressed(JFile::read($sourceJs));
  119 + $this->object->compress();
  120 + $this->object->clear();
  121 +
  122 + $this->assertEquals(null, $this->object->getUncompressed());
  123 +
  124 + $this->assertEquals(null, $this->object->getcompressed());
  125 +
  126 + $this->assertAttributeEquals(null, '_compressedSize', $this->object);
  127 +
  128 + $this->assertAttributeEquals(null, '_uncompressedSize', $this->object);
  129 +
  130 + $this->assertAttributeEquals("\n", '_a', $this->object);
  131 +
  132 + $this->assertAttributeEquals('', '_b', $this->object);
  133 +
  134 + $this->assertAttributeEquals(0, '_nextIndex', $this->object);
  135 +
  136 + $this->assertAttributeEquals(0, '_startLength', $this->object);
  137 +
  138 + $this->assertAttributeEquals('', '_preLoaded', $this->object);
  139 +
  140 + $this->assertAttributeEquals('', '_previousChar', $this->object);
  141 + }
86 142 }

0 comments on commit 019853b

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