From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- tests/phpunit/includes/libs/IEUrlExtensionTest.php | 118 +++++++++++++++++++++ .../includes/libs/JavaScriptMinifierTest.php | 105 ++++++++++++++++++ 2 files changed, 223 insertions(+) create mode 100644 tests/phpunit/includes/libs/IEUrlExtensionTest.php create mode 100644 tests/phpunit/includes/libs/JavaScriptMinifierTest.php (limited to 'tests/phpunit/includes/libs') diff --git a/tests/phpunit/includes/libs/IEUrlExtensionTest.php b/tests/phpunit/includes/libs/IEUrlExtensionTest.php new file mode 100644 index 00000000..c6270e90 --- /dev/null +++ b/tests/phpunit/includes/libs/IEUrlExtensionTest.php @@ -0,0 +1,118 @@ +assertEquals( + 'y', + IEUrlExtension::findIE6Extension( 'x.y' ), + 'Simple extension' + ); + } + + function testSimpleNoExt() { + $this->assertEquals( + '', + IEUrlExtension::findIE6Extension( 'x' ), + 'No extension' + ); + } + + function testEmpty() { + $this->assertEquals( + '', + IEUrlExtension::findIE6Extension( '' ), + 'Empty string' + ); + } + + function testQuestionMark() { + $this->assertEquals( + '', + IEUrlExtension::findIE6Extension( '?' ), + 'Question mark only' + ); + } + + function testExtQuestionMark() { + $this->assertEquals( + 'x', + IEUrlExtension::findIE6Extension( '.x?' ), + 'Extension then question mark' + ); + } + + function testQuestionMarkExt() { + $this->assertEquals( + 'x', + IEUrlExtension::findIE6Extension( '?.x' ), + 'Question mark then extension' + ); + } + + function testInvalidChar() { + $this->assertEquals( + '', + IEUrlExtension::findIE6Extension( '.x*' ), + 'Extension with invalid character' + ); + } + + function testInvalidCharThenExtension() { + $this->assertEquals( + 'x', + IEUrlExtension::findIE6Extension( '*.x' ), + 'Invalid character followed by an extension' + ); + } + + function testMultipleQuestionMarks() { + $this->assertEquals( + 'c', + IEUrlExtension::findIE6Extension( 'a?b?.c?.d?e?f' ), + 'Multiple question marks' + ); + } + + function testExeException() { + $this->assertEquals( + 'd', + IEUrlExtension::findIE6Extension( 'a?b?.exe?.d?.e' ), + '.exe exception' + ); + } + + function testExeException2() { + $this->assertEquals( + 'exe', + IEUrlExtension::findIE6Extension( 'a?b?.exe' ), + '.exe exception 2' + ); + } + + function testHash() { + $this->assertEquals( + '', + IEUrlExtension::findIE6Extension( 'a#b.c' ), + 'Hash character preceding extension' + ); + } + + function testHash2() { + $this->assertEquals( + '', + IEUrlExtension::findIE6Extension( 'a?#b.c' ), + 'Hash character preceding extension 2' + ); + } + + function testDotAtEnd() { + $this->assertEquals( + '', + IEUrlExtension::findIE6Extension( '.' ), + 'Dot at end of string' + ); + } +} diff --git a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php new file mode 100644 index 00000000..aa05500e --- /dev/null +++ b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php @@ -0,0 +1,105 @@ + bar", "" ), + array( "--> Foo", "" ), + array( "x --> y", "x-->y" ), + // Semicolon insertion + array( "(function(){return\nx;})", "(function(){return\nx;})" ), + array( "throw\nx;", "throw\nx;" ), + array( "while(p){continue\nx;}", "while(p){continue\nx;}" ), + array( "while(p){break\nx;}", "while(p){break\nx;}" ), + array( "var\nx;", "var x;" ), + array( "x\ny;", "x\ny;" ), + array( "x\n++y;", "x\n++y;" ), + array( "x\n!y;", "x\n!y;" ), + array( "x\n{y}", "x\n{y}" ), + array( "x\n+y;", "x+y;" ), + array( "x\n(y);", "x(y);" ), + array( "5.\nx;", "5.\nx;" ), + array( "0xFF.\nx;", "0xFF.x;" ), + array( "5.3.\nx;", "5.3.x;" ), + // Token separation + array( "x in y", "x in y" ), + array( "/x/g in y", "/x/g in y" ), + array( "x in 30", "x in 30" ), + array( "x + ++ y", "x+ ++y" ), + array( "x / /y/.exec(z)", "x/ /y/.exec(z)" ), + // State machine + array( "/ x/g", "/ x/g" ), + array( "(function(){return/ x/g})", "(function(){return/ x/g})" ), + array( "+/ x/g", "+/ x/g" ), + array( "++/ x/g", "++/ x/g" ), + array( "x/ x/g", "x/x/g" ), + array( "(/ x/g)", "(/ x/g)" ), + array( "if(/ x/g);", "if(/ x/g);" ), + array( "(x/ x/g)", "(x/x/g)" ), + array( "([/ x/g])", "([/ x/g])" ), + array( "+x/ x/g", "+x/x/g" ), + array( "{}/ x/g", "{}/ x/g" ), + array( "+{}/ x/g", "+{}/x/g" ), + array( "(x)/ x/g", "(x)/x/g" ), + array( "if(x)/ x/g", "if(x)/ x/g" ), + array( "for(x;x;{}/ x/g);", "for(x;x;{}/x/g);" ), + array( "x;x;{}/ x/g", "x;x;{}/ x/g" ), + array( "x:{}/ x/g", "x:{}/ x/g" ), + array( "switch(x){case y?z:{}/ x/g:{}/ x/g;}", "switch(x){case y?z:{}/x/g:{}/ x/g;}" ), + array( "function x(){}/ x/g", "function x(){}/ x/g" ), + array( "+function x(){}/ x/g", "+function x(){}/x/g" ), + + // Tests for things that broke in the past + // Multiline quoted string + array( "var foo=\"\\\nblah\\\n\";", "var foo=\"\\\nblah\\\n\";" ), + // Multiline quoted string followed by string with spaces + array( "var foo=\"\\\nblah\\\n\";\nvar baz = \" foo \";\n", "var foo=\"\\\nblah\\\n\";var baz=\" foo \";" ), + // URL in quoted string ( // is not a comment) + array( "aNode.setAttribute('href','http://foo.bar.org/baz');", "aNode.setAttribute('href','http://foo.bar.org/baz');" ), + // URL in quoted string after multiline quoted string + array( "var foo=\"\\\nblah\\\n\";\naNode.setAttribute('href','http://foo.bar.org/baz');", "var foo=\"\\\nblah\\\n\";aNode.setAttribute('href','http://foo.bar.org/baz');" ), + // Division vs. regex nastiness + array( "alert( (10+10) / '/'.charCodeAt( 0 ) + '//' );", "alert((10+10)/'/'.charCodeAt(0)+'//');" ), + array( "if(1)/a /g.exec('Pa ss');", "if(1)/a /g.exec('Pa ss');" ), + + // newline insertion after 1000 chars: break after the "++", not before + array( str_repeat( ';', 996 ) . "if(x++);", str_repeat( ';', 996 ) . "if(x++\n);" ), + + // Unicode letter characters should pass through ok in identifiers (bug 31187) + array( "var KaŝSkatolVal = {}", 'var KaŝSkatolVal={}'), + // And also per spec unicode char escape values should work in identifiers, + // as long as it's a valid char. In future it might get normalized. + array( "var Ka\\u015dSkatolVal = {}", 'var Ka\\u015dSkatolVal={}'), + ); + } + + /** + * @dataProvider provideCases + */ + function testJavaScriptMinifierOutput( $code, $expectedOutput ) { + $minified = JavaScriptMinifier::minify( $code ); + + // JSMin+'s parser will throw an exception if output is not valid JS. + // suppression of warnings needed for stupid crap + wfSuppressWarnings(); + $parser = new JSParser(); + wfRestoreWarnings(); + $parser->parse( $minified, 'minify-test.js', 1 ); + + $this->assertEquals( $expectedOutput, $minified, "Minified output should be in the form expected." ); + } +} -- cgit v1.2.3-54-g00ecf