mediawiki.test: Fix mw.config interaction with wgScriptPath
authorKrinkle <krinkle@users.mediawiki.org>
Sun, 28 Aug 2011 22:04:49 +0000 (22:04 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Sun, 28 Aug 2011 22:04:49 +0000 (22:04 +0000)
* 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
tests/qunit/index.html
tests/qunit/suites/resources/mediawiki/mediawiki.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js

index 446add1..ed7b3cd 100644 (file)
@@ -14,7 +14,7 @@ QUnit.fixurl = function(value) {
  *  Load TestSwarm agent
  */
 if ( QUnit.urlParams.swarmURL  ) {
-       document.write("<scr" + "ipt src='" + QUnit.fixurl( 'data/testwarm.inject.js' ) + "'></scr" + "ipt>");
+       document.write("<scr" + "ipt src='" + QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/testwarm.inject.js' ) + "'></scr" + "ipt>");
 }
 
 /**
index 4fc3a5c..1fa3103 100644 (file)
@@ -9,6 +9,25 @@
        <script>
        function startUp(){
                mw.config = new mw.Map( false );
+
+               /**
+                * Guess wgScriptPath (for access to /tests/qunit/data/)
+                */
+
+               // 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))*\/?/;
+
+               // Extract path to /tests/qunit/
+               var qunitTestsPath = rePath.exec( location.href )[0];
+
+               // Traverse up to script path
+               var pathParts = qunitTestsPath.split( '/' );
+               pathParts.pop(); pathParts.pop(); pathParts.pop();
+               var scriptPath = pathParts.join( '/' );
+               
+               mw.config.set( 'wgScriptPath', scriptPath );
        }
        </script>
 
index c19066f..6fc8567 100644 (file)
@@ -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() {
 
index 83fabf8..12c14ca 100644 (file)
@@ -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() {