Daniel Kinzler has uploaded a new change for review.
https://gerrit.wikimedia.org/r/56330
Change subject: Implement PropertyLookup on top of TermIndex (WIP).
......................................................................
Implement PropertyLookup on top of TermIndex (WIP).
DO NOT MERGE, WORK IN PROGRESS!
Change-Id: I3866c4243247345766d7a34af671e304a7732994
---
M DataModel/DataModel/Snak/SnakList.php
M DataModel/tests/phpunit/Snak/SnakListTest.php
M lib/WikibaseLib.php
R lib/includes/store/PropertyEntityLookup.php
A lib/includes/store/PropertyTermLookup.php
M lib/tests/phpunit/store/PropertyEntityLookupTest.php
A lib/tests/phpunit/store/PropertyLookupTest.php
A lib/tests/phpunit/store/PropertyTermLookupTest.php
8 files changed, 480 insertions(+), 176 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/30/56330/1
diff --git a/DataModel/DataModel/Snak/SnakList.php
b/DataModel/DataModel/Snak/SnakList.php
index 5ad98dc..055370f 100644
--- a/DataModel/DataModel/Snak/SnakList.php
+++ b/DataModel/DataModel/Snak/SnakList.php
@@ -137,6 +137,26 @@
}
/**
+ * Returns an array of EntityIds, containing the IDs of all properties
used by
+ * the Snaks in this list. The array keys will be the numeric IDs of
the properties.
+ *
+ * @since 0.4
+ *
+ * @return EntityId[]
+ */
+ public function getPropertyIds() {
+ $ids = array();
+
+ /* @var Snak $snak */
+ foreach ( $this as $snak ) {
+ $id = $snak->getPropertyId()->getNumericId();
+ $ids[$id] = $snak->getPropertyId();
+ }
+
+ return $ids;
+ }
+
+ /**
* Factory for constructing a SnakList from its array representation.
*
* @since 0.3
@@ -154,5 +174,4 @@
return new static( $snaks );
}
-
}
diff --git a/DataModel/tests/phpunit/Snak/SnakListTest.php
b/DataModel/tests/phpunit/Snak/SnakListTest.php
index 799d2d6..a16484f 100644
--- a/DataModel/tests/phpunit/Snak/SnakListTest.php
+++ b/DataModel/tests/phpunit/Snak/SnakListTest.php
@@ -182,4 +182,24 @@
}
}
+ /**
+ * @dataProvider instanceProvider
+ *
+ * @param SnakList $snaks
+ */
+ public function testGetIDs( SnakList $snaks ) {
+ $ids = $snaks->getPropertyIds();
+
+ $this->assertInternalType( 'array', $ids,
+ 'getPropertyIds() should return array' );
+
+ $this->assertTrue( count( $ids ) <= count($snaks), $ids,
+ 'the number of properties can\'t be greater than the
number of snaks' );
+
+ foreach ( $ids as $n => $id ) {
+ $this->assertEquals( \Wikibase\Property::ENTITY_TYPE,
$id->getEntityType(), "entity type" );
+ $this->assertEquals( $n, $id->getNumericId(), "array
key vs. numeric ID" );
+ }
+ }
+
}
diff --git a/lib/WikibaseLib.php b/lib/WikibaseLib.php
index 859cb92..6d36916 100644
--- a/lib/WikibaseLib.php
+++ b/lib/WikibaseLib.php
@@ -199,6 +199,7 @@
// tests
$wgAutoloadClasses['Wikibase\Test\SpecialPageTestBase'] = $dir .
'tests/phpunit/specials/SpecialPageTestBase.php';
+$wgAutoloadClasses['Wikibase\Test\PropertyLookupTest'] = $dir
. 'tests/phpunit/store/PropertyLookupTest.php';
$wgAutoloadClasses['Wikibase\Test\HashArrayTest'] = $dir
. 'tests/phpunit/hasharray/HashArrayTest.php';
$wgAutoloadClasses['Wikibase\Test\HashArrayElement'] = $dir .
'tests/phpunit/hasharray/HashArrayElement.php';
diff --git a/lib/includes/store/sql/PropertyEntityLookup.php
b/lib/includes/store/PropertyEntityLookup.php
similarity index 90%
rename from lib/includes/store/sql/PropertyEntityLookup.php
rename to lib/includes/store/PropertyEntityLookup.php
index e832c04..db7ddb2 100644
--- a/lib/includes/store/sql/PropertyEntityLookup.php
+++ b/lib/includes/store/PropertyEntityLookup.php
@@ -33,7 +33,7 @@
*/
class PropertyEntityLookup implements PropertyLookup {
- /* @var WikiPageEntityLookup */
+ /* @var EntityLookup */
protected $entityLookup;
/* @var array */
@@ -106,24 +106,6 @@
wfProfileOut( __METHOD__ );
return $propertyLabel;
- }
-
- /**
- * @since 0.4
- *
- * @param EntityId $propertyId
- *
- * @return Statement[]
- */
- protected function getStatementsByProperty( EntityId $propertyId ) {
- wfProfileIn( __METHOD__ );
- $numericId = $propertyId->getNumericId();
-
- $statements = array_key_exists( $numericId,
$this->statementsByProperty )
- ? $this->statementsByProperty[$numericId] : array();
-
- wfProfileOut( __METHOD__ );
- return $statements;
}
/**
diff --git a/lib/includes/store/PropertyTermLookup.php
b/lib/includes/store/PropertyTermLookup.php
new file mode 100644
index 0000000..1e0b6b7
--- /dev/null
+++ b/lib/includes/store/PropertyTermLookup.php
@@ -0,0 +1,130 @@
+<?php
+
+namespace Wikibase;
+
+/**
+ * Implementation of PropertyLookup based on a TermIndex
+ *
+ * @todo add caching (LRU in memcached?)
+ *
+ * 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 WikibaseLib
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Kinzler
+ */
+class PropertyTermLookup implements PropertyLookup {
+
+ /**
+ * @var TermIndex
+ **/
+ protected $termIndex;
+
+ /**
+ * @var array[] An array of arrays of item IDs:
+ * $propertiesByLabel[$lang][$label] = $propertyId.
+ **/
+ protected $propertiesByLabel;
+
+ /**
+ * @since 0.4
+ *
+ * @param EntityLookup $entityLookup
+ */
+ public function __construct( TermIndex $termIndex ) {
+ $this->$termIndex = $termIndex;
+ }
+
+ /**
+ * Fetches the labels for the given properties from the TermIndex
+ * and caches them in $this->propertiesByLabel[$lang].
+ *
+ * @param EntityId[] $propertyIds
+ * @param string $lang
+ */
+ protected function prefetchLabels( array $propertyIds, $lang ) {
+ $terms = $this->termIndex->getTermsOfEntities( $propertyIds,
Property::ENTITY_TYPE, $lang );
+
+ if ( !isset( $this->propertiesByLabel[$lang] ) ) {
+ $this->propertiesByLabel[$lang] = array();
+ }
+
+ /* @var Term $term */
+ foreach ( $terms as $term ) {
+ if ( $term->getType() === Term::TYPE_LABEL ) {
+ $label = $term->getText();
+ $this->propertiesByLabel[$lang][$label] =
$term->getEntityId();
+ }
+ }
+ }
+
+ /**
+ * @since 0.4
+ *
+ * @param string $propertyLabel
+ * @param string $langCode
+ *
+ * @return int|null|bool The property's integer ID, or false of known
to be undefined,
+ * or null if not yet loaded.
+ */
+ protected function getCachedPropertyId( $propertyLabel, $langCode ) {
+ if ( isset( $this->propertiesByLabel[$langCode][$propertyLabel]
) ) {
+ return
$this->propertiesByLabel[$langCode][$propertyLabel];
+ }
+
+ return null;
+ }
+
+ /**
+ * @since 0.4
+ *
+ * @param Entity $entity
+ * @param string $propertyLabel
+ * @param string $langCode
+ *
+ * @return Claims
+ */
+ public function getClaimsByPropertyLabel( Entity $entity,
$propertyLabel, $langCode ) {
+ wfProfileIn( __METHOD__ );
+
+ $allClaims = new Claims( $entity->getClaims() );
+
+ $propertyId = $this->getCachedPropertyId( $propertyLabel,
$langCode );
+
+ if ( $propertyId === null ) {
+ $propertyIds =
$allClaims->getMainSnaks()->getPropertyIds();
+
+ $this->prefetchLabels( $propertyIds, $langCode );
+ $propertyId = $this->getCachedPropertyId(
$propertyLabel, $langCode );
+ }
+
+ if ( $propertyId !== null && $propertyId !== false ) {
+ $claims = $allClaims->getClaimsForProperty( $propertyId
);
+ } else {
+ // negative caching!
+ $this->propertiesByLabel[$langCode][$propertyLabel] =
false;
+ $claims = new Claims();
+ }
+
+ wfProfileOut( __METHOD__ );
+ return $claims;
+ }
+
+}
diff --git a/lib/tests/phpunit/store/PropertyEntityLookupTest.php
b/lib/tests/phpunit/store/PropertyEntityLookupTest.php
index d45c53d..6ef1553 100644
--- a/lib/tests/phpunit/store/PropertyEntityLookupTest.php
+++ b/lib/tests/phpunit/store/PropertyEntityLookupTest.php
@@ -6,10 +6,6 @@
use Wikibase\EntityId;
use Wikibase\Property;
use Wikibase\Item;
-use Wikibase\Statement;
-use Wikibase\Claims;
-use Wikibase\PropertyValueSnak;
-use DataValues\StringValue;
/**
* Tests for the Wikibase\PropertyEntityLookup class.
@@ -42,7 +38,7 @@
* @author Katie Filbert < [email protected] >
* @author Daniel Kinzler
*/
-class PropertyEntityLookupTest extends \MediaWikiTestCase {
+class PropertyEntityLookupTest extends PropertyLookupTest {
/**
* @var \Wikibase\EntityLookup
@@ -54,126 +50,13 @@
*/
protected $propertyLookup;
- public function getPropertyData() {
- $propertyData = array(
- array(
- 'id' => 4,
- 'type' => 'wikibase-item',
- 'lang' => 'en',
- 'label' => 'capital'
- ),
- array(
- 'id' => 6,
- 'type' => 'wikibase-item',
- 'lang' => 'en',
- 'label' => 'currency'
- ),
- array(
- 'id' => 7,
- 'type' => 'commonsMedia',
- 'lang' => 'en',
- 'label' => 'flag',
- ),
- array(
- 'id' => 9,
- 'type' => 'string',
- 'lang' => 'en',
- 'label' => 'country code'
- ),
- array(
- 'id' => 10,
- 'type' => 'wikibase-item',
- )
- );
-
- $properties = array();
-
- foreach( $propertyData as $data ) {
- $property = Property::newFromType( $data['type'] );
- $property->setId( new EntityId( Property::ENTITY_TYPE,
$data['id'] ) );
-
- if ( array_key_exists( 'label', $data ) ) {
- $property->setLabel( $data['lang'],
$data['label'] );
- }
-
- $properties[] = $property;
- }
-
- return $properties;
- }
-
- public function getItems() {
- $items = array();
-
- $properties = $this->getPropertyData();
-
- $snakData = array(
- array( 'property' => clone $properties[0], 'value' =>
new EntityId( Item::ENTITY_TYPE, 42 ) ),
- array( 'property' => clone $properties[0], 'value' =>
new EntityId( Item::ENTITY_TYPE, 44 ) ),
- array( 'property' => clone $properties[1], 'value' =>
new EntityId( Item::ENTITY_TYPE, 45 ) ),
- array( 'property' => clone $properties[2], 'value' =>
new StringValue( 'Flag of Canada.svg' ) ),
- array( 'property' => clone $properties[4], 'value' =>
new EntityId( Item::ENTITY_TYPE, 46 ) ),
- );
-
- $statements = array();
-
- foreach( $snakData as $data ) {
- $property = $data['property'];
- $statements[] = new Statement(
- new PropertyValueSnak( $property->getId(),
$data['value'] )
- );
- }
-
- $item = Item::newEmpty();
- $itemId = new EntityId( Item::ENTITY_TYPE, 126 );
- $item->setId( $itemId );
- $item->setLabel( 'en', 'Canada' );
-
- $claims = new Claims();
-
- foreach( $statements as $statement ) {
- $claims->addClaim( $statement );
- }
-
- $item->setClaims( $claims );
-
- $items[] = $item;
-
- // -------------
- $item = $item->copy();
-
- $itemId = new EntityId( Item::ENTITY_TYPE, 128 );
- $item->setId( $itemId );
- $item->setLabel( 'en', 'Nanada' );
-
- $statement = new Statement(
- new \Wikibase\PropertyNoValueSnak(
$properties[3]->getId() )
- );
-
- $claims = new Claims();
- $claims->addClaim( $statement );
- $item->setClaims( $claims );
-
- $items[] = $item;
-
- return $items;
- }
-
public function setUp() {
parent::setUp();
$this->entityLookup = new \Wikibase\Test\MockRepository();
- $properties = $this->getPropertyData();
-
- foreach( $properties as $property ) {
- $this->entityLookup->putEntity( $property );
- }
-
- $items = $this->getItems();
-
- foreach ( $items as $item ) {
- $this->entityLookup->putEntity( $item );
+ foreach ( $this->entities as $entity ) {
+ $this->entityLookup->putEntity( $entity );
}
$this->propertyLookup = new PropertyEntityLookup(
$this->entityLookup );
@@ -184,51 +67,23 @@
$this->assertInstanceOf( '\Wikibase\PropertyEntityLookup',
$instance );
}
- public function getMainSnaksByPropertyLabelProvider() {
- $entity126 = new EntityId( Item::ENTITY_TYPE, 126 );
- $entity128 = new EntityId( Item::ENTITY_TYPE, 128 );
-
- return array(
- array( $entity126, 'capital', 'en', 2 ),
- array( $entity126, 'currency', 'en', 1 ),
- array( $entity126, 'president', 'en', 0 ),
- array( $entity128, 'country code', 'en', 1 )
- );
- }
-
/**
- * @dataProvider getMainSnaksByPropertyLabelProvider
+ * @dataProvider getClaimsByPropertyLabelProvider
*/
- public function testGetMainSnaksByPropertyLabel( $entityId,
$propertyLabel, $langCode, $expected ) {
+ public function testGetClaimsByPropertyLabel( $entityId,
$propertyLabel, $langCode, $expected ) {
if ( !defined( 'WB_EXPERIMENTAL_FEATURES' ) ||
!WB_EXPERIMENTAL_FEATURES ) {
- $this->markTestSkipped( "getMainSnaksByPropertyLabel is
experimental" );
+ $this->markTestSkipped( "getClaimsByPropertyLabel is
experimental" );
}
- $entity = $this->entityLookup->getEntity( $entityId );
- $claims = $this->propertyLookup->getClaimsByPropertyLabel(
$entity, $propertyLabel, $langCode );
-
- $this->assertInstanceOf( '\Wikibase\Claims', $claims );
- $this->assertEquals( $expected, count( $claims ) );
+ parent::testGetClaimsByPropertyLabel( $entityId,
$propertyLabel, $langCode, $expected );
}
- public function testGetMainSnaksByPropertyLabel2( ) {
+ public function testGetClaimsByPropertyLabel2( ) {
if ( !defined( 'WB_EXPERIMENTAL_FEATURES' ) ||
!WB_EXPERIMENTAL_FEATURES ) {
- $this->markTestSkipped( "getMainSnaksByPropertyLabel is
experimental" );
+ $this->markTestSkipped( "getClaimsByPropertyLabel is
experimental" );
}
- $entity126 = $this->entityLookup->getEntity( new EntityId(
Item::ENTITY_TYPE, 126 ) );
-
- $claims = $this->propertyLookup->getClaimsByPropertyLabel(
$entity126, 'capital', 'en' );
- $this->assertEquals( 2, count( $claims ) );
-
- $claims = $this->propertyLookup->getClaimsByPropertyLabel(
$entity126, 'country code', 'en' );
- $this->assertEquals( 0, count( $claims ) );
-
- // try to find a property in another entity, if that property
wasn't used by the previous entity.
- $entity128 = $this->entityLookup->getEntity( new EntityId(
Item::ENTITY_TYPE, 128 ) );
-
- $claims = $this->propertyLookup->getClaimsByPropertyLabel(
$entity128, 'country code', 'en' );
- $this->assertEquals( 1, count( $claims ), "property unknown to
the first item" );
+ parent::testGetClaimsByPropertyLabel2();
}
public function getPropertyLabelProvider() {
@@ -240,7 +95,7 @@
}
/**
- * @depends testGetMainSnaksByPropertyLabel
+ * @depends testGetClaimsByPropertyLabel
* @dataProvider getPropertyLabelProvider
*/
public function testGetPropertyLabel( $expected, $lang, $id ) {
diff --git a/lib/tests/phpunit/store/PropertyLookupTest.php
b/lib/tests/phpunit/store/PropertyLookupTest.php
new file mode 100644
index 0000000..8262b27
--- /dev/null
+++ b/lib/tests/phpunit/store/PropertyLookupTest.php
@@ -0,0 +1,228 @@
+<?php
+
+namespace Wikibase\Test;
+use Wikibase\PropertyEntityLookup;
+use Wikibase\EntityFactory;
+use Wikibase\EntityId;
+use Wikibase\Property;
+use Wikibase\Item;
+use Wikibase\Statement;
+use Wikibase\Claims;
+use Wikibase\PropertyValueSnak;
+use DataValues\StringValue;
+
+/**
+ * Base class for testing the Wikibase\PropertyLookup implementations.
+ *
+ * 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 WikibaseLib
+ * @ingroup Test
+ *
+ * @group Wikibase
+ * @group WikibaseLib
+ *
+ * @licence GNU GPL v2+
+ * @author Katie Filbert < [email protected] >
+ * @author Daniel Kinzler
+ */
+abstract class PropertyLookupTest extends \MediaWikiTestCase {
+
+ /**
+ * @var \Wikibase\PropertyLookup
+ */
+ protected $propertyLookup;
+
+ /**
+ * @var \Wikibase\Entity[]
+ */
+ protected $entities;
+
+ public function getPropertyData() {
+ $propertyData = array(
+ array(
+ 'id' => 4,
+ 'type' => 'wikibase-item',
+ 'lang' => 'en',
+ 'label' => 'capital'
+ ),
+ array(
+ 'id' => 6,
+ 'type' => 'wikibase-item',
+ 'lang' => 'en',
+ 'label' => 'currency'
+ ),
+ array(
+ 'id' => 7,
+ 'type' => 'commonsMedia',
+ 'lang' => 'en',
+ 'label' => 'flag',
+ ),
+ array(
+ 'id' => 9,
+ 'type' => 'string',
+ 'lang' => 'en',
+ 'label' => 'country code'
+ ),
+ array(
+ 'id' => 10,
+ 'type' => 'wikibase-item',
+ )
+ );
+
+ $properties = array();
+
+ foreach( $propertyData as $data ) {
+ $property = Property::newFromType( $data['type'] );
+ $property->setId( new EntityId( Property::ENTITY_TYPE,
$data['id'] ) );
+
+ if ( array_key_exists( 'label', $data ) ) {
+ $property->setLabel( $data['lang'],
$data['label'] );
+ }
+
+ $properties[] = $property;
+ }
+
+ return $properties;
+ }
+
+ public function getItems() {
+ $items = array();
+
+ $properties = $this->getPropertyData();
+
+ $snakData = array(
+ array( 'property' => clone $properties[0], 'value' =>
new EntityId( Item::ENTITY_TYPE, 42 ) ),
+ array( 'property' => clone $properties[0], 'value' =>
new EntityId( Item::ENTITY_TYPE, 44 ) ),
+ array( 'property' => clone $properties[1], 'value' =>
new EntityId( Item::ENTITY_TYPE, 45 ) ),
+ array( 'property' => clone $properties[2], 'value' =>
new StringValue( 'Flag of Canada.svg' ) ),
+ array( 'property' => clone $properties[4], 'value' =>
new EntityId( Item::ENTITY_TYPE, 46 ) ),
+ );
+
+ $statements = array();
+
+ foreach( $snakData as $data ) {
+ $property = $data['property'];
+ $statements[] = new Statement(
+ new PropertyValueSnak( $property->getId(),
$data['value'] )
+ );
+ }
+
+ $item = Item::newEmpty();
+ $itemId = new EntityId( Item::ENTITY_TYPE, 126 );
+ $item->setId( $itemId );
+ $item->setLabel( 'en', 'Canada' );
+
+ $claims = new Claims();
+
+ foreach( $statements as $statement ) {
+ $claims->addClaim( $statement );
+ }
+
+ $item->setClaims( $claims );
+
+ $items[] = $item;
+
+ // -------------
+ $item = $item->copy();
+
+ $itemId = new EntityId( Item::ENTITY_TYPE, 128 );
+ $item->setId( $itemId );
+ $item->setLabel( 'en', 'Nanada' );
+
+ $statement = new Statement(
+ new \Wikibase\PropertyNoValueSnak(
$properties[3]->getId() )
+ );
+
+ $claims = new Claims();
+ $claims->addClaim( $statement );
+ $item->setClaims( $claims );
+
+ $items[] = $item;
+
+ return $items;
+ }
+
+ public function setUp() {
+ parent::setUp();
+
+ $properties = $this->getPropertyData();
+
+ foreach( $properties as $property ) {
+ $id = $property->getId()->getPrefixedId();
+ $this->entities[$id] = $property;
+ }
+
+ $items = $this->getItems();
+
+ foreach ( $items as $item ) {
+ $id = $item->getId()->getPrefixedId();
+ $this->entities[$id] = $item;
+ }
+ }
+
+ /**
+ * @param $id
+ *
+ * @return \Wikibase\Entity
+ */
+ protected function getEntity( $id ) {
+ if ( $id instanceof EntityId ) {
+ $id = $id->getPrefixedId();
+ }
+
+ return $this->entities[$id];
+ }
+
+ public function getClaimsByPropertyLabelProvider() {
+ return array(
+ array( 'q126', 'capital', 'en', 2 ),
+ array( 'q126', 'currency', 'en', 1 ),
+ array( 'q126', 'president', 'en', 0 ),
+ array( 'q128', 'country code', 'en', 1 )
+ );
+ }
+
+ /**
+ * @dataProvider getClaimsByPropertyLabelProvider
+ */
+ public function testGetClaimsByPropertyLabel( $entityId,
$propertyLabel, $langCode, $expected ) {
+ $entity = $this->getEntity( $entityId );
+ $claims = $this->propertyLookup->getClaimsByPropertyLabel(
$entity, $propertyLabel, $langCode );
+
+ $this->assertInstanceOf( '\Wikibase\Claims', $claims );
+ $this->assertEquals( $expected, count( $claims ) );
+ }
+
+ public function testGetClaimsByPropertyLabel2( ) {
+ $entity126 = $this->getEntity( 'q126' );
+
+ $claims = $this->propertyLookup->getClaimsByPropertyLabel(
$entity126, 'capital', 'en' );
+ $this->assertEquals( 2, count( $claims ) );
+
+ $claims = $this->propertyLookup->getClaimsByPropertyLabel(
$entity126, 'country code', 'en' );
+ $this->assertEquals( 0, count( $claims ) );
+
+ // try to find a property in another entity, if that property
wasn't used by the previous entity.
+ $entity128 = $this->getEntity( 'q128' );
+
+ $claims = $this->propertyLookup->getClaimsByPropertyLabel(
$entity128, 'country code', 'en' );
+ $this->assertEquals( 1, count( $claims ), "property unknown to
the first item" );
+ }
+}
diff --git a/lib/tests/phpunit/store/PropertyTermLookupTest.php
b/lib/tests/phpunit/store/PropertyTermLookupTest.php
new file mode 100644
index 0000000..06aa120
--- /dev/null
+++ b/lib/tests/phpunit/store/PropertyTermLookupTest.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace Wikibase\Test;
+use Wikibase\PropertyTermLookup;
+use Wikibase\EntityFactory;
+use Wikibase\EntityId;
+use Wikibase\Property;
+use Wikibase\Item;
+
+/**
+ * Tests for the Wikibase\PropertyTermLookup 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 WikibaseLib
+ * @ingroup Test
+ *
+ * @group Wikibase
+ * @group WikibaseLib
+ *
+ * @licence GNU GPL v2+
+ * @author Katie Filbert < [email protected] >
+ * @author Daniel Kinzler
+ */
+class PropertyTermLookupTest extends PropertyLookupTest {
+
+ /**
+ * @var \Wikibase\TermIndex
+ */
+ protected $termIndex;
+
+ /**
+ * @var \Wikibase\PropertyTermLookup
+ */
+ protected $propertyLookup;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->termIndex = new \Wikibase\Test\MockTermIndex();
+
+ foreach( $this->entities as $entity ) {
+ $this->termIndex->saveTermsOfEntity( $property );
+ }
+
+ $this->propertyLookup = new PropertyTermLookup(
$this->termIndex );
+ }
+
+ public function testConstructor() {
+ $instance = new PropertyTermLookup( $this->termIndex );
+ $this->assertInstanceOf( '\Wikibase\PropertyTermLookup',
$instance );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/56330
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3866c4243247345766d7a34af671e304a7732994
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits