diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2011-12-03 13:29:22 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2011-12-03 13:29:22 +0100 |
commit | ca32f08966f1b51fcb19460f0996bb0c4048e6fe (patch) | |
tree | ec04cc15b867bc21eedca904cea9af0254531a11 /tests/qunit/suites/resources/mediawiki | |
parent | a22fbfc60f36f5f7ee10d5ae6fe347340c2ee67c (diff) |
Update to MediaWiki 1.18.0
* also update ArchLinux skin to chagnes in MonoBook
* Use only css to hide our menu bar when printing
Diffstat (limited to 'tests/qunit/suites/resources/mediawiki')
4 files changed, 603 insertions, 0 deletions
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.js b/tests/qunit/suites/resources/mediawiki/mediawiki.js new file mode 100644 index 00000000..4beed881 --- /dev/null +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.js @@ -0,0 +1,232 @@ +module( 'mediawiki.js' ); + +test( '-- Initial check', function() { + expect(8); + + ok( window.jQuery, 'jQuery defined' ); + ok( window.$, '$j defined' ); + ok( window.$j, '$j defined' ); + strictEqual( window.$, window.jQuery, '$ alias to jQuery' ); + strictEqual( window.$j, window.jQuery, '$j alias to jQuery' ); + + ok( window.mediaWiki, 'mediaWiki defined' ); + ok( window.mw, 'mw defined' ); + strictEqual( window.mw, window.mediaWiki, 'mw alias to mediaWiki' ); +}); + +test( 'mw.Map', function() { + expect(17); + + ok( mw.Map, 'mw.Map defined' ); + + var conf = new mw.Map(), + // Dummy variables + funky = function() {}, + arry = [], + nummy = 7; + + // Tests for input validation + strictEqual( conf.get( 'inexistantKey' ), null, 'Map.get returns null if selection was a string and the key was not found' ); + strictEqual( conf.set( 'myKey', 'myValue' ), true, 'Map.set returns boolean true if a value was set for a valid key string' ); + strictEqual( conf.set( funky, 'Funky' ), false, 'Map.set returns boolean false if key was invalid (Function)' ); + strictEqual( conf.set( arry, 'Arry' ), false, 'Map.set returns boolean false if key was invalid (Array)' ); + strictEqual( conf.set( nummy, 'Nummy' ), false, 'Map.set returns boolean false if key was invalid (Number)' ); + equal( conf.get( 'myKey' ), 'myValue', 'Map.get returns a single value value correctly' ); + strictEqual( conf.get( nummy ), null, 'Map.get ruturns null if selection was invalid (Number)' ); + strictEqual( conf.get( funky ), null, 'Map.get ruturns null if selection was invalid (Function)' ); + + // Multiple values at once + var someValues = { + 'foo': 'bar', + 'lorem': 'ipsum', + 'MediaWiki': true + }; + strictEqual( conf.set( someValues ), true, 'Map.set returns boolean true if multiple values were set by passing an object' ); + deepEqual( conf.get( ['foo', 'lorem'] ), { + 'foo': 'bar', + 'lorem': 'ipsum' + }, 'Map.get returns multiple values correctly as an object' ); + + deepEqual( conf.get( ['foo', 'notExist'] ), { + 'foo': 'bar', + 'notExist': null + }, 'Map.get return includes keys that were not found as null values' ); + + strictEqual( conf.exists( 'foo' ), true, 'Map.exists returns boolean true if a key exists' ); + strictEqual( conf.exists( 'notExist' ), false, 'Map.exists returns boolean false if a key does not exists' ); + + // Interacting with globals and accessing the values object + strictEqual( conf.get(), conf.values, 'Map.get returns the entire values object by reference (if called without arguments)' ); + + conf.set( 'globalMapChecker', 'Hi' ); + + ok( false === 'globalMapChecker' in window, 'new mw.Map did not store its values in the global window object by default' ); + + var globalConf = new mw.Map( true ); + globalConf.set( 'anotherGlobalMapChecker', 'Hello' ); + + ok( 'anotherGlobalMapChecker' in window, 'new mw.Map( true ) did store its values in the global window object' ); + + // Whitelist this global variable for QUnit's 'noglobal' mode + if ( QUnit.config.noglobals ) { + QUnit.config.pollution.push( 'anotherGlobalMapChecker' ); + } +}); + +test( 'mw.config', function() { + expect(1); + + ok( mw.config instanceof mw.Map, 'mw.config instance of mw.Map' ); +}); + +test( 'mw.message & mw.messages', function() { + expect(17); + + ok( mw.messages, 'messages defined' ); + ok( mw.messages instanceof mw.Map, 'mw.messages instance of mw.Map' ); + ok( mw.messages.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' ); + + var hello = mw.message( 'hello' ); + + equal( hello.format, 'parse', 'Message property "format" defaults to "parse"' ); + strictEqual( hello.map, mw.messages, 'Message property "map" defaults to the global instance in mw.messages' ); + equal( hello.key, 'hello', 'Message property "key" (currect key)' ); + deepEqual( hello.parameters, [], 'Message property "parameters" defaults to an empty array' ); + + // Todo + ok( hello.params, 'Message prototype "params"' ); + + hello.format = 'plain'; + equal( hello.toString(), 'Hello <b>awesome</b> world', 'Message.toString returns the message as a string with the current "format"' ); + + equal( hello.escaped(), 'Hello <b>awesome</b> world', 'Message.escaped returns the escaped message' ); + equal( hello.format, 'escaped', 'Message.escaped correctly updated the "format" property' ); + + hello.parse(); + equal( hello.format, 'parse', 'Message.parse correctly updated the "format" property' ); + + hello.plain(); + equal( hello.format, 'plain', 'Message.plain correctly updated the "format" property' ); + + strictEqual( hello.exists(), true, 'Message.exists returns true for existing messages' ); + + var goodbye = mw.message( 'goodbye' ); + strictEqual( goodbye.exists(), false, 'Message.exists returns false for inexisting messages' ); + + equal( goodbye.plain(), '<goodbye>', 'Message.toString returns plain <key> if format is "plain" and key does not exist' ); + // bug 30684 + equal( goodbye.escaped(), '<goodbye>', 'Message.toString returns properly escaped <key> if format is "escaped" and key does not exist' ); +}); + +test( 'mw.msg', function() { + expect(3); + + ok( mw.messages.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' ); + + equal( mw.msg( 'hello' ), 'Hello <b>awesome</b> world', 'Gets message with default options (existing message)' ); + equal( mw.msg( 'goodbye' ), '<goodbye>', 'Gets message with default options (inexisting message)' ); +}); + +test( 'mw.loader', function() { + expect(5); + + // Regular expression to extract the path for the QUnit tests + // Takes into account that tests could be run from a file:// URL + // by excluding the 'index.html' part from the URL + var rePath = /(?:[^#\?](?!index.html))*\/?/; + + // Four assertions to test the above regular expression: + equal( + rePath.exec( 'http://path/to/tests/?foobar' )[0], + "http://path/to/tests/", + "Extracting path from http URL with query" + ); + equal( + rePath.exec( 'http://path/to/tests/#frag' )[0], + "http://path/to/tests/", + "Extracting path from http URL with fragment" + ); + equal( + rePath.exec( 'file://path/to/tests/index.html?foobar' )[0], + "file://path/to/tests/", + "Extracting path from local URL (file://) with query" + ); + equal( + rePath.exec( 'file://path/to/tests/index.html#frag' )[0], + "file://path/to/tests/", + "Extracting path from local URL (file://) with fragment" + ); + + // Asynchronous ahead + stop(5000); + + // Extract path + var tests_path = rePath.exec( location.href ); + + mw.loader.implement( 'is.awesome', [QUnit.fixurl( tests_path + 'data/defineTestCallback.js')], {}, {} ); + + mw.loader.using( 'is.awesome', function() { + + // /sample/awesome.js declares the "mw.loader.testCallback" function + // which contains a call to start() and ok() + mw.loader.testCallback(); + mw.loader.testCallback = undefined; + + }, function() { + start(); + ok( false, 'Error callback fired while implementing "is.awesome" module' ); + }); + +}); + +test( 'mw.loader.bug29107' , function() { + expect(2); + + // Message doesn't exist already + ok( !mw.messages.exists( 'bug29107' ) ); + + // Async! Include a timeout, as failure in this test leads to neither the + // success nor failure callbacks getting called. + stop(5000); + + mw.loader.implement( 'bug29107.messages-only', [], {}, {'bug29107': 'loaded'} ); + mw.loader.using( 'bug29107.messages-only', function() { + start(); + ok( mw.messages.exists( 'bug29107' ), 'Bug 29107: messages-only module should implement ok' ); + }, function() { + start(); + ok( false, 'Error callback fired while implementing "bug29107.messages-only" module' ); + }); +}); + +test( 'mw.html', function() { + expect(7); + + raises( function(){ + mw.html.escape(); + }, TypeError, 'html.escape throws a TypeError if argument given is not a string' ); + + equal( mw.html.escape( '<mw awesome="awesome" value=\'test\' />' ), + '<mw awesome="awesome" value='test' />', 'html.escape escapes html snippet' ); + + equal( mw.html.element(), + '<undefined/>', 'html.element Always return a valid html string (even without arguments)' ); + + equal( mw.html.element( 'div' ), '<div/>', 'html.element DIV (simple)' ); + + equal( mw.html.element( 'div', + { id: 'foobar' } ), + '<div id="foobar"/>', + 'html.element DIV (attribs)' ); + + equal( mw.html.element( 'div', + null, 'a' ), + '<div>a</div>', + 'html.element DIV (content)' ); + + equal( mw.html.element( 'a', + { href: 'http://mediawiki.org/w/index.php?title=RL&action=history' }, 'a' ), + '<a href="http://mediawiki.org/w/index.php?title=RL&action=history">a</a>', + 'html.element DIV (attribs + content)' ); + +}); diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js new file mode 100644 index 00000000..52cd32c8 --- /dev/null +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js @@ -0,0 +1,35 @@ +/* Some misc JavaScript compatibility tests, just to make sure the environments we run in are consistent */ + +module( 'mediawiki.jscompat' ); + +test( 'Variable with Unicode letter in name', function() { + expect(3); + var orig = "some token"; + var ŝablono = orig; + deepEqual( ŝablono, orig, 'ŝablono' ); + deepEqual( \u015dablono, orig, '\\u015dablono' ); + deepEqual( \u015Dablono, orig, '\\u015Dablono' ); +}); + +/* +// Not that we need this. ;) +// This fails on IE 6-8 +// Works on IE 9, Firefox 6, Chrome 14 +test( 'Keyword workaround: "if" as variable name using Unicode escapes', function() { + var orig = "another token"; + \u0069\u0066 = orig; + deepEqual( \u0069\u0066, orig, '\\u0069\\u0066' ); +}); +*/ + +/* +// Not that we need this. ;) +// This fails on IE 6-9 +// Works on Firefox 6, Chrome 14 +test( 'Keyword workaround: "if" as member variable name using Unicode escapes', function() { + var orig = "another token"; + var foo = {}; + foo.\u0069\u0066 = orig; + deepEqual( foo.\u0069\u0066, orig, 'foo.\\u0069\\u0066' ); +}); +*/ diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.user.js b/tests/qunit/suites/resources/mediawiki/mediawiki.user.js new file mode 100644 index 00000000..d5c6baad --- /dev/null +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.user.js @@ -0,0 +1,29 @@ +module( 'mediawiki.user.js' ); + +test( '-- Initial check', function() { + expect(1); + + ok( mw.user, 'mw.user defined' ); +}); + + +test( 'options', function() { + expect(1); + + ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' ); +}); + +test( 'User login status', function() { + expect(5); + + strictEqual( mw.user.name(), null, 'user.name should return null when anonymous' ); + ok( mw.user.anonymous(), 'user.anonymous should reutrn true when anonymous' ); + + // Not part of startUp module + mw.config.set( 'wgUserName', 'John' ); + + equal( mw.user.name(), 'John', 'user.name returns username when logged-in' ); + ok( !mw.user.anonymous(), 'user.anonymous returns false when logged-in' ); + + equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' ); +}); diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.js new file mode 100644 index 00000000..9c05d9b2 --- /dev/null +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.js @@ -0,0 +1,307 @@ +module( 'mediawiki.util.js' ); + +test( '-- Initial check', function() { + expect(1); + + ok( mw.util, 'mw.util defined' ); +}); + +test( 'rawurlencode', function() { + expect(1); + + equal( mw.util.rawurlencode( 'Test:A & B/Here' ), 'Test%3AA%20%26%20B%2FHere' ); +}); + +test( 'wikiUrlencode', function() { + expect(1); + + equal( mw.util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' ); +}); + +test( 'wikiGetlink', function() { + expect(3); + + // Not part of startUp module + mw.config.set( 'wgArticlePath', '/wiki/$1' ); + mw.config.set( 'wgPageName', 'Foobar' ); + + var hrefA = mw.util.wikiGetlink( 'Sandbox' ); + equal( hrefA, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' ); + + var hrefB = mw.util.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' ); + equal( hrefB, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage', + 'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' ); + + var hrefC = mw.util.wikiGetlink(); + equal( hrefC, '/wiki/Foobar', 'Default title; Get link for current page ("Foobar")' ); +}); + +test( 'wikiScript', function() { + expect(2); + + mw.config.set({ + 'wgScript': '/w/index.php', + 'wgScriptPath': '/w', + 'wgScriptExtension': '.php' + }); + + equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'Defaults to index.php and is equal to wgScript' ); + equal( mw.util.wikiScript( 'api' ), '/w/api.php', 'API path' ); + +}); + +test( 'addCSS', function() { + expect(3); + + var $testEl = $( '<div>' ).attr( 'id', 'mw-addcsstest' ).appendTo( 'body' ); + + var style = mw.util.addCSS( '#mw-addcsstest { visibility: hidden; }' ); + equal( typeof style, 'object', 'addCSS returned an object' ); + strictEqual( style.disabled, false, 'property "disabled" is available and set to false' ); + + equal( $testEl.css( 'visibility' ), 'hidden', 'Added style properties are in effect' ); + + // Clean up + $( style.ownerNode ) + .add( $testEl ) + .remove(); +}); + +test( 'toggleToc', function() { + expect(4); + + strictEqual( mw.util.toggleToc(), null, 'Return null if there is no table of contents on the page.' ); + + var tocHtml = + '<table id="toc" class="toc"><tr><td>' + + '<div id="toctitle">' + + '<h2>Contents</h2>' + + '<span class="toctoggle"> [<a href="#" class="internal" id="togglelink">Hide</a> ]</span>' + + '</div>' + + '<ul><li></li></ul>' + + '</td></tr></table>', + $toc = $(tocHtml).appendTo( 'body' ), + $toggleLink = $( '#togglelink' ); + + strictEqual( $toggleLink.length, 1, 'Toggle link is appended to the page.' ); + + // Toggle animation is asynchronous + // QUnit should not finish this test() untill they are all done + stop(); + + var actionC = function() { + start(); + + // Clean up + $toc.remove(); + }; + var actionB = function() { + start(); stop(); + strictEqual( mw.util.toggleToc( $toggleLink, actionC ), true, 'Return boolean true if the TOC is now visible.' ); + }; + var actionA = function() { + strictEqual( mw.util.toggleToc( $toggleLink, actionB ), false, 'Return boolean false if the TOC is now hidden.' ); + }; + + actionA(); +}); + +test( 'getParamValue', function() { + expect(5); + + var url1 = 'http://mediawiki.org/?foo=wrong&foo=right#&foo=bad'; + + equal( mw.util.getParamValue( 'foo', url1 ), 'right', 'Use latest one, ignore hash' ); + strictEqual( mw.util.getParamValue( 'bar', url1 ), null, 'Return null when not found' ); + + var url2 = 'http://mediawiki.org/#&foo=bad'; + strictEqual( mw.util.getParamValue( 'foo', url2 ), null, 'Ignore hash if param is not in querystring but in hash (bug 27427)' ); + + var url3 = 'example.com?' + $.param({ 'TEST': 'a b+c' }); + strictEqual( mw.util.getParamValue( 'TEST', url3 ), 'a b+c', 'Bug 30441: getParamValue must understand "+" encoding of space' ); + + var url4 = 'example.com?' + $.param({ 'TEST': 'a b+c d' }); // check for sloppy code from r95332 :) + strictEqual( mw.util.getParamValue( 'TEST', url4 ), 'a b+c d', 'Bug 30441: getParamValue must understand "+" encoding of space (multiple spaces)' ); +}); + +test( 'tooltipAccessKey', function() { + expect(3); + + equal( typeof mw.util.tooltipAccessKeyPrefix, 'string', 'mw.util.tooltipAccessKeyPrefix must be a string' ); + ok( mw.util.tooltipAccessKeyRegexp instanceof RegExp, 'mw.util.tooltipAccessKeyRegexp instance of RegExp' ); + ok( mw.util.updateTooltipAccessKeys, 'mw.util.updateTooltipAccessKeys' ); +}); + +test( '$content', function() { + expect(2); + + ok( mw.util.$content instanceof jQuery, 'mw.util.$content instance of jQuery' ); + strictEqual( mw.util.$content.length, 1, 'mw.util.$content must have length of 1' ); +}); + +test( 'addPortletLink', function() { + expect(7); + + var mwPanel = '<div id="mw-panel" class="noprint">\ + <h5>Toolbox</h5>\ + <div class="portlet" id="p-tb">\ + <ul class="body"></ul>\ + </div>\ +</div>', + vectorTabs = '<div id="p-views" class="vectorTabs">\ + <h5>Views</h5>\ + <ul></ul>\ +</div>', + $mwPanel = $(mwPanel).appendTo( 'body' ), + $vectorTabs = $(vectorTabs).appendTo( 'body' ); + + var tbRL = mw.util.addPortletLink( 'p-tb', 'http://mediawiki.org/wiki/ResourceLoader', + 'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l' ); + + ok( $.isDomElement( tbRL ), 'addPortletLink returns a valid DOM Element according to $.isDomElement' ); + + var tbMW = mw.util.addPortletLink( 'p-tb', 'http://mediawiki.org/', + 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org ', 'm', tbRL ), + $tbMW = $( tbMW ); + + + equal( $tbMW.attr( 'id' ), 't-mworg', 'Link has correct ID set' ); + equal( $tbMW.closest( '.portlet' ).attr( 'id' ), 'p-tb', 'Link was inserted within correct portlet' ); + equal( $tbMW.next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing nextnode)' ); + + var tbRLDM = mw.util.addPortletLink( 'p-tb', 'http://mediawiki.org/wiki/RL/DM', + 'Default modules', 't-rldm', 'List of all default modules ', 'd', '#t-rl' ); + + equal( $( tbRLDM ).next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing CSS selector)' ); + + var caFoo = mw.util.addPortletLink( 'p-views', '#', 'Foo' ); + + strictEqual( $tbMW.find( 'span').length, 0, 'No <span> element should be added for porlets without vectorTabs class.' ); + strictEqual( $( caFoo ).find( 'span').length, 1, 'A <span> element should be added for porlets with vectorTabs class.' ); + + // Clean up + $( [tbRL, tbMW, tbRLDM, caFoo] ) + .add( $mwPanel ) + .add( $vectorTabs ) + .remove(); +}); + +test( 'jsMessage', function() { + expect(1); + + var a = mw.util.jsMessage( "MediaWiki is <b>Awesome</b>." ); + ok( a, 'Basic checking of return value' ); + + // Clean up + $( '#mw-js-message' ).remove(); +}); + +test( 'validateEmail', function() { + expect(6); + + strictEqual( mw.util.validateEmail( "" ), null, 'Should return null for empty string ' ); + strictEqual( mw.util.validateEmail( "user@localhost" ), true, 'Return true for a valid e-mail address' ); + + // testEmailWithCommasAreInvalids + strictEqual( mw.util.validateEmail( "user,foo@example.org" ), false, 'Emails with commas are invalid' ); + strictEqual( mw.util.validateEmail( "userfoo@ex,ample.org" ), false, 'Emails with commas are invalid' ); + + // testEmailWithHyphens + strictEqual( mw.util.validateEmail( "user-foo@example.org" ), true, 'Emails may contain a hyphen' ); + strictEqual( mw.util.validateEmail( "userfoo@ex-ample.org" ), true, 'Emails may contain a hyphen' ); +}); + +test( 'isIPv6Address', function() { + expect(40); + + // Shortcuts + var assertFalseIPv6 = function( addy, summary ) { + return strictEqual( mw.util.isIPv6Address( addy ), false, summary ); + }, + assertTrueIPv6 = function( addy, summary ) { + return strictEqual( mw.util.isIPv6Address( addy ), true, summary ); + }; + + // Based on IPTest.php > testisIPv6 + assertFalseIPv6( ':fc:100::', 'IPv6 starting with lone ":"' ); + assertFalseIPv6( 'fc:100:::', 'IPv6 ending with a ":::"' ); + assertFalseIPv6( 'fc:300', 'IPv6 with only 2 words' ); + assertFalseIPv6( 'fc:100:300', 'IPv6 with only 3 words' ); + + $.each( + ['fc:100::', + 'fc:100:a::', + 'fc:100:a:d::', + 'fc:100:a:d:1::', + 'fc:100:a:d:1:e::', + 'fc:100:a:d:1:e:ac::'], function( i, addy ){ + assertTrueIPv6( addy, addy + ' is a valid IP' ); + }); + + assertFalseIPv6( 'fc:100:a:d:1:e:ac:0::', 'IPv6 with 8 words ending with "::"' ); + assertFalseIPv6( 'fc:100:a:d:1:e:ac:0:1::', 'IPv6 with 9 words ending with "::"' ); + + assertFalseIPv6( ':::' ); + assertFalseIPv6( '::0:', 'IPv6 ending in a lone ":"' ); + + assertTrueIPv6( '::', 'IPv6 zero address' ); + $.each( + ['::0', + '::fc', + '::fc:100', + '::fc:100:a', + '::fc:100:a:d', + '::fc:100:a:d:1', + '::fc:100:a:d:1:e', + '::fc:100:a:d:1:e:ac', + + 'fc:100:a:d:1:e:ac:0'], function( i, addy ){ + assertTrueIPv6( addy, addy + ' is a valid IP' ); + }); + + assertFalseIPv6( '::fc:100:a:d:1:e:ac:0', 'IPv6 with "::" and 8 words' ); + assertFalseIPv6( '::fc:100:a:d:1:e:ac:0:1', 'IPv6 with 9 words' ); + + assertFalseIPv6( ':fc::100', 'IPv6 starting with lone ":"' ); + assertFalseIPv6( 'fc::100:', 'IPv6 ending with lone ":"' ); + assertFalseIPv6( 'fc:::100', 'IPv6 with ":::" in the middle' ); + + assertTrueIPv6( 'fc::100', 'IPv6 with "::" and 2 words' ); + assertTrueIPv6( 'fc::100:a', 'IPv6 with "::" and 3 words' ); + assertTrueIPv6( 'fc::100:a:d', 'IPv6 with "::" and 4 words' ); + assertTrueIPv6( 'fc::100:a:d:1', 'IPv6 with "::" and 5 words' ); + assertTrueIPv6( 'fc::100:a:d:1:e', 'IPv6 with "::" and 6 words' ); + assertTrueIPv6( 'fc::100:a:d:1:e:ac', 'IPv6 with "::" and 7 words' ); + assertTrueIPv6( '2001::df', 'IPv6 with "::" and 2 words' ); + assertTrueIPv6( '2001:5c0:1400:a::df', 'IPv6 with "::" and 5 words' ); + assertTrueIPv6( '2001:5c0:1400:a::df:2', 'IPv6 with "::" and 6 words' ); + + assertFalseIPv6( 'fc::100:a:d:1:e:ac:0', 'IPv6 with "::" and 8 words' ); + assertFalseIPv6( 'fc::100:a:d:1:e:ac:0:1', 'IPv6 with 9 words' ); +}); + +test( 'isIPv4Address', function() { + expect(11); + + // Shortcuts + var assertFalseIPv4 = function( addy, summary ) { + return strictEqual( mw.util.isIPv4Address( addy ), false, summary ); + }, + assertTrueIPv4 = function( addy, summary ) { + return strictEqual( mw.util.isIPv4Address( addy ), true, summary ); + }; + + // Based on IPTest.php > testisIPv4 + assertFalseIPv4( false, 'Boolean false is not an IP' ); + assertFalseIPv4( true, 'Boolean true is not an IP' ); + assertFalseIPv4( '', 'Empty string is not an IP' ); + assertFalseIPv4( 'abc', '"abc" is not an IP' ); + assertFalseIPv4( ':', 'Colon is not an IP' ); + assertFalseIPv4( '124.24.52', 'IPv4 not enough quads' ); + assertFalseIPv4( '24.324.52.13', 'IPv4 out of range' ); + assertFalseIPv4( '.24.52.13', 'IPv4 starts with period' ); + + assertTrueIPv4( '124.24.52.13', '124.24.52.134 is a valid IP' ); + assertTrueIPv4( '1.24.52.13', '1.24.52.13 is a valid IP' ); + assertFalseIPv4( '74.24.52.13/20', 'IPv4 ranges are not recogzized as valid IPs' ); +}); |