From c4f70e144adc247f88ce6c9d502a7cfcf8e1b959 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Sun, 28 Aug 2011 22:04:49 +0000 Subject: [PATCH] mediawiki.test: Fix mw.config interaction with wgScriptPath * Previously the the load test in mediawiki.test.js failed when ran within a wiki because the regex to extract the path from window.location doesn't know take in account stuff like wiki-pagenames (which can contain slashes in the title) or action paths and what not. Changes: * Use wgScriptPath from mw.config when available in the mediawiki.test.js (instead of the regexed window.location) * To make sure the test still works in the static /qunit/index.html (where wgScriptPath is obviously not defined by php), re-introduced the removed regex extration hack. This also allows other modules to use wgScriptPath and removes the hack from the test suite to where it is needed and keeps the test module clean. When the on-wiki testrunner is ready and added to core, /qunit/index.html can be nuked all together including this hack. Now the hack is at least part of what-is-to-be-removed. * Added save/restore for manipulated mw.config vars in mediawiki.util.test.js (to avoid it from messing up the real wgScriptPath for other tests) * Fixed load path to 'data/' in testrunner.js as well --- tests/qunit/data/testrunner.js | 2 +- tests/qunit/index.html | 19 +++++++++++ .../resources/mediawiki/mediawiki.test.js | 34 ++----------------- .../mediawiki/mediawiki.util.test.js | 3 ++ 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js index 446add1831..ed7b3cdf17 100644 --- a/tests/qunit/data/testrunner.js +++ b/tests/qunit/data/testrunner.js @@ -14,7 +14,7 @@ QUnit.fixurl = function(value) { * Load TestSwarm agent */ if ( QUnit.urlParams.swarmURL ) { - document.write(""); + document.write(""); } /** diff --git a/tests/qunit/index.html b/tests/qunit/index.html index 4fc3a5c918..1fa3103786 100644 --- a/tests/qunit/index.html +++ b/tests/qunit/index.html @@ -9,6 +9,25 @@ diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js index c19066fc33..6fc856736b 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js @@ -124,42 +124,12 @@ test( 'mw.msg', function() { }); test( 'mw.loader', function() { - expect(5); - - // Regular expression to extract the path for the QUnit tests - // Takes into account that tests could be run from a file:// URL - // by excluding the 'index.html' part from the URL - var rePath = /(?:[^#\?](?!index.html))*\/?/; - - // Four assertions to test the above regular expression: - equal( - rePath.exec( 'http://path/to/tests/?foobar' )[0], - "http://path/to/tests/", - "Extracting path from http URL with query" - ); - equal( - rePath.exec( 'http://path/to/tests/#frag' )[0], - "http://path/to/tests/", - "Extracting path from http URL with fragment" - ); - equal( - rePath.exec( 'file://path/to/tests/index.html?foobar' )[0], - "file://path/to/tests/", - "Extracting path from local URL (file://) with query" - ); - equal( - rePath.exec( 'file://path/to/tests/index.html#frag' )[0], - "file://path/to/tests/", - "Extracting path from local URL (file://) with fragment" - ); + expect(1); // Asynchronous ahead stop(5000); - // Extract path - var tests_path = rePath.exec( location.href ); - - mw.loader.implement( 'is.awesome', [QUnit.fixurl( tests_path + 'data/defineTestCallback.js' )], {}, {} ); + mw.loader.implement( 'is.awesome', [QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/defineTestCallback.js' )], {}, {} ); mw.loader.using( 'is.awesome', function() { diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js index 83fabf81da..12c14ca394 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js @@ -39,6 +39,7 @@ test( 'wikiGetlink', function() { test( 'wikiScript', function() { expect(2); + var prevConfig = mw.config.get([ 'wgScript', 'wgScriptPath', 'wgScriptExtension' ]); mw.config.set({ 'wgScript': '/w/index.php', 'wgScriptPath': '/w', @@ -48,6 +49,8 @@ test( 'wikiScript', function() { equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'Defaults to index.php and is equal to wgScript' ); equal( mw.util.wikiScript( 'api' ), '/w/api.php', 'API path' ); + // Restore mw.config + mw.config.set( prevConfig ); }); test( 'addCSS', function() { -- 2.20.1