r95638 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95637‎ | r95638 | r95639 >
Date:22:04, 28 August 2011
Author:krinkle
Status:ok
Tags:
Comment:
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 (modified) (history)
  • /trunk/phase3/tests/qunit/index.html (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.test.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/qunit/data/testrunner.js
@@ -14,7 +14,7 @@
1515 * Load TestSwarm agent
1616 */
1717 if ( QUnit.urlParams.swarmURL ) {
18 - document.write("<scr" + "ipt src='" + QUnit.fixurl( 'data/testwarm.inject.js' ) + "'></scr" + "ipt>");
 18+ document.write("<scr" + "ipt src='" + QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/testwarm.inject.js' ) + "'></scr" + "ipt>");
1919 }
2020
2121 /**
Index: trunk/phase3/tests/qunit/index.html
@@ -9,6 +9,25 @@
1010 <script>
1111 function startUp(){
1212 mw.config = new mw.Map( false );
 13+
 14+ /**
 15+ * Guess wgScriptPath (for access to /tests/qunit/data/)
 16+ */
 17+
 18+ // Regular expression to extract the path for the QUnit tests
 19+ // Takes into account that tests could be run from a file:// URL
 20+ // by excluding the 'index.html' part from the URL
 21+ var rePath = /(?:[^#\?](?!index.html))*\/?/;
 22+
 23+ // Extract path to /tests/qunit/
 24+ var qunitTestsPath = rePath.exec( location.href )[0];
 25+
 26+ // Traverse up to script path
 27+ var pathParts = qunitTestsPath.split( '/' );
 28+ pathParts.pop(); pathParts.pop(); pathParts.pop();
 29+ var scriptPath = pathParts.join( '/' );
 30+
 31+ mw.config.set( 'wgScriptPath', scriptPath );
1332 }
1433 </script>
1534
Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
@@ -39,6 +39,7 @@
4040 test( 'wikiScript', function() {
4141 expect(2);
4242
 43+ var prevConfig = mw.config.get([ 'wgScript', 'wgScriptPath', 'wgScriptExtension' ]);
4344 mw.config.set({
4445 'wgScript': '/w/index.php',
4546 'wgScriptPath': '/w',
@@ -48,6 +49,8 @@
4950 equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'Defaults to index.php and is equal to wgScript' );
5051 equal( mw.util.wikiScript( 'api' ), '/w/api.php', 'API path' );
5152
 53+ // Restore mw.config
 54+ mw.config.set( prevConfig );
5255 });
5356
5457 test( 'addCSS', function() {
Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
@@ -124,43 +124,13 @@
125125 });
126126
127127 test( 'mw.loader', function() {
128 - expect(5);
 128+ expect(1);
129129
130 - // Regular expression to extract the path for the QUnit tests
131 - // Takes into account that tests could be run from a file:// URL
132 - // by excluding the 'index.html' part from the URL
133 - var rePath = /(?:[^#\?](?!index.html))*\/?/;
134 -
135 - // Four assertions to test the above regular expression:
136 - equal(
137 - rePath.exec( 'http://path/to/tests/?foobar' )[0],
138 - "http://path/to/tests/",
139 - "Extracting path from http URL with query"
140 - );
141 - equal(
142 - rePath.exec( 'http://path/to/tests/#frag' )[0],
143 - "http://path/to/tests/",
144 - "Extracting path from http URL with fragment"
145 - );
146 - equal(
147 - rePath.exec( 'file://path/to/tests/index.html?foobar' )[0],
148 - "file://path/to/tests/",
149 - "Extracting path from local URL (file://) with query"
150 - );
151 - equal(
152 - rePath.exec( 'file://path/to/tests/index.html#frag' )[0],
153 - "file://path/to/tests/",
154 - "Extracting path from local URL (file://) with fragment"
155 - );
156 -
157130 // Asynchronous ahead
158131 stop(5000);
159132
160 - // Extract path
161 - var tests_path = rePath.exec( location.href );
 133+ mw.loader.implement( 'is.awesome', [QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/defineTestCallback.js' )], {}, {} );
162134
163 - mw.loader.implement( 'is.awesome', [QUnit.fixurl( tests_path + 'data/defineTestCallback.js' )], {}, {} );
164 -
165135 mw.loader.using( 'is.awesome', function() {
166136
167137 // /sample/awesome.js declares the "mw.loader.testCallback" function

Status & tagging log