From: Krinkle Date: Wed, 13 Jul 2011 23:31:48 +0000 (+0000) Subject: Fix broken test introduced in r92113 for Gecko-browsers. X-Git-Tag: 1.31.0-rc.0~28853 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=5d91442df9ecb392ca08d39beef0c7fc1c76f5ab;p=lhc%2Fweb%2Fwiklou.git Fix broken test introduced in r92113 for Gecko-browsers. - Checking text() and attr() separately instead of comparing the resulting HTML (which was problematic due to browsers putting attributes in a different order) --- diff --git a/tests/qunit/suites/resources/jquery/jquery.localize.js b/tests/qunit/suites/resources/jquery/jquery.localize.js index 66b4a98ed3..52ae4672ca 100644 --- a/tests/qunit/suites/resources/jquery/jquery.localize.js +++ b/tests/qunit/suites/resources/jquery/jquery.localize.js @@ -8,66 +8,58 @@ test( '-- Initial check', function() { test( 'Handle basic replacements', function() { expect(4); - var html, $lc, expected; + var html, $lc; mw.messages.set( 'basic', 'Basic stuff' ); // Tag: html:msg - html = '
'; + html = ''; $lc = $( html ).localize(); - expected = 'Basic stuff'; - strictEqual( $lc.html(), expected, 'Tag: html:msg' ); + strictEqual( $lc.html(), 'Basic stuff', 'Tag: html:msg' ); // Tag: msg (deprecated) - html = '
'; + html = ''; $lc = $( html ).localize(); - expected = 'Basic stuff'; - strictEqual( $lc.html(), expected, 'Tag: msg' ); + strictEqual( $lc.html(), 'Basic stuff', 'Tag: msg' ); // Attribute: title-msg - html = '
'; - $lc = $( html ).localize(); - expected = ''; + html = '
'; + $lc = $( html ).localize().find( 'span' ); - strictEqual( $lc.html(), expected, 'Attribute: title-msg' ); + strictEqual( $lc.attr( 'title' ), 'Basic stuff', 'Attribute: title-msg' ); // Attribute: alt-msg - html = '
'; - $lc = $( html ).localize(); - expected = ''; + html = '
'; + $lc = $( html ).localize().find( 'span' ); - strictEqual( $lc.html(), expected, 'Attribute: alt-msg' ); + strictEqual( $lc.attr( 'alt' ), 'Basic stuff', 'Attribute: alt-msg' ); } ); test( 'Proper escaping', function() { expect(2); - var html, $lc, expected; + 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 = '
'; + html = ''; $lc = $( html ).localize(); - expected = '<proper esc="test">'; - strictEqual( $lc.html(), expected, 'Content is inserted as text, not as html.' ); + strictEqual( $lc.text(), mw.msg( 'properfoo' ), 'Content is inserted as text, not as html.' ); // Attribute escaping - html = '
'; - $lc = $( html ).localize(); - expected = ''; - - strictEqual( $lc.html(), expected, 'Attributes are not inserted raw.' ); - + html = '
'; + $lc = $( html ).localize().find( 'span' ); + strictEqual( $lc.attr( 'title' ), mw.msg( 'properfoo' ), 'Attributes are not inserted raw.' ); } ); test( 'Options', function() { - expect(4); + expect(7); mw.messages.set( { 'foo-lorem': 'Lorem', @@ -78,16 +70,16 @@ test( 'Options', function() { 'foo-bazz-label': 'The Bazz ($1)', 'foo-welcome': 'Welcome to $1! (last visit: $2)' } ); - var html, $lc, expected, x, sitename = 'Wikipedia'; + var html, $lc, attrs, x, sitename = 'Wikipedia'; // Message key prefix html = '
'; $lc = $( html ).localize( { prefix: 'foo-' - } ); - expected = 'Ipsum'; + } ).find( 'span' ); - strictEqual( $lc.html(), expected, 'Message key prefix' ); + strictEqual( $lc.attr( 'title' ), 'Lorem', 'Message key prefix - attr' ); + strictEqual( $lc.text(), 'Ipsum', 'Message key prefix - text' ); // Variable keys mapping x = 'bar'; @@ -97,21 +89,20 @@ test( 'Options', function() { 'title': 'foo-' + x + '-title', 'label': 'foo-' + x + '-label' } - } ); - expected = 'The Bars'; + } ).find( 'span' ); - strictEqual( $lc.html(), expected, 'Message prefix' ); + 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 = '
'; + html = ''; $lc = $( html ).localize( { params: { 'foo-welcome': [sitename, 'yesterday'] } } ); - expected = 'Welcome to Wikipedia! (last visit: yesterday)'; - strictEqual( $lc.html(), expected, 'Message prefix' ); + strictEqual( $lc.text(), 'Welcome to Wikipedia! (last visit: yesterday)', 'Passing parameteters to mw.msg' ); // Combination of options prefix, params and keys x = 'bazz'; @@ -127,8 +118,8 @@ test( 'Options', function() { 'label': [sitename, '3 minutes ago'] } - } ); - expected = 'The Bazz (Wikipedia)'; + } ).find( 'span' ); - strictEqual( $lc.html(), expected, 'Message prefix' ); + 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' ); } );