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

Change subject: Implement Api ResultBuilder and basic tests
......................................................................


Implement Api ResultBuilder and basic tests

This takes the logic of adding bits of entities to
results out of the API base and puts it in its own
result builder class.

Change-Id: Ic25fcef8632952266d9c9768944b03bb8636c6cb
---
M repo/Wikibase.classes.php
M repo/includes/api/ApiWikibase.php
A repo/includes/api/ResultBuilder.php
A repo/tests/phpunit/includes/api/ResultBuilderTest.php
4 files changed, 483 insertions(+), 156 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/Wikibase.classes.php b/repo/Wikibase.classes.php
index de62de9..8665b86 100644
--- a/repo/Wikibase.classes.php
+++ b/repo/Wikibase.classes.php
@@ -108,6 +108,7 @@
                'Wikibase\Api\SnakValidationHelper' => 
'includes/api/SnakValidationHelper.php',
                'Wikibase\Api\ModifyClaim' => 'includes/api/ModifyClaim.php',
                'Wikibase\Api\ClaimModificationHelper' => 
'includes/api/ClaimModificationHelper.php',
+               'Wikibase\Api\ResultBuilder' => 
'includes/api/ResultBuilder.php',
 
                // includes/serializers
                'Wikibase\Serializers\EntityRevisionSerializer' => 
'includes/serializers/EntityRevisionSerializer.php',
diff --git a/repo/includes/api/ApiWikibase.php 
b/repo/includes/api/ApiWikibase.php
index a4926f3..e6c88e7 100644
--- a/repo/includes/api/ApiWikibase.php
+++ b/repo/includes/api/ApiWikibase.php
@@ -2,6 +2,8 @@
 
 namespace Wikibase\Api;
 
+use Revision;
+use Title;
 use User, Status, ApiBase;
 use Wikibase\Claims;
 use Wikibase\DataModel\SimpleSiteLink;
@@ -17,6 +19,7 @@
 use Wikibase\Lib\Serializers\SiteLinkSerializer;
 use Wikibase\Lib\Serializers\SerializationOptions;
 use Wikibase\Summary;
+use WikiPage;
 
 /**
  * Base class for API modules
@@ -104,166 +107,37 @@
                return 'https://www.mediawiki.org/wiki/Extension:Wikibase/API#' 
. $this->getModuleName();
        }
 
-       /**
-        * Get serialized aliases and add them to result
-        *
-        * @since 0.4
-        *
-        * @param array $aliases the aliases to set in the result
-        * @param array|string $path where the data is located
-        * @param string $name name used for the entry
-        * @param string $tag tag used for indexed entries in xml formats and 
similar
-        *
-        */
+       /** @deprecated */
        protected function addAliasesToResult( array $aliases, $path, $name = 
'aliases', $tag = 'alias' ) {
-               $options = new SerializationOptions();
-               $options->setIndexTags( $this->getResult()->getIsRawMode() );
-               $aliasSerializer = new AliasSerializer( $options );
-               $value = $aliasSerializer->getSerialized( $aliases );
-
-               if ( $value !== array() ) {
-                       if ( $this->getResult()->getIsRawMode() ) {
-                               $this->getResult()->setIndexedTagName( $value, 
$tag );
-                       }
-                       $this->getResult()->addValue( $path, $name, $value );
-               }
-
+               $builder = new ResultBuilder( $this->getResult() );
+               $builder->addAliases( $aliases, $path, $name, $tag );
        }
-
-       /**
-        * Get serialized sitelinks and add them to result
-        *
-        * @since 0.4
-        *
-        * @param array $siteLinks the site links to insert in the result, as 
SiteLink objects
-        * @param array|string $path where the data is located
-        * @param string $name name used for the entry
-        * @param string $tag tag used for indexed entries in xml formats and 
similar
-        * @param array $options additional information to include in the 
listelinks structure. For example:
-        *              * 'url' will include the full URL of the sitelink in 
the result
-        *              * 'removed' will mark the sitelinks as removed
-        *
-        */
+       /** @deprecated */
        protected function addSiteLinksToResult( array $siteLinks, $path, $name 
= 'sitelinks', $tag = 'sitelink', $options = null ) {
-               $serializerOptions = new SerializationOptions();
-               $serializerOptions->setOption( 
EntitySerializer::OPT_SORT_ORDER, EntitySerializer::SORT_NONE );
-               $serializerOptions->setIndexTags( 
$this->getResult()->getIsRawMode() );
-
-               if ( isset( $options ) ) {
-                       if ( in_array( EntitySerializer::SORT_ASC, $options ) ) 
{
-                               $serializerOptions->setOption( 
EntitySerializer::OPT_SORT_ORDER, EntitySerializer::SORT_ASC );
-                       } elseif ( in_array( EntitySerializer::SORT_DESC, 
$options ) ) {
-                               $serializerOptions->setOption( 
EntitySerializer::OPT_SORT_ORDER, EntitySerializer::SORT_DESC );
-                       }
-
-                       if ( in_array( 'url', $options ) ) {
-                               $serializerOptions->addToOption( 
EntitySerializer::OPT_PARTS, "sitelinks/urls" );
-                       }
-
-                       if ( in_array( 'removed', $options ) ) {
-                               $serializerOptions->addToOption( 
EntitySerializer::OPT_PARTS, "sitelinks/removed" );
-                       }
-               }
-
-               $siteStore = \SiteSQLStore::newInstance();
-               $siteLinkSerializer = new SiteLinkSerializer( 
$serializerOptions, $siteStore );
-               $value = $siteLinkSerializer->getSerialized( $siteLinks );
-
-               if ( $value !== array() ) {
-                       if ( $this->getResult()->getIsRawMode() ) {
-                               $this->getResult()->setIndexedTagName( $value, 
$tag );
-                       }
-
-                       $this->getResult()->addValue( $path, $name, $value );
-               }
+               $builder = new ResultBuilder( $this->getResult() );
+               $builder->addSiteLinks( $siteLinks, $path, $name, $tag, 
$options );
        }
-
-       /**
-        * Get serialized descriptions and add them to result
-        *
-        * @since 0.4
-        *
-        * @param array $descriptions the descriptions to insert in the result
-        * @param array|string $path where the data is located
-        * @param string $name name used for the entry
-        * @param string $tag tag used for indexed entries in xml formats and 
similar
-        *
-        */
+       /** @deprecated */
        protected function addDescriptionsToResult( array $descriptions, $path, 
$name = 'descriptions', $tag = 'description' ) {
-               $options = new SerializationOptions();
-               $options->setIndexTags( $this->getResult()->getIsRawMode() );
-               $descriptionSerializer = new DescriptionSerializer( $options );
-
-               $value = $descriptionSerializer->getSerialized( $descriptions );
-
-               if ( $value !== array() ) {
-                       if ( $this->getResult()->getIsRawMode() ) {
-                               $this->getResult()->setIndexedTagName( $value, 
$tag );
-                       }
-
-                       $this->getResult()->addValue( $path, $name, $value );
-               }
+               $builder = new ResultBuilder( $this->getResult() );
+               $builder->addDescriptions( $descriptions, $path, $name, $tag );
        }
-
-       /**
-        * Get serialized labels and add them to result
-        *
-        * @since 0.4
-        *
-        * @param array $labels the labels to set in the result
-        * @param array|string $path where the data is located
-        * @param string $name name used for the entry
-        * @param string $tag tag used for indexed entries in xml formats and 
similar
-        *
-        */
+       /** @deprecated */
        protected function addLabelsToResult( array $labels, $path, $name = 
'labels', $tag = 'label' ) {
-               $options = new SerializationOptions();
-               $options->setIndexTags( $this->getResult()->getIsRawMode() );
-               $labelSerializer = new LabelSerializer( $options );
-
-               $value = $labelSerializer->getSerialized( $labels );
-
-               if ( $value !== array() ) {
-                       if ( $this->getResult()->getIsRawMode() ) {
-                               $this->getResult()->setIndexedTagName( $value, 
$tag );
-                       }
-
-                       $this->getResult()->addValue( $path, $name, $value );
-               }
+               $builder = new ResultBuilder( $this->getResult() );
+               $builder->addLabels( $labels, $path, $name, $tag );
        }
-
-       /**
-        * Get serialized claims and add them to result
-        *
-        * @since 0.5
-        *
-        * @param array $claims the labels to set in the result
-        * @param array|string $path where the data is located
-        * @param string $name name used for the entry
-        * @param string $tag tag used for indexed entries in xml formats and 
similar
-        *
-        */
+       /** @deprecated */
        protected function addClaimsToResult( array $claims, $path, $name = 
'claims', $tag = 'claim' ) {
-               $options = new SerializationOptions();
-               $options->setIndexTags( $this->getResult()->getIsRawMode() );
-               $claimSerializer = new ClaimsSerializer( $options );
-
-               $value = $claimSerializer->getSerialized( new Claims( $claims ) 
);
-
-               if ( $value !== array() ) {
-                       if ( $this->getResult()->getIsRawMode() ) {
-                               $this->getResult()->setIndexedTagName( $value, 
$tag );
-                       }
-
-                       $this->getResult()->addValue( $path, $name, $value );
-               }
+               $builder = new ResultBuilder( $this->getResult() );
+               $builder->addClaims( $claims, $path, $name, $tag );
        }
 
        /**
         * Returns the permissions that are required to perform the operation 
specified by
         * the parameters.
         *
-        * @param \Wikibase\EntityContent $entityContent the entityContent to 
check permissions for
+        * @param EntityContent $entityContent the entityContent to check 
permissions for
         * @param $params array of arguments for the module, describing the 
operation to be performed
         *
         * @return \Status the check's result
@@ -281,7 +155,7 @@
        /**
         * Check the rights for the user accessing the module.
         *
-        * @param $entityContent \Wikibase\EntityContent the entity to check
+        * @param $entityContent EntityContent the entity to check
         * @param $user User doing the action
         * @param $params array of arguments for the module, passed for 
ModifyItem
         *
@@ -333,25 +207,25 @@
         *
         * @since 0.3
         *
-        * @param \Title   $title   : the title of the page to load the 
revision for
+        * @param Title   $title   : the title of the page to load the revision 
for
         * @param bool|int $revId   : the revision to load. If not given, the 
current revision will be loaded.
         * @param int      $audience
-        * @param \User    $user
+        * @param User $user
         * @param int      $audience: the audience to load this for, see 
Revision::FOR_XXX constants and
         *                          Revision::getContent().
-        * @param \User    $user    : the user to consider if $audience == 
Revision::FOR_THIS_USER
+        * @param User $user    : the user to consider if $audience == 
Revision::FOR_THIS_USER
         *
-        * @return \Wikibase\EntityContent the revision's content.
+        * @return EntityContent the revision's content.
         */
-       protected function loadEntityContent( \Title $title, $revId = false,
-               $audience = \Revision::FOR_PUBLIC,
-               \User $user = null
+       protected function loadEntityContent( Title $title, $revId = false,
+               $audience = Revision::FOR_PUBLIC,
+               User $user = null
        ) {
                if ( $revId === null || $revId === false || $revId === 0 ) {
-                       $page = \WikiPage::factory( $title );
+                       $page = WikiPage::factory( $title );
                        $content = $page->getContent( $audience, $user );
                } else {
-                       $revision = \Revision::newFromId( $revId );
+                       $revision = Revision::newFromId( $revId );
 
                        if ( !$revision ) {
                                $this->dieUsage( "Revision not found: $revId", 
'nosuchrevid' );
@@ -673,7 +547,7 @@
        protected function addRevisionIdFromStatusToResult( $path, $name, 
Status $status ) {
                $statusValue = $status->getValue();
 
-               /* @var \Revision $revision */
+               /* @var Revision $revision */
                $revision = isset( $statusValue['revision'] )
                        ? $statusValue['revision'] : null;
 
diff --git a/repo/includes/api/ResultBuilder.php 
b/repo/includes/api/ResultBuilder.php
new file mode 100644
index 0000000..0a6aafe
--- /dev/null
+++ b/repo/includes/api/ResultBuilder.php
@@ -0,0 +1,217 @@
+<?php
+
+namespace Wikibase\Api;
+
+use ApiResult;
+use InvalidArgumentException;
+use SiteSQLStore;
+use Wikibase\Claims;
+use Wikibase\Lib\Serializers\AliasSerializer;
+use Wikibase\Lib\Serializers\ClaimsSerializer;
+use Wikibase\Lib\Serializers\DescriptionSerializer;
+use Wikibase\Lib\Serializers\EntitySerializer;
+use Wikibase\Lib\Serializers\LabelSerializer;
+use Wikibase\Lib\Serializers\SerializationOptions;
+use Wikibase\Lib\Serializers\SiteLinkSerializer;
+
+/**
+ * Builder for Api Results
+ *
+ * @since 0.5
+ *
+ * @licence GNU GPL v2+
+ * @author Adam Shorland
+ */
+class ResultBuilder {
+
+       /**
+        * @var ApiResult
+        */
+       protected $result;
+
+       /**
+        * @var int
+        */
+       protected $missingEntityCounter;
+
+       public function __construct( $result ) {
+               if( !$result instanceof ApiResult ){
+                       throw new InvalidArgumentException( 'Result builder 
must be constructed with an ApiWikibase' );
+               }
+
+               $this->result = $result;
+               $this->missingEntityCounter = -1;
+       }
+
+       private function getResult(){
+               return $this->result;
+       }
+
+       /**
+        * @since 0.5
+        *
+        * @param $success bool|int|null
+        *
+        * @throws InvalidArgumentException
+        */
+       public function markSuccess( $success ) {
+               $value = intval( $success );
+               if( $value !== 1 && $value !== 0 ){
+                       throw new InvalidArgumentException( '$wasSuccess must 
evaluate to either 1 or 0 when using intval()' );
+               }
+               $this->result->addValue( null, 'success', $value );
+       }
+
+       /**
+        * Get serialized labels and add them to result
+        *
+        * @since 0.5
+        *
+        * @param array $labels the labels to set in the result
+        * @param array|string $path where the data is located
+        * @param string $name name used for the entry
+        * @param string $tag tag used for indexed entries in xml formats and 
similar
+        *
+        */
+       public function addLabels( array $labels, $path, $name = 'labels', $tag 
= 'label' ) {
+               $options = new SerializationOptions();
+               $options->setIndexTags( $this->getResult()->getIsRawMode() );
+               $labelSerializer = new LabelSerializer( $options );
+
+               $value = $labelSerializer->getSerialized( $labels );
+
+               if ( $value !== array() ) {
+                       if ( $this->getResult()->getIsRawMode() ) {
+                               $this->getResult()->setIndexedTagName( $value, 
$tag );
+                       }
+
+                       $this->getResult()->addValue( $path, $name, $value );
+               }
+       }
+
+       /**
+        * Get serialized descriptions and add them to result
+        *
+        * @since 0.5
+        *
+        * @param array $descriptions the descriptions to insert in the result
+        * @param array|string $path where the data is located
+        * @param string $name name used for the entry
+        * @param string $tag tag used for indexed entries in xml formats and 
similar
+        *
+        */
+       public function addDescriptions( array $descriptions, $path, $name = 
'descriptions', $tag = 'description' ) {
+               $options = new SerializationOptions();
+               $options->setIndexTags( $this->getResult()->getIsRawMode() );
+               $descriptionSerializer = new DescriptionSerializer( $options );
+
+               $value = $descriptionSerializer->getSerialized( $descriptions );
+
+               if ( $value !== array() ) {
+                       if ( $this->getResult()->getIsRawMode() ) {
+                               $this->getResult()->setIndexedTagName( $value, 
$tag );
+                       }
+
+                       $this->getResult()->addValue( $path, $name, $value );
+               }
+       }
+
+       /**
+        * Get serialized aliases and add them to result
+        *
+        * @since 0.5
+        *
+        * @param array $aliases the aliases to set in the result
+        * @param array|string $path where the data is located
+        * @param string $name name used for the entry
+        * @param string $tag tag used for indexed entries in xml formats and 
similar
+        *
+        */
+       public function addAliases( array $aliases, $path, $name = 'aliases', 
$tag = 'alias' ) {
+               $options = new SerializationOptions();
+               $options->setIndexTags( $this->getResult()->getIsRawMode() );
+               $aliasSerializer = new AliasSerializer( $options );
+               $value = $aliasSerializer->getSerialized( $aliases );
+
+               if ( $value !== array() ) {
+                       if ( $this->getResult()->getIsRawMode() ) {
+                               $this->getResult()->setIndexedTagName( $value, 
$tag );
+                       }
+                       $this->getResult()->addValue( $path, $name, $value );
+               }
+
+       }
+
+       /**
+        * Get serialized sitelinks and add them to result
+        *
+        * @since 0.5
+        *
+        * @param array $siteLinks the site links to insert in the result, as 
SiteLink objects
+        * @param array|string $path where the data is located
+        * @param string $name name used for the entry
+        * @param string $tag tag used for indexed entries in xml formats and 
similar
+        * @param $options
+        */
+       public function addSiteLinks( array $siteLinks, $path, $name = 
'sitelinks', $tag = 'sitelink', $options ) {
+               $serializerOptions = new SerializationOptions();
+               $serializerOptions->setOption( 
EntitySerializer::OPT_SORT_ORDER, EntitySerializer::SORT_NONE );
+               $serializerOptions->setIndexTags( 
$this->getResult()->getIsRawMode() );
+
+               if ( isset( $options ) ) {
+                       if ( in_array( EntitySerializer::SORT_ASC, $options ) ) 
{
+                               $serializerOptions->setOption( 
EntitySerializer::OPT_SORT_ORDER, EntitySerializer::SORT_ASC );
+                       } elseif ( in_array( EntitySerializer::SORT_DESC, 
$options ) ) {
+                               $serializerOptions->setOption( 
EntitySerializer::OPT_SORT_ORDER, EntitySerializer::SORT_DESC );
+                       }
+
+                       if ( in_array( 'url', $options ) ) {
+                               $serializerOptions->addToOption( 
EntitySerializer::OPT_PARTS, "sitelinks/urls" );
+                       }
+
+                       if ( in_array( 'removed', $options ) ) {
+                               $serializerOptions->addToOption( 
EntitySerializer::OPT_PARTS, "sitelinks/removed" );
+                       }
+               }
+
+               $siteStore = \SiteSQLStore::newInstance();
+               $siteLinkSerializer = new SiteLinkSerializer( 
$serializerOptions, $siteStore );
+               $value = $siteLinkSerializer->getSerialized( $siteLinks );
+
+               if ( $value !== array() ) {
+                       if ( $this->getResult()->getIsRawMode() ) {
+                               $this->getResult()->setIndexedTagName( $value, 
$tag );
+                       }
+
+                       $this->getResult()->addValue( $path, $name, $value );
+               }
+       }
+
+       /**
+        * Get serialized claims and add them to result
+        *
+        * @since 0.5
+        *
+        * @param array $claims the labels to set in the result
+        * @param array|string $path where the data is located
+        * @param string $name name used for the entry
+        * @param string $tag tag used for indexed entries in xml formats and 
similar
+        *
+        */
+       public function addClaims( array $claims, $path, $name = 'claims', $tag 
= 'claim' ) {
+               $options = new SerializationOptions();
+               $options->setIndexTags( $this->getResult()->getIsRawMode() );
+               $claimSerializer = new ClaimsSerializer( $options );
+
+               $value = $claimSerializer->getSerialized( new Claims( $claims ) 
);
+
+               if ( $value !== array() ) {
+                       if ( $this->getResult()->getIsRawMode() ) {
+                               $this->getResult()->setIndexedTagName( $value, 
$tag );
+                       }
+
+                       $this->getResult()->addValue( $path, $name, $value );
+               }
+       }
+
+}
\ No newline at end of file
diff --git a/repo/tests/phpunit/includes/api/ResultBuilderTest.php 
b/repo/tests/phpunit/includes/api/ResultBuilderTest.php
new file mode 100644
index 0000000..f3d00c1
--- /dev/null
+++ b/repo/tests/phpunit/includes/api/ResultBuilderTest.php
@@ -0,0 +1,235 @@
+<?php
+
+namespace Wikibase\Test\Api;
+
+use ApiResult;
+use DataValues\StringValue;
+use PHPUnit_Framework_TestCase;
+use Wikibase\Api\ResultBuilder;
+use Wikibase\Claim;
+use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\DataModel\SimpleSiteLink;
+use Wikibase\PropertyValueSnak;
+
+/**
+ * @covers Wikibase\Api\ResultBuilder
+ * @todo mock and inject serializers to avoid massive expected output
+ *
+ * @licence GNU GPL v2+
+ * @author Adam Shorland
+ */
+class ResultBuilderTest extends PHPUnit_Framework_TestCase {
+
+       protected function getDefaultResult(){
+               $apiMain =  $this->getMockBuilder( 'ApiMain' 
)->disableOriginalConstructor()->getMockForAbstractClass();
+               return new ApiResult( $apiMain );
+       }
+
+       public function testCanConstruct(){
+               $resultBuilder = new ResultBuilder( $this->getDefaultResult() );
+               $this->assertInstanceOf( '\Wikibase\Api\ResultBuilder', 
$resultBuilder );
+       }
+
+       /**
+        * @dataProvider provideBadConstructionData
+        */
+       public function testBadConstruction( $result ){
+               $this->setExpectedException( 'InvalidArgumentException' );
+               new ResultBuilder( $result );
+       }
+
+       public static function provideBadConstructionData() {
+               return array(
+                       array( null ),
+                       array( 1234 ),
+                       array( "imastring" ),
+                       array( array() ),
+               );
+       }
+
+       /**
+        * @dataProvider provideMarkResultSuccess
+        */
+       public function testMarkResultSuccess( $param, $expected ){
+               $result = $this->getDefaultResult();
+               $resultBuilder = new ResultBuilder( $result );
+               $resultBuilder->markSuccess( $param );
+               $this->assertEquals( array( 'success' => $expected ),  
$result->getData() );
+       }
+
+       public static function provideMarkResultSuccess() {
+               return array( array( true, 1 ), array( 1, 1 ), array( false, 0 
), array( 0, 0 ), array( null, 0 ) );
+       }
+
+       /**
+        * @dataProvider provideMarkResultSuccessExceptions
+        */
+       public function testMarkResultSuccessExceptions( $param ){
+               $this->setExpectedException( 'InvalidArgumentException' );
+               $result = $this->getDefaultResult();
+               $resultBuilder = new ResultBuilder( $result );
+               $resultBuilder->markSuccess( $param );
+       }
+
+       public static function provideMarkResultSuccessExceptions() {
+               return array( array( 3 ), array( -1 ) );
+       }
+
+       public function testAddLabels(){
+               $result = $this->getDefaultResult();
+               $labels = array( 'en' => 'foo', 'de' => 'bar' );
+               $path = array( 'entities', 'Q1' );
+               $expected = array(
+                       'entities' => array(
+                               'Q1' => array(
+                                       'labels' => array(
+                                               'en' => array(
+                                                       'language' => 'en',
+                                                       'value' => 'foo',
+                                               ),
+                                               'de' => array(
+                                                       'language' => 'de',
+                                                       'value' => 'bar',
+                                               ),
+                                       ),
+                               ),
+                       ),
+               );
+
+               $resultBuilder = new ResultBuilder( $result );
+               $resultBuilder->addLabels( $labels, $path );
+
+               $this->assertEquals( $expected, $result->getData() );
+       }
+
+       public function testAddDescriptions(){
+               $result = $this->getDefaultResult();
+               $descriptions = array( 'en' => 'foo', 'de' => 'bar' );
+               $path = array( 'entities', 'Q1' );
+               $expected = array(
+                       'entities' => array(
+                               'Q1' => array(
+                                       'descriptions' => array(
+                                               'en' => array(
+                                                       'language' => 'en',
+                                                       'value' => 'foo',
+                                               ),
+                                               'de' => array(
+                                                       'language' => 'de',
+                                                       'value' => 'bar',
+                                               ),
+                                       ),
+                               ),
+                       ),
+               );
+
+               $resultBuilder = new ResultBuilder( $result );
+               $resultBuilder->addDescriptions( $descriptions, $path );
+
+               $this->assertEquals( $expected, $result->getData() );
+       }
+
+       public function testAddAliases(){
+               $result = $this->getDefaultResult();
+               $aliases = array( 'en' => array( 'boo', 'hoo' ), 'de' => array( 
'ham', 'cheese' ) );
+               $path = array( 'entities', 'Q1' );
+               $expected = array(
+                       'entities' => array(
+                               'Q1' => array(
+                                       'aliases' => array(
+                                               'en' => array(
+                                                       array(
+                                                               'language' => 
'en',
+                                                               'value' => 
'boo',
+                                                       ),
+                                                       array(
+                                                               'language' => 
'en',
+                                                               'value' => 
'hoo',
+                                                       ),
+                                               ),
+                                               'de' => array(
+                                                       array(
+                                                               'language' => 
'de',
+                                                               'value' => 
'ham',
+                                                       ),
+                                                       array(
+                                                               'language' => 
'de',
+                                                               'value' => 
'cheese',
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       ),
+               );
+
+               $resultBuilder = new ResultBuilder( $result );
+               $resultBuilder->addAliases( $aliases, $path );
+
+               $this->assertEquals( $expected, $result->getData() );
+       }
+
+       public function testAddSiteLinks(){
+               $result = $this->getDefaultResult();
+               $sitelinks = array( new SimpleSiteLink( 'enwiki', 
'User:Addshore' ), new SimpleSiteLink( 'dewikivoyage', 'Berlin' ) );
+               $path = array( 'entities', 'Q1' );
+               $expected = array(
+                       'entities' => array(
+                               'Q1' => array(
+                                       'sitelinks' => array(
+                                               'enwiki' => array(
+                                                       'site' => 'enwiki',
+                                                       'title' => 
'User:Addshore',
+                                                       'badges' => array(),
+                                               ),
+                                               'dewikivoyage' => array(
+                                                       'site' => 
'dewikivoyage',
+                                                       'title' => 'Berlin',
+                                                       'badges' => array(),
+                                               ),
+                                       ),
+                               ),
+                       ),
+               );
+
+               $resultBuilder = new ResultBuilder( $result );
+               $resultBuilder->addSiteLinks( $sitelinks, $path );
+
+               $this->assertEquals( $expected, $result->getData() );
+       }
+
+       public function testAddClaims(){
+               $result = $this->getDefaultResult();
+               $claim1 = new Claim( new PropertyValueSnak( new PropertyId( 
'P12' ), new StringValue( 'stringVal' ) ) );
+               $claim1->setGuid( 'fooguidbar' );
+               $claims = array( $claim1 );
+               $path = array( 'entities', 'Q1' );
+               $expected = array(
+                       'entities' => array(
+                               'Q1' => array(
+                                       'claims' => array(
+                                               'P12' => array(
+                                                       array(
+                                                               'id' => 
'fooguidbar',
+                                                               'mainsnak' => 
array(
+                                                                       
'snaktype' => 'value',
+                                                                       
'property' => 'P12',
+                                                                       
'datavalue' => array(
+                                                                               
'value' => 'stringVal',
+                                                                               
'type' => 'string',
+                                                                       ),
+                                                               ),
+                                                               'type' => 
'claim',
+                                                       )
+                                               )
+                                       ),
+                               ),
+                       ),
+               );
+
+               $resultBuilder = new ResultBuilder( $result );
+               $resultBuilder->addClaims( $claims, $path );
+
+               $this->assertEquals( $expected, $result->getData() );
+       }
+
+}
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic25fcef8632952266d9c9768944b03bb8636c6cb
Gerrit-PatchSet: 13
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[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