From d9022f63880ce039446fba8364f68e656b7bf4cb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 3 May 2012 13:01:35 +0200 Subject: Update to MediaWiki 1.19.0 --- tests/qunit/QUnitTestResources.php | 52 ++++ tests/qunit/data/qunitOkCall.js | 2 + tests/qunit/data/testrunner.js | 130 +++++++-- tests/qunit/index.html | 79 ++++-- .../suites/resources/jquery/jquery.autoEllipsis.js | 58 ---- .../resources/jquery/jquery.autoEllipsis.test.js | 55 ++++ .../suites/resources/jquery/jquery.byteLength.js | 42 --- .../resources/jquery/jquery.byteLength.test.js | 42 +++ .../suites/resources/jquery/jquery.byteLimit.js | 155 ----------- .../resources/jquery/jquery.byteLimit.test.js | 187 +++++++++++++ .../qunit/suites/resources/jquery/jquery.client.js | 205 -------------- .../suites/resources/jquery/jquery.client.test.js | 309 +++++++++++++++++++++ .../suites/resources/jquery/jquery.colorUtil.js | 71 ----- .../resources/jquery/jquery.colorUtil.test.js | 71 +++++ .../resources/jquery/jquery.delayedBind.test.js | 4 +- .../suites/resources/jquery/jquery.getAttrs.js | 17 -- .../resources/jquery/jquery.getAttrs.test.js | 17 ++ .../resources/jquery/jquery.highlightText.test.js | 239 ++++++++++++++++ .../suites/resources/jquery/jquery.localize.js | 119 -------- .../resources/jquery/jquery.localize.test.js | 119 ++++++++ .../resources/jquery/jquery.mwExtension.test.js | 58 ++++ .../suites/resources/jquery/jquery.mwPrototypes.js | 56 ---- .../suites/resources/jquery/jquery.tabIndex.js | 50 ---- .../resources/jquery/jquery.tabIndex.test.js | 44 +++ .../resources/jquery/jquery.tablesorter.test.js | 227 ++++++++++----- .../resources/jquery/jquery.textSelection.test.js | 279 +++++++++++++++++++ .../mediawiki.special.recentchanges.js | 71 ----- .../mediawiki.special.recentchanges.test.js | 67 +++++ .../resources/mediawiki/mediawiki.Title.test.js | 201 ++++++++++++++ .../mediawiki/mediawiki.jqueryMsg.test.js | 43 +++ .../qunit/suites/resources/mediawiki/mediawiki.js | 232 ---------------- .../resources/mediawiki/mediawiki.jscompat.test.js | 29 +- .../suites/resources/mediawiki/mediawiki.test.js | 270 ++++++++++++++++++ .../suites/resources/mediawiki/mediawiki.user.js | 29 -- .../resources/mediawiki/mediawiki.user.test.js | 39 +++ .../suites/resources/mediawiki/mediawiki.util.js | 307 -------------------- .../resources/mediawiki/mediawiki.util.test.js | 305 ++++++++++++++++++++ 37 files changed, 2757 insertions(+), 1523 deletions(-) create mode 100644 tests/qunit/QUnitTestResources.php create mode 100644 tests/qunit/data/qunitOkCall.js delete mode 100644 tests/qunit/suites/resources/jquery/jquery.autoEllipsis.js create mode 100644 tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js delete mode 100644 tests/qunit/suites/resources/jquery/jquery.byteLength.js create mode 100644 tests/qunit/suites/resources/jquery/jquery.byteLength.test.js delete mode 100644 tests/qunit/suites/resources/jquery/jquery.byteLimit.js create mode 100644 tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js delete mode 100644 tests/qunit/suites/resources/jquery/jquery.client.js create mode 100644 tests/qunit/suites/resources/jquery/jquery.client.test.js delete mode 100644 tests/qunit/suites/resources/jquery/jquery.colorUtil.js create mode 100644 tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js delete mode 100644 tests/qunit/suites/resources/jquery/jquery.getAttrs.js create mode 100644 tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js create mode 100644 tests/qunit/suites/resources/jquery/jquery.highlightText.test.js delete mode 100644 tests/qunit/suites/resources/jquery/jquery.localize.js create mode 100644 tests/qunit/suites/resources/jquery/jquery.localize.test.js create mode 100644 tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js delete mode 100644 tests/qunit/suites/resources/jquery/jquery.mwPrototypes.js delete mode 100644 tests/qunit/suites/resources/jquery/jquery.tabIndex.js create mode 100644 tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js create mode 100644 tests/qunit/suites/resources/jquery/jquery.textSelection.test.js delete mode 100644 tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.js create mode 100644 tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.test.js create mode 100644 tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js create mode 100644 tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js delete mode 100644 tests/qunit/suites/resources/mediawiki/mediawiki.js create mode 100644 tests/qunit/suites/resources/mediawiki/mediawiki.test.js delete mode 100644 tests/qunit/suites/resources/mediawiki/mediawiki.user.js create mode 100644 tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js delete mode 100644 tests/qunit/suites/resources/mediawiki/mediawiki.util.js create mode 100644 tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js (limited to 'tests/qunit') diff --git a/tests/qunit/QUnitTestResources.php b/tests/qunit/QUnitTestResources.php new file mode 100644 index 00000000..670e3d11 --- /dev/null +++ b/tests/qunit/QUnitTestResources.php @@ -0,0 +1,52 @@ + array( + 'scripts' => array( + 'tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js', + 'tests/qunit/suites/resources/jquery/jquery.byteLength.test.js', + 'tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js', + 'tests/qunit/suites/resources/jquery/jquery.client.test.js', + 'tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js', + 'tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js', + 'tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js', + 'tests/qunit/suites/resources/jquery/jquery.highlightText.test.js', + 'tests/qunit/suites/resources/jquery/jquery.localize.test.js', + 'tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js', + 'tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js', + 'tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js', + 'tests/qunit/suites/resources/jquery/jquery.textSelection.test.js', + 'tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js', + 'tests/qunit/suites/resources/mediawiki/mediawiki.test.js', + 'tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js', + 'tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js', + 'tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js', + 'tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.test.js', + "tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js", + ), + 'dependencies' => array( + 'jquery.autoEllipsis', + 'jquery.byteLength', + 'jquery.byteLimit', + 'jquery.client', + 'jquery.colorUtil', + 'jquery.delayedBind', + 'jquery.getAttrs', + 'jquery.highlightText', + 'jquery.localize', + 'jquery.mwExtension', + 'jquery.tabIndex', + 'jquery.tablesorter', + 'jquery.textSelection', + 'mediawiki', + 'mediawiki.Title', + 'mediawiki.user', + 'mediawiki.util', + 'mediawiki.special.recentchanges', + 'mediawiki.jqueryMsg', + ), + ) +); diff --git a/tests/qunit/data/qunitOkCall.js b/tests/qunit/data/qunitOkCall.js new file mode 100644 index 00000000..2fb6e01d --- /dev/null +++ b/tests/qunit/data/qunitOkCall.js @@ -0,0 +1,2 @@ +start(); +ok( true, 'Successfully loaded!'); diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js index dbfe9fad..fdd3116b 100644 --- a/tests/qunit/data/testrunner.js +++ b/tests/qunit/data/testrunner.js @@ -1,36 +1,61 @@ -( function( $ ) { +( function ( $, mw, QUnit, undefined ) { +"use strict"; + +var mwTestIgnore, mwTester, addons; /** * Add bogus to url to prevent IE crazy caching * - * @param value {String} a relative path (eg. 'data/defineTestCallback.js' or 'data/test.php?foo=bar') + * @param value {String} a relative path (eg. 'data/defineTestCallback.js' + * or 'data/test.php?foo=bar'). * @return {String} Such as 'data/defineTestCallback.js?131031765087663960' */ -QUnit.fixurl = function(value) { - return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000); +QUnit.fixurl = function (value) { + return value + (/\?/.test( value ) ? '&' : '?') + + String( new Date().getTime() ) + + String( parseInt( Math.random()*100000, 10 ) ); }; +/** + * Configuration + */ +QUnit.config.testTimeout = 5000; + +/** + * MediaWiki debug mode + */ +QUnit.config.urlConfig.push( 'debug' ); + /** * Load TestSwarm agent */ if ( QUnit.urlParams.swarmURL ) { - document.write(""); + document.write( "" ); } /** - * Load completenesstest + * CompletenessTest */ +// Adds toggle checkbox to header +QUnit.config.urlConfig.push( 'completenesstest' ); + +// Initiate when enabled if ( QUnit.urlParams.completenesstest ) { // Return true to ignore - var mwTestIgnore = function( val, tester, funcPath ) { + mwTestIgnore = function ( val, tester, funcPath ) { // Don't record methods of the properties of constructors, // to avoid getting into a loop (prototype.constructor.prototype..). // Since we're therefor skipping any injection for // "new mw.Foo()", manually set it to true here. if ( val instanceof mw.Map ) { - tester.methodCallTracker['Map'] = true; + tester.methodCallTracker.Map = true; + return true; + } + if ( val instanceof mw.Title ) { + tester.methodCallTracker.Title = true; return true; } @@ -42,42 +67,113 @@ if ( QUnit.urlParams.completenesstest ) { return false; }; - var mwTester = new CompletenessTest( mw, mwTestIgnore ); + mwTester = new CompletenessTest( mw, mwTestIgnore ); } +/** + * Test environment recommended for all QUnit test modules + */ +// Whether to log environment changes to the console +QUnit.config.urlConfig.push( 'mwlogenv' ); + +/** + * Reset mw.config to a fresh copy of the live config for each test(); + * @param override {Object} [optional] + * @example: + * + * module( .., newMwEnvironment() ); + * + * test( .., function () { + * mw.config.set( 'foo', 'bar' ); // just for this test + * } ); + * + * test( .., function () { + * mw.config.get( 'foo' ); // doesn't exist + * } ); + * + * + * module( .., newMwEnvironment({ quux: 'corge' }) ); + * + * test( .., function () { + * mw.config.get( 'quux' ); // "corge" + * mw.config.set( 'quux', "grault" ); + * } ); + * + * test( .., function () { + * mw.config.get( 'quux' ); // "corge" + * } ); + * + */ +QUnit.newMwEnvironment = ( function () { + var liveConfig, freshConfigCopy, log; + + liveConfig = mw.config.values; + + freshConfigCopy = function ( custom ) { + // "deep=true" is important here. + // Otherwise we just create a new object with values referring to live config. + // e.g. mw.config.set( 'wgFileExtensions', [] ) would not effect liveConfig, + // but mw.config.get( 'wgFileExtensions' ).push( 'png' ) would as the array + // was passed by reference in $.extend's loop. + return $.extend({}, liveConfig, custom, /*deep=*/true ); + }; + + log = QUnit.urlParams.mwlogenv ? mw.log : function () {}; + + return function ( override ) { + override = override || {}; + + return { + setup: function () { + log( 'MwEnvironment> SETUP for "' + QUnit.config.current.module + + ': ' + QUnit.config.current.testName + '"' ); + // Greetings, mock configuration! + mw.config.values = freshConfigCopy( override ); + }, + + teardown: function () { + log( 'MwEnvironment> TEARDOWN for "' + QUnit.config.current.module + + ': ' + QUnit.config.current.testName + '"' ); + // Farewell, mock configuration! + mw.config.values = liveConfig; + } + }; + }; +}() ); + /** * Add-on assertion helpers */ // Define the add-ons -var addons = { +addons = { // Expect boolean true - assertTrue: function( actual, message ) { + assertTrue: function ( actual, message ) { strictEqual( actual, true, message ); }, // Expect boolean false - assertFalse: function( actual, message ) { + assertFalse: function ( actual, message ) { strictEqual( actual, false, message ); }, // Expect numerical value less than X - lt: function( actual, expected, message ) { + lt: function ( actual, expected, message ) { QUnit.push( actual < expected, actual, 'less than ' + expected, message ); }, // Expect numerical value less than or equal to X - ltOrEq: function( actual, expected, message ) { + ltOrEq: function ( actual, expected, message ) { QUnit.push( actual <= expected, actual, 'less than or equal to ' + expected, message ); }, // Expect numerical value greater than X - gt: function( actual, expected, message ) { + gt: function ( actual, expected, message ) { QUnit.push( actual > expected, actual, 'greater than ' + expected, message ); }, // Expect numerical value greater than or equal to X - gtOrEq: function( actual, expected, message ) { + gtOrEq: function ( actual, expected, message ) { QUnit.push( actual >= expected, actual, 'greater than or equal to ' + expected, message ); }, @@ -89,4 +185,4 @@ var addons = { $.extend( QUnit, addons ); $.extend( window, addons ); -})( jQuery ); +})( jQuery, mediaWiki, QUnit ); diff --git a/tests/qunit/index.html b/tests/qunit/index.html index f748b87f..ef7ff8de 100644 --- a/tests/qunit/index.html +++ b/tests/qunit/index.html @@ -9,6 +9,43 @@ @@ -18,15 +55,15 @@ + - + - - + @@ -45,9 +82,14 @@ + + + + + @@ -59,23 +101,27 @@ - - + + - - - + + + - - - - + + + + - - - + + + + - + + + +

MediaWiki JavaScript Test Suite

@@ -85,6 +131,7 @@

    +
    diff --git a/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.js b/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.js deleted file mode 100644 index caf5a6f1..00000000 --- a/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.js +++ /dev/null @@ -1,58 +0,0 @@ -module( 'jquery.autoEllipsis.js' ); - -test( '-- Initial check', function() { - expect(1); - ok( $.fn.autoEllipsis, 'jQuery.fn.autoEllipsis defined' ); -}); - -function createWrappedDiv( text, width ) { - var $wrapper = $( '
    ' ).css( 'width', width ); - var $div = $( '
    ' ).text( text ); - $wrapper.append( $div ); - return $wrapper; -} - -function findDivergenceIndex( a, b ) { - var i = 0; - while ( i < a.length && i < b.length && a[i] == b[i] ) { - i++; - } - return i; -} - -test( 'Position right', function() { - expect(4); - - // We need this thing to be visible, so append it to the DOM - var origText = 'This is a really long random string and there is no way it fits in 100 pixels.'; - var $wrapper = createWrappedDiv( origText, '100px' ); - $( 'body' ).append( $wrapper ); - $wrapper.autoEllipsis( { position: 'right' } ); - - // Verify that, and only one, span element was created - var $span = $wrapper.find( '> span' ); - strictEqual( $span.length, 1, 'autoEllipsis wrapped the contents in a span element' ); - - // Check that the text fits by turning on word wrapping - $span.css( 'whiteSpace', 'nowrap' ); - ltOrEq( $span.width(), $span.parent().width(), "Text fits (making the span 'white-space:nowrap' does not make it wider than its parent)" ); - - // Add two characters using scary black magic - var spanText = $span.text(); - var d = findDivergenceIndex( origText, spanText ); - var spanTextNew = spanText.substr( 0, d ) + origText[d] + origText[d] + '...'; - - gt( spanTextNew.length, spanText.length, 'Verify that the new span-length is indeed greater' ); - - // Put this text in the span and verify it doesn't fit - $span.text( spanTextNew ); - // In IE6 width works like min-width, allow IE6's width to be "equal to" - if ( $.browser.msie && Number( $.browser.version ) == 6 ) { - gtOrEq( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more) - IE6: Maybe equal to as well due to width behaving like min-width in IE6' ); - } else { - gt( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more)' ); - } - - // Clean up - $wrapper.remove(); -}); diff --git a/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js b/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js new file mode 100644 index 00000000..6e371384 --- /dev/null +++ b/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js @@ -0,0 +1,55 @@ +module( 'jquery.autoEllipsis', QUnit.newMwEnvironment() ); + +test( '-- Initial check', function() { + expect(1); + ok( $.fn.autoEllipsis, 'jQuery.fn.autoEllipsis defined' ); +}); + +function createWrappedDiv( text, width ) { + var $wrapper = $( '
    ' ).css( 'width', width ); + var $div = $( '
    ' ).text( text ); + $wrapper.append( $div ); + return $wrapper; +} + +function findDivergenceIndex( a, b ) { + var i = 0; + while ( i < a.length && i < b.length && a[i] == b[i] ) { + i++; + } + return i; +} + +test( 'Position right', function() { + expect(4); + + // We need this thing to be visible, so append it to the DOM + var origText = 'This is a really long random string and there is no way it fits in 100 pixels.'; + var $wrapper = createWrappedDiv( origText, '100px' ); + $( '#qunit-fixture' ).append( $wrapper ); + $wrapper.autoEllipsis( { position: 'right' } ); + + // Verify that, and only one, span element was created + var $span = $wrapper.find( '> span' ); + strictEqual( $span.length, 1, 'autoEllipsis wrapped the contents in a span element' ); + + // Check that the text fits by turning on word wrapping + $span.css( 'whiteSpace', 'nowrap' ); + ltOrEq( $span.width(), $span.parent().width(), "Text fits (making the span 'white-space:nowrap' does not make it wider than its parent)" ); + + // Add two characters using scary black magic + var spanText = $span.text(); + var d = findDivergenceIndex( origText, spanText ); + var spanTextNew = spanText.substr( 0, d ) + origText[d] + origText[d] + '...'; + + gt( spanTextNew.length, spanText.length, 'Verify that the new span-length is indeed greater' ); + + // Put this text in the span and verify it doesn't fit + $span.text( spanTextNew ); + // In IE6 width works like min-width, allow IE6's width to be "equal to" + if ( $.browser.msie && Number( $.browser.version ) === 6 ) { + gtOrEq( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more) - IE6: Maybe equal to as well due to width behaving like min-width in IE6' ); + } else { + gt( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more)' ); + } +}); diff --git a/tests/qunit/suites/resources/jquery/jquery.byteLength.js b/tests/qunit/suites/resources/jquery/jquery.byteLength.js deleted file mode 100644 index f82fda27..00000000 --- a/tests/qunit/suites/resources/jquery/jquery.byteLength.js +++ /dev/null @@ -1,42 +0,0 @@ -module( 'jquery.byteLength.js' ); - -test( '-- Initial check', function() { - expect(1); - ok( $.byteLength, 'jQuery.byteLength defined' ); -} ); - -test( 'Simple text', function() { - expect(5); - - var azLc = 'abcdefghijklmnopqrstuvwxyz', - azUc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', - num = '0123456789', - x = '*', - space = ' '; - - equal( $.byteLength( azLc ), 26, 'Lowercase a-z' ); - equal( $.byteLength( azUc ), 26, 'Uppercase A-Z' ); - equal( $.byteLength( num ), 10, 'Numbers 0-9' ); - equal( $.byteLength( x ), 1, 'An asterisk' ); - equal( $.byteLength( space ), 3, '3 spaces' ); - -} ); - -test( 'Special text', window.foo = function() { - expect(5); - - // http://en.wikipedia.org/wiki/UTF-8 - var U_0024 = '\u0024', - U_00A2 = '\u00A2', - U_20AC = '\u20AC', - U_024B62 = '\u024B62', - // The normal one doesn't display properly, try the below which is the same - // according to http://www.fileformat.info/info/unicode/char/24B62/index.htm - U_024B62_alt = '\uD852\uDF62'; - - strictEqual( $.byteLength( U_0024 ), 1, 'U+0024: 1 byte. \u0024 (dollar sign)' ); - strictEqual( $.byteLength( U_00A2 ), 2, 'U+00A2: 2 bytes. \u00A2 (cent sign)' ); - strictEqual( $.byteLength( U_20AC ), 3, 'U+20AC: 3 bytes. \u20AC (euro sign)' ); - strictEqual( $.byteLength( U_024B62 ), 4, 'U+024B62: 4 bytes. \uD852\uDF62 (a Han character)' ); - strictEqual( $.byteLength( U_024B62_alt ), 4, 'U+024B62: 4 bytes. \uD852\uDF62 (a Han character) - alternative method' ); -} ); diff --git a/tests/qunit/suites/resources/jquery/jquery.byteLength.test.js b/tests/qunit/suites/resources/jquery/jquery.byteLength.test.js new file mode 100644 index 00000000..15fac691 --- /dev/null +++ b/tests/qunit/suites/resources/jquery/jquery.byteLength.test.js @@ -0,0 +1,42 @@ +module( 'jquery.byteLength', QUnit.newMwEnvironment() ); + +test( '-- Initial check', function() { + expect(1); + ok( $.byteLength, 'jQuery.byteLength defined' ); +} ); + +test( 'Simple text', function() { + expect(5); + + var azLc = 'abcdefghijklmnopqrstuvwxyz', + azUc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', + num = '0123456789', + x = '*', + space = ' '; + + equal( $.byteLength( azLc ), 26, 'Lowercase a-z' ); + equal( $.byteLength( azUc ), 26, 'Uppercase A-Z' ); + equal( $.byteLength( num ), 10, 'Numbers 0-9' ); + equal( $.byteLength( x ), 1, 'An asterisk' ); + equal( $.byteLength( space ), 3, '3 spaces' ); + +} ); + +test( 'Special text', window.foo = function() { + expect(5); + + // http://en.wikipedia.org/wiki/UTF-8 + var U_0024 = '\u0024', + U_00A2 = '\u00A2', + U_20AC = '\u20AC', + U_024B62 = '\u024B62', + // The normal one doesn't display properly, try the below which is the same + // according to http://www.fileformat.info/info/unicode/char/24B62/index.htm + U_024B62_alt = '\uD852\uDF62'; + + strictEqual( $.byteLength( U_0024 ), 1, 'U+0024: 1 byte. \u0024 (dollar sign)' ); + strictEqual( $.byteLength( U_00A2 ), 2, 'U+00A2: 2 bytes. \u00A2 (cent sign)' ); + strictEqual( $.byteLength( U_20AC ), 3, 'U+20AC: 3 bytes. \u20AC (euro sign)' ); + strictEqual( $.byteLength( U_024B62 ), 4, 'U+024B62: 4 bytes. \uD852\uDF62 (a Han character)' ); + strictEqual( $.byteLength( U_024B62_alt ), 4, 'U+024B62: 4 bytes. \uD852\uDF62 (a Han character) - alternative method' ); +} ); diff --git a/tests/qunit/suites/resources/jquery/jquery.byteLimit.js b/tests/qunit/suites/resources/jquery/jquery.byteLimit.js deleted file mode 100644 index 461ea49b..00000000 --- a/tests/qunit/suites/resources/jquery/jquery.byteLimit.js +++ /dev/null @@ -1,155 +0,0 @@ -module( 'jquery.byteLimit.js' ); - -test( '-- Initial check', function() { - expect(1); - ok( $.fn.byteLimit, 'jQuery.fn.byteLimit defined' ); -} ); - -// Basic sendkey-implementation -$.addChars = function( $input, charstr ) { - var len = charstr.length; - for ( var i = 0; i < len; i++ ) { - // Keep track of the previous value - var prevVal = $input.val(); - - // Get the key code - var code = charstr.charCodeAt(i); - - // Trigger event and undo if prevented - var event = new jQuery.Event( 'keypress', { keyCode: code, which: code, charCode: code } ); - $input.trigger( event ); - if ( !event.isDefaultPrevented() ) { - $input.val( prevVal + charstr.charAt(i) ); - } - } -}; -var blti = 0; -/** - * Test factory for $.fn.byteLimit - * - * @param $input {jQuery} jQuery object in an input element - * @param useLimit {Boolean} Wether a limit should apply at all - * @param limit {Number} Limit (if used) otherwise undefined - * The limit should be less than 20 (the sample data's length) - */ -var byteLimitTest = function( options ) { - var opt = $.extend({ - description: '', - $input: null, - sample: '', - useLimit: false, - expected: 0, - limit: null - }, options); - var i = blti++; - - test( opt.description, function() { - - opt.$input.appendTo( 'body' ); - - // Simulate pressing keys for each of the sample characters - $.addChars( opt.$input, opt.sample ); - var newVal = opt.$input.val(); - - if ( opt.useLimit ) { - expect(2); - - ltOrEq( $.byteLength( newVal ), opt.limit, 'Prevent keypresses after byteLimit was reached, length never exceeded the limit' ); - equal( $.byteLength( newVal ), opt.expected, 'Not preventing keypresses too early, length has reached the expected length' ); - - } else { - expect(1); - equal( $.byteLength( newVal ), opt.expected, 'Unlimited scenarios are not affected, expected length reached' ); - } - - opt.$input.remove(); - } ); -}; - -var - // Simple sample (20 chars, 20 bytes) - simpleSample = '12345678901234567890', - - // 3 bytes (euro-symbol) - U_20AC = '\u20AC', - - // Multi-byte sample (22 chars, 26 bytes) - mbSample = '1234567890' + U_20AC + '1234567890' + U_20AC; - -byteLimitTest({ - description: 'Plain text input', - $input: $( '' ) - .attr( { - 'type': 'text' - }), - sample: simpleSample, - useLimit: false, - expected: $.byteLength( simpleSample ) -}); - -byteLimitTest({ - description: 'Limit using the maxlength attribute', - $input: $( '' ) - .attr( { - 'type': 'text', - 'maxlength': '10' - }) - .byteLimit(), - sample: simpleSample, - useLimit: true, - limit: 10, - expected: 10 -}); - -byteLimitTest({ - description: 'Limit using a custom value', - $input: $( '' ) - .attr( { - 'type': 'text' - }) - .byteLimit( 10 ), - sample: simpleSample, - useLimit: true, - limit: 10, - expected: 10 -}); - -byteLimitTest({ - description: 'Limit using a custom value, overriding maxlength attribute', - $input: $( '' ) - .attr( { - 'type': 'text', - 'maxLength': '10' - }) - .byteLimit( 15 ), - sample: simpleSample, - useLimit: true, - limit: 15, - expected: 15 -}); - -byteLimitTest({ - description: 'Limit using a custom value (multibyte)', - $input: $( '' ) - .attr( { - 'type': 'text' - }) - .byteLimit( 14 ), - sample: mbSample, - useLimit: true, - limit: 14, - expected: 14 // (10 x 1-byte char) + (1 x 3-byte char) + (1 x 1-byte char) -}); - -byteLimitTest({ - description: 'Limit using a custom value (multibyte) overlapping a byte', - $input: $( '' ) - .attr( { - 'type': 'text' - }) - .byteLimit( 12 ), - sample: mbSample, - useLimit: true, - limit: 12, - expected: 12 // 10 x 1-byte char. The next 3-byte char exceeds limit of 12, but 2 more 1-byte chars come in after. -}); diff --git a/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js b/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js new file mode 100644 index 00000000..3346c2d5 --- /dev/null +++ b/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js @@ -0,0 +1,187 @@ +( function () { + +module( 'jquery.byteLimit', QUnit.newMwEnvironment() ); + +test( '-- Initial check', function() { + expect(1); + ok( $.fn.byteLimit, 'jQuery.fn.byteLimit defined' ); +} ); + +// Basic sendkey-implementation +$.addChars = function( $input, charstr ) { + var len = charstr.length; + for ( var i = 0; i < len; i++ ) { + // Keep track of the previous value + var prevVal = $input.val(); + + // Get the key code + var code = charstr.charCodeAt(i); + + // Trigger event and undo if prevented + var event = new jQuery.Event( 'keypress', { keyCode: code, which: code, charCode: code } ); + $input.trigger( event ); + if ( !event.isDefaultPrevented() ) { + $input.val( prevVal + charstr.charAt(i) ); + } + } +}; + +/** + * Test factory for $.fn.byteLimit + * + * @param $input {jQuery} jQuery object in an input element + * @param hasLimit {Boolean} Wether a limit should apply at all + * @param limit {Number} Limit (if used) otherwise undefined + * The limit should be less than 20 (the sample data's length) + */ +var byteLimitTest = function( options ) { + var opt = $.extend({ + description: '', + $input: null, + sample: '', + hasLimit: false, + expected: '', + limit: null + }, options); + + test( opt.description, function() { + + opt.$input.appendTo( '#qunit-fixture' ); + + // Simulate pressing keys for each of the sample characters + $.addChars( opt.$input, opt.sample ); + var rawVal = opt.$input.val(), + fn = opt.$input.data( 'byteLimit-callback' ), + newVal = $.isFunction( fn ) ? fn( rawVal ) : rawVal; + + if ( opt.hasLimit ) { + expect(3); + + ltOrEq( $.byteLength( newVal ), opt.limit, 'Prevent keypresses after byteLimit was reached, length never exceeded the limit' ); + equal( $.byteLength( rawVal ), $.byteLength( opt.expected ), 'Not preventing keypresses too early, length has reached the expected length' ); + equal( rawVal, opt.expected, 'New value matches the expected string' ); + + } else { + expect(2); + equal( newVal, opt.expected, 'New value matches the expected string' ); + equal( $.byteLength( newVal ), $.byteLength( opt.expected ), 'Unlimited scenarios are not affected, expected length reached' ); + } + } ); +}; + +var + // Simple sample (20 chars, 20 bytes) + simpleSample = '12345678901234567890', + + // 3 bytes (euro-symbol) + U_20AC = '\u20AC', + + // Multi-byte sample (22 chars, 26 bytes) + mbSample = '1234567890' + U_20AC + '1234567890' + U_20AC; + +byteLimitTest({ + description: 'Plain text input', + $input: $( '' ) + .attr( 'type', 'text' ), + sample: simpleSample, + hasLimit: false, + expected: simpleSample +}); + +byteLimitTest({ + description: 'Limit using the maxlength attribute', + $input: $( '' ) + .attr( 'type', 'text' ) + .prop( 'maxLength', '10' ) + .byteLimit(), + sample: simpleSample, + hasLimit: true, + limit: 10, + expected: '1234567890' +}); + +byteLimitTest({ + description: 'Limit using a custom value', + $input: $( '' ) + .attr( 'type', 'text' ) + .byteLimit( 10 ), + sample: simpleSample, + hasLimit: true, + limit: 10, + expected: '1234567890' +}); + +byteLimitTest({ + description: 'Limit using a custom value, overriding maxlength attribute', + $input: $( '' ) + .attr( 'type', 'text' ) + .prop( 'maxLength', '10' ) + .byteLimit( 15 ), + sample: simpleSample, + hasLimit: true, + limit: 15, + expected: '123456789012345' +}); + +byteLimitTest({ + description: 'Limit using a custom value (multibyte)', + $input: $( '' ) + .attr( 'type', 'text' ) + .byteLimit( 14 ), + sample: mbSample, + hasLimit: true, + limit: 14, + expected: '1234567890' + U_20AC + '1' +}); + +byteLimitTest({ + description: 'Limit using a custom value (multibyte) overlapping a byte', + $input: $( '' ) + .attr( 'type', 'text' ) + .byteLimit( 12 ), + sample: mbSample, + hasLimit: true, + limit: 12, + expected: '1234567890' + '12' +}); + +byteLimitTest({ + description: 'Pass the limit and a callback as input filter', + $input: $( '' ) + .attr( 'type', 'text' ) + .byteLimit( 6, function( val ) { + // Invalid title + if ( val == '' ) { + return ''; + } + + // Return without namespace prefix + return new mw.Title( '' + val ).getMain(); + } ), + sample: 'User:Sample', + hasLimit: true, + limit: 6, // 'Sample' length + expected: 'User:Sample' +}); + +byteLimitTest({ + description: 'Limit using the maxlength attribute and pass a callback as input filter', + $input: $( '' ) + .attr( 'type', 'text' ) + .prop( 'maxLength', '6' ) + .byteLimit( function( val ) { + // Invalid title + if ( val === '' ) { + return ''; + } + + // Return without namespace prefix + return new mw.Title( '' + val ).getMain(); + } ), + sample: 'User:Sample', + hasLimit: true, + limit: 6, // 'Sample' length + expected: 'User:Sample' +}); + +}() ); \ No newline at end of file diff --git a/tests/qunit/suites/resources/jquery/jquery.client.js b/tests/qunit/suites/resources/jquery/jquery.client.js deleted file mode 100644 index 50df2928..00000000 --- a/tests/qunit/suites/resources/jquery/jquery.client.js +++ /dev/null @@ -1,205 +0,0 @@ -module( 'jquery.client.js' ); - -test( '-- Initial check', function() { - expect(1); - ok( jQuery.client, 'jQuery.client defined' ); -}); - -test( 'profile userAgent support', function() { - expect(8); - - // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value) - // Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/ - var uas = { - // Internet Explorer 6 - // Internet Explorer 7 - 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': { - title: 'Internet Explorer 7', - platform: 'Win32', - profile: { - "name": "msie", - "layout": "trident", - "layoutVersion": "unknown", - "platform": "win", - "version": "7.0", - "versionBase": "7", - "versionNumber": 7 - } - }, - // Internet Explorer 8 - // Internet Explorer 9 - // Internet Explorer 10 - // Firefox 2 - // Firefox 3.5 - 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': { - title: 'Firefox 3.5', - platform: 'MacIntel', - profile: { - "name": "firefox", - "layout": "gecko", - "layoutVersion": 20110420, - "platform": "mac", - "version": "3.5.19", - "versionBase": "3", - "versionNumber": 3.5 - } - }, - // Firefox 3.6 - 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': { - title: 'Firefox 3.6', - platform: 'Linux i686', - profile: { - "name": "firefox", - "layout": "gecko", - "layoutVersion": 20110422, - "platform": "linux", - "version": "3.6.17", - "versionBase": "3", - "versionNumber": 3.6 - } - }, - // Firefox 4 - 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': { - title: 'Firefox 4', - platform: 'Win32', - profile: { - "name": "firefox", - "layout": "gecko", - "layoutVersion": 20100101, - "platform": "win", - "version": "4.0.1", - "versionBase": "4", - "versionNumber": 4 - } - }, - // Firefox 5 - // Safari 3 - // Safari 4 - 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; nl-nl) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7': { - title: 'Safari 4', - platform: 'MacIntel', - profile: { - "name": "safari", - "layout": "webkit", - "layoutVersion": 531, - "platform": "mac", - "version": "4.0.5", - "versionBase": "4", - "versionNumber": 4 - } - }, - 'Mozilla/5.0 (Windows; U; Windows NT 6.0; cs-CZ) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7': { - title: 'Safari 4', - platform: 'Win32', - profile: { - "name": "safari", - "layout": "webkit", - "layoutVersion": 533, - "platform": "win", - "version": "4.0.5", - "versionBase": "4", - "versionNumber": 4 - } - }, - // Safari 5 - // Opera 10 - // Chrome 5 - // Chrome 6 - // Chrome 7 - // Chrome 8 - // Chrome 9 - // Chrome 10 - // Chrome 11 - // Chrome 12 - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30': { - title: 'Chrome 12', - platform: 'MacIntel', - profile: { - "name": "chrome", - "layout": "webkit", - "layoutVersion": 534, - "platform": "mac", - "version": "12.0.742.112", - "versionBase": "12", - "versionNumber": 12 - } - }, - 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': { - title: 'Chrome 12', - platform: 'Linux i686', - profile: { - "name": "chrome", - "layout": "webkit", - "layoutVersion": 534, - "platform": "linux", - "version": "12.0.742.68", - "versionBase": "12", - "versionNumber": 12 - } - } - }; - - // Generate a client profile object and compare recursively - var uaTest = function( rawUserAgent, data ) { - var ret = $.client.profile( { - userAgent: rawUserAgent, - platform: data.platform - } ); - deepEqual( ret, data.profile, 'Client profile support check for ' + data.title + ' (' + data.platform + '): ' + rawUserAgent ); - }; - - // Loop through and run tests - $.each( uas, uaTest ); -} ); - -test( 'profile return validation for current user agent', function() { - expect(7); - var p = $.client.profile(); - var unknownOrType = function( val, type, summary ) { - return ok( typeof val === type || val === 'unknown', summary ); - }; - - equal( typeof p, 'object', 'profile returns an object' ); - unknownOrType( p.layout, 'string', 'p.layout is a string (or "unknown")' ); - unknownOrType( p.layoutVersion, 'number', 'p.layoutVersion is a number (or "unknown")' ); - unknownOrType( p.platform, 'string', 'p.platform is a string (or "unknown")' ); - unknownOrType( p.version, 'string', 'p.version is a string (or "unknown")' ); - unknownOrType( p.versionBase, 'string', 'p.versionBase is a string (or "unknown")' ); - equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' ); -}); - -test( 'test', function() { - expect(1); - - // Example from WikiEditor - var testMap = { - 'ltr': { - 'msie': [['>=', 7]], - 'firefox': [['>=', 2]], - 'opera': [['>=', 9.6]], - 'safari': [['>=', 3]], - 'chrome': [['>=', 3]], - 'netscape': [['>=', 9]], - 'blackberry': false, - 'ipod': false, - 'iphone': false - }, - 'rtl': { - 'msie': [['>=', 8]], - 'firefox': [['>=', 2]], - 'opera': [['>=', 9.6]], - 'safari': [['>=', 3]], - 'chrome': [['>=', 3]], - 'netscape': [['>=', 9]], - 'blackberry': false, - 'ipod': false, - 'iphone': false - } - }; - // .test() uses eval, make sure no exceptions are thrown - // then do a basic return value type check - var testMatch = $.client.test( testMap ); - - equal( typeof testMatch, 'boolean', 'test returns a boolean value' ); - -}); diff --git a/tests/qunit/suites/resources/jquery/jquery.client.test.js b/tests/qunit/suites/resources/jquery/jquery.client.test.js new file mode 100644 index 00000000..7be41971 --- /dev/null +++ b/tests/qunit/suites/resources/jquery/jquery.client.test.js @@ -0,0 +1,309 @@ +module( 'jquery.client', QUnit.newMwEnvironment() ); + +test( '-- Initial check', function() { + expect(1); + ok( jQuery.client, 'jQuery.client defined' ); +}); + +/** Number of user-agent defined */ +var uacount = 0; + +var uas = (function() { + + // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value) + // Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/ + var uas = { + // Internet Explorer 6 + // Internet Explorer 7 + 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': { + title: 'Internet Explorer 7', + platform: 'Win32', + profile: { + "name": "msie", + "layout": "trident", + "layoutVersion": "unknown", + "platform": "win", + "version": "7.0", + "versionBase": "7", + "versionNumber": 7 + }, + wikiEditor: { + ltr: true, + rtl: false + } + }, + // Internet Explorer 8 + // Internet Explorer 9 + // Internet Explorer 10 + 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)': { + title: 'Internet Explorer 10', + platform: 'Win32', + profile: { + "name": "msie", + "layout": "trident", + "layoutVersion": "unknown", // should be able to report 6? + "platform": "win", + "version": "10.0", + "versionBase": "10", + "versionNumber": 10 + }, + wikiEditor: { + ltr: true, + rtl: true + } + }, + // Firefox 2 + // Firefox 3.5 + 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': { + title: 'Firefox 3.5', + platform: 'MacIntel', + profile: { + "name": "firefox", + "layout": "gecko", + "layoutVersion": 20110420, + "platform": "mac", + "version": "3.5.19", + "versionBase": "3", + "versionNumber": 3.5 + }, + wikiEditor: { + ltr: true, + rtl: true + } + }, + // Firefox 3.6 + 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': { + title: 'Firefox 3.6', + platform: 'Linux i686', + profile: { + "name": "firefox", + "layout": "gecko", + "layoutVersion": 20110422, + "platform": "linux", + "version": "3.6.17", + "versionBase": "3", + "versionNumber": 3.6 + }, + wikiEditor: { + ltr: true, + rtl: true + } + }, + // Firefox 4 + 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': { + title: 'Firefox 4', + platform: 'Win32', + profile: { + "name": "firefox", + "layout": "gecko", + "layoutVersion": 20100101, + "platform": "win", + "version": "4.0.1", + "versionBase": "4", + "versionNumber": 4 + }, + wikiEditor: { + ltr: true, + rtl: true + } + }, + // Firefox 10 nightly build + 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': { + title: 'Firefox 10 nightly', + platform: 'Linux', + profile: { + "name": "firefox", + "layout": "gecko", + "layoutVersion": 20111103, + "platform": "linux", + "version": "10.0a1", + "versionBase": "10", + "versionNumber": 10 + }, + wikiEditor: { + ltr: true, + rtl: true + } + }, + // Firefox 5 + // Safari 3 + // Safari 4 + 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; nl-nl) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7': { + title: 'Safari 4', + platform: 'MacIntel', + profile: { + "name": "safari", + "layout": "webkit", + "layoutVersion": 531, + "platform": "mac", + "version": "4.0.5", + "versionBase": "4", + "versionNumber": 4 + }, + wikiEditor: { + ltr: true, + rtl: true + } + }, + 'Mozilla/5.0 (Windows; U; Windows NT 6.0; cs-CZ) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7': { + title: 'Safari 4', + platform: 'Win32', + profile: { + "name": "safari", + "layout": "webkit", + "layoutVersion": 533, + "platform": "win", + "version": "4.0.5", + "versionBase": "4", + "versionNumber": 4 + }, + wikiEditor: { + ltr: true, + rtl: true + } + }, + // Safari 5 + // Opera 10 + // Chrome 5 + // Chrome 6 + // Chrome 7 + // Chrome 8 + // Chrome 9 + // Chrome 10 + // Chrome 11 + // Chrome 12 + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30': { + title: 'Chrome 12', + platform: 'MacIntel', + profile: { + "name": "chrome", + "layout": "webkit", + "layoutVersion": 534, + "platform": "mac", + "version": "12.0.742.112", + "versionBase": "12", + "versionNumber": 12 + }, + wikiEditor: { + ltr: true, + rtl: true + } + }, + 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': { + title: 'Chrome 12', + platform: 'Linux i686', + profile: { + "name": "chrome", + "layout": "webkit", + "layoutVersion": 534, + "platform": "linux", + "version": "12.0.742.68", + "versionBase": "12", + "versionNumber": 12 + }, + wikiEditor: { + ltr: true, + rtl: true + } + } + }; + $.each( uas, function() { uacount++ }); + return uas; +})(); + +test( 'profile userAgent support', function() { + expect(uacount); + + // Generate a client profile object and compare recursively + var uaTest = function( rawUserAgent, data ) { + var ret = $.client.profile( { + userAgent: rawUserAgent, + platform: data.platform + } ); + deepEqual( ret, data.profile, 'Client profile support check for ' + data.title + ' (' + data.platform + '): ' + rawUserAgent ); + }; + + // Loop through and run tests + $.each( uas, uaTest ); +} ); + +test( 'profile return validation for current user agent', function() { + expect(7); + var p = $.client.profile(); + var unknownOrType = function( val, type, summary ) { + return ok( typeof val === type || val === 'unknown', summary ); + }; + + equal( typeof p, 'object', 'profile returns an object' ); + unknownOrType( p.layout, 'string', 'p.layout is a string (or "unknown")' ); + unknownOrType( p.layoutVersion, 'number', 'p.layoutVersion is a number (or "unknown")' ); + unknownOrType( p.platform, 'string', 'p.platform is a string (or "unknown")' ); + unknownOrType( p.version, 'string', 'p.version is a string (or "unknown")' ); + unknownOrType( p.versionBase, 'string', 'p.versionBase is a string (or "unknown")' ); + equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' ); +}); + +// Example from WikiEditor +// Make sure to use raw numbers, a string like "7.0" would fail on a +// version 10 browser since in string comparaison "10" is before "7.0" :) +var testMap = { + 'ltr': { + 'msie': [['>=', 7.0]], + 'firefox': [['>=', 2]], + 'opera': [['>=', 9.6]], + 'safari': [['>=', 3]], + 'chrome': [['>=', 3]], + 'netscape': [['>=', 9]], + 'blackberry': false, + 'ipod': false, + 'iphone': false + }, + 'rtl': { + 'msie': [['>=', 8]], + 'firefox': [['>=', 2]], + 'opera': [['>=', 9.6]], + 'safari': [['>=', 3]], + 'chrome': [['>=', 3]], + 'netscape': [['>=', 9]], + 'blackberry': false, + 'ipod': false, + 'iphone': false + } +}; + +test( 'test', function() { + expect(1); + + // .test() uses eval, make sure no exceptions are thrown + // then do a basic return value type check + var testMatch = $.client.test( testMap ); + + equal( typeof testMatch, 'boolean', 'test returns a boolean value' ); + +}); + +test( 'User-agent matches against WikiEditor\'s compatibility map', function() { + expect( uacount * 2 ); // double since we test both LTR and RTL + + var $body = $( 'body' ), + bodyClasses = $body.attr( 'class' ); + + // Loop through and run tests + $.each( uas, function ( agent, data ) { + $.each( ['ltr', 'rtl'], function ( i, dir ) { + $body.removeClass( 'ltr rtl' ).addClass( dir ); + var profile = $.client.profile( { + userAgent: agent, + platform: data.platform + } ); + var testMatch = $.client.test( testMap, profile ); + $body.removeClass( dir ); + + equal( testMatch, data.wikiEditor[dir], 'testing comparison based on ' + dir + ', ' + agent ); + }); + }); + + // Restore body classes + $body.attr( 'class', bodyClasses ); +}); + diff --git a/tests/qunit/suites/resources/jquery/jquery.colorUtil.js b/tests/qunit/suites/resources/jquery/jquery.colorUtil.js deleted file mode 100644 index 93f12b82..00000000 --- a/tests/qunit/suites/resources/jquery/jquery.colorUtil.js +++ /dev/null @@ -1,71 +0,0 @@ -module( 'jquery.colorUtil.js' ); - -test( '-- Initial check', function() { - expect(1); - ok( $.colorUtil, '$.colorUtil defined' ); -}); - -test( 'getRGB', function() { - expect(18); - - strictEqual( $.colorUtil.getRGB(), undefined, 'No arguments' ); - strictEqual( $.colorUtil.getRGB( '' ), undefined, 'Empty string' ); - deepEqual( $.colorUtil.getRGB( [0, 100, 255] ), [0, 100, 255], 'Parse array of rgb values' ); - deepEqual( $.colorUtil.getRGB( 'rgb(0,100,255)' ), [0, 100, 255], 'Parse simple rgb string' ); - deepEqual( $.colorUtil.getRGB( 'rgb(0, 100, 255)' ), [0, 100, 255], 'Parse simple rgb string with spaces' ); - deepEqual( $.colorUtil.getRGB( 'rgb(0%,20%,40%)' ), [0, 51, 102], 'Parse rgb string with percentages' ); - deepEqual( $.colorUtil.getRGB( 'rgb(0%, 20%, 40%)' ), [0, 51, 102], 'Parse rgb string with percentages and spaces' ); - deepEqual( $.colorUtil.getRGB( '#f2ddee' ), [242, 221, 238], 'Hex string: 6 char lowercase' ); - deepEqual( $.colorUtil.getRGB( '#f2DDEE' ), [242, 221, 238], 'Hex string: 6 char uppercase' ); - deepEqual( $.colorUtil.getRGB( '#f2DdEe' ), [242, 221, 238], 'Hex string: 6 char mixed' ); - deepEqual( $.colorUtil.getRGB( '#eee' ), [238, 238, 238], 'Hex string: 3 char lowercase' ); - deepEqual( $.colorUtil.getRGB( '#EEE' ), [238, 238, 238], 'Hex string: 3 char uppercase' ); - deepEqual( $.colorUtil.getRGB( '#eEe' ), [238, 238, 238], 'Hex string: 3 char mixed' ); - deepEqual( $.colorUtil.getRGB( 'rgba(0, 0, 0, 0)' ), [255, 255, 255], 'Zero rgba for Safari 3; Transparent (whitespace)' ); - - // Perhaps this is a bug in colorUtil, but it is the current behaviour so, let's keep - // track of it, so we will know in case it would ever change. - strictEqual( $.colorUtil.getRGB( 'rgba(0,0,0,0)' ), undefined, 'Zero rgba without whitespace' ); - - deepEqual( $.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (lightGreen)' ); - deepEqual( $.colorUtil.getRGB( 'transparent' ), [255, 255, 255], 'Color names (transparent)' ); - strictEqual( $.colorUtil.getRGB( 'mediaWiki' ), undefined, 'Inexisting color name' ); -}); - -test( 'rgbToHsl', function() { - expect(1); - - var hsl = $.colorUtil.rgbToHsl( 144, 238, 144 ); - - // Cross-browser differences in decimals... - // Round to two decimals so they can be more reliably checked. - var dualDecimals = function(a,b){ - return Math.round(a*100)/100; - }; - // Re-create the rgbToHsl return array items, limited to two decimals. - var ret = [dualDecimals(hsl[0]), dualDecimals(hsl[1]), dualDecimals(hsl[2])]; - - deepEqual( ret, [0.33, 0.73, 0.75], 'rgb(144, 238, 144): hsl(0.33, 0.73, 0.75)' ); -}); - -test( 'hslToRgb', function() { - expect(1); - - var rgb = $.colorUtil.hslToRgb( 0.3, 0.7, 0.8 ); - - // Cross-browser differences in decimals... - // Re-create the hslToRgb return array items, rounded to whole numbers. - var ret = [Math.round(rgb[0]), Math.round(rgb[1]), Math.round(rgb[2])]; - - deepEqual( ret ,[183, 240, 168], 'hsl(0.3, 0.7, 0.8): rgb(183, 240, 168)' ); -}); - -test( 'getColorBrightness', function() { - expect(2); - - var a = $.colorUtil.getColorBrightness( 'red', +0.1 ); - equal( a, 'rgb(255,50,50)', 'Start with named color "red", brighten 10%' ); - - var b = $.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 ); - equal( b, 'rgb(118,29,29)', 'Start with rgb string "rgb(200,50,50)", darken 20%' ); -}); diff --git a/tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js b/tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js new file mode 100644 index 00000000..655ee564 --- /dev/null +++ b/tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js @@ -0,0 +1,71 @@ +module( 'jquery.colorUtil', QUnit.newMwEnvironment() ); + +test( '-- Initial check', function() { + expect(1); + ok( $.colorUtil, '$.colorUtil defined' ); +}); + +test( 'getRGB', function() { + expect(18); + + strictEqual( $.colorUtil.getRGB(), undefined, 'No arguments' ); + strictEqual( $.colorUtil.getRGB( '' ), undefined, 'Empty string' ); + deepEqual( $.colorUtil.getRGB( [0, 100, 255] ), [0, 100, 255], 'Parse array of rgb values' ); + deepEqual( $.colorUtil.getRGB( 'rgb(0,100,255)' ), [0, 100, 255], 'Parse simple rgb string' ); + deepEqual( $.colorUtil.getRGB( 'rgb(0, 100, 255)' ), [0, 100, 255], 'Parse simple rgb string with spaces' ); + deepEqual( $.colorUtil.getRGB( 'rgb(0%,20%,40%)' ), [0, 51, 102], 'Parse rgb string with percentages' ); + deepEqual( $.colorUtil.getRGB( 'rgb(0%, 20%, 40%)' ), [0, 51, 102], 'Parse rgb string with percentages and spaces' ); + deepEqual( $.colorUtil.getRGB( '#f2ddee' ), [242, 221, 238], 'Hex string: 6 char lowercase' ); + deepEqual( $.colorUtil.getRGB( '#f2DDEE' ), [242, 221, 238], 'Hex string: 6 char uppercase' ); + deepEqual( $.colorUtil.getRGB( '#f2DdEe' ), [242, 221, 238], 'Hex string: 6 char mixed' ); + deepEqual( $.colorUtil.getRGB( '#eee' ), [238, 238, 238], 'Hex string: 3 char lowercase' ); + deepEqual( $.colorUtil.getRGB( '#EEE' ), [238, 238, 238], 'Hex string: 3 char uppercase' ); + deepEqual( $.colorUtil.getRGB( '#eEe' ), [238, 238, 238], 'Hex string: 3 char mixed' ); + deepEqual( $.colorUtil.getRGB( 'rgba(0, 0, 0, 0)' ), [255, 255, 255], 'Zero rgba for Safari 3; Transparent (whitespace)' ); + + // Perhaps this is a bug in colorUtil, but it is the current behaviour so, let's keep + // track of it, so we will know in case it would ever change. + strictEqual( $.colorUtil.getRGB( 'rgba(0,0,0,0)' ), undefined, 'Zero rgba without whitespace' ); + + deepEqual( $.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (lightGreen)' ); + deepEqual( $.colorUtil.getRGB( 'transparent' ), [255, 255, 255], 'Color names (transparent)' ); + strictEqual( $.colorUtil.getRGB( 'mediaWiki' ), undefined, 'Inexisting color name' ); +}); + +test( 'rgbToHsl', function() { + expect(1); + + var hsl = $.colorUtil.rgbToHsl( 144, 238, 144 ); + + // Cross-browser differences in decimals... + // Round to two decimals so they can be more reliably checked. + var dualDecimals = function(a,b){ + return Math.round(a*100)/100; + }; + // Re-create the rgbToHsl return array items, limited to two decimals. + var ret = [dualDecimals(hsl[0]), dualDecimals(hsl[1]), dualDecimals(hsl[2])]; + + deepEqual( ret, [0.33, 0.73, 0.75], 'rgb(144, 238, 144): hsl(0.33, 0.73, 0.75)' ); +}); + +test( 'hslToRgb', function() { + expect(1); + + var rgb = $.colorUtil.hslToRgb( 0.3, 0.7, 0.8 ); + + // Cross-browser differences in decimals... + // Re-create the hslToRgb return array items, rounded to whole numbers. + var ret = [Math.round(rgb[0]), Math.round(rgb[1]), Math.round(rgb[2])]; + + deepEqual( ret ,[183, 240, 168], 'hsl(0.3, 0.7, 0.8): rgb(183, 240, 168)' ); +}); + +test( 'getColorBrightness', function() { + expect(2); + + var a = $.colorUtil.getColorBrightness( 'red', +0.1 ); + equal( a, 'rgb(255,50,50)', 'Start with named color "red", brighten 10%' ); + + var b = $.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 ); + equal( b, 'rgb(118,29,29)', 'Start with rgb string "rgb(200,50,50)", darken 20%' ); +}); diff --git a/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js b/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js index 8688f12e..6489a1f1 100644 --- a/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js @@ -1,5 +1,5 @@ test('jquery.delayedBind with data option', function() { - var $fixture = $('
    ').appendTo('body'), + var $fixture = $('
    ').appendTo('#qunit-fixture'), data = { magic: "beeswax" }, delay = 50; @@ -20,7 +20,7 @@ test('jquery.delayedBind with data option', function() { }); test('jquery.delayedBind without data option', function() { - var $fixture = $('
    ').appendTo('body'), + var $fixture = $('
    ').appendTo('#qunit-fixture'), data = { magic: "beeswax" }, delay = 50; diff --git a/tests/qunit/suites/resources/jquery/jquery.getAttrs.js b/tests/qunit/suites/resources/jquery/jquery.getAttrs.js deleted file mode 100644 index 3d3d01e1..00000000 --- a/tests/qunit/suites/resources/jquery/jquery.getAttrs.js +++ /dev/null @@ -1,17 +0,0 @@ -module( 'jquery.getAttrs.js' ); - -test( '-- Initial check', function() { - expect(1); - ok( $.fn.getAttrs, 'jQuery.fn.getAttrs defined' ); -} ); - -test( 'Check', function() { - expect(1); - var attrs = { - foo: 'bar', - 'class': 'lorem' - }, - $el = $( '
    ', attrs ); - - deepEqual( $el.getAttrs(), attrs, 'getAttrs() return object should match the attributes set, no more, no less' ); -} ); diff --git a/tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js b/tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js new file mode 100644 index 00000000..9377a2f6 --- /dev/null +++ b/tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js @@ -0,0 +1,17 @@ +module( 'jquery.getAttrs', QUnit.newMwEnvironment() ); + +test( '-- Initial check', function() { + expect(1); + ok( $.fn.getAttrs, 'jQuery.fn.getAttrs defined' ); +} ); + +test( 'Check', function() { + expect(1); + var attrs = { + foo: 'bar', + 'class': 'lorem' + }, + $el = $( '
    ', attrs ); + + deepEqual( $el.getAttrs(), attrs, 'getAttrs() return object should match the attributes set, no more, no less' ); +} ); diff --git a/tests/qunit/suites/resources/jquery/jquery.highlightText.test.js b/tests/qunit/suites/resources/jquery/jquery.highlightText.test.js new file mode 100644 index 00000000..4750d2b8 --- /dev/null +++ b/tests/qunit/suites/resources/jquery/jquery.highlightText.test.js @@ -0,0 +1,239 @@ +module( 'jquery.highlightText', QUnit.newMwEnvironment() ); + +test( '-- Initial check', function() { + expect(1); + ok( $.fn.highlightText, 'jQuery.fn.highlightText defined' ); +} ); + +test( 'Check', function() { + var cases = [ + { + desc: 'Test 001', + text: 'Blue Öyster Cult', + highlight: 'Blue', + expected: 'Blue Öyster Cult' + }, + { + desc: 'Test 002', + text: 'Blue Öyster Cult', + highlight: 'Blue ', + expected: 'Blue Öyster Cult' + }, + { + desc: 'Test 003', + text: 'Blue Öyster Cult', + highlight: 'Blue Ö', + expected: 'Blue Öyster Cult' + }, + { + desc: 'Test 004', + text: 'Blue Öyster Cult', + highlight: 'Blue Öy', + expected: 'Blue Öyster Cult' + }, + { + desc: 'Test 005', + text: 'Blue Öyster Cult', + highlight: ' Blue', + expected: 'Blue Öyster Cult' + }, + { + desc: 'Test 006', + text: 'Blue Öyster Cult', + highlight: ' Blue ', + expected: 'Blue Öyster Cult' + }, + { + desc: 'Test 007', + text: 'Blue Öyster Cult', + highlight: ' Blue Ö', + expected: 'Blue Öyster Cult' + }, + { + desc: 'Test 008', + text: 'Blue Öyster Cult', + highlight: ' Blue Öy', + expected: 'Blue Öyster Cult' + }, + { + desc: 'Test 009: Highlighter broken on starting Umlaut?', + text: 'Österreich', + highlight: 'Österreich', + expected: 'Österreich' + }, + { + desc: 'Test 010: Highlighter broken on starting Umlaut?', + text: 'Österreich', + highlight: 'Ö', + expected: 'Österreich' + }, + { + desc: 'Test 011: Highlighter broken on starting Umlaut?', + text: 'Österreich', + highlight: 'Öst', + expected: 'Österreich' + }, + { + desc: 'Test 012: Highlighter broken on starting Umlaut?', + text: 'Österreich', + highlight: 'Oe', + expected: 'Österreich' + }, + { + desc: 'Test 013: Highlighter broken on punctuation mark?', + text: 'So good. To be there', + highlight: 'good', + expected: 'So good. To be there' + }, + { + desc: 'Test 014: Highlighter broken on space?', + text: 'So good. To be there', + highlight: 'be', + expected: 'So good. To be there' + }, + { + desc: 'Test 015: Highlighter broken on space?', + text: 'So good. To be there', + highlight: ' be', + expected: 'So good. To be there' + }, + { + desc: 'Test 016: Highlighter broken on space?', + text: 'So good. To be there', + highlight: 'be ', + expected: 'So good. To be there' + }, + { + desc: 'Test 017: Highlighter broken on space?', + text: 'So good. To be there', + highlight: ' be ', + expected: 'So good. To be there' + }, + { + desc: 'Test 018: en de Highlighter broken on special character at the end?', + text: 'So good. xbß', + highlight: 'xbß', + expected: 'So good. xbß' + }, + { + desc: 'Test 019: en de Highlighter broken on special character at the end?', + text: 'So good. xbß.', + highlight: 'xbß.', + expected: 'So good. xbß.' + }, + { + desc: 'Test 020: RTL he Hebrew', + text: 'חסיד אומות העולם', + highlight: 'חסיד אומות העולם', + expected: 'חסיד אומות העולם' + }, + { + desc: 'Test 021: RTL he Hebrew', + text: 'חסיד אומות העולם', + highlight: 'חסי', + expected: 'חסיד אומות העולם' + }, + { + desc: 'Test 022: ja Japanese', + text: '諸国民の中の正義の人', + highlight: '諸国民の中の正義の人', + expected: '諸国民の中の正義の人' + }, + { + desc: 'Test 023: ja Japanese', + text: '諸国民の中の正義の人', + highlight: '諸国', + expected: '諸国民の中の正義の人' + }, + { + desc: 'Test 024: fr French text and « french quotes » (guillemets)', + text: "« L'oiseau est sur l’île »", + highlight: "« L'oiseau est sur l’île »", + expected: '« L\'oiseau est sur l’île »' + }, + { + desc: 'Test 025: fr French text and « french quotes » (guillemets)', + text: "« L'oiseau est sur l’île »", + highlight: "« L'oise", + expected: '« L\'oiseau est sur l’île »' + }, + { + desc: 'Test 025a: fr French text and « french quotes » (guillemets) - does it match the single strings "«" and "L" separately?', + text: "« L'oiseau est sur l’île »", + highlight: "« L", + expected: '« L\'oiseau est sur l’île »' + }, + { + desc: 'Test 026: ru Russian', + text: 'Праведники мира', + highlight: 'Праведники мира', + expected: 'Праведники мира' + }, + { + desc: 'Test 027: ru Russian', + text: 'Праведники мира', + highlight: 'Праве', + expected: 'Праведники мира' + }, + { + desc: 'Test 028 ka Georgian', + text: 'მთავარი გვერდი', + highlight: 'მთავარი გვერდი', + expected: 'მთავარი გვერდი' + }, + { + desc: 'Test 029 ka Georgian', + text: 'მთავარი გვერდი', + highlight: 'მთა', + expected: 'მთავარი გვერდი' + }, + { + desc: 'Test 030 hy Armenian', + text: 'Նոնա Գափրինդաշվիլի', + highlight: 'Նոնա Գափրինդաշվիլի', + expected: 'Նոնա Գափրինդաշվիլի' + }, + { + desc: 'Test 031 hy Armenian', + text: 'Նոնա Գափրինդաշվիլի', + highlight: 'Նոն', + expected: 'Նոնա Գափրինդաշվիլի' + }, + { + desc: 'Test 032: th Thai', + text: 'พอล แอร์ดิช', + highlight: 'พอล แอร์ดิช', + expected: 'พอล แอร์ดิช' + }, + { + desc: 'Test 033: th Thai', + text: 'พอล แอร์ดิช', + highlight: 'พอ', + expected: 'พอล แอร์ดิช' + }, + { + desc: 'Test 034: RTL ar Arabic', + text: 'بول إيردوس', + highlight: 'بول إيردوس', + expected: 'بول إيردوس' + }, + { + desc: 'Test 035: RTL ar Arabic', + text: 'بول إيردوس', + highlight: 'بو', + expected: 'بول إيردوس' + } + ]; + expect(cases.length); + var $fixture; + + $.each(cases, function( i, item ) { + $fixture = $( '

    ' ).text( item.text ); + $fixture.highlightText( item.highlight ); + equals( + $fixture.html(), + $('

    ' + item.expected + '

    ').html(), // re-parse to normalize! + item.desc || undefined + ); + } ); +} ); diff --git a/tests/qunit/suites/resources/jquery/jquery.localize.js b/tests/qunit/suites/resources/jquery/jquery.localize.js deleted file mode 100644 index 40b58687..00000000 --- a/tests/qunit/suites/resources/jquery/jquery.localize.js +++ /dev/null @@ -1,119 +0,0 @@ -module( 'jquery.localize.js' ); - -test( '-- Initial check', function() { - expect(1); - ok( $.fn.localize, 'jQuery.fn.localize defined' ); -} ); - -test( 'Handle basic replacements', function() { - expect(3); - - var html, $lc; - mw.messages.set( 'basic', 'Basic stuff' ); - - // Tag: html:msg - html = '
    '; - $lc = $( html ).localize().find( 'span' ); - - strictEqual( $lc.text(), 'Basic stuff', 'Tag: html:msg' ); - - // Attribute: title-msg - html = '
    '; - $lc = $( html ).localize().find( 'span' ); - - strictEqual( $lc.attr( 'title' ), 'Basic stuff', 'Attribute: title-msg' ); - - // Attribute: alt-msg - html = '
    '; - $lc = $( html ).localize().find( 'span' ); - - strictEqual( $lc.attr( 'alt' ), 'Basic stuff', 'Attribute: alt-msg' ); -} ); - -test( 'Proper escaping', function() { - expect(2); - - var html, $lc; - mw.messages.set( 'properfoo', '' ); - - // This is handled by jQuery inside $.fn.localize, just a simple sanity checked - // making sure it is actually using text() and attr() (or something with the same effect) - - // Text escaping - html = '
    '; - $lc = $( html ).localize().find( 'span' ); - - strictEqual( $lc.text(), mw.msg( 'properfoo' ), 'Content is inserted as text, not as html.' ); - - // Attribute escaping - html = '
    '; - $lc = $( html ).localize().find( 'span' ); - - strictEqual( $lc.attr( 'title' ), mw.msg( 'properfoo' ), 'Attributes are not inserted raw.' ); -} ); - -test( 'Options', function() { - expect(7); - - mw.messages.set( { - 'foo-lorem': 'Lorem', - 'foo-ipsum': 'Ipsum', - 'foo-bar-title': 'Read more about bars', - 'foo-bar-label': 'The Bars', - 'foo-bazz-title': 'Read more about bazz at $1 (last modified: $2)', - 'foo-bazz-label': 'The Bazz ($1)', - 'foo-welcome': 'Welcome to $1! (last visit: $2)' - } ); - var html, $lc, attrs, x, sitename = 'Wikipedia'; - - // Message key prefix - html = '
    '; - $lc = $( html ).localize( { - prefix: 'foo-' - } ).find( 'span' ); - - strictEqual( $lc.attr( 'title' ), 'Lorem', 'Message key prefix - attr' ); - strictEqual( $lc.text(), 'Ipsum', 'Message key prefix - text' ); - - // Variable keys mapping - x = 'bar'; - html = '
    '; - $lc = $( html ).localize( { - keys: { - 'title': 'foo-' + x + '-title', - 'label': 'foo-' + x + '-label' - } - } ).find( 'span' ); - - strictEqual( $lc.attr( 'title' ), 'Read more about bars', 'Variable keys mapping - attr' ); - strictEqual( $lc.text(), 'The Bars', 'Variable keys mapping - text' ); - - // Passing parameteters to mw.msg - html = '
    '; - $lc = $( html ).localize( { - params: { - 'foo-welcome': [sitename, 'yesterday'] - } - } ).find( 'span' ); - - strictEqual( $lc.text(), 'Welcome to Wikipedia! (last visit: yesterday)', 'Passing parameteters to mw.msg' ); - - // Combination of options prefix, params and keys - x = 'bazz'; - html = '
    '; - $lc = $( html ).localize( { - prefix: 'foo-', - keys: { - 'title': x + '-title', - 'label': x + '-label' - }, - params: { - 'title': [sitename, '3 minutes ago'], - 'label': [sitename, '3 minutes ago'] - - } - } ).find( 'span' ); - - strictEqual( $lc.text(), 'The Bazz (Wikipedia)', 'Combination of options prefix, params and keys - text' ); - strictEqual( $lc.attr( 'title' ), 'Read more about bazz at Wikipedia (last modified: 3 minutes ago)', 'Combination of options prefix, params and keys - attr' ); -} ); diff --git a/tests/qunit/suites/resources/jquery/jquery.localize.test.js b/tests/qunit/suites/resources/jquery/jquery.localize.test.js new file mode 100644 index 00000000..cd828634 --- /dev/null +++ b/tests/qunit/suites/resources/jquery/jquery.localize.test.js @@ -0,0 +1,119 @@ +module( 'jquery.localize', QUnit.newMwEnvironment() ); + +test( '-- Initial check', function() { + expect(1); + ok( $.fn.localize, 'jQuery.fn.localize defined' ); +} ); + +test( 'Handle basic replacements', function() { + expect(3); + + var html, $lc; + mw.messages.set( 'basic', 'Basic stuff' ); + + // Tag: html:msg + html = '
    '; + $lc = $( html ).localize().find( 'span' ); + + strictEqual( $lc.text(), 'Basic stuff', 'Tag: html:msg' ); + + // Attribute: title-msg + html = '
    '; + $lc = $( html ).localize().find( 'span' ); + + strictEqual( $lc.attr( 'title' ), 'Basic stuff', 'Attribute: title-msg' ); + + // Attribute: alt-msg + html = '
    '; + $lc = $( html ).localize().find( 'span' ); + + strictEqual( $lc.attr( 'alt' ), 'Basic stuff', 'Attribute: alt-msg' ); +} ); + +test( 'Proper escaping', function() { + expect(2); + + var html, $lc; + mw.messages.set( 'properfoo', '' ); + + // This is handled by jQuery inside $.fn.localize, just a simple sanity checked + // making sure it is actually using text() and attr() (or something with the same effect) + + // Text escaping + html = '
    '; + $lc = $( html ).localize().find( 'span' ); + + strictEqual( $lc.text(), mw.msg( 'properfoo' ), 'Content is inserted as text, not as html.' ); + + // Attribute escaping + html = '
    '; + $lc = $( html ).localize().find( 'span' ); + + strictEqual( $lc.attr( 'title' ), mw.msg( 'properfoo' ), 'Attributes are not inserted raw.' ); +} ); + +test( 'Options', function() { + expect(7); + + mw.messages.set( { + 'foo-lorem': 'Lorem', + 'foo-ipsum': 'Ipsum', + 'foo-bar-title': 'Read more about bars', + 'foo-bar-label': 'The Bars', + 'foo-bazz-title': 'Read more about bazz at $1 (last modified: $2)', + 'foo-bazz-label': 'The Bazz ($1)', + 'foo-welcome': 'Welcome to $1! (last visit: $2)' + } ); + var html, $lc, attrs, x, sitename = 'Wikipedia'; + + // Message key prefix + html = '
    '; + $lc = $( html ).localize( { + prefix: 'foo-' + } ).find( 'span' ); + + strictEqual( $lc.attr( 'title' ), 'Lorem', 'Message key prefix - attr' ); + strictEqual( $lc.text(), 'Ipsum', 'Message key prefix - text' ); + + // Variable keys mapping + x = 'bar'; + html = '
    '; + $lc = $( html ).localize( { + keys: { + 'title': 'foo-' + x + '-title', + 'label': 'foo-' + x + '-label' + } + } ).find( 'span' ); + + strictEqual( $lc.attr( 'title' ), 'Read more about bars', 'Variable keys mapping - attr' ); + strictEqual( $lc.text(), 'The Bars', 'Variable keys mapping - text' ); + + // Passing parameteters to mw.msg + html = '
    '; + $lc = $( html ).localize( { + params: { + 'foo-welcome': [sitename, 'yesterday'] + } + } ).find( 'span' ); + + strictEqual( $lc.text(), 'Welcome to Wikipedia! (last visit: yesterday)', 'Passing parameteters to mw.msg' ); + + // Combination of options prefix, params and keys + x = 'bazz'; + html = '
    '; + $lc = $( html ).localize( { + prefix: 'foo-', + keys: { + 'title': x + '-title', + 'label': x + '-label' + }, + params: { + 'title': [sitename, '3 minutes ago'], + 'label': [sitename, '3 minutes ago'] + + } + } ).find( 'span' ); + + strictEqual( $lc.text(), 'The Bazz (Wikipedia)', 'Combination of options prefix, params and keys - text' ); + strictEqual( $lc.attr( 'title' ), 'Read more about bazz at Wikipedia (last modified: 3 minutes ago)', 'Combination of options prefix, params and keys - attr' ); +} ); diff --git a/tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js b/tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js new file mode 100644 index 00000000..3a2d0d83 --- /dev/null +++ b/tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js @@ -0,0 +1,58 @@ +module( 'jquery.mwExtension', QUnit.newMwEnvironment() ); + +test( 'String functions', function() { + + equal( $.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' ); + equal( $.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' ); + equal( $.ucFirst( 'foo' ), 'Foo', 'ucFirst' ); + + equal( $.escapeRE( '