From: Neil Kandalgaonkar Date: Mon, 10 Oct 2011 23:29:07 +0000 (+0000) Subject: ensure tests for mw.Uri work in non-browser environments X-Git-Tag: 1.31.0-rc.0~27158 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=a6eaac24e3cacf19ffc50add2dd5b05ce7cafb2f;p=lhc%2Fweb%2Fwiklou.git ensure tests for mw.Uri work in non-browser environments --- diff --git a/resources/mediawiki/mediawiki.Uri.js b/resources/mediawiki/mediawiki.Uri.js index 192837e39d..16a724aa47 100644 --- a/resources/mediawiki/mediawiki.Uri.js +++ b/resources/mediawiki/mediawiki.Uri.js @@ -275,9 +275,9 @@ return Uri; }; - // inject the current document location, for relative URLs - mw.Uri = mw.UriRelative( document.location.href ); - - + // if we are running in a browser, inject the current document location, for relative URLs + if ( document && document.location && document.location.href ) { + mw.Uri = mw.UriRelative( document.location.href ); + } } )( jQuery, mediaWiki ); diff --git a/tests/jasmine/spec/mediawiki.Uri.spec.js b/tests/jasmine/spec/mediawiki.Uri.spec.js index a21ba673ab..c8df13f64e 100644 --- a/tests/jasmine/spec/mediawiki.Uri.spec.js +++ b/tests/jasmine/spec/mediawiki.Uri.spec.js @@ -1,5 +1,10 @@ ( function() { + // ensure we have a generic URI parser if not running in a browser + if ( !mw.Uri ) { + mw.Uri = mw.UriRelative( 'http://sample.com/' ); + } + describe( "mw.Uri", function() { describe( "should work well in loose and strict mode", function() {