jenkins-bot has submitted this change and it was merged.
Change subject: Track usage via Lua
......................................................................
Track usage via Lua
Entity usages via the wikibase Lua modules need to be tracked
in the UsageTracker service.
Bug: 71288
Change-Id: Ib47e3d9348f60b50c176162ca686cb06672fdfe9
---
M client/includes/DataAccess/PropertyParserFunction/LanguageAwareRenderer.php
M client/includes/scribunto/Scribunto_LuaWikibaseEntityLibrary.php
M client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
M client/includes/scribunto/WikibaseLuaBindings.php
M client/includes/scribunto/WikibaseLuaEntityBindings.php
M
client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseEntityLibraryTest.php
M client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryTest.php
M client/tests/phpunit/includes/scribunto/WikibaseLuaBindingsTest.php
M client/tests/phpunit/includes/scribunto/WikibaseLuaEntityBindingsTest.php
9 files changed, 193 insertions(+), 41 deletions(-)
Approvals:
Hoo man: Looks good to me, approved
jenkins-bot: Verified
diff --git
a/client/includes/DataAccess/PropertyParserFunction/LanguageAwareRenderer.php
b/client/includes/DataAccess/PropertyParserFunction/LanguageAwareRenderer.php
index 8af6deb..2632ff9 100644
---
a/client/includes/DataAccess/PropertyParserFunction/LanguageAwareRenderer.php
+++
b/client/includes/DataAccess/PropertyParserFunction/LanguageAwareRenderer.php
@@ -132,6 +132,7 @@
}
/**
+ * @todo Share code with WikibaseLuaEntityBindings::trackUsage
* @param Snak[] $snaks
*/
private function trackUsage( array $snaks ) {
@@ -153,6 +154,8 @@
}
/**
+ * @todo Share code with WikibaseLuaEntityBindings.
+ *
* @param EntityId $entityId
* @param PropertyId $propertyId
*
diff --git a/client/includes/scribunto/Scribunto_LuaWikibaseEntityLibrary.php
b/client/includes/scribunto/Scribunto_LuaWikibaseEntityLibrary.php
index 67323e7..5d43ab4 100644
--- a/client/includes/scribunto/Scribunto_LuaWikibaseEntityLibrary.php
+++ b/client/includes/scribunto/Scribunto_LuaWikibaseEntityLibrary.php
@@ -2,6 +2,7 @@
use ValueFormatters\FormatterOptions;
use Wikibase\Client\Scribunto\WikibaseLuaEntityBindings;
+use Wikibase\Client\Usage\ParserOutputUsageAccumulator;
use Wikibase\Client\WikibaseClient;
use Wikibase\Lib\SnakFormatter;
@@ -21,13 +22,15 @@
*/
private $wbLibrary;
- /**
- * Constructor for wrapper class, initialize member object holding
implementation
- *
- * @param Scribunto_LuaEngine $engine
- * @since 0.5
- */
- public function __construct( $engine ) {
+ private function getImplementation() {
+ if ( !$this->wbLibrary ) {
+ $this->wbLibrary = $this->newImplementation();
+ }
+
+ return $this->wbLibrary;
+ }
+
+ private function newImplementation() {
// For the language we need $wgContLang, not parser target
language or anything else.
// See Scribunto_LuaLanguageLibrary::getContLangCode().
global $wgContLang;
@@ -40,14 +43,13 @@
SnakFormatter::FORMAT_WIKI, $formatterOptions
);
- $this->wbLibrary = new WikibaseLuaEntityBindings(
+ return new WikibaseLuaEntityBindings(
$snakFormatter,
$wikibaseClient->getStore()->getEntityLookup(),
+ new ParserOutputUsageAccumulator(
$this->getParser()->getOutput() ),
$wikibaseClient->getSettings()->getSetting(
'siteGlobalID' ),
$wgContLang
);
-
- parent::__construct( $engine );
}
/**
@@ -76,7 +78,7 @@
* @return string[]
*/
public function getGlobalSiteId() {
- return array( $this->wbLibrary->getGlobalSiteId() );
+ return array( $this->getImplementation()->getGlobalSiteId() );
}
/**
@@ -99,7 +101,7 @@
$this->checkType( 'formatPropertyValues', 1, $propertyId,
'string' );
$this->checkType( 'formatPropertyValues', 2, $acceptableRanks,
'table' );
try {
- return array( $this->wbLibrary->formatPropertyValues(
$entityId, $propertyId, $acceptableRanks ) );
+ return array(
$this->getImplementation()->formatPropertyValues( $entityId, $propertyId,
$acceptableRanks ) );
} catch ( InvalidArgumentException $e ) {
throw new ScribuntoException(
'wikibase-error-invalid-entity-id' );
}
diff --git a/client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
b/client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
index 5abe2aa..5a9fac5 100644
--- a/client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
+++ b/client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
@@ -1,6 +1,7 @@
<?php
use Wikibase\Client\Scribunto\WikibaseLuaBindings;
+use Wikibase\Client\Usage\ParserOutputUsageAccumulator;
use Wikibase\Client\WikibaseClient;
use Wikibase\DataModel\Entity\EntityIdParsingException;
use Wikibase\Lib\Store\EntityRetrievingTermLookup;
@@ -22,13 +23,15 @@
*/
private $wbLibrary;
- /**
- * Constructor for wrapper class, initialize member object holding
implementation
- *
- * @param Scribunto_LuaEngine $engine
- * @since 0.5
- */
- public function __construct( $engine ) {
+ private function getImplementation() {
+ if ( !$this->wbLibrary ) {
+ $this->wbLibrary = $this->newImplementation();
+ }
+
+ return $this->wbLibrary;
+ }
+
+ private function newImplementation() {
// For the language we need $wgContLang, not parser target
language or anything else.
// See Scribunto_LuaLanguageLibrary::getContLangCode().
global $wgContLang;
@@ -42,7 +45,7 @@
$wgContLang->getCode()
);
- $this->wbLibrary = new WikibaseLuaBindings(
+ return new WikibaseLuaBindings(
$wikibaseClient->getEntityIdParser(),
$entityLookup,
$wikibaseClient->getStore()->getSiteLinkTable(),
@@ -51,11 +54,10 @@
$wikibaseClient->getSettings(),
$wikibaseClient->getPropertyDataTypeLookup(),
$labelLookup,
+ new ParserOutputUsageAccumulator(
$this->getParser()->getOutput() ),
Utils::getLanguageCodes(),
$wikibaseClient->getSettings()->getSetting(
'siteGlobalID' )
);
-
- parent::__construct( $engine );
}
/**
@@ -95,7 +97,7 @@
$this->checkType( 'getEntity', 1, $prefixedEntityId, 'string' );
$this->checkType( 'getEntity', 2, $legacyStyle, 'boolean' );
try {
- $entityArr = $this->wbLibrary->getEntity(
$prefixedEntityId, $legacyStyle );
+ $entityArr = $this->getImplementation()->getEntity(
$prefixedEntityId, $legacyStyle );
return array( $entityArr );
}
catch ( EntityIdParsingException $e ) {
@@ -117,7 +119,7 @@
*/
public function getEntityId( $pageTitle = null ) {
$this->checkType( 'getEntityByTitle', 1, $pageTitle, 'string' );
- return array( $this->wbLibrary->getEntityId( $pageTitle ) );
+ return array( $this->getImplementation()->getEntityId(
$pageTitle ) );
}
/**
@@ -128,7 +130,7 @@
* @return string[]
*/
public function getGlobalSiteId() {
- return array( $this->wbLibrary->getGlobalSiteId() );
+ return array( $this->getImplementation()->getGlobalSiteId() );
}
/**
@@ -142,7 +144,7 @@
*/
public function getSetting( $setting ) {
$this->checkType( 'setting', 1, $setting, 'string' );
- return array( $this->wbLibrary->getSetting( $setting ) );
+ return array( $this->getImplementation()->getSetting( $setting
) );
}
/**
@@ -156,7 +158,7 @@
*/
public function getLabel( $prefixedEntityId ) {
$this->checkType( 'getLabel', 1, $prefixedEntityId, 'string' );
- return array( $this->wbLibrary->getLabel( $prefixedEntityId ) );
+ return array( $this->getImplementation()->getLabel(
$prefixedEntityId ) );
}
/**
@@ -170,6 +172,6 @@
*/
public function getSiteLinkPageName( $prefixedEntityId ) {
$this->checkType( 'getSiteLinkPageName', 1, $prefixedEntityId,
'string' );
- return array( $this->wbLibrary->getSiteLinkPageName(
$prefixedEntityId ) );
+ return array( $this->getImplementation()->getSiteLinkPageName(
$prefixedEntityId ) );
}
}
diff --git a/client/includes/scribunto/WikibaseLuaBindings.php
b/client/includes/scribunto/WikibaseLuaBindings.php
index ada4285..0bf16dd 100644
--- a/client/includes/scribunto/WikibaseLuaBindings.php
+++ b/client/includes/scribunto/WikibaseLuaBindings.php
@@ -5,6 +5,7 @@
use InvalidArgumentException;
use Language;
use OutOfBoundsException;
+use Wikibase\Client\Usage\UsageAccumulator;
use Wikibase\DataModel\Entity\Entity;
use Wikibase\DataModel\Entity\EntityIdParser;
use Wikibase\DataModel\Entity\EntityIdParsingException;
@@ -82,6 +83,11 @@
private $labelLookup;
/**
+ * @var UsageAccumulator
+ */
+ private $usageAccumulator;
+
+ /**
* @param EntityIdParser $entityIdParser
* @param EntityLookup $entityLookup
* @param SiteLinkLookup $siteLinkTable
@@ -90,6 +96,7 @@
* @param SettingsArray $settings
* @param PropertyDataTypeLookup $dataTypeLookup
* @param LabelLookup $labelLookup
+ * @param UsageAccumulator $usageAccumulator
* @param string[] $languageCodes
* @param string $siteId
*/
@@ -102,6 +109,7 @@
SettingsArray $settings,
PropertyDataTypeLookup $dataTypeLookup,
LabelLookup $labelLookup,
+ UsageAccumulator $usageAccumulator,
$languageCodes,
$siteId
) {
@@ -115,6 +123,7 @@
$this->labelLookup = $labelLookup;
$this->languageCodes = $languageCodes;
$this->siteId = $siteId;
+ $this->usageAccumulator = $usageAccumulator;
}
/**
@@ -171,6 +180,7 @@
$entityArr['schemaVersion'] = 2;
}
+ $this->usageAccumulator->addAllUsage( $entityId );
return $entityArr;
}
@@ -224,6 +234,7 @@
return null;
}
+ $this->usageAccumulator->addPageUsage( $id );
return $id->getSerialization();
}
@@ -270,6 +281,12 @@
return '';
}
+ // NOTE: This tracks a label usage in the wiki's content
language.
+ // If the actual label is derived via language fallback,
+ // updates to the source language will not be seen to
apply
+ // to this usage. We would need to trigger on changes to
+ // *all* languages to fix that.
+ $this->usageAccumulator->addLabelUsage( $entityId );
return $label;
}
@@ -291,6 +308,8 @@
return '';
}
+ $this->usageAccumulator->addPageUsage( $itemId );
return $item->getSiteLinkList()->getBySiteId( $this->siteId
)->getPageName();
}
+
}
diff --git a/client/includes/scribunto/WikibaseLuaEntityBindings.php
b/client/includes/scribunto/WikibaseLuaEntityBindings.php
index 381afff..cf68e20 100644
--- a/client/includes/scribunto/WikibaseLuaEntityBindings.php
+++ b/client/includes/scribunto/WikibaseLuaEntityBindings.php
@@ -3,11 +3,14 @@
namespace Wikibase\Client\Scribunto;
use Language;
+use Wikibase\Client\Usage\UsageAccumulator;
use Wikibase\DataModel\Claim\Claims;
use Wikibase\DataModel\Entity\Entity;
use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Entity\EntityIdValue;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Snak\Snak;
use Wikibase\Lib\SnakFormatter;
use Wikibase\Lib\Store\EntityLookup;
@@ -34,6 +37,11 @@
private $entityLookup;
/**
+ * @var UsageAccumulator
+ */
+ private $usageAccumulator;
+
+ /**
* @var string
*/
private $siteId;
@@ -50,18 +58,21 @@
/**
* @param SnakFormatter $snakFormatter
- * @param EntityLookup $entityLookup,
- * @param string $siteId,
+ * @param EntityLookup $entityLookup
+ * @param UsageAccumulator $usageAccumulator
+ * @param string $siteId
* @param Language $language
*/
public function __construct(
SnakFormatter $snakFormatter,
EntityLookup $entityLookup,
+ UsageAccumulator $usageAccumulator,
$siteId,
Language $language
) {
$this->snakFormatter = $snakFormatter;
$this->entityLookup = $entityLookup;
+ $this->usageAccumulator = $usageAccumulator;
$this->siteId = $siteId;
$this->language = $language;
}
@@ -125,9 +136,32 @@
}
/**
+ * @todo Share code with LanguageAwareRenderer::trackUsage
+ * @param Snak[] $snaks
+ */
+ private function trackUsage( array $snaks ) {
+ // Note: we track any EntityIdValue as a label usage.
+ // This is making assumptions about what the respective
formatter actually does.
+ // Ideally, the formatter itself would perform the tracking,
but that seems nasty to model.
+
+ foreach ( $snaks as $snak ) {
+ if ( !( $snak instanceof PropertyValueSnak ) ) {
+ continue;
+ }
+
+ $value = $snak->getDataValue();
+
+ if ( $value instanceof EntityIdValue ) {
+ $this->usageAccumulator->addLabelUsage(
$value->getEntityId() );
+ }
+ }
+ }
+
+ /**
* Render the main Snaks belonging to a Claim (which is identified by a
PropertyId).
*
* @since 0.5
+ * @todo Share code with LanguageAwareRenderer.
*
* @param string $entityId
* @param string $propertyId
@@ -161,6 +195,8 @@
}
$snakList = $claims->getMainSnaks();
+
+ $this->trackUsage( $snakList );
return $this->formatSnakList( $snakList );
}
diff --git
a/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseEntityLibraryTest.php
b/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseEntityLibraryTest.php
index a87eda4..e1dfeb4 100644
---
a/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseEntityLibraryTest.php
+++
b/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseEntityLibraryTest.php
@@ -2,6 +2,8 @@
namespace Wikibase\Test;
+use Parser;
+use ParserOptions;
use Scribunto;
use Scribunto_LuaWikibaseEntityLibrary;
use Title;
@@ -69,8 +71,13 @@
}
private function newScribuntoLuaWikibaseLibrary() {
+ $title = Title::newFromText( 'Whatever' );
+ $parser = new Parser();
+ $parser->startExternalParse( $title, new ParserOptions(),
Parser::OT_HTML );
+
$engine = Scribunto::newDefaultEngine( array(
- 'title' => Title::newFromText( 'Whatever' )
+ 'parser' => $parser,
+ 'title' => $title
) );
$engine->load();
diff --git
a/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryTest.php
b/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryTest.php
index bba0a7f..985b973 100644
---
a/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryTest.php
+++
b/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryTest.php
@@ -2,6 +2,8 @@
namespace Wikibase\Test;
+use Parser;
+use ParserOptions;
use Scribunto;
use Scribunto_LuaWikibaseLibrary;
use Title;
@@ -80,8 +82,13 @@
}
private function newScribuntoLuaWikibaseLibrary() {
+ $title = Title::newFromText( 'Whatever' );
+ $parser = new Parser();
+ $parser->startExternalParse( $title, new ParserOptions(),
Parser::OT_HTML );
+
$engine = Scribunto::newDefaultEngine( array(
- 'title' => Title::newFromText( 'Whatever' )
+ 'parser' => $parser,
+ 'title' => $title
) );
$engine->load();
diff --git
a/client/tests/phpunit/includes/scribunto/WikibaseLuaBindingsTest.php
b/client/tests/phpunit/includes/scribunto/WikibaseLuaBindingsTest.php
index 0692c74..de0759b 100644
--- a/client/tests/phpunit/includes/scribunto/WikibaseLuaBindingsTest.php
+++ b/client/tests/phpunit/includes/scribunto/WikibaseLuaBindingsTest.php
@@ -4,7 +4,11 @@
use Language;
use Wikibase\Client\Scribunto\WikibaseLuaBindings;
+use Wikibase\Client\Usage\EntityUsage;
+use Wikibase\Client\Usage\HashUsageAccumulator;
+use Wikibase\Client\Usage\UsageAccumulator;
use Wikibase\DataModel\Entity\BasicEntityIdParser;
+use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\SiteLink;
@@ -35,7 +39,10 @@
);
}
- private function getWikibaseLibraryImplementation( EntityLookup
$entityLookup = null ) {
+ private function getWikibaseLibraryImplementation(
+ EntityLookup $entityLookup = null,
+ UsageAccumulator $usageAccumulator = null
+ ) {
$language = new Language( "en" );
$siteLinkTable = $this->getMockBuilder(
'Wikibase\Lib\Store\SiteLinkTable' )
@@ -68,9 +75,16 @@
new SettingsArray(),
$propertyDataTypeLookup,
$labelLookup,
+ $usageAccumulator ? $usageAccumulator : new
HashUsageAccumulator(),
array( 'de', 'en', 'es', 'ja' ),
"enwiki" // siteId
);
+ }
+
+ private function hasUsage( $actualUsages, EntityId $entityId, $aspect )
{
+ $usage = new EntityUsage( $entityId, $aspect );
+ $key = $usage->getIdentityString();
+ return isset( $actualUsages[$key] );
}
/**
@@ -79,9 +93,24 @@
public function testGetEntity( array $expected, Item $item,
EntityLookup $entityLookup ) {
$prefixedId = $item->getId()->getSerialization();
$wikibaseLibrary = $this->getWikibaseLibraryImplementation(
$entityLookup );
+
$entityArr = $wikibaseLibrary->getEntity( $prefixedId );
$actual = is_array( $entityArr ) ? array_keys( $entityArr ) :
array();
$this->assertEquals( $expected, $actual );
+ }
+
+ public function testGetEntity_usage() {
+ $item = $this->getItem();
+ $itemId = $item->getId();
+
+ $entityLookup = new MockRepository();
+ $entityLookup->putEntity( $item );
+
+ $usages = new HashUsageAccumulator();
+ $wikibaseLibrary = $this->getWikibaseLibraryImplementation(
$entityLookup, $usages );
+
+ $wikibaseLibrary->getEntity( $itemId->getSerialization() );
+ $this->assertTrue( $this->hasUsage( $usages->getUsages(),
$item->getId(), EntityUsage::ALL_USAGE ), 'all usage' );
}
public function getEntityProvider() {
@@ -100,9 +129,14 @@
}
public function testGetEntityId() {
- $wikibaseLibrary = $this->getWikibaseLibraryImplementation();
+ $usages = new HashUsageAccumulator();
+ $wikibaseLibrary = $this->getWikibaseLibraryImplementation(
null, $usages );
+
$itemId = $wikibaseLibrary->getEntityId( 'Rome' );
$this->assertEquals( 'Q33' , $itemId );
+
+ $this->assertTrue( $this->hasUsage( $usages->getUsages(), new
ItemId( $itemId ), EntityUsage::TITLE_USAGE ), 'title usage' );
+ $this->assertFalse( $this->hasUsage( $usages->getUsages(), new
ItemId( $itemId ), EntityUsage::SITELINK_USAGE ), 'sitelink usage' );
$itemId = $wikibaseLibrary->getEntityId( 'Barcelona' );
$this->assertSame( null, $itemId );
@@ -131,6 +165,18 @@
$this->assertSame( $expected, $wikibaseLibrary->getLabel(
$itemId ) );
}
+ public function testGetLabel_usage() {
+ $usages = new HashUsageAccumulator();
+ $wikibaseLibrary = $this->getWikibaseLibraryImplementation(
null, $usages );
+
+ $itemId = new ItemId( 'Q7' );
+ $wikibaseLibrary->getLabel( $itemId->getSerialization() );
+
+ $this->assertTrue( $this->hasUsage( $usages->getUsages(),
$itemId, EntityUsage::LABEL_USAGE ), 'label usage' );
+ $this->assertFalse( $this->hasUsage( $usages->getUsages(),
$itemId, EntityUsage::TITLE_USAGE ), 'title usage' );
+ $this->assertFalse( $this->hasUsage( $usages->getUsages(),
$itemId, EntityUsage::ALL_USAGE ), 'all usage' );
+ }
+
public function getSiteLinkPageNameProvider() {
return array(
array( 'Beer', 'Q666' ),
@@ -154,6 +200,23 @@
$this->assertSame( $expected,
$wikibaseLibrary->getSiteLinkPageName( $itemId ) );
}
+ public function testGetSiteLinkPageName_usage() {
+ $item = $this->getItem();
+
+ $entityLookup = new MockRepository();
+ $entityLookup->putEntity( $item );
+
+ $usages = new HashUsageAccumulator();
+ $wikibaseLibrary = $this->getWikibaseLibraryImplementation(
$entityLookup, $usages );
+
+ $itemId = $item->getId();
+ $wikibaseLibrary->getSiteLinkPageName(
$itemId->getSerialization() );
+
+ $this->assertTrue( $this->hasUsage( $usages->getUsages(),
$itemId, EntityUsage::TITLE_USAGE ), 'title usage' );
+ $this->assertFalse( $this->hasUsage( $usages->getUsages(),
$itemId, EntityUsage::LABEL_USAGE ), 'label usage' );
+ $this->assertFalse( $this->hasUsage( $usages->getUsages(),
$itemId, EntityUsage::ALL_USAGE ), 'all usage' );
+ }
+
protected function getItem() {
$itemId = new ItemId( 'Q666' );
diff --git
a/client/tests/phpunit/includes/scribunto/WikibaseLuaEntityBindingsTest.php
b/client/tests/phpunit/includes/scribunto/WikibaseLuaEntityBindingsTest.php
index 4662ee6..43c5da6 100644
--- a/client/tests/phpunit/includes/scribunto/WikibaseLuaEntityBindingsTest.php
+++ b/client/tests/phpunit/includes/scribunto/WikibaseLuaEntityBindingsTest.php
@@ -4,10 +4,16 @@
use Language;
use Wikibase\Client\Scribunto\WikibaseLuaEntityBindings;
+use Wikibase\Client\Usage\EntityUsage;
+use Wikibase\Client\Usage\HashUsageAccumulator;
+use Wikibase\Client\Usage\UsageAccumulator;
use Wikibase\DataModel\Claim\Claim;
use Wikibase\DataModel\Entity\Entity;
+use Wikibase\DataModel\Entity\EntityIdValue;
use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\Lib\SnakFormatter;
use Wikibase\Lib\Store\EntityLookup;
@@ -34,12 +40,16 @@
);
}
- private function getWikibaseLibraryImplementation( EntityLookup
$entityLookup = null ) {
+ private function getWikibaseLibraryImplementation(
+ EntityLookup $entityLookup = null,
+ UsageAccumulator $usageAccumulator = null
+ ) {
$language = new Language( 'en' );
return new WikibaseLuaEntityBindings(
$this->newSnakFormatterMock(),
$entityLookup ? $entityLookup : new MockRepository(),
+ $usageAccumulator ? $usageAccumulator : new
HashUsageAccumulator(),
'enwiki',
$language // language
);
@@ -49,11 +59,8 @@
* @return Item
*/
private function getItem() {
- $snakFactory = new SnakFactory();
- $snak = $snakFactory->newSnak(
- new PropertyId( 'P123456' ),
- 'somevalue'
- );
+ $propertyId = new PropertyId( 'P123456' );
+ $snak = new PropertyValueSnak( $propertyId, new EntityIdValue(
new ItemId( 'Q11' ) ));
$statement = new Statement( new Claim( $snak ) );
$statement->setGuid( 'gsdfgsadg' );
@@ -94,10 +101,16 @@
$item = $this->getItem();
$entityLookup = $this->getEntityLookupMock( $item );
- $wikibaseLibrary = $this->getWikibaseLibraryImplementation(
$entityLookup );
+ $usageAccumulator = new HashUsageAccumulator();
+ $wikibaseLibrary = $this->getWikibaseLibraryImplementation(
$entityLookup, $usageAccumulator );
+
$ret = $wikibaseLibrary->formatPropertyValues( 'Q1', 'P123456'
);
$this->assertSame( 'Snak snak snak', $ret );
+
+ $expectedUsage = new EntityUsage( new ItemId( 'Q11' ),
EntityUsage::LABEL_USAGE );
+ $usages = $usageAccumulator->getUsages();
+ $this->assertArrayHasKey( $expectedUsage->getIdentityString(),
$usages );
}
public function testFormatPropertyValuesNoProperty() {
--
To view, visit https://gerrit.wikimedia.org/r/172248
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib47e3d9348f60b50c176162ca686cb06672fdfe9
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits