http://www.mediawiki.org/wiki/Special:Code/MediaWiki/95638

Revision: 95638
Author:   krinkle
Date:     2011-08-28 22:04:49 +0000 (Sun, 28 Aug 2011)
Log Message:
-----------
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

Modified Paths:
--------------
    trunk/phase3/tests/qunit/data/testrunner.js
    trunk/phase3/tests/qunit/index.html
    trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
    trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js

Modified: trunk/phase3/tests/qunit/data/testrunner.js
===================================================================
--- trunk/phase3/tests/qunit/data/testrunner.js 2011-08-28 21:21:55 UTC (rev 
95637)
+++ trunk/phase3/tests/qunit/data/testrunner.js 2011-08-28 22:04:49 UTC (rev 
95638)
@@ -14,7 +14,7 @@
  *  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>");
 }
 
 /**

Modified: trunk/phase3/tests/qunit/index.html
===================================================================
--- trunk/phase3/tests/qunit/index.html 2011-08-28 21:21:55 UTC (rev 95637)
+++ trunk/phase3/tests/qunit/index.html 2011-08-28 22:04:49 UTC (rev 95638)
@@ -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>
 

Modified: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
===================================================================
--- trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.test.js       
2011-08-28 21:21:55 UTC (rev 95637)
+++ trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.test.js       
2011-08-28 22:04:49 UTC (rev 95638)
@@ -124,43 +124,13 @@
 });
 
 test( 'mw.loader', function() {
-       expect(5);
+       expect(1);
 
-       // 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"
-               );
-
        // Asynchronous ahead
        stop(5000);
 
-       // Extract path
-       var tests_path = rePath.exec( location.href );
+       mw.loader.implement( 'is.awesome', [QUnit.fixurl( mw.config.get( 
'wgScriptPath' ) + '/tests/qunit/data/defineTestCallback.js' )], {}, {} );
 
-       mw.loader.implement( 'is.awesome', [QUnit.fixurl( tests_path + 
'data/defineTestCallback.js' )], {}, {} );
-
        mw.loader.using( 'is.awesome', function() {
 
                // /sample/awesome.js declares the "mw.loader.testCallback" 
function

Modified: 
trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
===================================================================
--- trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js  
2011-08-28 21:21:55 UTC (rev 95637)
+++ trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js  
2011-08-28 22:04:49 UTC (rev 95638)
@@ -39,6 +39,7 @@
 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 @@
        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() {


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to