Henning Snater has submitted this change and it was merged.

Change subject: RepoApi.getClaims() added
......................................................................


RepoApi.getClaims() added

Change-Id: Id25b789ff605b655b4e467fdc20a2b6c643980cc
---
M lib/resources/wikibase.RepoApi/wikibase.RepoApi.js
M lib/tests/qunit/wikibase.RepoApi/wikibase.RepoApi.tests.js
M repo/includes/api/GetClaims.php
3 files changed, 147 insertions(+), 26 deletions(-)

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



diff --git a/lib/resources/wikibase.RepoApi/wikibase.RepoApi.js 
b/lib/resources/wikibase.RepoApi/wikibase.RepoApi.js
index 21856c4..12edd5b 100644
--- a/lib/resources/wikibase.RepoApi/wikibase.RepoApi.js
+++ b/lib/resources/wikibase.RepoApi/wikibase.RepoApi.js
@@ -243,11 +243,11 @@
        /**
         * Creates a claim.
         *
-        * @param {String} entityId Entity id
-        * @param {Number} baseRevId revision id
-        * @param {string} snaktype The type of the snak
+        * @param {string} entityId Entity id
+        * @param {number} baseRevId revision id
+        * @param {string} snakType The type of the snak
         * @param {string} property Id of the snak's property
-        * @param {object} value The value to set the datavalue of the the main 
snak of the claim to
+        * @param {Object|string} value The value to set the datavalue of the 
claim's main snak to
         * @return {jQuery.Promise}
         */
        createClaim: function( entityId, baseRevId, snakType, property, value ) 
{
@@ -280,6 +280,31 @@
        },
 
        /**
+        * Returns claims of a specific entity by providing an entity id or a 
specific claim by
+        * providing a claim GUID.
+        *
+        * @param {string} entityId Entity id
+        * @param {string} [propertyId] Only return claims featuring this 
property
+        * @param {string} claimGuid GUID of the claim to return. Either 
claimGuid or entityID has to be
+        *        provided.
+        * @param {string} [rank] Only return claims of this rank
+        * @param {string} [props] Optional parts of the claims to return
+        * @return {jQuery.Promise}
+        */
+       getClaims: function( entityId, propertyId, claimGuid, rank, props ) {
+               var params = {
+                       action: 'wbgetclaims',
+                       entity: entityId,
+                       property: propertyId,
+                       claim: claimGuid,
+                       rank: rank,
+                       props: props
+               };
+
+               return this.get( params );
+       },
+
+       /**
         * Changes the Main Snak of an existing claim.
         *
         * @param {String} claimGuid The GUID of the Claim to be changed 
(wb.Claim.getGuid)
diff --git a/lib/tests/qunit/wikibase.RepoApi/wikibase.RepoApi.tests.js 
b/lib/tests/qunit/wikibase.RepoApi/wikibase.RepoApi.tests.js
index f1f4eb5..488a70c 100644
--- a/lib/tests/qunit/wikibase.RepoApi/wikibase.RepoApi.tests.js
+++ b/lib/tests/qunit/wikibase.RepoApi/wikibase.RepoApi.tests.js
@@ -37,11 +37,11 @@
        var qkey = 'asyncTests';
 
        /**
-        * Since jQuery.queue does not allow passing parameters, this variable 
will cache an entity's.
-        * data structure.
+        * Since jQuery.queue does not allow passing parameters, this variable 
will cache the data
+        * structures of entities.
         * @var {Object}
         */
-       var entity = null;
+       var entityStack = [];
 
        /**
         * Triggers running the tests attached to the test queue.
@@ -71,30 +71,41 @@
        /**
         * Creates an entity via the API.
         *
-        * @param {Object} [data] Stringified JSON representing the item content
+        * @param {string} [entityType] Either "item" or "property"
+        * @param {Object} [data] Stringified JSON representing the entity 
content
         */
-       var createItem = function( data ) {
+       var createEntity = function( entityType, data ) {
                data = data || {};
 
-               api.createEntity( 'item', data ).done( function( response ) {
+               api.createEntity( entityType, data ).done( function( response ) 
{
                        QUnit.assert.equal(
                                response.success,
                                1,
-                               'Created item.'
+                               'Created ' + entityType + '.'
                        );
-                       entity = response.entity;
+                       entityStack.push( response.entity );
                        testrun.dequeue( qkey );
                } ).fail( onFail );
        };
 
-
-       QUnit.module( 'wikibase.RepoApi', QUnit.newWbEnvironment() );
+       QUnit.module( 'wikibase.RepoApi', QUnit.newWbEnvironment( {
+               teardown: function() {
+                       entityStack = [];
+               }
+       } ) );
 
        // This test does nothing more than creating an empty entity. It would 
not need to invoke a
        // queue but can be used as basic template for creating other API tests.
        QUnit.test( 'Create an empty entity', function( assert ) {
-               testrun.queue( qkey, function() { createItem(); } );
+               testrun.queue( qkey, function() { createEntity( 'item' ); } );
                // testrun.queue( qkey, function() { ...; testrun.dequeue( qkey 
); } );
+               runTest();
+       } );
+
+       QUnit.test( 'Create an empty property', function( assert ) {
+               testrun.queue( qkey, function() {
+                       createEntity( 'property', { datatype: 'string' } );
+               } );
                runTest();
        } );
 
@@ -106,7 +117,7 @@
                        } }
                };
 
-               testrun.queue( qkey, function() { createItem( data ); } );
+               testrun.queue( qkey, function() { createEntity( 'item', data ); 
} );
 
                testrun.queue( qkey, function() {
                        api.searchEntities( data.labels.de.value, 
data.labels.de.language, 'item', 2, 0 )
@@ -132,9 +143,11 @@
        });
 
        QUnit.test( 'Edit an entity', function( assert ) {
-               testrun.queue( qkey, function() { createItem(); } );
+               testrun.queue( qkey, function() { createEntity( 'item' ); } );
 
                testrun.queue( qkey, function() {
+                       var entity = entityStack[0];
+
                        var data = {
                                labels: {
                                        de: {
@@ -171,6 +184,86 @@
 
        } );
 
+       QUnit.test( 'Create a claim (string value)', function( assert ) {
+
+               testrun.queue( qkey, function() { createEntity( 'item' ); } );
+               testrun.queue( qkey, function() { createEntity( 'property', { 
datatype: 'string' } ); } );
+
+               testrun.queue( qkey, function() {
+                       var entity = entityStack[0],
+                               property = entityStack[1];
+
+                       api.createClaim(
+                               entity.id,
+                               entity.lastrevid,
+                               'value',
+                               property.id,
+                               'This claim is true'
+                       ).done( function( response ) {
+
+                               assert.equal(
+                                       response.claim.mainsnak.property,
+                                       property.id,
+                                       'Verified claim\'s property id.'
+                               );
+
+                               testrun.dequeue( qkey );
+
+                       } ).fail( onFail );
+
+               } );
+
+               runTest();
+
+       } );
+
+       QUnit.test( 'Get claim (string value)', function( assert ) {
+
+               var answer = '42', entity, property;
+
+               testrun.queue( qkey, function() { createEntity( 'item' ); } );
+               testrun.queue( qkey, function() { createEntity( 'property', { 
datatype: 'string' } ); } );
+
+               testrun.queue( qkey, function() {
+                       entity = entityStack[0];
+                       property = entityStack[1];
+
+                       api.createClaim(
+                               entity.id,
+                               entity.lastrevid,
+                               'value',
+                               property.id,
+                               answer
+                       ).done( function( response ) {
+                               testrun.dequeue( qkey );
+                       } ).fail( onFail );
+
+               } );
+
+               testrun.queue( qkey, function() {
+                       api.getClaims( entity.id, property.id ).done( function( 
response ) {
+
+                               assert.ok(
+                                       property.id in response.claims,
+                                       'Claim data for given property found.'
+                               );
+
+                               assert.equal(
+                                       
response.claims[property.id][0].mainsnak.datavalue.value,
+                                       answer,
+                                       'Claim value verified.'
+                               );
+
+                               testrun.dequeue( qkey );
+
+                       } ).fail( onFail );
+
+               } );
+
+               runTest();
+
+       } );
+
        /**
         * Will test the RepoApi's function to set one of the multilingual 
basic values, e.g. label or
         * description.
@@ -180,13 +273,16 @@
         * @param {string} apiFnName The name of the wb.RepoApi function to set 
the value
         */
        function testSetBasicMultiLingualValue( assert, type, apiFnName ) {
-               var typesApiPropName = type + 's', // API uses plural form of 
the type: 'label' -> 'labels'
+               var entity,
+                       typesApiPropName = type + 's', // API uses plural form 
of the type: 'label' -> 'labels'
                        language = 'en',
                        value = language + '-' + type; // could be anything 
really
 
-               testrun.queue( qkey, function() { createItem(); } );
+               testrun.queue( qkey, function() { createEntity( 'item' ); } );
 
                testrun.queue( qkey, function() {
+                       entity = entityStack[0];
+
                        api[ apiFnName ](
                                entity.id, entity.lastrevid, value, language
                        ).done( function( response ) {
@@ -284,7 +380,7 @@
                        }
                };
 
-               testrun.queue( qkey, function() { createItem(); } );
+               testrun.queue( qkey, function() { createEntity( 'item' ); } );
 
                testrun.queue( qkey, function() {
                        api.setSitelink(
@@ -373,11 +469,11 @@
        } );
 */
        QUnit.test( 'Set aliases', function( assert ) {
-               testrun.queue( qkey, function() { createItem(); } );
+               testrun.queue( qkey, function() { createEntity( 'item' ); } );
 
                testrun.queue( qkey, function() {
                        api.setAliases(
-                               entity.id, entity.lastrevid, [ 'alias1', 
'alias2' ], [], 'en'
+                               entityStack[0].id, entityStack[0].lastrevid, [ 
'alias1', 'alias2' ], [], 'en'
                        ).done( function( response ) {
 
                                assert.deepEqual(
@@ -395,7 +491,7 @@
 
                testrun.queue( qkey, function() {
                        api.setAliases(
-                               entity.id, entity.lastrevid, [ 'alias1', 
'alias2' ], [], 'doesnotexist'
+                               entityStack[0].id, entityStack[0].lastrevid, [ 
'alias1', 'alias2' ], [], 'doesnotexist'
                        ).done( function( response ) {
 
                                assert.ok(
@@ -419,7 +515,7 @@
 /*
                testrun.queue( qkey, function() {
                        api.setAliases(
-                               entity.id, entity.lastrevid, 'alias3', 
'alias1', 'en'
+                               entityStack[0].id, entityStack[0].lastrevid, 
'alias3', 'alias1', 'en'
                        ).done( function( response ) {
 
                                assert.deepEqual(
@@ -437,7 +533,7 @@
 
                testrun.queue( qkey, function() {
                        api.setAliases(
-                               entity.id, entity.lastrevid, '', [ 'alias2', 
'alias3' ], 'en'
+                               entityStack[0].id, entityStack[0].lastrevid, 
'', [ 'alias2', 'alias3' ], 'en'
                        ).done( function( response ) {
 
                                assert.equal(
diff --git a/repo/includes/api/GetClaims.php b/repo/includes/api/GetClaims.php
index 68ca8cc..c7fa9aa 100644
--- a/repo/includes/api/GetClaims.php
+++ b/repo/includes/api/GetClaims.php
@@ -250,7 +250,7 @@
         */
        public function getParamDescription() {
                return array(
-                       'entity' => 'Id of the entity from which to obtain 
claims. Required unless key is provided.',
+                       'entity' => 'Id of the entity from which to obtain 
claims. Required unless claim GUID is provided.',
                        'property' => 'Optional filter to only return claims 
with a main snak that has the specified property.',
                        'claim' => 'A GUID identifying the claim. Required 
unless entity is provided.',
                        'rank' => 'Optional filter to return only the claims 
that have the specified rank',

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id25b789ff605b655b4e467fdc20a2b6c643980cc
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: LivingShadow <simon...@gmail.com>
Gerrit-Reviewer: Daniel Werner <daniel.wer...@wikimedia.de>
Gerrit-Reviewer: Henning Snater <henning.sna...@wikimedia.de>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to