Henning Snater has submitted this change and it was merged.

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
D DataValues/tests/qunit/DataValues.tests.js
R DataValues/tests/qunit/dataValues.DataValue.tests.js
M ValueView/ValueView.tests.qunit.php
8 files changed, 200 insertions(+), 224 deletions(-)

Approvals:
  Henning Snater: Verified; Looks good to me, approved
  jenkins-bot: Verified



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..b3309b6
--- /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/DataValues.tests.js 
b/DataValues/tests/qunit/DataValues.tests.js
deleted file mode 100644
index 633f91b..0000000
--- a/DataValues/tests/qunit/DataValues.tests.js
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * @file
- * @ingroup DataValues
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-( function( dv, $, QUnit ) {
-       'use strict';
-
-       // Fix for most of our tests no having the number of required 
assertions.
-       // This is required since I214b3d4 got merged into core.
-       // TODO: figure out some non-global alternative to deal with this.
-       QUnit.config.requireExpects = false;
-
-       QUnit.module( 'DataValues.js', QUnit.newMwEnvironment() );
-
-       QUnit.test(
-               'getDataValues',
-               function( assert ) {
-                       var dvs = dv.getDataValues();
-
-                       assert.ok( $.isArray( dvs ), 'Returns an array' );
-
-                       for ( var i = 0, s = dvs.length; i < s; i++ ) {
-                               assert.ok(
-                                       typeof dvs[i] === 'string',
-                                       'Returned DV type "' + dvs[i] + '" is a 
string'
-                               );
-
-                               assert.ok(
-                                       dv.hasDataValue( dvs[i] ),
-                                       'Returned DV type "' + dvs[i] + '" is 
present according to hasDataValue'
-                               );
-                       }
-               }
-       );
-
-       QUnit.test(
-               'hasDataValue',
-               function( assert ) {
-                       // Already partially tested in getDataValues
-
-                       assert.strictEqual(
-                               dv.hasDataValue( 'in your code, being silly' ),
-                               false,
-                               'Non existing DV type is not present'
-                       );
-
-                       var dvs = dv.getDataValues();
-
-                       assert.strictEqual(
-                               dv.hasDataValue( dvs.pop() ),
-                               true,
-                               'Existing DV type is present'
-                       );
-               }
-       );
-
-       QUnit.test(
-               'newDataValue',
-               function( assert ) {
-                       // This test needs dv.MonolingualTextValue to be loaded 
and registered
-
-                       var dataValue = dv.newDataValue(
-                               'monolingualtext',
-                               {
-                                       'language': 'en',
-                                       'text': '~=[,,_,,]:3'
-                               }
-                       );
-
-                       assert.strictEqual(
-                               dataValue.getText(),
-                               '~=[,,_,,]:3',
-                               'Value was constructed and the text was set 
correctly'
-                       );
-
-                       assert.strictEqual(
-                               dataValue.getLanguageCode(),
-                               'en',
-                               'Value was constructed and the language code 
was set correctly'
-                       );
-               }
-       );
-
-}( dataValues, jQuery, QUnit ) );
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/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: merged
Gerrit-Change-Id: I9ba230dba1c1df572b5d6eac952ea6043c2b2a8a
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to