r107506 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107505‎ | r107506 | r107507 >
Date:18:30, 28 December 2011
Author:krinkle
Status:ok
Tags:
Comment:
[JSTesting] several updates

* Sync QUnitTestResources.php with qunit/index.html

* Fix usage of global wg var

* Fix tablesorter.test (to be merged to trunk[1])
-- In the table sorter code it applies certain conditions if the content language is "en", and otherwise to whatever is specified. In qunit/index.html there is no wgContentLanguage set, so it assumed it's not default and used the "dmy" date format. On Special:JavaScriptTest however it refused to use it since wgContentLanguage was set to "en" (as is default in MediaWiki). Changing test suite to declare the language itself, instead of relying on globals.

TODO: Hook into QUnit "setup" and "teardown" for each test() so that globals are reset automatically.
This is actually pretty cool, as for mw.config/QUnit all we need to do is save mw.config.values in a temp val, and set it to a new empty object in "setup" and restore in "teardown". Instant "complete config scope" mock & restore.
Modified paths:
  • /branches/JSTesting/resources/Resources.php (modified) (history)
  • /branches/JSTesting/tests/qunit/QUnitTestResources.php (modified) (history)
  • /branches/JSTesting/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js (modified) (history)
  • /branches/JSTesting/tests/qunit/suites/resources/mediawiki/mediawiki.test.js (modified) (history)

Diff [purge]

Index: branches/JSTesting/tests/qunit/QUnitTestResources.php
@@ -12,12 +12,13 @@
1313 'tests/qunit/suites/resources/jquery/jquery.client.test.js',
1414 'tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js',
1515 'tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js',
 16+ 'tests/qunit/suites/resources/jquery/jquery.highlightText.test.js',
1617 'tests/qunit/suites/resources/jquery/jquery.localize.test.js',
1718 'tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js',
1819 'tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js',
19 - # jquery.tablesorter.test.js: Broken
20 - #'tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js', // has mw-config def
 20+ 'tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js', // has mw-config def
2121 'tests/qunit/suites/resources/jquery/jquery.textSelection.test.js',
 22+ 'tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js',
2223 'tests/qunit/suites/resources/mediawiki/mediawiki.test.js',
2324 'tests/qunit/suites/resources/mediawiki/mediawiki.title.test.js', // has mw-config def
2425 'tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js',
@@ -28,8 +29,8 @@
2930 // This means the module overwrites/sets mw.config variables, reason being that
3031 // the static /qunit/index.html has an empty mw.config since it's static.
3132 // Until /qunit/index.html is fully replaceable and WMF's TestSwarm is up and running
32 - // with Special:JavaScriptTest, untill it is important that tests do not depend on anything
33 - // being in mw.config (not even wgServer).
 33+ // with Special:JavaScriptTest - untill then, it is important that tests do not depend
 34+ // on anything being in mw.config (not even wgServer).
3435 ),
3536 'dependencies' => array(
3637 'jquery.autoEllipsis',
@@ -38,6 +39,7 @@
3940 'jquery.client',
4041 'jquery.colorUtil',
4142 'jquery.getAttrs',
 43+ 'jquery.highlightText',
4244 'jquery.localize',
4345 'jquery.mwExtension',
4446 'jquery.tabIndex',
Index: branches/JSTesting/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
@@ -6,6 +6,7 @@
77 mw.config.set( 'wgMonthNames', ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']);
88 mw.config.set( 'wgMonthNamesShort', ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']);
99 mw.config.set( 'wgDefaultDateFormat', 'dmy' );
 10+mw.config.set( 'wgContentLanguage', 'en' );
1011
1112 test( '-- Initial check', function() {
1213 expect(1);
@@ -182,6 +183,7 @@
183184 function( $table ) {
184185 // @fixme reset it at end or change module to allow us to override it
185186 mw.config.set( 'wgDefaultDateFormat', 'dmy' );
 187+ mw.config.set( 'wgContentLanguage', 'de' );
186188 $table.tablesorter();
187189 $table.find( '.headerSort:eq(0)' ).click();
188190 }
Index: branches/JSTesting/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
@@ -175,20 +175,20 @@
176176
177177 expect(2);
178178
179 - var wgServer = mw.config.get( 'wgServer' ),
 179+ var server = mw.config.get( 'wgServer' ),
180180 basePath = mw.config.get( 'wgScriptPath' );
181181
182182 // From [[Special:JavaScriptTest]] we need to preprend the script path
183183 // with the actual server (http://localhost/).
184184 // Running from file tests/qunit/index.html, wgScriptPath is already
185185 // including the wgServer part
186 - if( wgServer !== null ) {
187 - basePath = wgServer + wgScriptPath;
 186+ if( server !== null ) {
 187+ basePath = server + basePath;
188188 }
189189 // Forge an URL to the test callback script
190190 var target = QUnit.fixurl(
191191 basePath + '/tests/qunit/data/qunitOkCall.js'
192 - );
 192+ );
193193
194194 // Confirm that mw.loader.load() works with protocol-relative URLs
195195 target = target.replace( /https?:/, '' );
Index: branches/JSTesting/resources/Resources.php
@@ -706,6 +706,8 @@
707707 'dependencies' => array(
708708 'jquery.qunit',
709709 'jquery.qunit.completenessTest',
 710+ 'mediawiki.page.startup',
 711+ 'mediawiki.page.ready',
710712 ),
711713 'position' => 'top',
712714 ),

Status & tagging log