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 |
1 | 66 | + native |
Index: trunk/extensions/Narayam/Narayam.php |
— | — | @@ -171,6 +171,7 @@ |
172 | 172 | $wgHooks['MakeGlobalVariablesScript'][] = 'NarayamHooks::addVariables'; |
173 | 173 | $wgHooks['GetPreferences'][] = 'NarayamHooks::addPreference'; |
174 | 174 | $wgHooks['UserGetDefaultOptions'][] = 'NarayamHooks::addDefaultOptions'; |
| 175 | +$wgHooks['ResourceLoaderTestModules'][] = 'NarayamHooks::addTestModules'; |
175 | 176 | |
176 | 177 | // Autoloader |
177 | 178 | $wgAutoloadClasses['NarayamHooks'] = $dir . '/Narayam.hooks.php'; |
Index: trunk/extensions/Narayam/Narayam.hooks.php |
— | — | @@ -19,6 +19,22 @@ |
20 | 20 | return true; |
21 | 21 | } |
22 | 22 | |
| 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 | + |
23 | 39 | /// Hook: ResourceLoaderGetConfigVars |
24 | 40 | public static function addConfig( &$vars ) { |
25 | 41 | global $wgNarayamRecentItemsLength, $wgNarayamEnabledByDefault; |