Addshore has submitted this change and it was merged.

Change subject: Allow (optional) title normalization in wbgetentities
......................................................................


Allow (optional) title normalization in wbgetentities

Allow normalizing the client page name we try to find
an entity for. For performance reasons we only do this
if the user asked for it and only for one title!

This also introduces the new API helper class
\Wikibase\Api\ItemByTitleHelper.

Change-Id: I1d010e5d5e07209f23c93636163f722d0d247a29
---
M repo/Wikibase.classes.php
M repo/Wikibase.hooks.php
M repo/includes/api/GetEntities.php
A repo/includes/api/ItemByTitleHelper.php
M repo/tests/phpunit/includes/api/GetEntitiesTest.php
A repo/tests/phpunit/includes/api/ItemByTitleHelperTest.php
M repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
7 files changed, 517 insertions(+), 35 deletions(-)

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



diff --git a/repo/Wikibase.classes.php b/repo/Wikibase.classes.php
index 4f7b4d0..d020271 100644
--- a/repo/Wikibase.classes.php
+++ b/repo/Wikibase.classes.php
@@ -75,6 +75,7 @@
                // includes/api
                'Wikibase\Api\ApiWikibase' => 'includes/api/ApiWikibase.php',
                'Wikibase\Api\IAutocomment' => 'includes/api/IAutocomment.php',
+               'Wikibase\Api\ItemByTitleHelper' => 
'includes/api/ItemByTitleHelper.php',
                'Wikibase\Api\EditEntity' => 'includes/api/EditEntity.php',
                'Wikibase\Api\GetEntities' => 'includes/api/GetEntities.php',
                'Wikibase\Api\LinkTitles' => 'includes/api/LinkTitles.php',
diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index 212e740..654dc58 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -186,6 +186,7 @@
                        'api/RemoveQualifiers',
                        'api/SetQualifier',
                        'api/SnakValidationHelper',
+                       'api/ItemByTitleHelper',
 
                        'changeop/ChangeOps',
                        'changeop/ChangeOpLabel',
diff --git a/repo/includes/api/GetEntities.php 
b/repo/includes/api/GetEntities.php
index cbe8632..2b79bf9 100644
--- a/repo/includes/api/GetEntities.php
+++ b/repo/includes/api/GetEntities.php
@@ -26,6 +26,7 @@
  * @licence GNU GPL v2+
  * @author John Erling Blad < jeb...@gmail.com >
  * @author Jeroen De Dauw < jeroended...@gmail.com >
+ * @author Marius Hoch < h...@online.de >
  */
 class GetEntities extends ApiWikibase {
 
@@ -48,43 +49,16 @@
 
                $params = $this->extractRequestParams();
 
-               if ( !( isset( $params['ids'] ) XOR ( isset( $params['sites'] ) 
&& isset( $params['titles'] ) ) ) ) {
+               if ( !( isset( $params['ids'] ) XOR ( !empty( $params['sites'] 
) && !empty( $params['titles'] ) ) ) ) {
                        wfProfileOut( __METHOD__ );
                        $this->dieUsage( 'Either provide the item "ids" or 
pairs of "sites" and "titles" for corresponding pages', 'param-missing' );
                }
 
-               $missing = 0;
-
                if ( !isset( $params['ids'] ) ) {
-                       $params['ids'] = array();
-                       $numSites = count( $params['sites'] );
-                       $numTitles = count( $params['titles'] );
-                       $max = max( $numSites, $numTitles );
-                       if ( $numSites === 0 || $numTitles === 0 ) {
-                               wfProfileOut( __METHOD__ );
-                               $this->dieUsage( 'Either provide the item "id" 
or pairs of "site" and "title" for a corresponding page', 'param-missing' );
-                       }
-                       else {
-                               $idxSites = 0;
-                               $idxTitles = 0;
-
-                               for ( $k = 0; $k < $max; $k++ ) {
-                                       $siteId = $params['sites'][$idxSites++ 
% $numSites];
-                                       $title = 
$this->stringNormalizer->trimToNFC( $params['titles'][$idxTitles++ % 
$numTitles] );
-
-                                       $id = 
StoreFactory::getStore()->newSiteLinkCache()->getItemIdForLink( $siteId, $title 
);
-
-                                       if ( $id === false ) {
-                                               $this->getResult()->addValue( 
'entities', (string)(--$missing),
-                                                       array( 'site' => 
$siteId, 'title' => $title, 'missing' => "" )
-                                               );
-                                       }
-                                       else {
-                                               $id = new EntityId( 
Item::ENTITY_TYPE, $id );
-                                               $params['ids'][] = 
$id->getPrefixedId();
-                                       }
-                               }
-                       }
+                       $siteLinkCache = 
StoreFactory::getStore()->newSiteLinkCache();
+                       $siteStore = \SiteSQLStore::newInstance();
+                       $itemByTitleHelper = new ItemByTitleHelper( $this, 
$siteLinkCache, $siteStore, $this->stringNormalizer );
+                       $params['ids'] = $itemByTitleHelper->getEntityIds( 
$params['sites'], $params['titles'], $params['normalize'] );
                }
 
                $params['ids'] = array_unique( $params['ids'] );
@@ -93,8 +67,7 @@
                        $props = array_flip( array_values( $params['props'] ) );
                        $props['sitelinks'] = true;
                        $props = array_keys( $props );
-               }
-               else {
+               } else {
                        $props = $params['props'];
                }
 
@@ -258,6 +231,10 @@
                                ApiBase::PARAM_TYPE => 
Utils::getLanguageCodes(),
                                ApiBase::PARAM_ISMULTI => true,
                        ),
+                       'normalize' => array(
+                               ApiBase::PARAM_TYPE => 'boolean',
+                               ApiBase::PARAM_DFLT => false
+                       ),
                ) );
        }
 
@@ -287,6 +264,9 @@
                        'languages' => array( 'By default the internationalized 
values are returned in all available languages.',
                                'This parameter allows filtering these down to 
one or more languages by providing one or more language codes.'
                        ),
+                       'normalize' => array( 'Try to normalize the page title 
against the client site.',
+                               'This only works if exactly one site and one 
page have been given.'
+                       ),
                ) );
        }
 
@@ -306,6 +286,10 @@
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'code' => 'param-missing', 'info' => $this->msg( 
'wikibase-api-param-missing' )->text() ),
                        array( 'code' => 'no-such-entity', 'info' => 
$this->msg( 'wikibase-api-no-such-entity' )->text() ),
+                       array(
+                               'code' => 'normalize-only-once',
+                               'info' => 'Normalize is only allowed if exactly 
one site and one page have been given'
+                       ),
                ) );
        }
 
@@ -332,6 +316,8 @@
                        => "Get entities with IDs q1 and q42 showing 
descriptions in English, German and French languages",
                        
'api.php?action=wbgetentities&sites=enwiki&titles=Berlin&languages=en'
                        => 'Get the item for page "Berlin" on the site 
"enwiki", with language attributes in English language',
+                       
'api.php?action=wbgetentities&sites=enwiki&titles=berlin&normalize='
+                       => 'Get the item for page "Berlin" on the site "enwiki" 
after normalizing the title from "berlin"',
                );
        }
 
diff --git a/repo/includes/api/ItemByTitleHelper.php 
b/repo/includes/api/ItemByTitleHelper.php
new file mode 100644
index 0000000..2aceb2a
--- /dev/null
+++ b/repo/includes/api/ItemByTitleHelper.php
@@ -0,0 +1,143 @@
+<?php
+
+namespace Wikibase\Api;
+use Wikibase\EntityId;
+use Wikibase\Item;
+
+/**
+ * Helper class for api modules to resolve page+title pairs into items.
+ *
+ * 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.4
+ *
+ * @file
+ * @ingroup WikibaseRepo
+ *
+ * @licence GNU GPL v2+
+ * @author Marius Hoch < h...@online.de >
+ */
+class ItemByTitleHelper {
+       /**
+        * @var \ApiBase
+        */
+       protected $apiBase;
+
+       /**
+        * @var \Wikibase\SiteLinkCache
+        */
+       protected $siteLinkCache;
+
+       /**
+        * @var \SiteStore
+        */
+       protected $siteStore;
+
+       /**
+        * @var \Wikibase\StringNormalizer
+        */
+       protected $stringNormalizer;
+
+       /**
+        * @param \ApiBase $apiBase
+        * @param \Wikibase\SiteLinkCache $siteLinkCache
+        * @param \SiteStore $siteStore
+        */
+       public function __construct( \ApiBase $apiBase, \Wikibase\SiteLinkCache 
$siteLinkCache, \SiteStore $siteStore, \Wikibase\StringNormalizer 
$stringNormalizer ) {
+               $this->apiBase = $apiBase;
+               $this->siteLinkCache = $siteLinkCache;
+               $this->siteStore = $siteStore;
+               $this->stringNormalizer = $stringNormalizer;
+       }
+
+       /**
+        * Tries to find entity ids for given client pages.
+        *
+        * @param array $sites
+        * @param array $titles
+        * @param bool $normalize
+        *
+        * @return array
+        */
+       public function getEntityIds( array $sites, array $titles, $normalize ) 
{
+               $ids = array();
+               $missing = 0;
+               $numSites = count( $sites );
+               $numTitles = count( $titles );
+               $max = max( $numSites, $numTitles );
+
+               if ( $normalize === true && $max > 1 ) {
+                       // For performance reasons we only do this if the user 
asked for it and only for one title!
+                       $this->apiBase->dieUsage(
+                               'Normalize is only allowed if exactly one site 
and one page have been given',
+                               'params-illegal'
+                       );
+               }
+
+               $idxSites = 0;
+               $idxTitles = 0;
+
+               for ( $k = 0; $k < $max; $k++ ) {
+                       $siteId = $sites[$idxSites++ % $numSites];
+                       $title = $this->stringNormalizer->trimToNFC( 
$titles[$idxTitles++ % $numTitles] );
+
+                       $id = $this->siteLinkCache->getItemIdForLink( $siteId, 
$title );
+
+                       // Try harder by requesting normalization on the 
external site.
+                       if ( $id === false && $normalize === true ) {
+                               $siteObj = $this->siteStore->getSite( $siteId );
+                               $id = $this->normalizeTitle( $title, $siteObj );
+                       }
+
+                       if ( $id === false ) {
+                               $this->apiBase->getResult()->addValue( 
'entities', (string)(--$missing),
+                                       array( 'site' => $siteId, 'title' => 
$title, 'missing' => "" )
+                               );
+                       } else {
+                               $id = new EntityId( Item::ENTITY_TYPE, $id );
+                               $ids[] = $id->getPrefixedId();
+                       }
+               }
+
+               return $ids;
+       }
+
+       /**
+        * Tries to normalize the given page title against the given client 
site.
+        * Updates $title accordingly and adds the normalization to the API 
output.
+        *
+        * @param string &$title
+        * @param \Site $siteId
+        *
+        * @return integer|boolean
+        */
+       public function normalizeTitle( &$title, \Site $site ) {
+               $normalizedTitle = $site->normalizePageName( $title );
+               if ( $normalizedTitle !== false && $normalizedTitle !== $title 
) {
+                       // Let the user know that we normalized
+                       $this->apiBase->getResult()->addValue(
+                               'normalized',
+                               'n',
+                               array( 'from' => $title, 'to' => 
$normalizedTitle )
+                       );
+
+                       $title = $normalizedTitle;
+                       return $this->siteLinkCache->getItemIdForLink( 
$site->getGlobalId(), $title );
+               }
+
+               return false;
+       }
+}
diff --git a/repo/tests/phpunit/includes/api/GetEntitiesTest.php 
b/repo/tests/phpunit/includes/api/GetEntitiesTest.php
index d0f5c0f..67bf2c9 100644
--- a/repo/tests/phpunit/includes/api/GetEntitiesTest.php
+++ b/repo/tests/phpunit/includes/api/GetEntitiesTest.php
@@ -30,6 +30,7 @@
  * @licence GNU GPL v2+
  * @author John Erling Blad < jeb...@gmail.com >
  * @author Daniel Kinzler
+ * @author Marius Hoch < h...@online.de >
  *
  * @group API
  * @group Wikibase
@@ -154,6 +155,102 @@
        }
 
        /**
+        * Test basic lookup of items to get the id.
+        * This is really a fast lookup without reparsing the stringified item.
+        *
+        * @dataProvider provideGetItemByTitle
+        */
+       public function testGetItemByTitleNormalized( $handle, $site, $title ) {
+               $title = lcfirst( $title );
+               list($res,,) = $this->doApiRequest( array(
+                       'action' => 'wbgetentities',
+                       'sites' => $site,
+                       'titles' => $title,
+                       'normalize' => true,
+                       'format' => 'json', // make sure IDs are used as keys
+               ) );
+
+               $item = $this->getEntityOutput( $handle );
+               $id = $item['id'];
+
+               $this->assertSuccess( $res, 'entities', $id );
+               $this->assertEntityEquals( $item,  $res['entities'][$id] );
+               $this->assertEquals( 1, count( $res['entities'] ), "requesting 
a single item should return exactly one item entry" );
+
+               // The normalization that has been applied should be noted
+               $this->assertEquals(
+                       $title,
+                       $res['normalized']['n']['from']
+               );
+
+               $this->assertEquals(
+                       // Normalization in unit tests is actually using 
Title::getPrefixedText instead of a real API call
+                       \Title::newFromText( $title )->getPrefixedText(),
+                       $res['normalized']['n']['to']
+               );
+       }
+
+       /**
+        * @return array
+        */
+       public static function provideGetEntitiesNormalizationNotAllowed() {
+               return array(
+                       array(
+                               // Two sites one page
+                               array( 'enwiki', 'dewiki' ),
+                               array( 'Foo' )
+                       ),
+                       array(
+                               // Two pages one site
+                               array( 'enwiki' ),
+                               array( 'Foo', 'Bar' )
+                       ),
+                       array(
+                               // Two sites two pages
+                               array( 'enwiki', 'dewiki' ),
+                               array( 'Foo', 'Bar' )
+                       )
+               );
+       }
+
+       /**
+        * Test that the API is throwing an error if the users wants to
+        * normalize with multiple sites/ pages.
+        *
+        * @group API
+        * @dataProvider provideGetEntitiesNormalizationNotAllowed
+        *
+        * @param array $sites
+        * @param array $titles
+        */
+       public function testGetEntitiesNormalizationNotAllowed( $sites, $titles 
) {
+               $this->setExpectedException( 'UsageException' );
+
+               list($res,,) = $this->doApiRequest( array(
+                       'action' => 'wbgetentities',
+                       'sites' => join( '|', $sites ),
+                       'titles' => join( '|', $titles ),
+                       'normalize' => true
+               ) );
+       }
+
+       /**
+        * Test that the API isn't showing the normalization note in case 
nothing changed.
+        *
+        * @group API
+        */
+       public function testGetEntitiesNoNormalizationApplied( ) {
+               list($res,,) = $this->doApiRequest( array(
+                       'action' => 'wbgetentities',
+                       'sites' => 'enwiki',
+                       'titles' => 'HasNoItemAndIsNormalized',
+                       'normalize' => true
+               ) );
+
+               $this->assertFalse( isset( $res['normalized'] ) );
+       }
+
+       /**
         * Testing if we can get missing items if we do lookup with single fake 
ids.
         * Note that this makes assumptions about which ids have been assigned.
         *
@@ -232,6 +329,43 @@
        }
 
        /**
+        * Testing if we can get missing items if we do lookup with failing 
titles and
+        * that the normalization that has been applied is being noted 
correctly.
+        *
+        * Note that this makes assumptions about which sitelinks they have 
been assigned.
+        *
+        * @group API
+        */
+       public function testGetEntitiesByBadTitleNormalized( ) {
+               $pageTitle = 'klaijehr qowienx_qopweiu';
+               list( $res,, ) = $this->doApiRequest( array(
+                       'action' => 'wbgetentities',
+                       'sites' => 'enwiki',
+                       'titles' => $pageTitle,
+                       'normalize' => true
+               ) );
+
+               $this->assertSuccess( $res, 'entities' );
+
+               $keys = array_keys( $res['entities'] );
+               $this->assertEquals( 1, count( $keys ), "requesting a single 
item should return exactly one item entry" );
+
+               $this->assertSuccess( $res, 'entities', $keys[0], 'missing' );
+
+               // The normalization that has been applied should be noted
+               $this->assertEquals(
+                       $pageTitle,
+                       $res['normalized']['n']['from']
+               );
+
+               $this->assertEquals(
+                       // Normalization in unit tests is actually using 
Title::getPrefixedText instead of a real API call
+                       \Title::newFromText( $pageTitle )->getPrefixedText(),
+                       $res['normalized']['n']['to']
+               );
+       }
+
+       /**
         * Testing if we can get all the complete stringified items if we do 
lookup with multiple ids.
         *
         * @group API
diff --git a/repo/tests/phpunit/includes/api/ItemByTitleHelperTest.php 
b/repo/tests/phpunit/includes/api/ItemByTitleHelperTest.php
new file mode 100644
index 0000000..1b2f6d8
--- /dev/null
+++ b/repo/tests/phpunit/includes/api/ItemByTitleHelperTest.php
@@ -0,0 +1,217 @@
+<?php
+namespace Wikibase\Test;
+
+use Wikibase\Api\ItemByTitleHelper;
+use Wikibase\EntityId;
+use Wikibase\Item;
+use Wikibase\Settings;
+use Wikibase\StringNormalizer;
+
+/**
+ * Tests for the ItemByTitleHelper api helper class.
+ *
+ * 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
+ *
+ * @file
+ * @since 0.4
+ *
+ * @ingroup Test
+ *
+ * @licence GNU GPL v2+
+ * @author Marius Hoch < h...@online.de >
+ */
+class ItemByTitleHelperTest extends \MediaWikiTestCase {
+
+       public function getSiteStoreMock() {
+               $dummySite = new \MediaWikiSite();
+
+               $siteStoreMock = $this->getMockBuilder( '\SiteStore' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $siteStoreMock->expects( $this->any() )
+                       ->method( 'getSite' )
+                       ->will( $this->returnValue( $dummySite ) );
+
+               return $siteStoreMock;
+       }
+
+       /**
+        * Gets a mock ApiBase object which excepts a certain number
+        * of calls to certain (sub)methods
+        *
+        * @param integer|null $expectedAddValueCount How many times
+        *              do we expect values to be added to the result 
(ApiResult::addValue)
+        * @param bool $expectDieUsage Whether we expect ApiBase::dieUsage
+        *              to be called
+        */
+       public function getApiBaseMock( $expectedAddValueCount = null, 
$expectDieUsage = false ) {
+               $apiBaseMock = $this->getMockBuilder( '\ApiBase' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $apiBaseMock
+                       ->expects( $expectDieUsage ? $this->once() : 
$this->never() )
+                       ->method( 'dieUsage' );
+
+               $apiResultMock = $this->getMockBuilder( '\ApiResult' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               if ( !is_null( $expectedAddValueCount ) ) {
+                       $apiResultMock->expects( $this->exactly( 
$expectedAddValueCount ) )
+                               ->method( 'addValue' );
+               }
+
+               $apiBaseMock->expects( $this->any() )
+                       ->method( 'getResult' )
+                       ->will( $this->returnValue( $apiResultMock ) );
+
+               return $apiBaseMock;
+       }
+
+       /**
+        * @param integer|null $entityId
+        */
+       public function getSiteLinkCacheMock( $entityId = null ) {
+               $siteLinkCacheMock = $this->getMockBuilder( 
'\Wikibase\SiteLinkCache' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               if ( !is_null( $entityId ) ) {
+                       $siteLinkCacheMock->expects( $this->any() )
+                               ->method( 'getItemIdForLink' )
+                               ->will( $this->returnValue( $entityId ) );
+               }
+
+               return $siteLinkCacheMock;
+       }
+
+       public function testGetEntityIdsSuccess() {
+               $expectedEntityId = new EntityId( Item::ENTITY_TYPE, 123 );
+               $expectedEntityId = $expectedEntityId->getPrefixedId();
+
+               $itemByTitleHelper = new ItemByTitleHelper(
+                       $this->getApiBaseMock( 0 ),
+                       $this->getSiteLinkCacheMock( 123 ),
+                       $this->getSiteStoreMock(),
+                       new StringNormalizer()
+               );
+
+               $sites = array( 'FooSite' );
+               $titles = array( 'Berlin', 'London' );
+
+               $entityIds = $itemByTitleHelper->getEntityIds( $sites, $titles, 
false );
+
+               foreach( $entityIds as $entityId ) {
+                       $this->assertEquals( $expectedEntityId, $entityId );
+               }
+       }
+
+       /**
+        * Try to get an entity id for a page that's normalized with 
normalization.
+        */
+       public function testGetEntityIdNormalized() {
+               $itemByTitleHelper = new ItemByTitleHelper(
+                       // Two values should be added: The normalization and 
the failure to find an entity
+                       $this->getApiBaseMock( 2 ),
+                       $this->getSiteLinkCacheMock( false ),
+                       $this->getSiteStoreMock(),
+                       new StringNormalizer()
+               );
+
+               $sites = array( 'FooSite' );
+               $titles = array( 'berlin_germany' );
+
+               $entityIds = $itemByTitleHelper->getEntityIds( $sites, $titles, 
true );
+
+               // Still nothing could be found
+               $this->assertEquals( array(), $entityIds );
+       }
+
+       /**
+        * Tries to get entity ids for two pages which don't exist.
+        * Makes sure that the failures are added to the API result.
+        */
+       public function testGetEntityIdsNotFound() {
+               $itemByTitleHelper = new ItemByTitleHelper(
+                       // Two result values should be added (for both titles 
which wont be found)
+                       $this->getApiBaseMock( 2 ),
+                       $this->getSiteLinkCacheMock( false ),
+                       $this->getSiteStoreMock(),
+                       new StringNormalizer()
+               );
+
+               $sites = array( 'FooSite' );
+               $titles = array( 'Berlin', 'London' );
+
+               $entityIds = $itemByTitleHelper->getEntityIds( $sites, $titles, 
false );
+       }
+
+       /**
+        * Makes sure the request will fail if we want normalization for two 
titles
+        */
+       public function testGetEntityIdsNormalizationNotAllowed() {
+               $itemByTitleHelper = new ItemByTitleHelper(
+                       $this->getApiBaseMock( 0, true ),
+                       $this->getSiteLinkCacheMock( 1 ),
+                       $this->getSiteStoreMock(),
+                       new StringNormalizer()
+               );
+
+               $sites = array( 'FooSite' );
+               $titles = array( 'Berlin', 'London' );
+
+               $entityIds = $itemByTitleHelper->getEntityIds( $sites, $titles, 
true );
+       }
+
+       static public function normalizeTitleProvider() {
+               return array(
+                       array(
+                               'foo_bar',
+                               123,
+                               // The normalization should be noted
+                               1
+                       ),
+                       array(
+                               'Bar',
+                               false,
+                               // Already normalized
+                               0
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider normalizeTitleProvider
+        */
+       public function testNormalizeTitle( $title, $expectedEntityId, 
$expectedAddValueCount ) {
+               $dummySite = new \MediaWikiSite();
+
+               $itemByTitleHelper = new ItemByTitleHelper(
+                       $this->getApiBaseMock( $expectedAddValueCount ),
+                       $this->getSiteLinkCacheMock( $expectedEntityId ),
+                       $this->getSiteStoreMock(),
+                       new StringNormalizer()
+               );
+
+               $entityId = $itemByTitleHelper->normalizeTitle( $title, 
$dummySite );
+
+               $this->assertEquals( $expectedEntityId, $entityId );
+               // Normalization in unit tests is actually using 
Title::getPrefixedText instead of a real API call
+               $this->assertEquals( \Title::newFromText( $title 
)->getPrefixedText(), $title );
+       }
+}
diff --git a/repo/tests/phpunit/includes/api/ModifyEntityTestBase.php 
b/repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
index 4a5953b..65132e3 100644
--- a/repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
+++ b/repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
@@ -644,7 +644,7 @@
         *
         * @param array $response
         * @param string $path1 first path element (optional)
-        * @param string $path2 seconds path element (optional)
+        * @param string $path2 second path element (optional)
         * @param ...
         */
        public function assertSuccess( $response ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1d010e5d5e07209f23c93636163f722d0d247a29
Gerrit-PatchSet: 19
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <h...@online.de>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Daniel Werner <daniel.wer...@wikimedia.de>
Gerrit-Reviewer: Denny Vrandecic <denny.vrande...@wikimedia.de>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com>
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