Skip to content

Commit

Permalink
transformed lib/ unittests to phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
dom-mel committed Apr 6, 2012
1 parent 4a0b564 commit 73d6aaf
Show file tree
Hide file tree
Showing 40 changed files with 357 additions and 1 deletion.
3 changes: 2 additions & 1 deletion _testing/unittests/bootstrap.php
@@ -1,6 +1,7 @@
<?php

define('DOKU_UNITTEST',true);
define('DOKU_UNITTEST', true);
define('SIMPLE_TEST', true);
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
define('DOKU_CONF',realpath(dirname(__FILE__).'/../../conf').'/');

Expand Down
68 changes: 68 additions & 0 deletions _testing/unittests/lib/exe/css_css_compress.test.php
@@ -0,0 +1,68 @@
<?php

require_once DOKU_INC.'lib/exe/css.php';


class css_css_compress_test extends PHPUnit_Framework_TestCase {

function test_mlcom1(){
$text = '/**
* A multi
* line *test*
* check
*/';
$this->assertEquals(css_compress($text), '');
}

function test_mlcom2(){
$text = '#comment/* */ {
color: lime;
}';
$this->assertEquals(css_compress($text), '#comment/* */{color:lime;}');
}

function test_slcom1(){
$text = '// this is a comment';
$this->assertEquals(css_compress($text), '');
}

function test_slcom2(){
$text = '#foo {
color: lime; // another comment
}';
$this->assertEquals(css_compress($text), '#foo{color:lime;}');
}

function test_slcom3(){
$text = '#foo {
background-image: url(http://foo.bar/baz.jpg);
}';
$this->assertEquals(css_compress($text), '#foo{background-image:url(http://foo.bar/baz.jpg);}');
}

function test_hack(){
$text = '/* Mac IE will not see this and continue with inline-block */
/* \\*/
display: inline;
/* */';
$this->assertEquals(css_compress($text), '/* \\*/display:inline;/* */');
}

function test_hack2(){
$text = '/* min-height hack for Internet Explorer http://www.cssplay.co.uk/boxes/minheight.html */
/*\\*/
* html .page {
height: 450px;
}
/**/';
$this->assertEquals(css_compress($text), '/*\\*/* html .page{height:450px;}/**/');
}

function test_nl1(){
$text = "a{left:20px;\ntop:20px}";
$this->assertEquals(css_compress($text), 'a{left:20px;top:20px}');
}

}

//Setup VIM: ex: et ts=4 :
55 changes: 55 additions & 0 deletions _testing/unittests/lib/exe/css_css_loadfile.test.php
@@ -0,0 +1,55 @@
<?php

require_once DOKU_INC.'lib/exe/css.php';

class css_css_loadfile_test extends PHPUnit_Framework_TestCase {
public function setUp() {
$this->file = tempnam('/tmp', 'css');
}

private function csstest($input, $output = null, $location = 'http://www.example.com/') {
io_saveFile($this->file, $input);
$this->assertEquals(css_loadfile($this->file, $location), (is_null($output) ? $input : $output));
}

public function test_url_relative() {
$this->csstest('#test { background: url("test/test.png"); }', '#test { background: url("http://www.example.com/test/test.png"); }');
$this->csstest('#test { background: url(\'test/test.png\'); }', '#test { background: url(\'http://www.example.com/test/test.png\'); }');
}

public function test_url_absolute() {
$this->csstest('#test { background: url("/test/test.png"); }');
$this->csstest('#test { background: url(\'/test/test.png\'); }');
}

public function test_url_with_protocol() {
$this->csstest('#test { background: url("http://www.test.com/test/test.png"); }');
$this->csstest('#test { background: url("https://www.test.com/test/test.png"); }');
$this->csstest('#test { background: url(\'http://www.test.com/test/test.png\'); }');
$this->csstest('#test { background: url(\'https://www.test.com/test/test.png\'); }');
}

public function test_import_relative() {
$this->csstest('@import "test/test.png";', '@import "http://www.example.com/test/test.png";');
$this->csstest('@import \'test/test.png\';', '@import \'http://www.example.com/test/test.png\';');
}

public function test_import_absolute() {
$this->csstest('@import "/test/test.png";');
$this->csstest('@import \'/test/test.png\';');
}

public function test_import_with_protocol() {
$this->csstest('@import "http://www.test.com/test/test.png";');
$this->csstest('@import "https://www.test.com/test/test.png";');
$this->csstest('@import \'http://www.test.com/test/test.png\';');
$this->csstest('@import \'https://www.test.com/test/test.png\';');
}

public function tearDown() {
unlink($this->file);
unset($this->file);
}
}

//Setup VIM: ex: et ts=4 sw=4 :
128 changes: 128 additions & 0 deletions _testing/unittests/lib/exe/js_js_compress.test.php
@@ -0,0 +1,128 @@
<?php

require_once DOKU_INC.'lib/exe/js.php';


class js_js_compress_test extends PHPUnit_Framework_TestCase {

function test_mlcom1(){
$text = '/**
* A multi
* line *test*
* check
*/';
$this->assertEquals(js_compress($text), '');
}

function test_mlcom2(){
$text = 'var foo=6;/* another comment */';
$this->assertEquals(js_compress($text), 'var foo=6;');
}

function test_mlcomcond(){
$text = '/*@if (@_win32)';
$this->assertEquals(js_compress($text), '/*@if(@_win32)');
}

function test_slcom1(){
$text = '// an comment';
$this->assertEquals(js_compress($text), '');
}

function test_slcom2(){
$text = 'var foo=6;// another comment ';
$this->assertEquals(js_compress($text), 'var foo=6;');
}

function test_slcom3(){
$text = 'var foo=6;// another comment / or something with // comments ';
$this->assertEquals(js_compress($text), 'var foo=6;');
}

function test_regex1(){
$text = 'foo.split( /[a-Z\/]*/ );';
$this->assertEquals(js_compress($text), 'foo.split(/[a-Z\/]*/);');
}

function test_regex_in_array(){
$text = '[/"/ , /"/ , /"/]';
$this->assertEquals(js_compress($text), '[/"/,/"/,/"/]');
}

function test_regex_in_hash(){
$text = '{ a : /"/ }';
$this->assertEquals(js_compress($text), '{a:/"/}');
}

function test_regex_preceded_by_spaces_caracters(){
$text = "text.replace( \t \r\n /\"/ , ".'"//" )';
$this->assertEquals(js_compress($text), 'text.replace(/"/,"//")');
}

function test_dquot1(){
$text = 'var foo="Now what \\" \'do we//get /*here*/ ?";';
$this->assertEquals(js_compress($text), $text);
}

function test_dquot2(){
$text = 'var foo="Now what \\\\\\" \'do we//get /*here*/ ?";';
$this->assertEquals(js_compress($text), $text);
}

function test_dquotrunaway(){
$text = 'var foo="Now where does it end';
$this->assertEquals(js_compress($text), $text);
}

function test_squot1(){
$text = "var foo='Now what \\' \"do we//get /*here*/ ?';";
$this->assertEquals(js_compress($text), $text);
}

function test_squotrunaway(){
$text = "var foo='Now where does it end";
$this->assertEquals(js_compress($text), $text);
}

function test_nl1(){
$text = "var foo=6;\nvar baz=7;";
$this->assertEquals(js_compress($text), 'var foo=6;var baz=7;');
}

function test_lws1(){
$text = " \t var foo=6;";
$this->assertEquals(js_compress($text), 'var foo=6;');
}

function test_tws1(){
$text = "var foo=6; \t ";
$this->assertEquals(js_compress($text), 'var foo=6;');
}

function test_shortcond(){
$text = "var foo = (baz) ? 'bar' : 'bla';";
$this->assertEquals(js_compress($text), "var foo=(baz)?'bar':'bla';");

}

function test_complexminified(){
$text = 'if(!k.isXML(a))try{if(e||!l.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return k(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="<div class=\'test e\'></div><div class=\'test\'></div>";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;foo="text/*";bla="*/"';

$this->assertEquals(js_compress($text),$text);
}

/**
* Test the files provided with the original JsStrip
*/
function test_original(){
$files = glob(dirname(__FILE__).'/js_js_compress/test-*-in.js');

foreach($files as $file){
$info = "Using file $file";
$this->assertEquals(js_compress(file_get_contents($file)),
file_get_contents(substr($file,0,-5).'out.js'), $info);
};
}
}

//Setup VIM: ex: et ts=4 :
@@ -0,0 +1,5 @@

var s = " /* this is a comment */ " ;



@@ -0,0 +1 @@
var s=" /* this is a comment */ ";
@@ -0,0 +1,5 @@


var s = "// this is a comment ";


@@ -0,0 +1 @@
var s="// this is a comment ";
@@ -0,0 +1,5 @@

var s = ' /* this is a comment */ ' ;



@@ -0,0 +1 @@
var s=' /* this is a comment */ ';
@@ -0,0 +1,5 @@


var s = '// this is a comment ';


@@ -0,0 +1 @@
var s='// this is a comment ';
@@ -0,0 +1,11 @@

if (true) {
/* this
* is a
* multiline comment */
document.write("true"); /* this
is another
*/

}

@@ -0,0 +1 @@
if(true){document.write("true");}
@@ -0,0 +1,7 @@

if (true) {
// this is a single line comment
document.write("true") ; // another
}


@@ -0,0 +1 @@
if(true){document.write("true");}
@@ -0,0 +1,7 @@


if ( true ) {
document.write("foo");
} else {
document.write("bar");
}
@@ -0,0 +1 @@
if(true){document.write("foo");}else{document.write("bar");}
@@ -0,0 +1,7 @@


if ( true )
document.write("foo");
else
document.write("bar");

@@ -0,0 +1 @@
if(true)document.write("foo");else document.write("bar");
@@ -0,0 +1,3 @@

var r = / a backslash\// ;

@@ -0,0 +1 @@
var r=/ a backslash\//;
@@ -0,0 +1,3 @@


var r = /simple/g ;
@@ -0,0 +1 @@
var r=/simple/g;
@@ -0,0 +1,5 @@


var r = / simple with whitespace /g ;


@@ -0,0 +1 @@
var r=/ simple with whitespace /g;
@@ -0,0 +1,3 @@

var r = "fruit" ;
r.replace ( /fruit/g, "apple") ;
@@ -0,0 +1 @@
var r="fruit";r.replace(/fruit/g,"apple");
@@ -0,0 +1,2 @@
var x = 0;
do x=x+1 while (x < 10);
@@ -0,0 +1 @@
var x=0;do x=x+1 while(x<10);
@@ -0,0 +1,2 @@
for ( var x in foo )
document.write(x);
@@ -0,0 +1 @@
for(var x in foo)document.write(x);
@@ -0,0 +1 @@
var x = new Object();
@@ -0,0 +1 @@
var x=new Object();

0 comments on commit 73d6aaf

Please sign in to comment.