Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/386422 )

Change subject: Introduce EntityByTitleLookup for use by EntityByTitleHelper 
and EntityLoadingHelper.
......................................................................

Introduce EntityByTitleLookup for use by EntityByTitleHelper and 
EntityLoadingHelper.

EntityByTitleLookup replaces SiteLinkLookup in this context, to provide a more 
narrow interface
that can more easily be used with alternative implementations.

Background: We want to be able to address MediaInfo entities via the name of 
the file page.

Bug: T177022
Change-Id: Ia43ebfa2449c10dc5c391a5d122e4ed989d7fc1d
---
A lib/includes/Store/EntityByTitleLookup.php
M lib/includes/Store/HashSiteLinkStore.php
M lib/includes/Store/SiteLinkStore.php
M lib/includes/Store/Sql/SiteLinkTable.php
M lib/tests/phpunit/Store/HashSiteLinkStoreTest.php
M lib/tests/phpunit/Store/Sql/SiteLinkTableTest.php
M repo/includes/Api/ApiHelperFactory.php
R repo/includes/Api/EntityByTitleHelper.php
M repo/includes/Api/EntityLoadingHelper.php
M repo/includes/Api/GetEntities.php
M repo/includes/Store/Sql/SqlStore.php
M repo/includes/Store/Store.php
M repo/includes/WikibaseRepo.php
R repo/tests/phpunit/includes/Api/EntityByTitleHelperTest.php
M repo/tests/phpunit/includes/Api/EntityLoadingHelperTest.php
15 files changed, 178 insertions(+), 79 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/22/386422/1

diff --git a/lib/includes/Store/EntityByTitleLookup.php 
b/lib/includes/Store/EntityByTitleLookup.php
new file mode 100644
index 0000000..3a31fe4
--- /dev/null
+++ b/lib/includes/Store/EntityByTitleLookup.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Wikibase\Lib\Store;
+
+use Wikibase\DataModel\Entity\EntityId;
+
+/**
+ * Service interface for services that allow Entities to be found by page 
title.
+ *
+ * @license GPL-2.0+
+ * @author Daniel Kinzler
+ */
+interface EntityByTitleLookup {
+
+       /**
+        * Returns the id of the entity that associated to the given page title.
+        * How the entity would be associated is not specified by this 
interface.
+        * A typical mechanism would be SiteLinks via the mapping implemented 
by a SiteLinkLookup.
+        *
+        * @param string $globalSiteId
+        * @param string $pageTitle
+        *
+        * @return EntityId|null
+        */
+       public function getEntityIdForLink( $globalSiteId, $pageTitle );
+
+}
diff --git a/lib/includes/Store/HashSiteLinkStore.php 
b/lib/includes/Store/HashSiteLinkStore.php
index a15f1a5..2c8893f 100644
--- a/lib/includes/Store/HashSiteLinkStore.php
+++ b/lib/includes/Store/HashSiteLinkStore.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Lib\Store;
 
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\SiteLink;
@@ -202,4 +203,14 @@
                return $siteLink->getSiteId() . ':' . $siteLink->getPageName();
        }
 
+       /**
+        * @param string $globalSiteId
+        * @param string $pageTitle
+        *
+        * @return EntityId|null
+        */
+       public function getEntityIdForLink( $globalSiteId, $pageTitle ) {
+               return $this->getItemIdForLink( $globalSiteId, $pageTitle );
+       }
+
 }
diff --git a/lib/includes/Store/SiteLinkStore.php 
b/lib/includes/Store/SiteLinkStore.php
index a002365..1512cfa 100644
--- a/lib/includes/Store/SiteLinkStore.php
+++ b/lib/includes/Store/SiteLinkStore.php
@@ -11,7 +11,7 @@
  * @license GPL-2.0+
  * @author Jeroen De Dauw < jeroended...@gmail.com >
  */
-interface SiteLinkStore extends SiteLinkLookup {
+interface SiteLinkStore extends SiteLinkLookup, EntityByTitleLookup {
 
        /**
         * Saves the links for the provided item.
diff --git a/lib/includes/Store/Sql/SiteLinkTable.php 
b/lib/includes/Store/Sql/SiteLinkTable.php
index c5304d5..28f0830 100644
--- a/lib/includes/Store/Sql/SiteLinkTable.php
+++ b/lib/includes/Store/Sql/SiteLinkTable.php
@@ -4,6 +4,7 @@
 
 use DBAccessBase;
 use MWException;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\SiteLink;
@@ -343,4 +344,14 @@
                return $siteLinks;
        }
 
+       /**
+        * @param string $globalSiteId
+        * @param string $pageTitle
+        *
+        * @return EntityId|null
+        */
+       public function getEntityIdForLink( $globalSiteId, $pageTitle ) {
+               return $this->getItemIdForLink( $globalSiteId, $pageTitle );
+       }
+
 }
diff --git a/lib/tests/phpunit/Store/HashSiteLinkStoreTest.php 
b/lib/tests/phpunit/Store/HashSiteLinkStoreTest.php
index 34ba82f..d3e651f 100644
--- a/lib/tests/phpunit/Store/HashSiteLinkStoreTest.php
+++ b/lib/tests/phpunit/Store/HashSiteLinkStoreTest.php
@@ -32,6 +32,19 @@
                $this->assertNull( $siteLinkStore->getItemIdForLink( 'xywiki', 
'Foo' ) );
        }
 
+       public function testGetEntityIdForLink() {
+               $itemId = new ItemId( 'Q900' );
+
+               $item = new Item( $itemId );
+               $item->getSiteLinkList()->addNewSiteLink( 'enwiki', 'Foo' );
+
+               $siteLinkStore = new HashSiteLinkStore();
+               $siteLinkStore->saveLinksOfItem( $item );
+
+               $this->assertEquals( $itemId, 
$siteLinkStore->getEntityIdForLink( 'enwiki', 'Foo' ) );
+               $this->assertNull( $siteLinkStore->getEntityIdForLink( 
'xywiki', 'Foo' ) );
+       }
+
        public function provideGetLinks() {
                $cases = [];
 
diff --git a/lib/tests/phpunit/Store/Sql/SiteLinkTableTest.php 
b/lib/tests/phpunit/Store/Sql/SiteLinkTableTest.php
index ecc8a9d..35e4422a 100644
--- a/lib/tests/phpunit/Store/Sql/SiteLinkTableTest.php
+++ b/lib/tests/phpunit/Store/Sql/SiteLinkTableTest.php
@@ -142,6 +142,19 @@
        /**
         * @dataProvider itemProvider
         */
+       public function testGetEntityIdForLink( Item $item ) {
+               $this->siteLinkTable->saveLinksOfItem( $item );
+               foreach ( $item->getSiteLinkList()->toArray() as $siteLink ) {
+                       $this->assertEquals(
+                               $item->getId(),
+                               $this->siteLinkTable->getEntityIdForLink( 
$siteLink->getSiteId(), $siteLink->getPageName() )
+                       );
+               }
+       }
+
+       /**
+        * @dataProvider itemProvider
+        */
        public function testDeleteLinksOfItem( Item $item ) {
                $this->siteLinkTable->saveLinksOfItem( $item );
                $this->assertTrue(
diff --git a/repo/includes/Api/ApiHelperFactory.php 
b/repo/includes/Api/ApiHelperFactory.php
index 0343696..f0827b4 100644
--- a/repo/includes/Api/ApiHelperFactory.php
+++ b/repo/includes/Api/ApiHelperFactory.php
@@ -13,7 +13,7 @@
 use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\EntityStore;
 use Wikibase\Lib\Store\EntityTitleLookup;
-use Wikibase\Lib\Store\SiteLinkLookup;
+use Wikibase\Lib\Store\EntityByTitleLookup;
 use Wikibase\Repo\Localizer\ExceptionLocalizer;
 use Wikibase\SummaryFormatter;
 
@@ -79,9 +79,9 @@
        private $idParser;
 
        /**
-        * @var SiteLinkLookup|null
+        * @var EntityByTitleLookup|null
         */
-       private $siteLinkLookup;
+       private $entityByTitleLookup;
 
        /**
         * @var EntityFactory|null
@@ -104,7 +104,7 @@
         * @param SerializerFactory $serializerFactory
         * @param Serializer $entitySerializer
         * @param EntityIdParser $idParser
-        * @param SiteLinkLookup|null $siteLinkLookup
+        * @param EntityByTitleLookup|null $entityByTitleLookup
         * @param EntityFactory|null $entityFactory
         * @param EntityStore|null $entityStore
         */
@@ -119,7 +119,7 @@
                SerializerFactory $serializerFactory,
                Serializer $entitySerializer,
                EntityIdParser $idParser,
-               SiteLinkLookup $siteLinkLookup = null,
+               EntityByTitleLookup $entityByTitleLookup = null,
                EntityFactory $entityFactory = null,
                EntityStore $entityStore = null
        ) {
@@ -133,7 +133,7 @@
                $this->serializerFactory = $serializerFactory;
                $this->entitySerializer = $entitySerializer;
                $this->idParser = $idParser;
-               $this->siteLinkLookup = $siteLinkLookup;
+               $this->entityByTitleLookup = $entityByTitleLookup;
                $this->entityFactory = $entityFactory;
                $this->entityStore = $entityStore;
        }
@@ -192,8 +192,8 @@
                        $this->editEntityFactory
                );
 
-               if ( $this->siteLinkLookup ) {
-                       $helper->setSiteLinkLookup( $this->siteLinkLookup );
+               if ( $this->entityByTitleLookup ) {
+                       $helper->setEntityByTitleLookup( 
$this->entityByTitleLookup );
                }
 
                if ( $this->entityFactory ) {
@@ -225,8 +225,8 @@
                        $this->getErrorReporter( $apiBase )
                );
 
-               if ( $this->siteLinkLookup ) {
-                       $helper->setSiteLinkLookup( $this->siteLinkLookup );
+               if ( $this->entityByTitleLookup ) {
+                       $helper->setEntityByTitleLookup( 
$this->entityByTitleLookup );
                }
 
                return $helper;
diff --git a/repo/includes/Api/ItemByTitleHelper.php 
b/repo/includes/Api/EntityByTitleHelper.php
similarity index 77%
rename from repo/includes/Api/ItemByTitleHelper.php
rename to repo/includes/Api/EntityByTitleHelper.php
index 1f57da4..878665d 100644
--- a/repo/includes/Api/ItemByTitleHelper.php
+++ b/repo/includes/Api/EntityByTitleHelper.php
@@ -7,18 +7,19 @@
 use Site;
 use SiteLookup;
 use ApiUsageException;
-use Wikibase\DataModel\Entity\ItemId;
-use Wikibase\Lib\Store\SiteLinkLookup;
+use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\Lib\Store\EntityByTitleLookup;
 use Wikibase\StringNormalizer;
 
 /**
- * Helper class for api modules to resolve page+title pairs into items.
+ * Helper class for api modules to resolve page+title pairs into entities.
  *
  * @license GPL-2.0+
  * @author Marius Hoch < h...@online.de >
  * @author Addshore
+ * @author Daniel Kinzler
  */
-class ItemByTitleHelper {
+class EntityByTitleHelper {
 
        /**
         * @var ApiBase
@@ -31,9 +32,9 @@
        private $resultBuilder;
 
        /**
-        * @var SiteLinkLookup
+        * @var EntityByTitleLookup
         */
-       private $siteLinkLookup;
+       private $entityByTitleLookup;
 
        /**
         * @var SiteLookup
@@ -48,13 +49,13 @@
        public function __construct(
                ApiBase $apiModule,
                ResultBuilder $resultBuilder,
-               SiteLinkLookup $siteLinkLookup,
+               EntityByTitleLookup $entityByTitleLookup,
                SiteLookup $siteLookup,
                StringNormalizer $stringNormalizer
        ) {
                $this->apiModule = $apiModule;
                $this->resultBuilder = $resultBuilder;
-               $this->siteLinkLookup = $siteLinkLookup;
+               $this->entityByTitleLookup = $entityByTitleLookup;
                $this->siteLookup = $siteLookup;
                $this->stringNormalizer = $stringNormalizer;
        }
@@ -67,10 +68,10 @@
         * @param bool $normalize
         *
         * @throws ApiUsageException
-        * @return array( ItemId[], array[] )
-        *         List containing valid ItemIds and MissingItem site title 
combinations
+        * @return array( EntityId[], array[] )
+        *         List containing valid $ids and $missingEntities site title 
combinations
         */
-       public function getItemIds( array $sites, array $titles, $normalize ) {
+       public function getEntityIds( array $sites, array $titles, $normalize ) 
{
                $ids = [];
                $numSites = count( $sites );
                $numTitles = count( $titles );
@@ -99,19 +100,19 @@
                        );
                }
 
-               $missingItems = [];
+               $missingEntities = [];
                foreach ( $sites as $siteId ) {
                        foreach ( $titles as $title ) {
-                               $itemId = $this->getItemId( $siteId, $title, 
$normalize );
+                               $itemId = $this->getEntityId( $siteId, $title, 
$normalize );
                                if ( !is_null( $itemId ) ) {
                                        $ids[] = $itemId;
                                } else {
-                                       $missingItems[] = [ 'site' => $siteId, 
'title' => $title ];
+                                       $missingEntities[] = [ 'site' => 
$siteId, 'title' => $title ];
                                }
                        }
                }
 
-               return [ $ids, $missingItems ];
+               return [ $ids, $missingEntities ];
        }
 
        /**
@@ -121,19 +122,19 @@
         * @param string $title
         * @param bool $normalize
         *
-        * @return ItemId|null
+        * @return EntityId|null
         */
-       private function getItemId( $siteId, $title, $normalize ) {
+       private function getEntityId( $siteId, $title, $normalize ) {
                // FIXME: This code is duplicated in 
SpecialItemByTitle::execute!
                $title = $this->stringNormalizer->trimToNFC( $title );
-               $id = $this->siteLinkLookup->getItemIdForLink( $siteId, $title 
);
+               $id = $this->entityByTitleLookup->getEntityIdForLink( $siteId, 
$title );
 
                // Try harder by requesting normalization on the external site.
                if ( $id === null && $normalize === true ) {
-                       $siteObj = $this->siteLookup->getSite( $siteId );
+                       $siteObj = $this->siteLookup->getSite( $siteId ); // 
XXX: is this really needed??
                        //XXX: this passes the normalized title back into 
$title by reference...
                        $this->normalizeTitle( $title, $siteObj );
-                       $id = $this->siteLinkLookup->getItemIdForLink( 
$siteObj->getGlobalId(), $title );
+                       $id = $this->entityByTitleLookup->getEntityIdForLink( 
$siteId, $title );
                }
 
                return $id;
diff --git a/repo/includes/Api/EntityLoadingHelper.php 
b/repo/includes/Api/EntityLoadingHelper.php
index 766f4cd..63f66e4 100644
--- a/repo/includes/Api/EntityLoadingHelper.php
+++ b/repo/includes/Api/EntityLoadingHelper.php
@@ -12,7 +12,7 @@
 use Wikibase\Lib\Store\EntityRevision;
 use Wikibase\Lib\Store\BadRevisionException;
 use Wikibase\Lib\Store\EntityRevisionLookup;
-use Wikibase\Lib\Store\SiteLinkLookup;
+use Wikibase\Lib\Store\EntityByTitleLookup;
 use Wikibase\Lib\Store\StorageException;
 use Wikibase\Lib\Store\RevisionedUnresolvedRedirectException;
 use Wikimedia\Assert\Assert;
@@ -52,9 +52,9 @@
        protected $defaultRetrievalMode = 
EntityRevisionLookup::LATEST_FROM_REPLICA;
 
        /**
-        * @var SiteLinkLookup|null
+        * @var EntityByTitleLookup|null
         */
-       private $siteLinkLookup = null;
+       private $entityByTitleLookup = null;
 
        /**
         * @var string
@@ -92,14 +92,14 @@
        }
 
        /**
-        * @return SiteLinkLookup|null
+        * @return EntityByTitleLookup|null
         */
-       public function getSiteLinkLookup() {
-               return $this->siteLinkLookup;
+       public function getEntityByTitleLookup() {
+               return $this->entityByTitleLookup;
        }
 
-       public function setSiteLinkLookup( SiteLinkLookup $siteLinkLookup ) {
-               $this->siteLinkLookup = $siteLinkLookup;
+       public function setEntityByTitleLookup( EntityByTitleLookup 
$entityByTitleLookup ) {
+               $this->entityByTitleLookup = $entityByTitleLookup;
        }
 
        /**
@@ -233,9 +233,9 @@
         * @return EntityId The ID of the entity connected to $title on $site.
         */
        private function getEntityIdFromSiteTitleCombination( $site, $title ) {
-               if ( $this->siteLinkLookup ) {
-                       // FIXME: Normalization missing, see T47282.
-                       $itemId = $this->siteLinkLookup->getItemIdForLink( 
$site, $title );
+               if ( $this->entityByTitleLookup ) {
+                       // FIXME: Normalization missing, see T47282. Use 
EntityByTitleHelper!
+                       $itemId = $this->entityByTitleLookup->getItemIdForLink( 
$site, $title );
                } else {
                        $itemId = null;
                }
diff --git a/repo/includes/Api/GetEntities.php 
b/repo/includes/Api/GetEntities.php
index e6278ce..be62951 100644
--- a/repo/includes/Api/GetEntities.php
+++ b/repo/includes/Api/GetEntities.php
@@ -151,7 +151,7 @@
         */
        private function getEntityIdsFromParams( array $params ) {
                $fromIds = $this->getEntityIdsFromIdParam( $params );
-               $fromSiteTitleCombinations = 
$this->getItemIdsFromSiteTitleParams( $params );
+               $fromSiteTitleCombinations = 
$this->getEntityIdsFromSiteTitleParams( $params );
                $ids = array_merge( $fromIds, $fromSiteTitleCombinations );
                return array_unique( $ids );
        }
@@ -186,23 +186,29 @@
         * @param array $params
         * @return EntityId[]
         */
-       private function getItemIdsFromSiteTitleParams( array $params ) {
+       private function getEntityIdsFromSiteTitleParams( array $params ) {
                $ids = [];
                if ( !empty( $params['sites'] ) && !empty( $params['titles'] ) 
) {
-                       $itemByTitleHelper = $this->getItemByTitleHelper();
-                       list( $ids, $missingItems ) = 
$itemByTitleHelper->getItemIds( $params['sites'], $params['titles'], 
$params['normalize'] );
+                       $entityByTitleHelper = $this->getItemByTitleHelper();
+
+                       list( $ids, $missingItems ) = 
$entityByTitleHelper->getEntityIds(
+                               $params['sites'],
+                               $params['titles'],
+                               $params['normalize']
+                       );
+
                        $this->addMissingItemsToResult( $missingItems );
                }
                return $ids;
        }
 
        /**
-        * @return ItemByTitleHelper
+        * @return EntityByTitleHelper
         */
        private function getItemByTitleHelper() {
                $wikibaseRepo = WikibaseRepo::getDefaultInstance();
-               $siteLinkStore = $wikibaseRepo->getStore()->newSiteLinkStore();
-               return new ItemByTitleHelper(
+               $siteLinkStore = 
$wikibaseRepo->getStore()->getEntityByTitleLookup();
+               return new EntityByTitleHelper(
                        $this,
                        $this->resultBuilder,
                        $siteLinkStore,
diff --git a/repo/includes/Store/Sql/SqlStore.php 
b/repo/includes/Store/Sql/SqlStore.php
index d3943ee..2e8324c 100644
--- a/repo/includes/Store/Sql/SqlStore.php
+++ b/repo/includes/Store/Sql/SqlStore.php
@@ -18,6 +18,7 @@
 use Wikibase\Lib\Store\CachingEntityRevisionLookup;
 use Wikibase\Lib\Store\CacheAwarePropertyInfoStore;
 use Wikibase\Lib\Store\CachingPropertyInfoLookup;
+use Wikibase\Lib\Store\EntityByTitleLookup;
 use Wikibase\Lib\Store\Sql\EntityChangeLookup;
 use Wikibase\Lib\Store\EntityInfoBuilderFactory;
 use Wikibase\Lib\Store\EntityRevisionLookup;
@@ -310,6 +311,15 @@
        }
 
        /**
+        * @see Store::newEntityByTitleLookup
+        *
+        * @return EntityByTitleLookup
+        */
+       public function getEntityByTitleLookup() {
+               return $this->newSiteLinkStore();
+       }
+
+       /**
         * @see Store::newEntitiesWithoutTermFinder
         *
         * @return EntitiesWithoutTermFinder
diff --git a/repo/includes/Store/Store.php b/repo/includes/Store/Store.php
index 2c4c702..5905da6 100644
--- a/repo/includes/Store/Store.php
+++ b/repo/includes/Store/Store.php
@@ -5,6 +5,7 @@
 use Wikibase\DataModel\Services\Entity\EntityPrefetcher;
 use Wikibase\DataModel\Services\Lookup\EntityLookup;
 use Wikibase\DataModel\Services\Lookup\EntityRedirectLookup;
+use Wikibase\Lib\Store\EntityByTitleLookup;
 use Wikibase\Lib\Store\Sql\EntityChangeLookup;
 use Wikibase\Lib\Store\EntityInfoBuilderFactory;
 use Wikibase\Lib\Store\EntityRevisionLookup;
@@ -37,6 +38,11 @@
        public function newSiteLinkStore();
 
        /**
+        * @return EntityByTitleLookup
+        */
+       public function getEntityByTitleLookup();
+
+       /**
         * Removes all data from the store.
         */
        public function clear();
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 2b3b881..606b586 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -1604,7 +1604,7 @@
                        $this->getBaseDataModelSerializerFactory(),
                        $this->getAllTypesEntitySerializer(),
                        $this->getEntityIdParser(),
-                       $this->getStore()->newSiteLinkStore(),
+                       $this->getStore()->getEntityByTitleLookup(),
                        $this->getEntityFactory(),
                        $this->getEntityStore()
                );
diff --git a/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php 
b/repo/tests/phpunit/includes/Api/EntityByTitleHelperTest.php
similarity index 77%
rename from repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
rename to repo/tests/phpunit/includes/Api/EntityByTitleHelperTest.php
index eeb3aef..6a2ae1e 100644
--- a/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
+++ b/repo/tests/phpunit/includes/Api/EntityByTitleHelperTest.php
@@ -10,8 +10,8 @@
 use Title;
 use ApiUsageException;
 use Wikibase\DataModel\Entity\ItemId;
-use Wikibase\Lib\Store\SiteLinkLookup;
-use Wikibase\Repo\Api\ItemByTitleHelper;
+use Wikibase\Lib\Store\EntityByTitleLookup;
+use Wikibase\Repo\Api\EntityByTitleHelper;
 use Wikibase\Repo\Api\ResultBuilder;
 use Wikibase\StringNormalizer;
 
@@ -25,7 +25,7 @@
  * @author Marius Hoch < h...@online.de >
  * @author Addshore
  */
-class ItemByTitleHelperTest extends \PHPUnit_Framework_TestCase {
+class EntityByTitleHelperTest extends \PHPUnit_Framework_TestCase {
 
        /**
         * @return ApiBase
@@ -68,13 +68,13 @@
        /**
         * @param mixed $itemId
         *
-        * @return SiteLinkLookup
+        * @return EntityByTitleLookup
         */
-       private function getSiteLinkLookupMock( $itemId ) {
-               $siteLinkLookupMock = $this->getMock( SiteLinkLookup::class );
+       private function getEntityByTitleLookupMock( $itemId ) {
+               $siteLinkLookupMock = $this->getMock( 
EntityByTitleLookup::class );
 
                $siteLinkLookupMock->expects( $this->any() )
-                       ->method( 'getItemIdForLink' )
+                       ->method( 'getEntityIdForLink' )
                                ->will( $this->returnValue( $itemId ) );
 
                return $siteLinkLookupMock;
@@ -84,10 +84,10 @@
                $expectedEntityId = new ItemId( 'Q123' );
                $expectedEntityId = $expectedEntityId->getSerialization();
 
-               $itemByTitleHelper = new ItemByTitleHelper(
+               $entityByTitleHelper = new EntityByTitleHelper(
                        $this->getApiBaseMock(),
                        $this->getResultBuilderMock(),
-                       $this->getSiteLinkLookupMock( new ItemId( 'Q123' ) ),
+                       $this->getEntityByTitleLookupMock( new ItemId( 'Q123' ) 
),
                        $this->getSiteLookupMock(),
                        new StringNormalizer()
                );
@@ -95,7 +95,7 @@
                $sites = [ 'FooSite' ];
                $titles = [ 'Berlin', 'London' ];
 
-               list( $entityIds, ) = $itemByTitleHelper->getItemIds( $sites, 
$titles, false );
+               list( $entityIds, ) = $entityByTitleHelper->getEntityIds( 
$sites, $titles, false );
 
                foreach ( $entityIds as $entityId ) {
                        $this->assertEquals( $expectedEntityId, $entityId );
@@ -106,11 +106,11 @@
         * Try to get an entity id for a page that's normalized with 
normalization.
         */
        public function testGetEntityIdNormalized() {
-               $itemByTitleHelper = new ItemByTitleHelper(
+               $entityByTitleHelper = new EntityByTitleHelper(
                        $this->getApiBaseMock(),
                // Two values should be added: The normalization and the 
failure to find an entity
                        $this->getResultBuilderMock( 1 ),
-                       $this->getSiteLinkLookupMock( null ),
+                       $this->getEntityByTitleLookupMock( null ),
                        $this->getSiteLookupMock(),
                        new StringNormalizer()
                );
@@ -118,7 +118,7 @@
                $sites = [ 'FooSite' ];
                $titles = [ 'berlin_germany' ];
 
-               list( $entityIds, ) = $itemByTitleHelper->getItemIds( $sites, 
$titles, true );
+               list( $entityIds, ) = $entityByTitleHelper->getEntityIds( 
$sites, $titles, true );
 
                // Still nothing could be found
                $this->assertEquals( [], $entityIds );
@@ -129,11 +129,11 @@
         * Makes sure that the failures are added to the API result.
         */
        public function testGetEntityIdsNotFound() {
-               $itemByTitleHelper = new ItemByTitleHelper(
+               $entityByTitleHelper = new EntityByTitleHelper(
                        $this->getApiBaseMock(),
                // Two result values should be added (for both titles which 
wont be found)
                        $this->getResultBuilderMock(),
-                       $this->getSiteLinkLookupMock( false ),
+                       $this->getEntityByTitleLookupMock( false ),
                        $this->getSiteLookupMock(),
                        new StringNormalizer()
                );
@@ -141,7 +141,7 @@
                $sites = [ 'FooSite' ];
                $titles = [ 'Berlin', 'London' ];
 
-               $itemByTitleHelper->getItemIds( $sites, $titles, false );
+               $entityByTitleHelper->getEntityIds( $sites, $titles, false );
        }
 
        /**
@@ -150,10 +150,10 @@
        public function testGetEntityIdsNormalizationNotAllowed() {
                $this->setExpectedException( ApiUsageException::class );
 
-               $itemByTitleHelper = new ItemByTitleHelper(
+               $entityByTitleHelper = new EntityByTitleHelper(
                        $this->getApiBaseMock(),
                        $this->getResultBuilderMock(),
-                       $this->getSiteLinkLookupMock( 1 ),
+                       $this->getEntityByTitleLookupMock( 1 ),
                        $this->getSiteLookupMock(),
                        new StringNormalizer()
                );
@@ -161,7 +161,7 @@
                $sites = [ 'FooSite' ];
                $titles = [ 'Berlin', 'London' ];
 
-               $itemByTitleHelper->getItemIds( $sites, $titles, true );
+               $entityByTitleHelper->getEntityIds( $sites, $titles, true );
        }
 
        public function normalizeTitleProvider() {
@@ -187,15 +187,15 @@
        public function testNormalizeTitle( $title, $expectedEntityId, 
$expectedAddNormalizedCalls ) {
                $dummySite = new MediaWikiSite();
 
-               $itemByTitleHelper = new ItemByTitleHelper(
+               $entityByTitleHelper = new EntityByTitleHelper(
                        $this->getApiBaseMock(),
                        $this->getResultBuilderMock( 
$expectedAddNormalizedCalls ),
-                       $this->getSiteLinkLookupMock( $expectedEntityId ),
+                       $this->getEntityByTitleLookupMock( $expectedEntityId ),
                        $this->getSiteLookupMock(),
                        new StringNormalizer()
                );
 
-               $itemByTitleHelper->normalizeTitle( $title, $dummySite );
+               $entityByTitleHelper->normalizeTitle( $title, $dummySite );
 
                // Normalization in unit tests is actually using 
Title::getPrefixedText instead of a real API call
                // XXX: The Normalized title is passed by via reference to 
$title...
@@ -225,15 +225,15 @@
        public function testNotEnoughInput( array $sites, array $titles, 
$normalize ) {
                $this->setExpectedException( ApiUsageException::class );
 
-               $itemByTitleHelper = new ItemByTitleHelper(
+               $entityByTitleHelper = new EntityByTitleHelper(
                        $this->getApiBaseMock(),
                        $this->getResultBuilderMock(),
-                       $this->getSiteLinkLookupMock( new ItemId( 'Q123' ) ),
+                       $this->getEntityByTitleLookupMock( new ItemId( 'Q123' ) 
),
                        $this->getSiteLookupMock(),
                        new StringNormalizer()
                );
 
-               $itemByTitleHelper->getItemIds( $sites, $titles, $normalize );
+               $entityByTitleHelper->getEntityIds( $sites, $titles, $normalize 
);
        }
 
 }
diff --git a/repo/tests/phpunit/includes/Api/EntityLoadingHelperTest.php 
b/repo/tests/phpunit/includes/Api/EntityLoadingHelperTest.php
index b53cdf9..3970c29 100644
--- a/repo/tests/phpunit/includes/Api/EntityLoadingHelperTest.php
+++ b/repo/tests/phpunit/includes/Api/EntityLoadingHelperTest.php
@@ -10,6 +10,7 @@
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\Entity\ItemIdParser;
+use Wikibase\Lib\Store\EntityByTitleLookup;
 use Wikibase\Lib\Store\EntityRevision;
 use Wikibase\Lib\Store\BadRevisionException;
 use Wikibase\Lib\Store\EntityRevisionLookup;
@@ -204,13 +205,13 @@
                        'revision' => $revision,
                ] );
 
-               $siteLinkLookup = $this->getMock( SiteLinkLookup::class );
-               $siteLinkLookup->expects( $this->once() )
-                       ->method( 'getItemIdForLink' )
+               $entityByTitleLookup = $this->getMock( 
EntityByTitleLookup::class );
+               $entityByTitleLookup->expects( $this->once() )
+                       ->method( 'getEntityIdForLink' )
                        ->with( 'foowiki', 'FooBar' )
                        ->will( $this->returnValue( $id ) );
 
-               $helper->setSiteLinkLookup( $siteLinkLookup );
+               $helper->setEntityByTitleLookup( $entityByTitleLookup );
 
                $return = $helper->loadEntity();
                $this->assertSame( $entity, $return );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia43ebfa2449c10dc5c391a5d122e4ed989d7fc1d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de>

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

Reply via email to