r111724 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111723‎ | r111724 | r111725 >
Date:04:38, 17 February 2012
Author:santhosh
Status:deferred (Comments)
Tags:i18nreview 
Comment:
Qunit Testcases for mediawiki.language. For now, just one test for convertGrammar. More tests coming.
Modified paths:
  • /branches/jsgrammar/tests/qunit/QUnitTestResources.php (modified) (history)
  • /branches/jsgrammar/tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js (added) (history)

Diff [purge]

Index: branches/jsgrammar/tests/qunit/QUnitTestResources.php
@@ -26,6 +26,7 @@
2727 'tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js',
2828 'tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.test.js',
2929 "tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js",
 30+ "tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js",
3031 ),
3132 'dependencies' => array(
3233 'jquery.autoEllipsis',
@@ -42,6 +43,7 @@
4344 'jquery.tablesorter',
4445 'jquery.textSelection',
4546 'mediawiki',
 47+ 'language',
4648 'mediawiki.Title',
4749 'mediawiki.user',
4850 'mediawiki.util',
Index: branches/jsgrammar/tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js
@@ -0,0 +1,43 @@
 2+module( 'mediawiki.language' );
 3+
 4+test( '-- Initial check', function() {
 5+ expect( 1 );
 6+ ok( mw.language, 'mw.language defined' );
 7+} );
 8+
 9+
 10+mw.language.grammartest = function( options ) {
 11+ var opt = $.extend({
 12+ language: '',
 13+ grammarForm: null,
 14+ word: '',
 15+ expected: '',
 16+ description: ''
 17+ }, options);
 18+ // The test works only if the content language is opt.language
 19+ // because it require [lang].js to be loaded.
 20+ if( mw.config.get ( 'wgContentLanguage' ) === opt.language ) {
 21+ test( opt.description, function() {
 22+ expect( 1 );
 23+ var langData = mw.language.data;
 24+ var grammarForms = [];
 25+ grammarForms[ opt.grammarForm ] = [] ;
 26+ if ( langData[opt.language] === undefined ) {
 27+ langData[opt.language] = new mw.Map();
 28+ }else{
 29+ grammarForms = langData[opt.language].get( 'grammarForms' );
 30+ }
 31+ grammarForms[opt.grammarForm][opt.word] = opt.expected ;
 32+ langData[opt.language].set( 'grammarForms', grammarForms );
 33+ equal( mw.language.convertGrammar( opt.word, opt.grammarForm ), opt.expected, opt.description );
 34+ } );
 35+ }
 36+}
 37+
 38+mw.language.grammartest({
 39+ language: 'en',
 40+ word: 'pen',
 41+ grammarForm: 'genitive',
 42+ expected: 'pen\'s',
 43+ description: 'Grammar test for English'
 44+});
Property changes on: branches/jsgrammar/tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js
___________________________________________________________________
Added: svn:eol-style
145 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r113350Add the test to qunit/index.html...santhosh08:49, 8 March 2012

Comments

#Comment by Krinkle (talk | contribs)   00:12, 5 March 2012
  • Also add it to ./tests/qunit/index.html
  • Some nitpicks about JS conventions (whitespace mostly)
#Comment by Krinkle (talk | contribs)   01:37, 5 March 2012

Is there a reason to have grammartest being defined into the mw.language object? This could/should probably just be a local function.

#Comment by Krinkle (talk | contribs)   01:41, 5 March 2012
+	if( mw.config.get ( 'wgContentLanguage' ) === opt.language ) {

We need a way to run these tests regardless of the content language, all of them.

#Comment by Santhosh.thottingal (talk | contribs)   08:56, 8 March 2012

Yes, That is required for all other language tests too. We will require loading each lang.js one after another, do testing for that language. But language.js loading being done based on contentlanguage by ResourceLoader, how can we achieve this?

#Comment by Krinkle (talk | contribs)   09:00, 8 March 2012

Good question :)

#Comment by Krinkle (talk | contribs)   09:01, 8 March 2012

Maybe knowns.

Status & tagging log