ensure tests for mw.Uri work in non-browser environments
authorNeil Kandalgaonkar <neilk@users.mediawiki.org>
Mon, 10 Oct 2011 23:29:07 +0000 (23:29 +0000)
committerNeil Kandalgaonkar <neilk@users.mediawiki.org>
Mon, 10 Oct 2011 23:29:07 +0000 (23:29 +0000)
resources/mediawiki/mediawiki.Uri.js
tests/jasmine/spec/mediawiki.Uri.spec.js

index 192837e..16a724a 100644 (file)
                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 );
index a21ba67..c8df13f 100644 (file)
@@ -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() {