jenkins-bot has submitted this change and it was merged.

Change subject: (Bug 48622) [DataValues] Introduction of UnUnserializableValue
......................................................................


(Bug 48622) [DataValues] Introduction of UnUnserializableValue

This data value represents another data value's JSON serialization plus the 
information that
unserializing this JSON was not a success for some reason.

Change-Id: I4dba21975c6592050167f527c9dddcc734df9041
---
M DataValues/DataValues.resources.php
M DataValues/DataValues.tests.qunit.php
A DataValues/resources/values/UnUnserializableValue.js
A DataValues/tests/qunit/values/UnUnserializableValue.tests.js
4 files changed, 239 insertions(+), 0 deletions(-)

Approvals:
  Tobias Gritschacher: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/DataValues/DataValues.resources.php 
b/DataValues/DataValues.resources.php
index c0879d5..22944c7 100644
--- a/DataValues/DataValues.resources.php
+++ b/DataValues/DataValues.resources.php
@@ -69,6 +69,7 @@
                                'values/NumberValue.js',
                                'values/TimeValue.js',
                                'values/UnknownValue.js',
+                               'values/UnUnserializableValue.js',
                        ),
                        'dependencies' => array(
                                'dataValues.DataValue',
diff --git a/DataValues/DataValues.tests.qunit.php 
b/DataValues/DataValues.tests.qunit.php
index 1c19353..519da6c 100644
--- a/DataValues/DataValues.tests.qunit.php
+++ b/DataValues/DataValues.tests.qunit.php
@@ -62,6 +62,7 @@
                                "$bp/values/NumberValue.tests.js",
                                "$bp/values/TimeValue.tests.js",
                                "$bp/values/UnknownValue.tests.js",
+                               "$bp/values/UnUnserializableValue.tests.js",
                        ),
                        'dependencies' => array(
                                'dataValues.DataValue.tests',
diff --git a/DataValues/resources/values/UnUnserializableValue.js 
b/DataValues/resources/values/UnUnserializableValue.js
new file mode 100644
index 0000000..96d1e81
--- /dev/null
+++ b/DataValues/resources/values/UnUnserializableValue.js
@@ -0,0 +1,136 @@
+/**
+ * @file
+ * @ingroup DataValues
+ *
+ * @licence GNU GPL v2+
+ *
+ * @author Daniel Werner < [email protected] >
+ */
+( function( dv, $ ) {
+       'use strict';
+
+       var PARENT = dv.DataValue,
+               constructor = function( unUnserializableStructure, ofType, 
unserializeError ) {
+                       if( !$.isPlainObject( unUnserializableStructure ) ) {
+                               throw new Error( 'The un-unserializable 
structure has to be a plain object' );
+                       }
+                       if( typeof ofType !== 'string' ) {
+                               throw new Error( '' );
+                       }
+                       if( !unserializeError || !( unserializeError instanceof 
Error ) ) {
+                               throw new Error( 'No Error object given' );
+                       }
+                       this._unUnserializableStructure = $.extend( {}, 
unUnserializableStructure );
+                       this._targetType = ofType;
+                       this._unserializeError = unserializeError;
+               };
+
+       /**
+        * Constructor for creating a data value representing a value which 
could not have been
+        * unserialized for some reason. Holds the serialized value which can 
not be unserialized as
+        * well as an error object describing the reason why the value can not 
be unserialized properly.
+        *
+        * @constructor
+        * @extends dv.DataValue
+        * @since 0.1
+        *
+        * @param {Object} unUnserializableStructure Plain object assumingly 
representing some data
+        *        value but the responsible unserializer was not able to 
unserialize it.
+        * @param {string} ofType The data value type the structure should have 
been unserialized to.
+        * @param {Error} unserializeError The error thrown during the attempt 
to unserialize the given
+        *        structure.
+        */
+       var SELF = dv.UnUnserializableValue = dv.util.inherit( 
'DvUnUnserializableValue', PARENT, constructor, {
+               /**
+                * @see dv.DataValue.getSortKey
+                *
+                * @since 0.1
+                *
+                * @return String
+                */
+               getSortKey: function() {
+                       return this.getReason().name;
+               },
+
+               /**
+                * @see dv.DataValue.getValue
+                *
+                * @since 0.1
+                *
+                * @return dataValues.UnUnserializableValue
+                */
+               getValue: function() {
+                       return this;
+               },
+
+               /**
+                * Returns the structure not possible to unserialize.
+                *
+                * @since 0.1
+                *
+                * @return Object
+                */
+               getStructure: function() {
+                       return $.extend( {}, this._unUnserializableStructure );
+               },
+
+               /**
+                * Returns the data value type into which the structure should 
have been unserialized.
+                *
+                * @returns string
+                */
+               getTargetType: function() {
+                       return this._targetType;
+               },
+
+               /**
+                * Returns the error object stating why some unserializer was 
not able to unserialize the
+                * structure.
+                *
+                * @since 0.1
+                *
+                * @returns Error
+                */
+               getReason: function() {
+                       return this._unserializeError;
+               },
+
+               /**
+                * @see dv.DataValue.equals
+                *
+                * @since 0.1
+                */
+               equals: function( other ) {
+                       // TODO: Do deep equal of the structures and reasons 
instead.
+                       return this === other;
+               },
+
+               /**
+                * @see dv.DataValue.toJSON
+                *
+                * @since 0.1
+                */
+               toJSON: function() {
+                       // TODO
+                       throw new Error( 'Not implemented yet.' );
+               }
+       } );
+
+       /**
+        * @see dv.DataValue.newFromJSON
+        */
+       SELF.newFromJSON = function( json ) {
+               // TODO
+               throw new Error( 'Not implemented yet.' );
+       };
+
+       /**
+        * @see dv.DataValue.TYPE
+        */
+       SELF.TYPE = 'ununserializable';
+
+       // NOTE: we don't have to register this one globally since this one is 
constructed on demand
+       //  rather than being constructed by some factory or builder.
+       //dv.registerDataValue( SELF );
+
+}( dataValues, jQuery ) );
diff --git a/DataValues/tests/qunit/values/UnUnserializableValue.tests.js 
b/DataValues/tests/qunit/values/UnUnserializableValue.tests.js
new file mode 100644
index 0000000..032087a
--- /dev/null
+++ b/DataValues/tests/qunit/values/UnUnserializableValue.tests.js
@@ -0,0 +1,101 @@
+/**
+ * @since 0.1
+ * @file
+ * @ingroup DataValues
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Werner < [email protected] >
+ */
+( function( dv, $, QUnit ) {
+       'use strict';
+
+       var PARENT = dv.tests.DataValueTest;
+
+       /**
+        * Constructor for creating a test object for the ununserializable 
DataValue.
+        *
+        * @constructor
+        * @extends dv.tests.DataValueTest
+        * @since 0.1
+        */
+       dv.tests.UnUnserializableValueTest = dv.util.inherit( PARENT, {
+
+               /**
+                * @see dv.tests.DataValueTest.getConstructor
+                */
+               getConstructor: function() {
+                       return dv.UnUnserializableValue;
+               },
+
+               /**
+                * @see dv.tests.DataValueTest.getConstructorArguments
+                */
+               getConstructorArguments: function() {
+                       return [
+                               [ {}, 'sometype', new Error( 'some error' ) ],
+                               [ { foo: 'bar' }, 'another-type', new Error( 
'another error' ) ]
+                       ];
+               },
+
+               /**
+                * Tests the getStructure method.
+                *
+                * @since 0.1
+                *
+                * @param {QUnit} assert
+                */
+               testGetStructure: function( assert ) {
+                       var instances = this.getInstances(),
+                               i,
+                               structure;
+
+                       for ( i in instances ) {
+                               structure = instances[i].getStructure();
+
+                               assert.ok(
+                                       $.isPlainObject( structure ),
+                                       'return value is plain object'
+                               );
+
+                               assert.ok(
+                                       structure !== 
instances[i].getStructure(),
+                                       'return value not returned by reference'
+                               );
+                       }
+               },
+
+               /**
+                * @see dv.tests.DataValueTest.testNewFromJSON
+                *
+                * skip
+                */
+               testNewFromJSON: null,
+
+               /**
+                * @see dv.tests.DataValueTest.testToJSON
+                *
+                * skip
+                */
+               testToJSON: null,
+
+               /**
+                * @see dv.tests.DataValueTest.testJsonRoundtripping
+                *
+                * skip
+                */
+               testJsonRoundtripping: null,
+
+               /**
+                * @see dv.tests.DataValueTest.testJsonRoundtripping
+                *
+                * skip
+                * TODO: activate after equals is implemented according to TODO 
in the data value's file
+                */
+               testEquals: null
+       } );
+
+       var test = new dv.tests.UnUnserializableValueTest();
+
+       test.runTests( 'dataValues.UnUnserializableValue' );
+
+}( dataValues, jQuery, QUnit ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/64543
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4dba21975c6592050167f527c9dddcc734df9041
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to