Skip to content
Snippets Groups Projects
Commit 73d6aaf0 authored by Dominik Eckelmann's avatar Dominik Eckelmann
Browse files

transformed lib/ unittests to phpunit

parent 4a0b564e
No related branches found
No related tags found
No related merge requests found
Showing
with 313 additions and 1 deletion
<?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').'/');
......
<?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 :
<?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 :
<?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 :
var s = " /* this is a comment */ " ;
var s=" /* this is a comment */ ";
\ No newline at end of file
var s = "// this is a comment ";
var s="// this is a comment ";
\ No newline at end of file
var s = ' /* this is a comment */ ' ;
var s=' /* this is a comment */ ';
\ No newline at end of file
var s = '// this is a comment ';
var s='// this is a comment ';
\ No newline at end of file
if (true) {
/* this
* is a
* multiline comment */
document.write("true"); /* this
is another
*/
}
if(true){document.write("true");}
\ No newline at end of file
if (true) {
// this is a single line comment
document.write("true") ; // another
}
if(true){document.write("true");}
\ No newline at end of file
if ( true ) {
document.write("foo");
} else {
document.write("bar");
}
if(true){document.write("foo");}else{document.write("bar");}
\ No newline at end of file
if ( true )
document.write("foo");
else
document.write("bar");
if(true)document.write("foo");else document.write("bar");
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment