http://www.mediawiki.org/wiki/Special:Code/MediaWiki/82775
Revision: 82775
Author: neilk
Date: 2011-02-25 01:11:09 +0000 (Fri, 25 Feb 2011)
Log Message:
-----------
make tests compatible with IE7
Modified Paths:
--------------
trunk/extensions/UploadWizard/resources/language/mw.Parser.js
trunk/extensions/UploadWizard/test/jasmine/SpecRunner.html
trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.js
trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.parser2.spec.js
Added Paths:
-----------
trunk/extensions/UploadWizard/test/jasmine/makeLanguageSpec.php
trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.data.js
Modified: trunk/extensions/UploadWizard/resources/language/mw.Parser.js
===================================================================
--- trunk/extensions/UploadWizard/resources/language/mw.Parser.js
2011-02-25 00:57:27 UTC (rev 82774)
+++ trunk/extensions/UploadWizard/resources/language/mw.Parser.js
2011-02-25 01:11:09 UTC (rev 82775)
@@ -3,73 +3,96 @@
*/
// Setup swap string constants
-var JQUERY_SWAP_STRING = 'ZjQuerySwapZ';
+var JQUERY_SWAP_STRING = 'ZjQuerySwapZ';
var LINK_SWAP_STRING = 'ZreplaceZ';
-
+
( function( mw ) {
-
- // The parser magic global
+
+ // The parser magic global
var pMagicSet = { };
-
+
/**
- * addTemplateTransform to the parser
+ * addTemplateTransform to the parser
*
* Lets you add a set template key to be transformed by a callback
function
*
* @param {Object} magicSet key:callback
*/
mw.addTemplateTransform = function( magicSet ) {
- for ( var name in magicSet ) {
- pMagicSet[name] = magicSet[name];
+ for ( var i in magicSet ) {
+ pMagicSet[ i ] = magicSet[i];
}
};
/**
- * MediaWiki wikitext "Parser" constructor
+ * MediaWiki wikitext "Parser" constructor
*
* @param {String} wikiText the wikitext to be parsed
* @return {Object} parserObj returns a parser object that has methods
for getting at
* things you would want
- */
+ */
mw.Parser = function( wikiText, options) {
// return the parserObj
- this.init( wikiText, options ) ;
+ this.init( wikiText, options ) ;
+ return this;
};
-
+
mw.Parser.prototype = {
-
+
// the parser output string container
pOut: false,
-
+
init: function( wikiText, parserOptions ) {
- this.wikiText = wikiText;
- },
-
+ this.wikiText = wikiText;
+
+ var defaultParserOptions = {
+ 'templateParCount' : 2
+ };
+
+ this.options = $j.extend( defaultParserOptions,
parserOptions);
+ },
+
// Update the text value
updateText : function( wikiText ) {
this.wikiText = wikiText;
-
+
// invalidate the output ( will force a re-parse )
this.pOut = false;
},
-
+ // checks if the required number of parenthesis are found
+ // xxx this is just a stop gap solution
+ checkParlookAheadOpen: function(text, a){
+ if( this.options.templateParCount == 2 ){
+ return ( text[a] == '{' && text[a + 1] == '{' );
+ } else if( this.options.templateParCount == 3 ) {
+ return ( text[a] == '{' && text[a + 1] == '{'
&& text[a + 2] == '{');
+ }
+ },
+ checkParlookAheadClose: function( text, a){
+ if( this.options.templateParCount == 2 ){
+ return ( text[a] == '}' && text[a + 1] == '}' );
+ } else if( this.options.templateParCount == 3 ) {
+ return ( text[a] == '}' && text[a + 1] == '}'
&& text[a + 2] == '}');
+ }
+ },
/**
- * Quickly recursive / parse out templates:
+ * Quickly recursive / parse out templates:
*/
parse: function() {
+ var _this = this;
function recurseTokenizeNodes ( text ) {
var node = { };
// Inspect each char
for ( var a = 0; a < text.length; a++ ) {
- if ( text[a] == '{' && text[a + 1] ==
'{' ) {
- a = a + 2;
+ if ( _this.checkParlookAheadOpen( text,
a ) ) {
+ a = a +
_this.options.templateParCount;
node['parent'] = node;
if ( !node['child'] ) {
node['child'] = new
Array();
}
node['child'].push(
recurseTokenizeNodes( text.substr( a ) ) );
- } else if ( text[a] == '}' && text[a +
1] == '}' ) {
+ } else if (
_this.checkParlookAheadClose( text, a ) ) {
a++;
if ( !node['parent'] ) {
return node;
@@ -80,20 +103,20 @@
node['text'] = '';
}
// Don't put }} closures into output:
- if ( text[a] && text[a] != '}' ) {
+ if ( text[a] && text[a] != '}' ) {
node['text'] += text[a];
}
}
return node;
}
-
+
/**
* Parse template text as template name and named params
- * @param {String} templateString Template String to be
parsed
+ * @param {String} templateString Template String to be
parsed
*/
function parseTmplTxt( templateString ) {
var templateObject = { };
-
+
// Get template name:
templateName = templateString.split( '\|'
).shift() ;
templateName = templateName.split( '\{'
).shift() ;
@@ -106,15 +129,15 @@
templateObject["name"] =
templateName.split( ':' ).shift();
templateObject["arg"] =
templateName.split( ':' ).pop();
}
-
+
var paramSet = templateString.split( '\|' );
paramSet.splice( 0, 1 );
if ( paramSet.length ) {
templateObject.param = new Array();
- for ( var pInx = 0; pInx <
paramSet.length; pInx++ ) {
+ for ( var pInx =0; pInx <
paramSet.length; pInx++ ) {
var paramString = paramSet[
pInx ];
// check for empty param
- if ( paramString === '' ) {
+ if ( paramString == '' ) {
templateObject.param[
pInx ] = '';
continue;
}
@@ -128,10 +151,10 @@
}
}
}
- }
+ }
return templateObject;
}
-
+
/**
* Get the Magic text from a template node
*/
@@ -146,58 +169,58 @@
return node.text;
}
}
-
+
/**
* swap links of form [ ] for html a links or jquery
helper spans
* NOTE: this could be integrated into the tokenizer but
for now
* is a staged process.
*
- * @param text to swapped
+ * @param text to swapped
*/
function linkSwapText( text ) {
//mw.log( "linkSwapText::" + text );
var re = new RegExp( /\[([^\s]+[\s]+[^\]]*)\]/g
);
var matchSet = text.match( re );
-
+
if( !matchSet ){
return text;
- }
+ }
- text = text.replace( re , LINK_SWAP_STRING );
-
+ text = text.replace( re , LINK_SWAP_STRING );
+
for( var i=0; i < matchSet.length; i++ ) {
// Strip the leading [ and trailing ]
var matchParts = matchSet[i].substr(1,
matchSet[i].length-2);
-
- // Check for special jQuery type swap
and replace inner JQUERY_SWAP_STRING not value
- if( matchParts.indexOf(
JQUERY_SWAP_STRING ) !== -1 ) {
- // parse the link as html
- var $matchParts = $j('<span>' +
matchParts + '</span>' );
-
+
+ // Check for special jQuery type swap
and replace inner JQUERY_SWAP_STRING not value
+ if( matchParts.indexOf(
JQUERY_SWAP_STRING ) !== -1 ) {
+ // parse the link as html
+ var $matchParts = $j('<span>' +
matchParts + '</span>' );
+
$jQuerySpan =
$matchParts.find('#' +JQUERY_SWAP_STRING + i );
-
+
var linkText =
$matchParts.text();
//mw.log(" going to swap in
linktext: " + linkText );
$jQuerySpan.text( linkText );
-
+
text = text.replace(
LINK_SWAP_STRING, $j('<span />' ).append( $jQuerySpan ).html() );
- } else {
- // do text string replace
- matchParts = matchParts.split(/
/);
- var link = matchParts[0];
- matchParts.shift();
- var linkText =
matchParts.join(' ');
-
- text = text.replace(
LINK_SWAP_STRING, '<a href="' + link + '">' + linkText + '</a>' );
+ } else {
+ // do text string replace
+ matchParts = matchParts.split(/
/);
+ var link = matchParts[0];
+ matchParts.shift();
+ var linkText =
matchParts.join(' ');
+
+ text = text.replace(
LINK_SWAP_STRING, '<a href="' + link + '">' + linkText + '</a>' );
}
}
return text;
}
-
+
/**
* recurse_magic_swap
*
- * Go last child first swap upward:
+ * Go last child first swap upward:
*/
var pNode = null;
function recurse_magic_swap( node ) {
@@ -206,41 +229,41 @@
if ( node['child'] ) {
// swap all the kids:
- for ( var i = 0; i <
node['child'].length; i++ ) {
+ for ( var i in node['child'] ) {
var nodeText =
recurse_magic_swap( node['child'][i] );
// swap it into current
if ( node.text ) {
node.text =
node.text.replace( node['child'][i].text, nodeText );
}
// swap into parent
- pNode.text =
pNode.text.replace( node['child'][i].text, nodeText );
+ pNode.text =
pNode.text.replace( node['child'][i].text, nodeText );
}
// Get the updated node text
var nodeText = getMagicTxtFromTempNode(
node );
pNode.text = pNode.text.replace(
node.text , nodeText );
// return the node text
return node.text;
- } else {
+ } else {
return getMagicTxtFromTempNode( node );
}
}
-
+
// Parse out the template node structure:
this.pNode = recurseTokenizeNodes ( this.wikiText );
-
- // Strip out the parent from the root
+
+ // Strip out the parent from the root
this.pNode['parent'] = null;
-
+
// Do the recursive magic swap text:
this.pOut = recurse_magic_swap( this.pNode );
-
- // Do link swap
- this.pOut = linkSwapText( this.pOut );
+
+ // Do link swap
+ this.pOut = linkSwapText( this.pOut );
},
-
+
/**
* templates
- *
+ *
* Get a requested template from the wikitext (if available)
* @param templateName
*/
@@ -249,7 +272,7 @@
var tmplSet = new Array();
function getMatchingTmpl( node ) {
if ( node['child'] ) {
- for ( var i = 0; i <
node['child'].length; i++ ) {
+ for ( var i in node['child'] ) {
getMatchingTmpl( node['child']
);
}
}
@@ -263,53 +286,53 @@
getMatchingTmpl( this.pNode );
return tmplSet;
},
-
+
/**
* getTemplateVars
* returns a set of template values in a given wikitext page
- *
+ *
* NOTE: should be integrated with the usability wikitext parser
*/
getTemplateVars: function() {
//mw.log('matching against: ' + wikiText);
templateVars = new Array();
var tempVars = wikiText.match(/\{\{\{([^\}]*)\}\}\}/gi);
-
+
// Clean up results:
for(var i=0; i < tempVars.length; i++) {
- //match
+ //match
var tvar =
tempVars[i].replace('{{{','').replace('}}}','');
-
+
// Strip anything after a |
if(tvar.indexOf('|') != -1) {
tvar = tvar.substr(0,
tvar.indexOf('|'));
}
-
+
// Check for duplicates:
var do_add=true;
for(var j=0; j < templateVars.length; j++) {
if( templateVars[j] == tvar)
do_add=false;
}
-
+
// Add the template vars to the output obj
if(do_add)
templateVars.push( tvar );
}
return templateVars;
},
-
+
/**
* Returns the transformed wikitext
- *
- * Build output from swappable index
- * (all transforms must be expanded in parse stage
and linearly rebuilt)
- * Alternatively we could build output using a place-holder &
replace system
+ *
+ * Build output from swappable index
+ * (all transforms must be expanded in parse stage
and linearly rebuilt)
+ * Alternatively we could build output using a place-holder &
replace system
* (this lets us be slightly more sloppy with
ordering and indexes, but probably slower)
- *
- * Ideal: we build a 'wiki DOM'
+ *
+ * Ideal: we build a 'wiki DOM'
* When editing you update the data structure
directly
- * Then in output time you just go DOM->html-ish
output without re-parsing anything
+ * Then in output time you just go DOM->html-ish
output without re-parsing anything
*/
getHTML: function() {
// wikiText updates should invalidate pOut
@@ -319,5 +342,5 @@
return this.pOut;
}
};
-
-}) ( window.mediaWiki );
+
+}) ( window.mw );
\ No newline at end of file
Modified: trunk/extensions/UploadWizard/test/jasmine/SpecRunner.html
===================================================================
--- trunk/extensions/UploadWizard/test/jasmine/SpecRunner.html 2011-02-25
00:57:27 UTC (rev 82774)
+++ trunk/extensions/UploadWizard/test/jasmine/SpecRunner.html 2011-02-25
01:11:09 UTC (rev 82775)
@@ -10,20 +10,25 @@
<script type="text/javascript"
src="/w/load.php?debug=true&lang=en&modules=jquery%7Cmediawiki&only=scripts&skin=vector"></script>
<script type="text/javascript"
src="lib/appendto-jquery-mockjax/jquery.mockjax.js"></script>
- <script type="text/javascript" src="../../resources/mw.js"></script>
+ <script type="text/javascript"
src="../../../../resources/mediawiki/mediawiki.js"></script>
+ <script type="text/javascript"
src="../../../../resources/mediawiki.language/mediawiki.language.js"></script>
+ <script type="text/javascript"
src="../../../../resources/mediawiki.language/mediawiki.language.parser.js"></script>
+ <script type="text/javascript"
src="../../../../resources/jquery/jquery.mwMessage.js"></script>
<script type="text/javascript"
src="../../resources/mw.Utilities.js"></script>
<script type="text/javascript" src="../../resources/mw.Uri.js"></script>
<script type="text/javascript" src="../../resources/mw.Api.js"></script>
<script type="text/javascript" src="../../resources/mw.Api.edit.js"></script>
- <script type="text/javascript"
src="../../resources/language/mw.Language.js"></script>
- <script type="text/javascript"
src="../../resources/language/mw.Parser.js"></script>
<script type="text/javascript" src="../../resources/mw.Title.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="spec/mw.Uri.spec.js"></script>
<script type="text/javascript" src="spec/mw.Api.spec.js"></script>
<script type="text/javascript" src="spec/mw.Api.edit.spec.js"></script>
- <!-- script type="text/javascript" src="spec/mw.Language.spec.js"></script>
-->
+
+ <script type="text/javascript"
src="spec/mediawiki.language.parser.spec.data.js"></script>
+ <script type="text/javascript"
src="spec/mediawiki.language.parser.spec.js"></script>
+
+ <script type="text/javascript" src="spec/jquery.mwMessage.spec.js"></script>
<script type="text/javascript" src="spec/mw.Title.spec.js"></script>
</head>
Added: trunk/extensions/UploadWizard/test/jasmine/makeLanguageSpec.php
===================================================================
--- trunk/extensions/UploadWizard/test/jasmine/makeLanguageSpec.php
(rev 0)
+++ trunk/extensions/UploadWizard/test/jasmine/makeLanguageSpec.php
2011-02-25 01:11:09 UTC (rev 82775)
@@ -0,0 +1,113 @@
+<?php
+
+/**
+ * This PHP script defines the spec that the Javascript message parser should
conform to.
+ *
+ * It does this by looking up the results of various string kinds of string
parsing, with various languages,
+ * in the current installation of MediaWiki. It then outputs a static
specification, mapping expected inputs to outputs,
+ * which can be used with the JasmineBDD framework. This specification can
then be used by simply including it into
+ * the SpecRunner.html file.
+ *
+ * This is similar to Michael Dale ([email protected])'s parser tests,
except that it doesn't look up the
+ * API results while doing the test, so the Jasmine run is much faster (at the
cost of being out of date in rare
+ * circumstances. But mostly the parsing that we are doing in Javascript
doesn't change much.)
+ *
+ */
+
+$maintenanceDir = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) )
) ) . '/maintenance';
+
+require( "$maintenanceDir/Maintenance.php" );
+
+class MakeLanguageSpec extends Maintenance {
+
+ static $keyToTestArgs = array(
+ 'undelete_short' => array(
+ array( 0 ),
+ array( 1 ),
+ array( 2 ),
+ array( 5 ),
+ array( 21 ),
+ array( 101 )
+ ),
+ 'category-subcat-count' => array(
+ array( 0, 10 ),
+ array( 1, 1 ),
+ array( 1, 2 ),
+ array( 3, 30 )
+ )
+ );
+
+ public function __construct() {
+ parent::__construct();
+ $this->mDescription = "Create a JasmineBDD-compatible
specification for message parsing";
+ // add any other options here
+ }
+
+ public function execute() {
+ list( $messages, $tests ) = $this->getMessagesAndTests();
+ $this->writeJavascriptFile( $messages, $tests,
"spec/mediawiki.language.parser.spec.data.js" );
+ }
+
+ private function getMessagesAndTests() {
+ $messages = array();
+ $tests = array();
+ $wfMsgExtOptions = array( 'parsemag' );
+ foreach ( array( 'en', 'fr', 'ar', 'jp', 'zh' ) as
$languageCode ) {
+ $wfMsgExtOptions['language'] = $languageCode;
+ foreach ( self::$keyToTestArgs as $key => $testArgs ) {
+ foreach ($testArgs as $args) {
+ // get the raw template, without any
transformations
+ $template = wfMsgGetKey( $key, /* useDb
*/ true, $languageCode, /* transform */ false );
+
+ // get the magic-parsed version with
args
+ $wfMsgExtArgs = array_merge( array(
$key, $wfMsgExtOptions ), $args );
+ $result = call_user_func_array(
'wfMsgExt', $wfMsgExtArgs );
+
+ // record the template, args, language,
and expected result
+ // fake multiple languages by
flattening them together
+ $langKey = $languageCode . '_' . $key;
+ $messages[ $langKey ] = $template;
+ $tests[] = array(
+ 'name' => $languageCode . " " .
$key . " " . join( ",", $args ),
+ 'key' => $langKey,
+ 'args' => $args,
+ 'result' => $result,
+ 'lang' => $languageCode
+ );
+ }
+ }
+ }
+ return array( $messages, $tests );
+ }
+
+ private function writeJavascriptFile( $messages, $tests, $dataSpecFile
) {
+ global $argv;
+ $arguments = count($argv) ? $argv : $_SERVER[ 'argv' ];
+
+ $json = new Services_JSON;
+ $json->pretty = true;
+ $javascriptPrologue = "// This file stores the results from the
PHP parser for certain messages and arguments,\n"
+ . "// so we can test the equivalent
Javascript libraries.\n"
+ . '// Last generated with ' . join(' ',
$arguments) . ' at ' . gmdate('c') . "\n\n";
+ $javascriptMessages = "mediaWiki.messages.set( " .
$json->encode( $messages, true ) . " );\n";
+ $javascriptTests = 'var jasmineMsgSpec = ' . $json->encode(
$tests, true ) . ";\n";
+
+ $fp = fopen( $dataSpecFile, 'w' );
+ if ( !$fp ) {
+ die( "couldn't open $dataSpecFile for writing" );
+ }
+ $success = fwrite( $fp, $javascriptPrologue .
$javascriptMessages . $javascriptTests );
+ if ( !$success ) {
+ die( "couldn't write to $dataSpecFile" );
+ }
+ $success = fclose( $fp );
+ if ( !$success ) {
+ die( "couldn't close $dataSpecFile" );
+ }
+ }
+}
+
+$maintClass = "MakeLanguageSpec";
+require_once( "$maintenanceDir/doMaintenance.php" );
+
+
Property changes on:
trunk/extensions/UploadWizard/test/jasmine/makeLanguageSpec.php
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ native
Added:
trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.data.js
===================================================================
---
trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.data.js
(rev 0)
+++
trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.data.js
2011-02-25 01:11:09 UTC (rev 82775)
@@ -0,0 +1,488 @@
+// This file stores the results from the PHP parser for certain messages and
arguments,
+// so we can test the equivalent Javascript libraries.
+// Last generated with makeLanguageSpec.php at 2011-01-28T02:04:09+00:00
+
+mediaWiki.messages.set( {
+ "en_undelete_short": "Undelete {{PLURAL:$1|one edit|$1 edits}}",
+ "en_category-subcat-count": "{{PLURAL:$2|This category has only the
following subcategory.|This category has the following
{{PLURAL:$1|subcategory|$1 subcategories}}, out of $2 total.}}",
+ "fr_undelete_short": "Restaurer $1 modification{{PLURAL:$1||s}}",
+ "fr_category-subcat-count": "Cette cat\u00e9gorie comprend
{{PLURAL:$2|la sous-cat\u00e9gorie|$2 sous-cat\u00e9gories, dont
{{PLURAL:$1|celle|les $1}}}} ci-dessous.",
+ "ar_undelete_short": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639
{{PLURAL:$1|\u062a\u0639\u062f\u064a\u0644
\u0648\u0627\u062d\u062f|\u062a\u0639\u062f\u064a\u0644\u064a\u0646|$1
\u062a\u0639\u062f\u064a\u0644\u0627\u062a|$1 \u062a\u0639\u062f\u064a\u0644|$1
\u062a\u0639\u062f\u064a\u0644\u0627}}",
+ "ar_category-subcat-count": "{{PLURAL:$2|\u0644\u0627
\u062a\u0635\u0627\u0646\u064a\u0641 \u0641\u0631\u0639\u064a\u0629
\u0641\u064a \u0647\u0630\u0627
\u0627\u0644\u062a\u0635\u0646\u064a\u0641|\u0647\u0630\u0627
\u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647
\u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a
\u0627\u0644\u062a\u0627\u0644\u064a \u0641\u0642\u0637.|\u0647\u0630\u0627
\u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647
{{PLURAL:$1||\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641
\u0627\u0644\u0641\u0631\u0639\u064a|\u0647\u0630\u064a\u0646
\u0627\u0644\u062a\u0635\u0646\u064a\u0641\u064a\u0646
\u0627\u0644\u0641\u0631\u0639\u064a\u064a\u0646|\u0647\u0630\u0647
\u0627\u0644$1 \u062a\u0635\u0627\u0646\u064a\u0641
\u0627\u0644\u0641\u0631\u0639\u064a\u0629|\u0647\u0630\u0647 \u0627\u0644$1
\u062a\u0635\u0646\u064a\u0641\u0627
\u0641\u0631\u0639\u064a\u0627|\u0647\u0630\u0647 \u0627\u0644$1
\u062a\u0635\u0646\u064a\u0641 \u0641\u0631\u0639\u064a}}\u060c \u0645\u0646
\u0625\u062c\u0645\u0627\u0644\u064a $2.}}",
+ "jp_undelete_short": "Undelete {{PLURAL:$1|one edit|$1 edits}}",
+ "jp_category-subcat-count": "{{PLURAL:$2|This category has only the
following subcategory.|This category has the following
{{PLURAL:$1|subcategory|$1 subcategories}}, out of $2 total.}}",
+ "zh_undelete_short":
"\u6062\u590d\u88ab\u5220\u9664\u7684$1\u9879\u4fee\u8ba2",
+ "zh_category-subcat-count":
"{{PLURAL:$2|\u672c\u5206\u7c7b\u53ea\u6709\u4e0b\u5217\u4e00\u4e2a\u5b50\u5206\u7c7b\u3002|\u672c\u5206\u7c7b\u5305\u542b\u4e0b\u5217$1\u4e2a\u5b50\u5206\u7c7b\uff0c\u5171\u6709$2\u4e2a\u5b50\u5206\u7c7b\u3002}}"
+} );
+var jasmineMsgSpec = [
+ {
+ "name": "en undelete_short 0",
+ "key": "en_undelete_short",
+ "args": [
+ 0
+ ],
+ "result": "Undelete 0 edits",
+ "lang": "en"
+ },
+ {
+ "name": "en undelete_short 1",
+ "key": "en_undelete_short",
+ "args": [
+ 1
+ ],
+ "result": "Undelete one edit",
+ "lang": "en"
+ },
+ {
+ "name": "en undelete_short 2",
+ "key": "en_undelete_short",
+ "args": [
+ 2
+ ],
+ "result": "Undelete 2 edits",
+ "lang": "en"
+ },
+ {
+ "name": "en undelete_short 5",
+ "key": "en_undelete_short",
+ "args": [
+ 5
+ ],
+ "result": "Undelete 5 edits",
+ "lang": "en"
+ },
+ {
+ "name": "en undelete_short 21",
+ "key": "en_undelete_short",
+ "args": [
+ 21
+ ],
+ "result": "Undelete 21 edits",
+ "lang": "en"
+ },
+ {
+ "name": "en undelete_short 101",
+ "key": "en_undelete_short",
+ "args": [
+ 101
+ ],
+ "result": "Undelete 101 edits",
+ "lang": "en"
+ },
+ {
+ "name": "en category-subcat-count 0,10",
+ "key": "en_category-subcat-count",
+ "args": [
+ 0,
+ 10
+ ],
+ "result": "This category has the following 0 subcategories, out
of 10 total.",
+ "lang": "en"
+ },
+ {
+ "name": "en category-subcat-count 1,1",
+ "key": "en_category-subcat-count",
+ "args": [
+ 1,
+ 1
+ ],
+ "result": "This category has only the following subcategory.",
+ "lang": "en"
+ },
+ {
+ "name": "en category-subcat-count 1,2",
+ "key": "en_category-subcat-count",
+ "args": [
+ 1,
+ 2
+ ],
+ "result": "This category has the following subcategory, out of
2 total.",
+ "lang": "en"
+ },
+ {
+ "name": "en category-subcat-count 3,30",
+ "key": "en_category-subcat-count",
+ "args": [
+ 3,
+ 30
+ ],
+ "result": "This category has the following 3 subcategories, out
of 30 total.",
+ "lang": "en"
+ },
+ {
+ "name": "fr undelete_short 0",
+ "key": "fr_undelete_short",
+ "args": [
+ 0
+ ],
+ "result": "Restaurer 0 modification",
+ "lang": "fr"
+ },
+ {
+ "name": "fr undelete_short 1",
+ "key": "fr_undelete_short",
+ "args": [
+ 1
+ ],
+ "result": "Restaurer 1 modification",
+ "lang": "fr"
+ },
+ {
+ "name": "fr undelete_short 2",
+ "key": "fr_undelete_short",
+ "args": [
+ 2
+ ],
+ "result": "Restaurer 2 modifications",
+ "lang": "fr"
+ },
+ {
+ "name": "fr undelete_short 5",
+ "key": "fr_undelete_short",
+ "args": [
+ 5
+ ],
+ "result": "Restaurer 5 modifications",
+ "lang": "fr"
+ },
+ {
+ "name": "fr undelete_short 21",
+ "key": "fr_undelete_short",
+ "args": [
+ 21
+ ],
+ "result": "Restaurer 21 modifications",
+ "lang": "fr"
+ },
+ {
+ "name": "fr undelete_short 101",
+ "key": "fr_undelete_short",
+ "args": [
+ 101
+ ],
+ "result": "Restaurer 101 modifications",
+ "lang": "fr"
+ },
+ {
+ "name": "fr category-subcat-count 0,10",
+ "key": "fr_category-subcat-count",
+ "args": [
+ 0,
+ 10
+ ],
+ "result": "Cette cat\u00e9gorie comprend 10
sous-cat\u00e9gories, dont celle ci-dessous.",
+ "lang": "fr"
+ },
+ {
+ "name": "fr category-subcat-count 1,1",
+ "key": "fr_category-subcat-count",
+ "args": [
+ 1,
+ 1
+ ],
+ "result": "Cette cat\u00e9gorie comprend la sous-cat\u00e9gorie
ci-dessous.",
+ "lang": "fr"
+ },
+ {
+ "name": "fr category-subcat-count 1,2",
+ "key": "fr_category-subcat-count",
+ "args": [
+ 1,
+ 2
+ ],
+ "result": "Cette cat\u00e9gorie comprend 2
sous-cat\u00e9gories, dont celle ci-dessous.",
+ "lang": "fr"
+ },
+ {
+ "name": "fr category-subcat-count 3,30",
+ "key": "fr_category-subcat-count",
+ "args": [
+ 3,
+ 30
+ ],
+ "result": "Cette cat\u00e9gorie comprend 30
sous-cat\u00e9gories, dont les 3 ci-dessous.",
+ "lang": "fr"
+ },
+ {
+ "name": "ar undelete_short 0",
+ "key": "ar_undelete_short",
+ "args": [
+ 0
+ ],
+ "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639
\u062a\u0639\u062f\u064a\u0644 \u0648\u0627\u062d\u062f",
+ "lang": "ar"
+ },
+ {
+ "name": "ar undelete_short 1",
+ "key": "ar_undelete_short",
+ "args": [
+ 1
+ ],
+ "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639
\u062a\u0639\u062f\u064a\u0644\u064a\u0646",
+ "lang": "ar"
+ },
+ {
+ "name": "ar undelete_short 2",
+ "key": "ar_undelete_short",
+ "args": [
+ 2
+ ],
+ "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 2
\u062a\u0639\u062f\u064a\u0644\u0627\u062a",
+ "lang": "ar"
+ },
+ {
+ "name": "ar undelete_short 5",
+ "key": "ar_undelete_short",
+ "args": [
+ 5
+ ],
+ "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 5
\u062a\u0639\u062f\u064a\u0644",
+ "lang": "ar"
+ },
+ {
+ "name": "ar undelete_short 21",
+ "key": "ar_undelete_short",
+ "args": [
+ 21
+ ],
+ "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 21
\u062a\u0639\u062f\u064a\u0644\u0627",
+ "lang": "ar"
+ },
+ {
+ "name": "ar undelete_short 101",
+ "key": "ar_undelete_short",
+ "args": [
+ 101
+ ],
+ "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 101
\u062a\u0639\u062f\u064a\u0644\u0627",
+ "lang": "ar"
+ },
+ {
+ "name": "ar category-subcat-count 0,10",
+ "key": "ar_category-subcat-count",
+ "args": [
+ 0,
+ 10
+ ],
+ "result": "\u0647\u0630\u0627
\u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 \u060c
\u0645\u0646 \u0625\u062c\u0645\u0627\u0644\u064a 10.",
+ "lang": "ar"
+ },
+ {
+ "name": "ar category-subcat-count 1,1",
+ "key": "ar_category-subcat-count",
+ "args": [
+ 1,
+ 1
+ ],
+ "result": "\u0647\u0630\u0627
\u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647
\u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a
\u0627\u0644\u062a\u0627\u0644\u064a \u0641\u0642\u0637.",
+ "lang": "ar"
+ },
+ {
+ "name": "ar category-subcat-count 1,2",
+ "key": "ar_category-subcat-count",
+ "args": [
+ 1,
+ 2
+ ],
+ "result": "\u0647\u0630\u0627
\u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647
\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641
\u0627\u0644\u0641\u0631\u0639\u064a\u060c \u0645\u0646
\u0625\u062c\u0645\u0627\u0644\u064a 2.",
+ "lang": "ar"
+ },
+ {
+ "name": "ar category-subcat-count 3,30",
+ "key": "ar_category-subcat-count",
+ "args": [
+ 3,
+ 30
+ ],
+ "result": "\u0647\u0630\u0627
\u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647
\u0647\u0630\u0647 \u0627\u06443 \u062a\u0635\u0627\u0646\u064a\u0641
\u0627\u0644\u0641\u0631\u0639\u064a\u0629\u060c \u0645\u0646
\u0625\u062c\u0645\u0627\u0644\u064a 30.",
+ "lang": "ar"
+ },
+ {
+ "name": "jp undelete_short 0",
+ "key": "jp_undelete_short",
+ "args": [
+ 0
+ ],
+ "result": "Undelete 0 edits",
+ "lang": "jp"
+ },
+ {
+ "name": "jp undelete_short 1",
+ "key": "jp_undelete_short",
+ "args": [
+ 1
+ ],
+ "result": "Undelete one edit",
+ "lang": "jp"
+ },
+ {
+ "name": "jp undelete_short 2",
+ "key": "jp_undelete_short",
+ "args": [
+ 2
+ ],
+ "result": "Undelete 2 edits",
+ "lang": "jp"
+ },
+ {
+ "name": "jp undelete_short 5",
+ "key": "jp_undelete_short",
+ "args": [
+ 5
+ ],
+ "result": "Undelete 5 edits",
+ "lang": "jp"
+ },
+ {
+ "name": "jp undelete_short 21",
+ "key": "jp_undelete_short",
+ "args": [
+ 21
+ ],
+ "result": "Undelete 21 edits",
+ "lang": "jp"
+ },
+ {
+ "name": "jp undelete_short 101",
+ "key": "jp_undelete_short",
+ "args": [
+ 101
+ ],
+ "result": "Undelete 101 edits",
+ "lang": "jp"
+ },
+ {
+ "name": "jp category-subcat-count 0,10",
+ "key": "jp_category-subcat-count",
+ "args": [
+ 0,
+ 10
+ ],
+ "result": "This category has the following 0 subcategories, out
of 10 total.",
+ "lang": "jp"
+ },
+ {
+ "name": "jp category-subcat-count 1,1",
+ "key": "jp_category-subcat-count",
+ "args": [
+ 1,
+ 1
+ ],
+ "result": "This category has only the following subcategory.",
+ "lang": "jp"
+ },
+ {
+ "name": "jp category-subcat-count 1,2",
+ "key": "jp_category-subcat-count",
+ "args": [
+ 1,
+ 2
+ ],
+ "result": "This category has the following subcategory, out of
2 total.",
+ "lang": "jp"
+ },
+ {
+ "name": "jp category-subcat-count 3,30",
+ "key": "jp_category-subcat-count",
+ "args": [
+ 3,
+ 30
+ ],
+ "result": "This category has the following 3 subcategories, out
of 30 total.",
+ "lang": "jp"
+ },
+ {
+ "name": "zh undelete_short 0",
+ "key": "zh_undelete_short",
+ "args": [
+ 0
+ ],
+ "result":
"\u6062\u590d\u88ab\u5220\u9664\u76840\u9879\u4fee\u8ba2",
+ "lang": "zh"
+ },
+ {
+ "name": "zh undelete_short 1",
+ "key": "zh_undelete_short",
+ "args": [
+ 1
+ ],
+ "result":
"\u6062\u590d\u88ab\u5220\u9664\u76841\u9879\u4fee\u8ba2",
+ "lang": "zh"
+ },
+ {
+ "name": "zh undelete_short 2",
+ "key": "zh_undelete_short",
+ "args": [
+ 2
+ ],
+ "result":
"\u6062\u590d\u88ab\u5220\u9664\u76842\u9879\u4fee\u8ba2",
+ "lang": "zh"
+ },
+ {
+ "name": "zh undelete_short 5",
+ "key": "zh_undelete_short",
+ "args": [
+ 5
+ ],
+ "result":
"\u6062\u590d\u88ab\u5220\u9664\u76845\u9879\u4fee\u8ba2",
+ "lang": "zh"
+ },
+ {
+ "name": "zh undelete_short 21",
+ "key": "zh_undelete_short",
+ "args": [
+ 21
+ ],
+ "result":
"\u6062\u590d\u88ab\u5220\u9664\u768421\u9879\u4fee\u8ba2",
+ "lang": "zh"
+ },
+ {
+ "name": "zh undelete_short 101",
+ "key": "zh_undelete_short",
+ "args": [
+ 101
+ ],
+ "result":
"\u6062\u590d\u88ab\u5220\u9664\u7684101\u9879\u4fee\u8ba2",
+ "lang": "zh"
+ },
+ {
+ "name": "zh category-subcat-count 0,10",
+ "key": "zh_category-subcat-count",
+ "args": [
+ 0,
+ 10
+ ],
+ "result":
"\u672c\u5206\u7c7b\u5305\u542b\u4e0b\u52170\u4e2a\u5b50\u5206\u7c7b\uff0c\u5171\u670910\u4e2a\u5b50\u5206\u7c7b\u3002",
+ "lang": "zh"
+ },
+ {
+ "name": "zh category-subcat-count 1,1",
+ "key": "zh_category-subcat-count",
+ "args": [
+ 1,
+ 1
+ ],
+ "result":
"\u672c\u5206\u7c7b\u53ea\u6709\u4e0b\u5217\u4e00\u4e2a\u5b50\u5206\u7c7b\u3002",
+ "lang": "zh"
+ },
+ {
+ "name": "zh category-subcat-count 1,2",
+ "key": "zh_category-subcat-count",
+ "args": [
+ 1,
+ 2
+ ],
+ "result":
"\u672c\u5206\u7c7b\u5305\u542b\u4e0b\u52171\u4e2a\u5b50\u5206\u7c7b\uff0c\u5171\u67092\u4e2a\u5b50\u5206\u7c7b\u3002",
+ "lang": "zh"
+ },
+ {
+ "name": "zh category-subcat-count 3,30",
+ "key": "zh_category-subcat-count",
+ "args": [
+ 3,
+ 30
+ ],
+ "result":
"\u672c\u5206\u7c7b\u5305\u542b\u4e0b\u52173\u4e2a\u5b50\u5206\u7c7b\uff0c\u5171\u670930\u4e2a\u5b50\u5206\u7c7b\u3002",
+ "lang": "zh"
+ }
+];
Property changes on:
trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.data.js
___________________________________________________________________
Added: svn:eol-style
+ native
Modified:
trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.js
===================================================================
---
trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.js
2011-02-25 00:57:27 UTC (rev 82774)
+++
trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.js
2011-02-25 01:11:09 UTC (rev 82775)
@@ -2,29 +2,30 @@
// boilerplate crap, can we eliminate this?
+/*
jQuery( document ).ready( function() {
// add "magic" to Language template parser for keywords
- mw.addTemplateTransform( { 'SITENAME' : function() { return wgSitename;
} } );
+ // mediaWiki.language.parser.templateProcessors.SITENAME = function() {
return wgSitename; };
// sets up plural "magic" and so on. Seems like a bad design to have to
do this, though.
- mw.Language.magicSetup();
+ // mediaWiki.language.magicSetup();
} );
+*/
-
/**
* Tests
*/
-describe( "mw.Language", function() {
+describe( "mediaWiki.language.parser", function() {
describe( "basic message functionality", function() {
- mw.addMessages( {
+ mediaWiki.messages.set( {
'simple-message': 'simple message'
} );
it( "should return identity for simple string", function() {
- expect( gM( 'simple-message' ) ).toEqual( 'simple
message' );
+ expect( mediaWiki.msg( 'simple-message' ) ).toEqual(
'simple message' );
} );
} );
@@ -34,16 +35,17 @@
/**
* Get a language transform key
* returns default "en" fallback if none found
+ * @FIXME the resource loader should do this anyway, should not
be necessary to know this client side
* @param String langKey The language key to be checked
*/
- mw.Language.getLangTransformKey = function( langKey ) {
- if( mw.Language.fallbackTransformMap[ langKey ] ) {
- langKey = mw.Language.fallbackTransformMap[
langKey ];
+ mediaWiki.language.getLangTransformKey = function( langKey ) {
+ if( mediaWiki.language.fallbackTransformMap[ langKey ]
) {
+ langKey =
mediaWiki.language.fallbackTransformMap[ langKey ];
}
// Make sure the langKey has a transformClass:
- for( var i = 0; i < mw.Language.transformClass.length ;
i++ ) {
- if( langKey == mw.Language.transformClass[i] ){
- return langKey
+ for( var i = 0; i <
mediaWiki.language.transformClass.length ; i++ ) {
+ if( langKey ==
mediaWiki.language.transformClass[i] ){
+ return langKey;
}
}
// By default return the base 'en' class
@@ -55,7 +57,7 @@
* so it keeps up-to-date with php maping.
* ( not explicitly listed here )
*/
- mw.Language.fallbackTransformMap = {
+ mediaWiki.language.fallbackTransformMap = {
'mwl' : 'pt',
'ace' : 'id',
'hsb' : 'de',
@@ -215,7 +217,7 @@
* @@FIXME again not needed if the resource loader manages this
mapping and gives
* us the "right" transform class regardless of what
language key we request.
*/
- mw.Language.transformClass = ['am', 'ar', 'bat_smg',
'be_tarak', 'be', 'bh',
+ mediaWiki.language.transformClass = ['am', 'ar', 'bat_smg',
'be_tarak', 'be', 'bh',
'bs', 'cs', 'cu', 'cy', 'dsb', 'fr', 'ga',
'gd', 'gv', 'he', 'hi',
'hr', 'hsb', 'hy', 'ksh', 'ln', 'lt', 'lv',
'mg', 'mk', 'mo', 'mt',
'nso', 'pl', 'pt_br', 'ro', 'ru', 'se', 'sh',
'sk', 'sl', 'sma',
@@ -224,7 +226,7 @@
// wgLang??
var wgLanguageCode = 'en';
// Set-up base convert plural and gender (to restore for
non-transform languages )
- var cachedConvertPlural = { 'en' : mw.Language.convertPlural };
+ var cachedConvertPlural = { 'en' :
mediaWiki.language.convertPlural };
// XXX THIS ONLY WORKS FOR NEIL
var wgScriptPath = 'http://wiki.ivy.local/w';
@@ -234,17 +236,17 @@
* @param {String} languageCode
* @param {Function} to be executed when related scripts have
loaded
*/
- mw.Language.resetForLang = function( lang, fn ) {
- mw.Language.digitTransformTable = null;
+ mediaWiki.language.resetForLang = function( lang, fn ) {
+ mediaWiki.language.digitTransformTable = null;
// Load the current language js file if it has a langKey
- var lang = mw.Language.getLangTransformKey( lang );
+ var lang = mediaWiki.language.getLangTransformKey( lang
);
if( cachedConvertPlural[lang] ) {
- mw.Language.convertPlural =
cachedConvertPlural[lang];
+ mediaWiki.language.convertPlural =
cachedConvertPlural[lang];
fn();
} else {
mw.log( lang + " load msg transform" );
- $j.getScript( wgScriptPath +
'/resources/mediawiki.language/languages/' + lang.toLowerCase() + '.js' ,
function(){
- cachedConvertPlural[lang] =
mw.Language.convertPlural;
+ $j.getScript( wgScriptPath +
'/resources/mediaWiki.language/languages/' + lang.toLowerCase() + '.js' ,
function(){
+ cachedConvertPlural[lang] =
mediaWiki.language.convertPlural;
fn();
});
}
@@ -253,12 +255,10 @@
$j.each( jasmineMsgSpec, function( i, test ) {
it( "should parse " + test.name, function() {
- mw.Language.resetForLang( test.lang, function()
{
+ mediaWiki.language.resetForLang( test.lang,
function() {
var argArray = [ test.key ].concat(
test.args );
- result = gM.apply( this, argArray );
- //if ( test.name == 'jp undelete_short
0' ) {
- // debugger;
- //}
+ var parsedText =
mediaWiki.language.parser.apply( this, argArray );
+ result = parsedText.getHTML();
expect( result ).toEqual( test.result );
} );
} );
Modified:
trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.parser2.spec.js
===================================================================
--- trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.parser2.spec.js
2011-02-25 00:57:27 UTC (rev 82774)
+++ trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.parser2.spec.js
2011-02-25 01:11:09 UTC (rev 82775)
@@ -373,13 +373,29 @@
it ( "should handle a simple link", function() {
var parser = new mediaWiki.language.parser();
var parsed = parser.parse( 'en_link' );
- expect( parsed.html() ).toEqual( 'Simple <a
href="http://example.com">link to example</a>.' );
+ var contents = parsed.contents();
+ expect( contents.length ).toEqual( 3 );
+ expect( contents[0].nodeName ).toEqual( '#text' );
+ expect( contents[0].nodeValue ).toEqual( 'Simple ' );
+ expect( contents[1].nodeName ).toEqual( 'A' );
+ expect( contents[1].getAttribute( 'href' ) ).toEqual(
'http://example.com' );
+ expect( contents[1].childNodes[0].nodeValue ).toEqual(
'link to example' );
+ expect( contents[2].nodeName ).toEqual( '#text' );
+ expect( contents[2].nodeValue ).toEqual( '.' );
} );
it ( "should replace a URL into a link", function() {
var parser = new mediaWiki.language.parser();
var parsed = parser.parse( 'en_link_replace', [
'http://example.com/foo', 'linking' ] );
- expect( parsed.html() ).toEqual( 'Complex <a
href="http://example.com/foo">linking</a> behaviour.' );
+ var contents = parsed.contents();
+ expect( contents.length ).toEqual( 3 );
+ expect( contents[0].nodeName ).toEqual( '#text' );
+ expect( contents[0].nodeValue ).toEqual( 'Complex ' );
+ expect( contents[1].nodeName ).toEqual( 'A' );
+ expect( contents[1].getAttribute( 'href' ) ).toEqual(
'http://example.com/foo' );
+ expect( contents[1].childNodes[0].nodeValue ).toEqual(
'linking' );
+ expect( contents[2].nodeName ).toEqual( '#text' );
+ expect( contents[2].nodeValue ).toEqual( ' behaviour.'
);
} );
it ( "should bind a click handler into a link", function() {
@@ -390,12 +406,12 @@
var contents = parsed.contents();
expect( contents.length ).toEqual( 3 );
expect( contents[0].nodeName ).toEqual( '#text' );
- expect( contents[0].textContent ).toEqual( 'Complex ' );
+ expect( contents[0].nodeValue ).toEqual( 'Complex ' );
expect( contents[1].nodeName ).toEqual( 'A' );
expect( contents[1].getAttribute( 'href' ) ).toEqual(
'#' );
- expect( contents[1].textContent ).toEqual( 'linking' );
+ expect( contents[1].childNodes[0].nodeValue ).toEqual(
'linking' );
expect( contents[2].nodeName ).toEqual( '#text' );
- expect( contents[2].textContent ).toEqual( '
behaviour.' );
+ expect( contents[2].nodeValue ).toEqual( ' behaviour.'
);
// determining bindings is hard in IE
var anchor = parsed.find( 'a' );
if ( ( $j.browser.mozilla || $j.browser.webkit ) &&
anchor.click ) {
@@ -414,11 +430,11 @@
var contents = parsed.contents();
expect( contents.length ).toEqual( 3 );
expect( contents[0].nodeName ).toEqual( '#text' );
- expect( contents[0].textContent ).toEqual( 'Complex ' );
+ expect( contents[0].nodeValue ).toEqual( 'Complex ' );
expect( contents[1].nodeName ).toEqual( 'BUTTON' );
- expect( contents[1].textContent ).toEqual( 'buttoning'
);
+ expect( contents[1].childNodes[0].nodeValue ).toEqual(
'buttoning' );
expect( contents[2].nodeName ).toEqual( '#text' );
- expect( contents[2].textContent ).toEqual( '
behaviour.' );
+ expect( contents[2].nodeValue ).toEqual( ' behaviour.'
);
// determining bindings is hard in IE
if ( ( $j.browser.mozilla || $j.browser.webkit ) &&
button.click ) {
expect( clicked ).toEqual( false );
@@ -474,9 +490,12 @@
describe( "easy message interface functions", function() {
it( "should allow a global that returns strings", function() {
var gM = mediaWiki.language.parser.getMessageFunction();
+ // passing this through jQuery and back to string,
because browsers may have subtle differences, like the case of tag names.
+ // a surrounding <SPAN> is needed for html() to work
right
+ var expectedHtml = $j( '<span>Complex <a
href="http://example.com/foo">linking</a> behaviour.</span>' ).html();
var result = gM( 'en_link_replace',
'http://example.com/foo', 'linking' );
expect( typeof result ).toEqual( 'string' );
- expect( result ).toEqual( 'Complex <a
href="http://example.com/foo">linking</a> behaviour.' );
+ expect( result ).toEqual( expectedHtml );
} );
it( "should allow a jQuery plugin that appends to nodes",
function() {
@@ -485,11 +504,18 @@
var clicked = false;
var $button = $j( '<button>' ).click( function() {
clicked = true; } );
$div.find( '.foo' ).msg( 'en_link_replace', $button,
'buttoning' );
- expect( $div.find( '.foo' ).html() ).toEqual( 'Complex
<button>buttoning</button> behaviour.' );
+ // passing this through jQuery and back to string,
because browsers may have subtle differences, like the case of tag names.
+ // a surrounding <SPAN> is needed for html() to work
right
+ var expectedHtml = $j( '<span>Complex
<button>buttoning</button> behaviour.</span>' ).html();
+ var createdHtml = $div.find( '.foo' ).html();
+ // it is hard to test for clicks with IE; also it
inserts or removes spaces around nodes when creating HTML tags, depending on
their type.
+ // so need to check the strings stripped of spaces.
if ( ( $j.browser.mozilla || $j.browser.webkit ) &&
$button.click ) {
- expect( clicked ).toEqual( false );
+ expect( createdHtml ).toEqual( expectedHtml );
$div.find( 'button ').click();
expect( clicked ).toEqual( true );
+ } else if ( $j.browser.ie ) {
+ expect( createdHtml.replace( /\s/, '' )
).toEqual( expectedHtml.replace( /\s/, '' ) );
}
delete $j.fn.msg;
} );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs