Daniel Werner has uploaded a new change for review. https://gerrit.wikimedia.org/r/60025
Change subject: Reorganization of DataValues extension's JS resources ...................................................................... Reorganization of DataValues extension's JS resources - Moved dataValues.util.inherit into separate file. - Test resource definitions cleanup (proper dependencies) and moved into separate file. - DataValues Extension's QUnit tests are not longer dependent on MediaWiki ( no longer using QUnit.newMwEnvironment). Change-Id: I9ba230dba1c1df572b5d6eac952ea6043c2b2a8a --- M DataValues/DataValues.mw.php R DataValues/DataValues.resources.php A DataValues/DataValues.tests.qunit.php A DataValues/resources/dataValues.util.inherit.js M DataValues/resources/dataValues.util.js R DataValues/tests/qunit/dataValues.DataValue.tests.js R DataValues/tests/qunit/dataValues.tests.js M ValueView/ValueView.tests.qunit.php 8 files changed, 200 insertions(+), 138 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues refs/changes/25/60025/1 diff --git a/DataValues/DataValues.mw.php b/DataValues/DataValues.mw.php index db2197d..dc461a8 100644 --- a/DataValues/DataValues.mw.php +++ b/DataValues/DataValues.mw.php @@ -92,7 +92,7 @@ }; /** - * Hook to add QUnit test cases. + * Hook for registering QUnit test cases. * @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules * @since 0.1 * @@ -101,53 +101,16 @@ * @return boolean */ $wgHooks['ResourceLoaderTestModules'][] = function ( array &$testModules, \ResourceLoader &$resourceLoader ) { - $moduleTemplate = array( + // Register DataValue QUnit tests. Take the predefined test definitions and make them + // suitable for registration with MediaWiki's resource loader. + $ownModules = include( __DIR__ . '/DataValues.tests.qunit.php' ); + $ownModulesTemplate = array( 'localBasePath' => __DIR__, - 'remoteExtPath' => 'DataValues/DataValues', + 'remoteExtPath' => 'DataValues/DataValues', ); - - $testModules['qunit']['ext.dataValues.DataValues'] = $moduleTemplate + array( - 'scripts' => array( - 'tests/qunit/DataValues.tests.js', - ), - 'dependencies' => array( - 'dataValues', - ), - ); - - $testModules['qunit']['ext.dataValues.DataValue'] = $moduleTemplate + array( - 'scripts' => array( - 'tests/qunit/DataValue.tests.js', - ), - 'dependencies' => array( - 'dataValues.values', - ), - ); - - $testModules['qunit']['ext.dataValues.values'] = $moduleTemplate + array( - 'scripts' => array( - 'tests/qunit/values/BoolValue.tests.js', - 'tests/qunit/values/MonolingualTextValue.tests.js', - 'tests/qunit/values/MultilingualTextValue.tests.js', - 'tests/qunit/values/StringValue.tests.js', - 'tests/qunit/values/NumberValue.tests.js', - 'tests/qunit/values/UnknownValue.tests.js', - ), - 'dependencies' => array( - 'ext.dataValues.DataValue', - ), - ); - - $testModules['qunit']['ext.dataValues.util'] = $moduleTemplate + array( - 'scripts' => array( - 'tests/qunit/dataValues.util.inherit.tests.js', - 'tests/qunit/dataValues.util.Notifier.tests.js', - ), - 'dependencies' => array( - 'dataValues.util', - ), - ); - + foreach( $ownModules as $ownModuleName => $ownModule ) { + $testModules['qunit'][ $ownModuleName ] = $ownModule + $ownModulesTemplate; + } return true; }; @@ -172,5 +135,5 @@ // Resource Loader module registration $wgResourceModules = array_merge( $wgResourceModules, - include( __DIR__ . '/Resources.php' ) + include( __DIR__ . '/DataValues.resources.php' ) ); diff --git a/DataValues/Resources.php b/DataValues/DataValues.resources.php similarity index 93% rename from DataValues/Resources.php rename to DataValues/DataValues.resources.php index 1a4f7dc..50b4ac0 100644 --- a/DataValues/Resources.php +++ b/DataValues/DataValues.resources.php @@ -3,6 +3,9 @@ * Definition of 'DataValues' resourceloader modules. * When included this returns an array with all the modules introduced by 'DataValues' extension. * + * External dependencies: + * - jQuery 1.8 + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -24,7 +27,7 @@ * @ingroup DataValues * * @licence GNU GPL v2+ - * @author Daniel Werner + * @author Daniel Werner < [email protected] > * * @codeCoverageIgnoreStart */ @@ -70,6 +73,7 @@ 'dataValues.util' => $moduleTemplate + array( 'scripts' => array( 'dataValues.util.js', + 'dataValues.util.inherit.js', 'dataValues.util.Notify.js', ), 'dependencies' => array( diff --git a/DataValues/DataValues.tests.qunit.php b/DataValues/DataValues.tests.qunit.php new file mode 100644 index 0000000..3a564d7 --- /dev/null +++ b/DataValues/DataValues.tests.qunit.php @@ -0,0 +1,83 @@ +<?php +/** + * Definition of 'DataValues' qunit test modules. + * When included this returns an array with all qunit test module definitions. Given file patchs + * are relative to the package's root. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @since 0.1 + * + * @file + * @ingroup DataValues + * + * @licence GNU GPL v2+ + * @author Daniel Werner < [email protected] > + * + * @codeCoverageIgnoreStart + */ +return call_user_func( function() { + + // base path from package root: + $bp = 'tests/qunit'; + + return array( + 'dataValues.tests' => array( + 'scripts' => array( + "$bp/datavalues.tests.js", + ), + 'dependencies' => array( + 'dataValues', + ), + ), + + 'dataValues.DataValue.tests' => array( + 'scripts' => array( + "$bp/dataValues.DataValue.tests.js", + ), + 'dependencies' => array( + 'dataValues.DataValue', + ), + ), + + 'dataValues.values.tests' => array( + 'scripts' => array( + "$bp/values/BoolValue.tests.js", + "$bp/values/MonolingualTextValue.tests.js", + "$bp/values/MultilingualTextValue.tests.js", + "$bp/values/StringValue.tests.js", + "$bp/values/NumberValue.tests.js", + "$bp/values/UnknownValue.tests.js", + ), + 'dependencies' => array( + 'dataValues.DataValue.tests', + 'dataValues.values' + ), + ), + + 'dataValues.util.tests' => array( + 'scripts' => array( + "$bp/dataValues.util.inherit.tests.js", + "$bp/dataValues.util.Notifier.tests.js", + ), + 'dependencies' => array( + 'dataValues.util', + ), + ), + ); + +} ); +// @codeCoverageIgnoreEnd diff --git a/DataValues/resources/dataValues.util.inherit.js b/DataValues/resources/dataValues.util.inherit.js new file mode 100644 index 0000000..43ff902 --- /dev/null +++ b/DataValues/resources/dataValues.util.inherit.js @@ -0,0 +1,90 @@ +/** + * @file + * @ingroup DataValues + * @licence GNU GPL v2+ + * @author Daniel Werner < [email protected] > + */ +( function( $, dataValues ) { + 'use strict'; + + var dv = dataValues; + + /** + * Helper for prototypical inheritance. + * @since 0.1 + * + * @param {string} name (optional) The name of the new constructor. This is handy for debugging + * purposes since instances of the constructor might be displayed under that name. + * @param {Function} base Constructor which will be used for the prototype chain. This function + * will not be the constructor returned by the function but will be called by it. + * @param {Function} [constructor] for overwriting base constructor. Can be omitted. + * @param {Object} [members] properties overwriting or extending those of the base. + * @return Function Constructor of the new, extended type. + * + * @throws {Error} In case a malicious function name is given or a reserved word is used + */ + dv.util.inherit = function( name, base, constructor, members ) { + // the name is optional + if( typeof name !== 'string' ) { + members = constructor; constructor = base; base = name; name = false; + } + + // allow to omit constructor since it can be inherited directly. But if given, require it as second parameter + // for readability. If no constructor, second parameter is the prototype extension object. + if( !members ) { + if( $.isFunction( constructor ) ) { + members = {}; + } else { + members = constructor || {}; // also support case where no parameters but base are given + constructor = false; + } + } + // if no name is given, find suitable constructor's name + name = name || constructor.name || ( base.name ? base.name + '_SubProto' : 'SomeInherited' ); + // make sure name is just a function name and not some executable JavaScript + name = name.replace( /(?:(^\d+)|[^\w$])/ig, '' ); + + if( !name ) { // only bad characters were in the name! + throw new Error( 'Bad constructor name given. Only word characters and $ are allowed.' ); + } + + // function we execute in our real constructor created by evil eval: + var evilsSeed = constructor || base, + NewConstructor; + + // for creating a named function with a variable name, there is just no other way... + eval( 'NewConstructor = function ' + name + + '(){ evilsSeed.apply( this, arguments ); }' ); + + var NewPrototype = function(){}; // new constructor for avoiding base constructor and with it any side-effects + NewPrototype.prototype = base.prototype; + + NewConstructor.prototype = $.extend( + new NewPrototype(), + members + ); + + // Make sure constructor property is set properly. The constructor has to be assigned + // explicitly since doing it along the $.extend() above will be ignored in IE8. + NewConstructor.prototype.constructor = NewConstructor; + + return NewConstructor; + }; + + /** + * Throw a kind of meaningful error whenever the function should be overwritten when inherited. + * @throws Error + * + * @since 0.1 + * + * @example: + * SomethingAbstract.prototype = { + * someFunc: function( a, b ) { doSomething() }, + * someAbstractFunc: wb.utilities.abstractFunction + * }; + */ + dv.util.abstractMember = function() { + throw new Error( 'Call to undefined abstract function' ); + }; + +}( jQuery, dataValues ) ); diff --git a/DataValues/resources/dataValues.util.js b/DataValues/resources/dataValues.util.js index b8d0ca5..f9fc073 100644 --- a/DataValues/resources/dataValues.util.js +++ b/DataValues/resources/dataValues.util.js @@ -4,92 +4,14 @@ * @licence GNU GPL v2+ * @author Daniel Werner < [email protected] > */ -( function( $, dv ) { + +/** + * Module for utilities of the DataValues extension. + * @since 0.1 + * @type Object + */ +dataValues.util = ( function(){ 'use strict'; - /** - * Module for utilities of the DataValues extension. - * @since 0.1 - * @type Object - */ - dv.util = {}; - - /** - * Helper for prototypical inheritance. - * @since 0.1 - * - * @param {string} name (optional) The name of the new constructor. This is handy for debugging - * purposes since instances of the constructor might be displayed under that name. - * @param {Function} base Constructor which will be used for the prototype chain. This function - * will not be the constructor returned by the function but will be called by it. - * @param {Function} [constructor] for overwriting base constructor. Can be omitted. - * @param {Object} [members] properties overwriting or extending those of the base. - * @return Function Constructor of the new, extended type. - * - * @throws {Error} In case a malicious function name is given or a reserved word is used - */ - dv.util.inherit = function( name, base, constructor, members ) { - // the name is optional - if( typeof name !== 'string' ) { - members = constructor; constructor = base; base = name; name = false; - } - - // allow to omit constructor since it can be inherited directly. But if given, require it as second parameter - // for readability. If no constructor, second parameter is the prototype extension object. - if( !members ) { - if( $.isFunction( constructor ) ) { - members = {}; - } else { - members = constructor || {}; // also support case where no parameters but base are given - constructor = false; - } - } - // if no name is given, find suitable constructor's name - name = name || constructor.name || ( base.name ? base.name + '_SubProto' : 'SomeInherited' ); - // make sure name is just a function name and not some executable JavaScript - name = name.replace( /(?:(^\d+)|[^\w$])/ig, '' ); - - if( !name ) { // only bad characters were in the name! - throw new Error( 'Bad constructor name given. Only word characters and $ are allowed.' ); - } - - // function we execute in our real constructor created by evil eval: - var evilsSeed = constructor || base, - NewConstructor; - - // for creating a named function with a variable name, there is just no other way... - eval( 'NewConstructor = function ' + name + - '(){ evilsSeed.apply( this, arguments ); }' ); - - var NewPrototype = function(){}; // new constructor for avoiding base constructor and with it any side-effects - NewPrototype.prototype = base.prototype; - - NewConstructor.prototype = $.extend( - new NewPrototype(), - members - ); - - // Make sure constructor property is set properly. The constructor has to be assigned - // explicitly since doing it along the $.extend() above will be ignored in IE8. - NewConstructor.prototype.constructor = NewConstructor; - - return NewConstructor; - }; - - /** - * Throw a kind of meaningful error whenever the function should be overwritten when inherited. - * @throws Error - * - * @since 0.1 - * - * @example: - * SomethingAbstract.prototype = { - * someFunc: function( a, b ) { doSomething() }, - * someAbstractFunc: wb.utilities.abstractFunction - * }; - */ - dv.util.abstractMember = function() { - throw new Error( 'Call to undefined abstract function' ); - }; - -}( jQuery, dataValues ) ); + return {}; +}() ); diff --git a/DataValues/tests/qunit/DataValue.tests.js b/DataValues/tests/qunit/dataValues.DataValue.tests.js similarity index 97% rename from DataValues/tests/qunit/DataValue.tests.js rename to DataValues/tests/qunit/dataValues.DataValue.tests.js index 1ea5477..3e5b9da 100644 --- a/DataValues/tests/qunit/DataValue.tests.js +++ b/DataValues/tests/qunit/dataValues.DataValue.tests.js @@ -81,7 +81,7 @@ * @param {String} moduleName */ runTests: function( moduleName ) { - QUnit.module( moduleName, QUnit.newMwEnvironment() ); + QUnit.module( moduleName ); var self = this; @@ -90,7 +90,7 @@ QUnit.test( property, function( assert ) { - self[property].call( self, assert ); + self[property]( assert ); } ); } diff --git a/DataValues/tests/qunit/DataValues.tests.js b/DataValues/tests/qunit/dataValues.tests.js similarity index 100% rename from DataValues/tests/qunit/DataValues.tests.js rename to DataValues/tests/qunit/dataValues.tests.js diff --git a/ValueView/ValueView.tests.qunit.php b/ValueView/ValueView.tests.qunit.php index 7f438f8..ffdaa94 100644 --- a/ValueView/ValueView.tests.qunit.php +++ b/ValueView/ValueView.tests.qunit.php @@ -1,6 +1,6 @@ <?php /** - * Definition of 'DataTypes' qunit test modules. + * Definition of 'ValueView' qunit test modules. * When included this returns an array with all qunit test module definitions. Given file patchs * are relative to the package's root. * -- To view, visit https://gerrit.wikimedia.org/r/60025 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9ba230dba1c1df572b5d6eac952ea6043c2b2a8a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DataValues Gerrit-Branch: master Gerrit-Owner: Daniel Werner <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
