r110734 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110733‎ | r110734 | r110735 >
Date:07:02, 6 February 2012
Author:amire80
Status:resolved (Comments)
Tags:
Comment:
Adding tests (only those that pass).
Modified paths:
  • /trunk/extensions/Narayam/Narayam.hooks.php (modified) (history)
  • /trunk/extensions/Narayam/Narayam.php (modified) (history)
  • /trunk/extensions/WebFonts/tests/qunit/ext.narayam.tests.js (added) (history)

Diff [purge]

Index: trunk/extensions/WebFonts/tests/qunit/ext.narayam.tests.js
@@ -0,0 +1,64 @@
 2+/**
 3+ * QUnit tests for Narayam
 4+ *
 5+ * @file
 6+ * @author Amir E. Aharoni
 7+ * @copyright Copyright © 2012 Amir E. Aharoni
 8+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 9+ */
 10+( function () {
 11+
 12+module( "ext.narayam", QUnit.newMwEnvironment() );
 13+
 14+var oldUserLang = mw.config.get( wgUserLanguage );
 15+// A language that definitely has input methods
 16+mw.config.set( { wgUserLanguage: "ml" } );
 17+$.narayam.setup();
 18+$.narayam.enable();
 19+
 20+test( "-- Initial check", function() {
 21+ expect( 1 );
 22+
 23+ ok( $.narayam, "$.narayam is defined" );
 24+} );
 25+
 26+test( "-- Initialization functions", function() {
 27+ expect( 10 );
 28+
 29+ var stateCookieName = "narayam-enabled";
 30+
 31+ // Now it's supposed to be enabled, so toggle() is supposed to disable.
 32+ $.narayam.toggle();
 33+ equals( $.narayam.enabled(), false, "toggle() disables Narayam when it is enabled." );
 34+ equals( $.cookie( stateCookieName ), "0", "The state cookie was set to 0." );
 35+ ok( $( "li#pt-narayam" ).hasClass( "narayam-inactive" ), "After disabling the Narayam menu header has the narayam-inactive class." );
 36+ ok( !$( "li#pt-narayam" ).hasClass( "narayam-active" ), "After disabling the Narayam menu header doesn't have the narayam-active class ." );
 37+ ok( !$( "#narayam-toggle" ).attr( "checked" ), "After disabling the Narayam checkbox is not checked." );
 38+
 39+ // Now it's supposed to be disabled, so toggle() is supposed to enable.
 40+ $.narayam.toggle();
 41+ equals( $.narayam.enabled(), true, "toggle() enables Narayam when it is disabled." );
 42+ equals( $.cookie( stateCookieName ), "1", "The state cookie was set to 1." );
 43+ ok( !$( "li#pt-narayam" ).hasClass( "narayam-inactive" ), "After enabling the Narayam menu header doesn't have the narayam-inactive class." );
 44+ ok( $( "li#pt-narayam" ).hasClass( "narayam-active" ), "After enabling the Narayam menu header has the narayam-active class ." );
 45+ ok( $( "#narayam-toggle" ).attr( "checked" ), "After enabling the Narayam checkbox is checked." );
 46+
 47+
 48+} );
 49+
 50+test( "-- Simple character functions", function() {
 51+ expect( 7 );
 52+
 53+ equals( $.narayam.lastNChars( "foobarbaz", 5, 2 ), "ba", "lastNChars works with short buffer." );
 54+ equals( $.narayam.lastNChars( "foobarbaz", 2, 5 ), "fo", "lastNChars works with long buffer." );
 55+
 56+ equals( $.narayam.firstDivergence( "abc", "abc" ), -1 );
 57+ equals( $.narayam.firstDivergence( "a", "b" ), 0 );
 58+ equals( $.narayam.firstDivergence( "a", "bb" ), 0 );
 59+ equals( $.narayam.firstDivergence( "abc", "abd" ), 2 );
 60+ equals( $.narayam.firstDivergence( "abcd", "abd" ), 2 );
 61+} );
 62+
 63+mw.config.set( { wgUserLanguage: oldUserLang } );
 64+
 65+}());
Property changes on: trunk/extensions/WebFonts/tests/qunit/ext.narayam.tests.js
___________________________________________________________________
Added: svn:eol-style
166 + native
Index: trunk/extensions/Narayam/Narayam.php
@@ -171,6 +171,7 @@
172172 $wgHooks['MakeGlobalVariablesScript'][] = 'NarayamHooks::addVariables';
173173 $wgHooks['GetPreferences'][] = 'NarayamHooks::addPreference';
174174 $wgHooks['UserGetDefaultOptions'][] = 'NarayamHooks::addDefaultOptions';
 175+$wgHooks['ResourceLoaderTestModules'][] = 'NarayamHooks::addTestModules';
175176
176177 // Autoloader
177178 $wgAutoloadClasses['NarayamHooks'] = $dir . '/Narayam.hooks.php';
Index: trunk/extensions/Narayam/Narayam.hooks.php
@@ -19,6 +19,22 @@
2020 return true;
2121 }
2222
 23+ /**
 24+ * ResourceLoaderTestModules hook handler.
 25+ * @param $testModules: array of javascript testing modules. 'qunit' is fed using tests/qunit/QUnitTestResources.php.
 26+ * @param $resourceLoader object
 27+ * @return bool
 28+ */
 29+ public static function addTestModules( array &$testModules, ResourceLoader &$resourceLoader ) {
 30+ $testModules['qunit']['ext.narayam.tests'] = array(
 31+ 'scripts' => array( 'tests/qunit/ext.narayam.tests.js' ),
 32+ 'dependencies' => array( 'ext.narayam.core' ),
 33+ 'localBasePath' => dirname( __FILE__ ),
 34+ 'remoteExtPath' => 'Narayam',
 35+ );
 36+ return true;
 37+ }
 38+
2339 /// Hook: ResourceLoaderGetConfigVars
2440 public static function addConfig( &$vars ) {
2541 global $wgNarayamRecentItemsLength, $wgNarayamEnabledByDefault;

Follow-up revisions

RevisionCommit summaryAuthorDate
r110735Move the Narayam tests file to the proper directory.amire8007:58, 6 February 2012

Comments

#Comment by Santhosh.thottingal (talk | contribs)   07:24, 6 February 2012

WebFonts/tests/qunit/ext.narayam.tests.js ?

#Comment by Amire80 (talk | contribs)   08:00, 6 February 2012

My mistake, but i would expect SVN to warn me. SVN kinda sucks.

Status & tagging log