Awight has uploaded a new change for review.
https://gerrit.wikimedia.org/r/172665
Change subject: WIP Basic QUnit tests
......................................................................
WIP Basic QUnit tests
Change-Id: I281f576b4a75458b15071167220c1c404e7bec6d
---
M CentralNotice.hooks.php
A tests/qunit/ext.centralNotice.bannerController/bannerController.tests.js
2 files changed, 88 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice
refs/changes/65/172665/1
diff --git a/CentralNotice.hooks.php b/CentralNotice.hooks.php
index b006246..94695c8 100644
--- a/CentralNotice.hooks.php
+++ b/CentralNotice.hooks.php
@@ -91,7 +91,9 @@
$wgAPIListModules[ 'centralnoticelogs' ] = 'ApiCentralNoticeLogs';
// Register hooks
- $wgHooks[ 'UnitTestsList' ][ ] = 'efCentralNoticeUnitTests';
+ // TODO: replace ef- global functions with static methods in
CentralNoticeHooks
+ $wgHooks['ResourceLoaderTestModules'][] =
'efCentralNoticeResourceLoaderTestModules';
+ $wgHooks['UnitTestsList'][] = 'efCentralNoticeUnitTests';
// If CentralNotice banners should be shown on this wiki, load the
components we need for
// showing banners. For discussion of banner loading strategies, see
@@ -358,6 +360,51 @@
}
/**
+ * ResourceLoaderTestModules hook handler
+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
+ *
+ * @param array $testModules
+ * @param ResourceLoader $resourceLoader
+ * @return bool
+ */
+function efCentralNoticeResourceLoaderTestModules( array &$testModules,
+ ResourceLoader $resourceLoader
+) {
+ global $wgResourceModules;
+
+ $testModuleBoilerplate = array(
+ 'localBasePath' => __DIR__,
+ 'remoteExtPath' => 'CentralNotice',
+ );
+
+ // TODO: Something similar should be provided by core.
+ // find test files for every RL module
+ $prefix = 'ext.centralNotice';
+ foreach ( $wgResourceModules as $key => $module ) {
+ if ( substr( $key, 0, strlen( $prefix ) ) === $prefix && isset(
$module['scripts'] ) ) {
+ $testFiles = array();
+ foreach ( ((array) $module['scripts'] ) as $script ) {
+ $testFile = 'tests/qunit/' . $key . '/' .
basename( $script );
+ $testFile = preg_replace( '/.js$/',
'.tests.js', $testFile );
+ // if a test file exists for a given JS file,
add it
+ if ( file_exists( __DIR__ . '/' . $testFile ) )
{
+ $testFiles[] = $testFile;
+ }
+ }
+ // if test files exist for given module, create a
corresponding test module
+ if ( count( $testFiles ) > 0 ) {
+ $testModules['qunit']["$key.tests"] =
$testModuleBoilerplate + array(
+ 'dependencies' => array( $key ),
+ 'scripts' => $testFiles,
+ );
+ }
+ }
+ }
+
+ return true;
+}
+
+/**
* EnableMobileModules callback for placing the CN resourceloader
* modules onto mobile pages.
*
diff --git
a/tests/qunit/ext.centralNotice.bannerController/bannerController.tests.js
b/tests/qunit/ext.centralNotice.bannerController/bannerController.tests.js
new file mode 100644
index 0000000..20d57b2
--- /dev/null
+++ b/tests/qunit/ext.centralNotice.bannerController/bannerController.tests.js
@@ -0,0 +1,40 @@
+( function ( mw, $ ) {
+ 'use strict';
+
+ QUnit.module( 'ext.centralNotice.bannerController',
QUnit.newMwEnvironment( {
+ setup: function () {
+ mw.centralNotice.initialize();
+ },
+ teardown: function () {
+ mw.centralNotice.alreadyRan = false;
+ }
+ } ) );
+
+ QUnit.test( 'hasAlreadyRan', 1, function( assert ) {
+ assert.ok( mw.centralNotice.alreadyRan );
+ } );
+
+ QUnit.test( 'canRecordImpression', 1, function( assert ) {
+ var endpoint =
'http://localhost.net/wiki/Special:RecordImpression',
+ impressionData = { language: 'gr' },
+ expectedUrl = endpoint + '?language=gr';
+
+ mw.config.set( 'wgCentralBannerRecorder', endpoint );
+ mw.centralNotice.recordImpression( impressionData );
+ assert.equal( $( 'img[src="' + expectedUrl + '"]' ).length, 1 );
+ } );
+
+ QUnit.test( 'canInsertBanner', 1, function( assert ) {
+ var bannerJson = {
+ bannerName: 'test_banner_insertBanner',
+ campaign: 'test_campaign_insertBanner',
+ category: 'test',
+ bannerHtml: '<div id="banner"></div>'
+ };
+
+ mw.centralNotice.insertBanner( bannerJson );
+
+ assert.equal( $( 'div#banner' ).length, 1 );
+ } );
+
+} ( mediaWiki, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/172665
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I281f576b4a75458b15071167220c1c404e7bec6d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits