From 42baefa774085a88f879683b54a26e13632ff649 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Tue, 3 Jan 2012 21:53:23 +0000 Subject: [PATCH] [JSTesting] Fix static html tests * r107919 merge broke it as it removed all the inline mw.config calls, and the tearDown is resetting them to the initial values. That works fine on a MediaWiki page but on the static page are now no variables at all. Copying a basic sample to it. This should've been in the static test suite all along actually. * Calculating wgScriptPath based on location.pathname instead of location.href, exclude wgServer * Follows-up r107919 --- tests/qunit/index.html | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/qunit/index.html b/tests/qunit/index.html index 5084961460..94428812e7 100644 --- a/tests/qunit/index.html +++ b/tests/qunit/index.html @@ -11,7 +11,17 @@ mw.config = new mw.Map( false ); /** - * Guess wgScriptPath (for access to /tests/qunit/data/) + * Simulate an average mw.config context + */ + /* StartUp module */ + mw.config.set({"wgLoadScript": "/mw/trunk/phase3/load.php", "debug": true, "skin": "vector", "stylepath": "/mw/trunk/phase3/skins", "wgUrlProtocols": "http\\:\\/\\/|https\\:\\/\\/|ftp\\:\\/\\/|irc\\:\\/\\/|ircs\\:\\/\\/|gopher\\:\\/\\/|telnet\\:\\/\\/|nntp\\:\\/\\/|worldwind\\:\\/\\/|mailto\\:|news\\:|svn\\:\\/\\/|git\\:\\/\\/|mms\\:\\/\\/|\\/\\/", "wgArticlePath": "/mw/trunk/phase3/index.php/$1", "wgScriptPath": "/mw/trunk/phase3", "wgScriptExtension": ".php", "wgScript": "/mw/trunk/phase3/index.php", "wgVariantArticlePath": false, "wgActionPaths": [], "wgServer": "http://localhost", "wgUserLanguage": "en", "wgContentLanguage": "en", "wgVersion": "1.19alpha", "wgEnableAPI": true, "wgEnableWriteAPI": true, "wgDefaultDateFormat": "dmy", "wgMonthNames": ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], "wgMonthNamesShort": ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], "wgMainPageTitle": "Main Page", "wgFormattedNamespaces": {"-2": "Media", "-1": "Special", "0": "", "1": "Talk", "2": "User", "3": "User talk", "4": "Testopedia", "5": "Testopedia talk", "6": "File", "7": "File talk", "8": "MediaWiki", "9": "MediaWiki talk", "10": "Template", "11": "Template talk", "12": "Help", "13": "Help talk", "14": "Category", "15": "Category talk"}, "wgNamespaceIds": {"media": -2, "special": -1, "": 0, "talk": 1, "user": 2, "user_talk": 3, "testopedia": 4, "testopedia_talk": 5, "file": 6, "file_talk": 7, "mediawiki": 8, "mediawiki_talk": 9, "template": 10, "template_talk": 11, "help": 12, "help_talk": 13, "category": 14, "category_talk": 15, "image": 6, "image_talk": 7, "project": 4, "project_talk": 5}, "wgSiteName": "Testopedia", "wgFileExtensions": ["png", "gif", "jpg", "jpeg"], "wgDBname": "mediawiki", "wgFileCanRotate": true, "wgAvailableSkins": {"chick": "Chick", "cologneblue": "CologneBlue", "modern": "Modern", "monobook": "MonoBook", "myskin": "MySkin", "nostalgia": "Nostalgia", "simple": "Simple", "standard": "Standard", "vector": "Vector"}, "wgExtensionAssetsPath": "/mw/trunk/phase3/extensions", "wgCookiePrefix": "mediawiki", "wgResourceLoaderMaxQueryLength": -1, "wgCaseSensitiveNamespaces": []}); + + /* WikiPage specific */ + mw.config.set({"wgCanonicalNamespace": "", "wgCanonicalSpecialPageName": false, "wgNamespaceNumber": 0, "wgPageName": "Sandbox", "wgTitle": "Sandbox", "wgCurRevisionId": 486, "wgArticleId": 84, "wgIsArticle": true, "wgAction": "view", "wgUserName": null, "wgUserGroups": ["*"], "wgCategories": [], "wgBreakFrames": false, "wgPageContentLanguage": "en", "wgSeparatorTransformTable": ["", ""], "wgDigitTransformTable": ["", ""], "wgRestrictionEdit": [], "wgRestrictionMove": [], "wgRedirectedFrom": "Sandbox"}); + + /** + * Fix wgScriptPath and the like to the real thing, + * instead of fake ones (for access to /tests/qunit/data/) */ // Regular expression to extract the path for the QUnit tests @@ -20,14 +30,21 @@ var rePath = /(?:[^#\?](?!index.html))*\/?/; // Extract path to /tests/qunit/ - var qunitTestsPath = rePath.exec( location.href )[0]; + var qunitTestsPath = rePath.exec( location.pathname )[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 ); + mw.config.set({ + "wgScriptPath": scriptPath, + "wgLoadScript": scriptPath + '/load.php', + "stylepath": scriptPath + '/skins', + "wgArticlePath": scriptPath + '/index.php/$1', + "wgScript": scriptPath + '/index.php', + "wgExtensionAssetsPath": scriptPath + '/extensions' + }); } -- 2.20.1