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

Change subject: TermLookup should not know about entity existance.
......................................................................


TermLookup should not know about entity existance.

TermLookup should not guarantee behavior based on whether an entity exists
or not. Doing so forces additional dependencies and queries, even in cases
where we are not interested in the entity's existance.

This patch removes any such guarantees, and reworks the only place where
we currently have been using this distinction (namely 
EntityIdHtmlLinkFormatter).

Change-Id: Id8eb6ec021810350c59e7bbdb7c2b9bf5e608238
---
M lib/includes/formatters/EntityIdHtmlLinkFormatter.php
M lib/includes/formatters/EntityIdLabelFormatter.php
M lib/includes/store/EntityInfo.php
M lib/includes/store/EntityRetrievingTermLookup.php
M lib/includes/store/EntityTermLookup.php
M lib/includes/store/LabelLookup.php
M lib/includes/store/TermLookup.php
M lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterTest.php
M lib/tests/phpunit/store/EntityInfoTermLookupTest.php
M lib/tests/phpunit/store/EntityInfoTest.php
M lib/tests/phpunit/store/EntityRetrievingTermLookupTest.php
M lib/tests/phpunit/store/EntityTermLookupTest.php
M lib/tests/phpunit/store/LanguageFallbackLabelLookupTest.php
M lib/tests/phpunit/store/LanguageLabelLookupTest.php
14 files changed, 204 insertions(+), 161 deletions(-)

Approvals:
  Thiemo Mättig (WMDE): Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/includes/formatters/EntityIdHtmlLinkFormatter.php 
b/lib/includes/formatters/EntityIdHtmlLinkFormatter.php
index 5378374..c99cebc 100644
--- a/lib/includes/formatters/EntityIdHtmlLinkFormatter.php
+++ b/lib/includes/formatters/EntityIdHtmlLinkFormatter.php
@@ -3,7 +3,6 @@
 namespace Wikibase\Lib;
 
 use Html;
-use OutOfBoundsException;
 use ValueFormatters\FormatterOptions;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\Lib\Store\EntityTitleLookup;
@@ -53,18 +52,15 @@
                $label = $entityId->getSerialization();
 
                if ( $this->getOption( self::OPT_LOOKUP_LABEL ) ) {
-                       try {
-                               $itemLabel = $this->lookupEntityLabel( 
$entityId );
-                               if ( is_string( $itemLabel ) ) {
-                                       $label = $itemLabel;
-                               }
-                       } catch ( OutOfBoundsException $ex ) {
+                       $itemLabel = $this->lookupEntityLabel( $entityId );
+                       if ( is_string( $itemLabel ) ) {
+                               $label = $itemLabel;
+                       } elseif ( !$title->exists() ) {
                                return $this->getHtmlForNonExistent( $entityId 
);
                        }
                }
 
                $html = Html::element( 'a', $attributes, $label );
-
                return $html;
        }
 
diff --git a/lib/includes/formatters/EntityIdLabelFormatter.php 
b/lib/includes/formatters/EntityIdLabelFormatter.php
index cb76ae1..2b9c957 100644
--- a/lib/includes/formatters/EntityIdLabelFormatter.php
+++ b/lib/includes/formatters/EntityIdLabelFormatter.php
@@ -8,7 +8,6 @@
 use ValueFormatters\FormattingException;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\Lib\Store\LabelLookup;
-use Wikibase\Lib\Store\StorageException;
 
 /**
  * @since 0.4
@@ -86,11 +85,7 @@
                $label = null;
 
                if ( $this->getOption( self::OPT_LOOKUP_LABEL ) ) {
-                       try {
-                               $label = $this->lookupEntityLabel( $entityId );
-                       } catch ( OutOfBoundsException $ex ) {
-                               /* Use fallbacks below */
-                       }
+                       $label = $this->lookupEntityLabel( $entityId );
                }
 
                // @fixme check if the entity is deleted and format differently?
@@ -117,7 +112,6 @@
         *
         * @param EntityId $entityId
         *
-        * @throws OutOfBoundsException If an entity with that ID could not be 
loaded.
         * @return string|bool False if no label was found in the language or 
language fallback chain.
         */
        protected function lookupEntityLabel( EntityId $entityId ) {
@@ -125,10 +119,6 @@
                        return $this->labelLookup->getLabel( $entityId );
                } catch ( OutOfBoundsException $e ) {
                        return false;
-               } catch ( StorageException $ex ) {
-                       // @todo maybe handle formatting in this in a better 
way.
-                       throw new OutOfBoundsException( "An Entity with the id 
$entityId "
-                               . "could not be loaded." );
                }
        }
 
diff --git a/lib/includes/store/EntityInfo.php 
b/lib/includes/store/EntityInfo.php
index dbc0782..219dd36 100644
--- a/lib/includes/store/EntityInfo.php
+++ b/lib/includes/store/EntityInfo.php
@@ -2,6 +2,8 @@
 
 namespace Wikibase\Lib\Store;
 
+use OutOfBoundsException;
+use RuntimeException;
 use Wikibase\DataModel\Entity\EntityId;
 
 /**
@@ -64,8 +66,11 @@
        /**
         * @param EntityId $id
         *
-        * @return array An array structure representing information about the 
given entity.
-        *         If that entity isn't know, the resulting structure will 
contain only the ID.
+        * @throws OutOfBoundsException If this EntityInfo does not have 
information about the
+        *         requested Entity. This does say anything about whether the 
Entity exists in
+        *         the database.
+        * @return array[] An array structure representing information about 
the given entity.
+        *         Refer to the class level documentation for information about 
the structure.
         */
        public function getEntityInfo( EntityId $id ) {
                $key = $id->getSerialization();
@@ -73,7 +78,7 @@
                if ( isset( $this->info[$key] ) ) {
                        return $this->info[$key];
                } else {
-                       return array( 'id' => $key );
+                       throw new OutOfBoundsException( 'Unknown entity: ' . 
$id );
                }
        }
 
@@ -81,9 +86,9 @@
         * @param EntityId $id
         * @param string $languageCode
         *
-        * @throws StorageException
+        * @throws OutOfBoundsException If nothing is known about the entity or 
its labels.
         * @return string|null The entity's label in the given language,
-        *         or null if no such descriptions is known.
+        *         or null if no such label exists on the entity.
         */
        public function getLabel( EntityId $id, $languageCode ) {
                return $this->getTermValue( $id, 'labels', $languageCode );
@@ -93,9 +98,9 @@
         * @param EntityId $id
         * @param string $languageCode
         *
-        * @throws StorageException
+        * @throws OutOfBoundsException If nothing is known about the entity or 
its descriptions.
         * @return string|null The entity's description in the given language,
-        *         or null if no such descriptions is known.
+        *         or null if no such description exists on the entity.
         */
        public function getDescription( EntityId $id, $languageCode ) {
                return $this->getTermValue( $id, 'descriptions', $languageCode 
);
@@ -104,7 +109,7 @@
        /**
         * @param EntityId $id
         *
-        * @throws StorageException
+        * @throws OutOfBoundsException If nothing is known about the entity or 
its labels.
         * @return string[] The given entity's labels, keyed by language.
         */
        public function getLabels( EntityId $id ) {
@@ -114,7 +119,7 @@
        /**
         * @param EntityId $id
         *
-        * @throws StorageException
+        * @throws OutOfBoundsException If nothing is known about the entity or 
its descriptions.
         * @return string[] The given entity's descriptions, keyed by language.
         */
        public function getDescriptions( EntityId $id ) {
@@ -126,18 +131,25 @@
         * @param string $termField The term field (e.g. 'labels' or 
'descriptions').
         * @param string $languageCode
         *
-        * @throws StorageException
-        * @return string|null The term value, or null if no such term is known.
+        * @throws RuntimeException
+        * @throws OutOfBoundsException If nothing is known about the entity
+        *         or terms of the requested type.
+        * @return string|null The term value of the requested type and 
language,
+        *         or null if no such term is set on the entity.
         */
        private function getTermValue( EntityId $id, $termField, $languageCode 
) {
                $entityInfo = $this->getEntityInfo( $id );
+
+               if ( !isset( $entityInfo[$termField] ) ) {
+                       throw new OutOfBoundsException( 'Term field ' . 
$termField . ' is unknown.' );
+               }
 
                if ( !isset( $entityInfo[$termField][$languageCode] ) ) {
                        return null;
                }
 
                if ( !isset( $entityInfo[$termField][$languageCode]['value'] ) 
) {
-                       throw new StorageException( 'Term record is missing 
`value` key (' . $id->getSerialization() . ')' );
+                       throw new RuntimeException( 'Term record is missing 
`value` key (' . $id->getSerialization() . ')' );
                }
 
                return $entityInfo[$termField][$languageCode]['value'];
@@ -147,21 +159,23 @@
         * @param EntityId $id
         * @param string $termField The term field (e.g. 'labels' or 
'descriptions').
         *
-        * @throws StorageException
-        * @return string[] The entity's term values, keyed by language.
+        * @throws RuntimeException
+        * @throws OutOfBoundsException If nothing is known about the entity
+        *         or terms of the requested type.
+        * @return string[] The entity's term values of the requested type, 
keyed by language.
         */
        private function getTermValues( EntityId $id, $termField ) {
                $entityInfo = $this->getEntityInfo( $id );
 
                if ( !isset( $entityInfo[$termField] ) ) {
-                       return array();
+                       throw new OutOfBoundsException( 'Term field `' . 
$termField . '` is unknown.' );
                }
 
                $values = array();
 
                foreach ( $entityInfo[$termField] as $key => $entry ) {
                        if ( !isset( $entry['value'] ) ) {
-                               throw new StorageException( 'Term record is 
missing `value` key (' . $id->getSerialization() . ')' );
+                               throw new RuntimeException( 'Term record is 
missing `value` key (' . $id->getSerialization() . ')' );
                        }
 
                        $values[$key] = $entry['value'];
diff --git a/lib/includes/store/EntityRetrievingTermLookup.php 
b/lib/includes/store/EntityRetrievingTermLookup.php
index 2a26e35..5d0699d 100644
--- a/lib/includes/store/EntityRetrievingTermLookup.php
+++ b/lib/includes/store/EntityRetrievingTermLookup.php
@@ -33,13 +33,11 @@
        }
 
        /**
-        * Gets the label of an Entity with the specified EntityId and language 
code.
+        * @see TermLookup::getLabel()
         *
         * @param EntityId $entityId
         * @param string $languageCode
         *
-        * @throws OutOfBoundsException
-        * @throws StorageException for entity not found
         * @return string
         */
        public function getLabel( EntityId $entityId, $languageCode ) {
@@ -48,11 +46,11 @@
        }
 
        /**
-        * Gets all labels of an Entity with the specified EntityId.
+        * @see TermLookup::getLabels()
         *
         * @param EntityId $entityId
         *
-        * @throws StorageException for entity not found
+        * @throws OutOfBoundsException if the entity does not exist
         * @return string[]
         */
        public function getLabels( EntityId $entityId ) {
@@ -60,13 +58,11 @@
        }
 
        /**
-        * Gets the description of an Entity with the specified EntityId and 
language code.
+        * @see TermLookup::getDescription()
         *
         * @param EntityId $entityId
         * @param string $languageCode
         *
-        * @throws OutOfBoundsException
-        * @throws StorageException for entity not found
         * @return string
         */
        public function getDescription( EntityId $entityId, $languageCode ) {
@@ -75,11 +71,11 @@
        }
 
        /**
-        * Gets all descriptions of an Entity with the specified EntityId.
+        * @see TermLookup::getDescriptions()
         *
         * @param EntityId $entityId
         *
-        * @throws StorageException for entity not found
+        * @throws OutOfBoundsException if the entity does not exist
         * @return string[]
         */
        public function getDescriptions( EntityId $entityId ) {
@@ -104,7 +100,7 @@
        /**
         * @param EntityId $entityId
         *
-        * @throws StorageException
+        * @throws OutOfBoundsException
         * @return Fingerprint
         */
        private function fetchFingerprint( EntityId $entityId ) {
@@ -121,7 +117,7 @@
 
                if ( $entity === null ) {
                        // double redirect, deleted entity, etc
-                       throw new StorageException( "An Entity with the id 
$entityId could not be loaded" );
+                       throw new OutOfBoundsException( "An Entity with the id 
$entityId could not be loaded" );
                }
 
                return $entity instanceof FingerprintProvider ? 
$entity->getFingerprint() : Fingerprint::newEmpty();
diff --git a/lib/includes/store/EntityTermLookup.php 
b/lib/includes/store/EntityTermLookup.php
index 227f7e9..c66badf 100644
--- a/lib/includes/store/EntityTermLookup.php
+++ b/lib/includes/store/EntityTermLookup.php
@@ -4,6 +4,7 @@
 
 use OutOfBoundsException;
 use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\Term;
 use Wikibase\TermIndex;
 
 /**
@@ -20,25 +21,18 @@
        private $termIndex;
 
        /**
-        * @var EntityLookup
-        */
-       private $entityLookup;
-
-       /**
         * @param TermIndex $termIndex
-        * @param EntityLookup $entityLookup
         */
-       public function __construct( TermIndex $termIndex, EntityLookup 
$entityLookup ) {
+       public function __construct( TermIndex $termIndex ) {
                $this->termIndex = $termIndex;
-               $this->entityLookup = $entityLookup;
        }
 
        /**
+        * @see TermLookup::getLabel
+        *
         * @param EntityId $entityId
         * @param string $languageCode
         *
-        * @throws StorageException if entity does not exist
-        * @throws OutOfBoundsException
         * @return string
         */
        public function getLabel( EntityId $entityId, $languageCode ) {
@@ -47,9 +41,10 @@
        }
 
        /**
+        * @see TermLookup::getLabels
+        *
         * @param EntityId $entityId
         *
-        * @throws StorageException if entity does not exist
         * @return string[]
         */
        public function getLabels( EntityId $entityId ) {
@@ -57,11 +52,11 @@
        }
 
        /**
+        * @see TermLookup::getDescription
+        *
         * @param EntityId $entityId
         * @param string $languageCode
         *
-        * @throws StorageException if entity does not exist
-        * @throws OutOfBoundsException
         * @return string
         */
        public function getDescription( EntityId $entityId, $languageCode ) {
@@ -70,9 +65,10 @@
        }
 
        /**
+        * @see TermLookup::getDescriptions
+        *
         * @param EntityId $entityId
         *
-        * @throws StorageException if entity does not exist
         * @return string[]
         */
        public function getDescriptions( EntityId $entityId ) {
@@ -83,18 +79,10 @@
         * @param EntityId $entityId
         * @param string $termType
         *
-        * @throws StorageException if entity does not exist.
         * @return string[]
         */
        private function getTermsOfType( EntityId $entityId, $termType ) {
                $wikibaseTerms = $this->termIndex->getTermsOfEntity( $entityId 
);
-
-               if ( $wikibaseTerms === array() ) {
-                       if ( !$this->entityLookup->hasEntity( $entityId ) ) {
-                               throw new StorageException( 'Entity not found 
for '
-                                       . $entityId->getSerialization() );
-                       }
-               }
 
                return $this->convertTermsToTermTypeArray( $wikibaseTerms, 
$termType );
        }
@@ -115,7 +103,7 @@
        }
 
        /**
-        * @param \Wikibase\Term[] $wikibaseTerms
+        * @param Term[] $wikibaseTerms
         * @param string $termType
         *
         * @return string[]
diff --git a/lib/includes/store/LabelLookup.php 
b/lib/includes/store/LabelLookup.php
index c91f36c..6ff88ce 100644
--- a/lib/includes/store/LabelLookup.php
+++ b/lib/includes/store/LabelLookup.php
@@ -16,8 +16,7 @@
        /**
         * @param EntityId $entityId
         *
-        * @throws OutOfBoundsException
-        * @throws StorageException for entity not found
+        * @throws OutOfBoundsException if no such label or entity could be 
found
         * @return string
         */
        public function getLabel( EntityId $entityId );
diff --git a/lib/includes/store/TermLookup.php 
b/lib/includes/store/TermLookup.php
index 7c07055..bb87872 100644
--- a/lib/includes/store/TermLookup.php
+++ b/lib/includes/store/TermLookup.php
@@ -6,6 +6,10 @@
 use Wikibase\DataModel\Entity\EntityId;
 
 /**
+ * A service interface for looking up entity terms.
+ *
+ * @note: A TermLookup cannot be used to determine whether an entity exists or 
not.
+ *
  * @since 0.5
  *
  * @licence GNU GPL v2+
@@ -19,8 +23,7 @@
         * @param EntityId $entityId
         * @param string $languageCode
         *
-        * @throws OutOfBoundsException for label not found
-        * @throws StorageException for Entity not found
+        * @throws OutOfBoundsException for label or entity not found
         *
         * @return string
         * @throws OutOfBoundsException if no such label was found
@@ -32,8 +35,9 @@
         *
         * @param EntityId $entityId
         *
-        * @throws StorageException for Entity not found
+        * @throws OutOfBoundsException if the entity was not found (not 
guaranteed).
         * @return string[] labels, keyed by language.
+        *         An empty array may or may not indicate that the entity does 
not exist.
         */
        public function getLabels( EntityId $entityId );
 
@@ -43,10 +47,8 @@
         * @param EntityId $entityId
         * @param string $languageCode
         *
-        * @throws OutOfBoundsException for description not found
-        * @throws StorageException for Entity not found
+        * @throws OutOfBoundsException for description or entity not found
         * @return string
-        * @throws OutOfBoundsException if no such description was found
         */
        public function getDescription( EntityId $entityId, $languageCode );
 
@@ -55,8 +57,9 @@
         *
         * @param EntityId $entityId
         *
-        * @throws StorageException for Entity not found
+        * @throws OutOfBoundsException if the entity was not found (not 
guaranteed).
         * @return string[] descriptions, keyed by language.
+        *         An empty array may or may not indicate that the entity does 
not exist.
         */
        public function getDescriptions( EntityId $entityId );
 
diff --git a/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterTest.php 
b/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterTest.php
index be80a51..1af7e72 100644
--- a/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterTest.php
+++ b/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterTest.php
@@ -7,7 +7,7 @@
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\Lib\EntityIdHtmlLinkFormatter;
-use Wikibase\Lib\Store\StorageException;
+use Wikibase\Lib\Store\EntityTitleLookup;
 use ValueFormatters\FormatterOptions;
 
 /**
@@ -31,15 +31,6 @@
                return $labelLookup;
        }
 
-       private function getLabelLookupNoEntity() {
-               $labelLookup = $this->getMock( 'Wikibase\Lib\Store\LabelLookup' 
);
-               $labelLookup->expects( $this->any() )
-                       ->method( 'getLabel' )
-                       ->will( $this->throwException( new StorageException( 
'meep' ) ) );
-
-               return $labelLookup;
-       }
-
        private function getLabelLookupNoLabel() {
                $labelLookup = $this->getMock( 'Wikibase\Lib\Store\LabelLookup' 
);
                $labelLookup->expects( $this->any() )
@@ -52,12 +43,15 @@
        /**
         * @return EntityTitleLookup
         */
-       private function newEntityTitleLookup() {
+       private function newEntityTitleLookup( $exists = true ) {
                $entityTitleLookup = $this->getMock( 
'Wikibase\Lib\Store\EntityTitleLookup' );
                $entityTitleLookup->expects( $this->any() )
                        ->method( 'getTitleForId' )
-                       ->will( $this->returnCallback( function ( EntityId 
$entityId ) {
-                               return Title::newFromText( 
$entityId->getSerialization() );
+                       ->will( $this->returnCallback( function ( EntityId 
$entityId ) use ( $exists ) {
+                               $title = Title::newFromText( 
$entityId->getSerialization() );
+                               $title->resetArticleID( $exists ? 
$entityId->getNumericId() : 0 );
+
+                               return $title;
                        } )
                );
 
@@ -116,14 +110,11 @@
 
                if ( $hasLabel ) {
                        $labelLookup = $this->getLabelLookup();
-               } elseif ( !$exists ) {
-                       $labelLookup = $this->getLabelLookupNoEntity();
                } else {
-                       // Exists, but w/o label
                        $labelLookup = $this->getLabelLookupNoLabel();
                }
 
-               $entityTitleLookup = $this->newEntityTitleLookup();
+               $entityTitleLookup = $this->newEntityTitleLookup( $exists );
 
                $entityIdHtmlLinkFormatter = new EntityIdHtmlLinkFormatter( 
$options, $labelLookup, $entityTitleLookup );
                $result = $entityIdHtmlLinkFormatter->format( new ItemId( 'Q42' 
) );
diff --git a/lib/tests/phpunit/store/EntityInfoTermLookupTest.php 
b/lib/tests/phpunit/store/EntityInfoTermLookupTest.php
index 689aaf0..33d1da4 100644
--- a/lib/tests/phpunit/store/EntityInfoTermLookupTest.php
+++ b/lib/tests/phpunit/store/EntityInfoTermLookupTest.php
@@ -27,7 +27,27 @@
                $termLookup = $this->getEntityInfoTermLookup();
 
                $this->setExpectedException( 'OutOfBoundsException' );
-               $termLookup->getLabel( new ItemId( 'Q120' ), 'en' );
+               $termLookup->getLabel( new ItemId( 'Q117' ), 'fr' );
+       }
+
+       public function testGetLabel_noEntityThrowsException() {
+               $termLookup = $this->getEntityInfoTermLookup();
+
+               $this->setExpectedException( 'OutOfBoundsException' );
+               $termLookup->getLabel( new ItemId( 'Q90000' ), 'en' );
+       }
+
+       public function getLabelsProvider() {
+               return array(
+                       array(
+                               array( 'en' => 'New York City', 'es' => 'Nueva 
York' ),
+                               new ItemId( 'Q116' )
+                       ),
+                       array(
+                               array( 'de' => 'Berlin' ),
+                               new ItemId( 'Q117' )
+                       )
+               );
        }
 
        /**
@@ -40,17 +60,11 @@
                $this->assertEquals( $expected, $labels );
        }
 
-       public function getLabelsProvider() {
-               return array(
-                       array(
-                               array( 'en' => 'New York City', 'es' => 'Nueva 
York' ),
-                               new ItemId( 'Q116' )
-                       ),
-                       array(
-                               array(),
-                               new ItemId( 'Q120' )
-                       )
-               );
+       public function testGetLabels_noEntityThrowsException() {
+               $termLookup = $this->getEntityInfoTermLookup();
+
+               $this->setExpectedException( 'OutOfBoundsException' );
+               $termLookup->getLabels( new ItemId( 'Q90000' ) );
        }
 
        public function testGetDescription() {
@@ -66,17 +80,14 @@
                $termLookup = $this->getEntityInfoTermLookup();
 
                $this->setExpectedException( 'OutOfBoundsException' );
-               $termLookup->getDescription( new ItemId( 'Q90000' ), 'fr' );
+               $termLookup->getDescription( new ItemId( 'Q117' ), 'fr' );
        }
 
-       /**
-        * @dataProvider getDescriptionsProvider
-        */
-       public function getDescriptions( $expected, EntityId $entityId ) {
+       public function testGetDescription_noEntityThrowsException() {
                $termLookup = $this->getEntityInfoTermLookup();
 
-               $descriptions = $termLookup->getDescriptions( $entityId );
-               $this->assertEquals( $expected, $descriptions );
+               $this->setExpectedException( 'OutOfBoundsException' );
+               $termLookup->getDescription( new ItemId( 'Q90000' ), 'en' );
        }
 
        public function getDescriptionsProvider() {
@@ -90,9 +101,26 @@
                        ),
                        array(
                                array(),
-                               new ItemId( 'Q90001' )
+                               new ItemId( 'Q117' )
                        )
                );
+       }
+
+       /**
+        * @dataProvider getDescriptionsProvider
+        */
+       public function testGetDescriptions( $expected, EntityId $entityId ) {
+               $termLookup = $this->getEntityInfoTermLookup();
+
+               $descriptions = $termLookup->getDescriptions( $entityId );
+               $this->assertEquals( $expected, $descriptions );
+       }
+
+       public function testGetDescriptions_noEntityThrowsException() {
+               $termLookup = $this->getEntityInfoTermLookup();
+
+               $this->setExpectedException( 'OutOfBoundsException' );
+               $termLookup->getDescriptions( new ItemId( 'Q90000' ) );
        }
 
        private function getEntityInfoTermLookup() {
@@ -117,6 +145,7 @@
                                'labels' => array(
                                        'de' => array( 'language' => 'de', 
'value' => 'Berlin' ),
                                ),
+                               'descriptions' => array()
                        ),
                );
 
diff --git a/lib/tests/phpunit/store/EntityInfoTest.php 
b/lib/tests/phpunit/store/EntityInfoTest.php
index 341184b..0ff806c 100644
--- a/lib/tests/phpunit/store/EntityInfoTest.php
+++ b/lib/tests/phpunit/store/EntityInfoTest.php
@@ -39,7 +39,6 @@
                );
 
                $builder->collectTerms();
-
                return $builder->getEntityInfo();
        }
 
@@ -74,14 +73,24 @@
        }
 
        public function asArrayProvider() {
-               $infoWithLabels = $this->getEntityInfo( array(
-                       $this->makeItemWithLabel( 'Q11', 'London' ),
-                       $this->makeItemWithLabel( 'Q33', 'Berlin' ),
-               ) );
-
                return array(
                        'empty' => array( array() ),
-                       'labels' => array( $infoWithLabels->asArray() ),
+                       'labels' => array( array(
+                               'Q11' => array(
+                                       'id' => 'Q11',
+                                       'type' => 'item',
+                                       'labels' => array(
+                                               'de' => array(
+                                                       'language' => 'de',
+                                                       'value' => 'London'
+                                               ),
+                                               'la' => array(
+                                                       'language' => 'la',
+                                                       'value' => 'Londinium'
+                                               ),
+                                       )
+                               )
+                       ) ),
                );
        }
 
@@ -121,10 +130,8 @@
                $this->assertEquals( 'Q33', $record['id'] );
                $this->assertArrayHasKey( 'labels', $record );
 
-               $record = $info->getEntityInfo( new ItemId( 'Q99' ) );
-               $this->assertInternalType( 'array', $record );
-               $this->assertEquals( 'Q99', $record['id'] );
-               $this->assertArrayNotHasKey( 'labels', $record );
+               $this->setExpectedException( 'OutOfBoundsException' );
+               $info->getEntityInfo( new ItemId( 'Q99' ) );
        }
 
        public function testGetLabel() {
@@ -136,18 +143,18 @@
                $this->assertEquals( 'London', $info->getLabel( new ItemId( 
'Q11' ), 'en' ) );
                $this->assertEquals( 'Berlin', $info->getLabel( new ItemId( 
'Q33' ), 'en' ) );
                $this->assertNull( $info->getLabel( new ItemId( 'Q11' ), 'zh' ) 
);
-               $this->assertNull( $info->getLabel( new ItemId( 'Q99' ), 'en' ) 
);
        }
 
        public function testGetLabels() {
                $info = $this->getEntityInfo( array(
                        $this->makeItemWithLabel( 'Q11', 'London' ),
                        $this->makeItemWithLabel( 'Q33', 'Berlin' ),
+                       $this->makeItemWithDescription( 'Q66', 'Barcelona' ),
                ) );
 
                $this->assertEquals( array( 'en' => 'London' ), 
$info->getLabels( new ItemId( 'Q11' ) ) );
                $this->assertEquals( array( 'en' => 'Berlin' ), 
$info->getLabels( new ItemId( 'Q33' ) ) );
-               $this->assertEquals( array(), $info->getLabels( new ItemId( 
'Q99' ) ) );
+               $this->assertEquals( array(), $info->getLabels( new ItemId( 
'Q66' ) ) );
        }
 
        public function testGetDescription() {
@@ -159,18 +166,72 @@
                $this->assertEquals( 'London', $info->getDescription( new 
ItemId( 'Q11' ), 'en' ) );
                $this->assertEquals( 'Berlin', $info->getDescription( new 
ItemId( 'Q33' ), 'en' ) );
                $this->assertNull( $info->getDescription( new ItemId( 'Q11' ), 
'zh' ) );
-               $this->assertNull( $info->getDescription( new ItemId( 'Q99' ), 
'en' ) );
        }
 
        public function testGetDescriptions() {
                $info = $this->getEntityInfo( array(
                        $this->makeItemWithDescription( 'Q11', 'London' ),
                        $this->makeItemWithDescription( 'Q33', 'Berlin' ),
+                       $this->makeItemWithLabel( 'Q66', 'Barcelona' ),
                ) );
 
                $this->assertEquals( array( 'en' => 'London' ), 
$info->getDescriptions( new ItemId( 'Q11' ) ) );
                $this->assertEquals( array( 'en' => 'Berlin' ), 
$info->getDescriptions( new ItemId( 'Q33' ) ) );
-               $this->assertEquals( array(), $info->getDescriptions( new 
ItemId( 'Q99' ) ) );
+               $this->assertEquals( array(), $info->getDescriptions( new 
ItemId( 'Q66' ) ) );
+       }
+
+       public function provideBlankInfo() {
+               return array(
+                       'unknown item' => array( array() ),
+                       'unknown terms' => array(
+                               array(
+                                       'Q99' => array(
+                                               'id' => 'Q99',
+                                               'type' => 'item',
+                                       )
+                               )
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideBlankInfo
+        */
+       public function testGetLabel_exception( $data ) {
+               $info = new EntityInfo( $data );
+
+               $this->setExpectedException( 'OutOfBoundsException' );
+               $info->getLabel( new ItemId( 'Q99' ), 'en' );
+       }
+
+       /**
+        * @dataProvider provideBlankInfo
+        */
+       public function testGetLabels_exception( $data ) {
+               $info = new EntityInfo( $data );
+
+               $this->setExpectedException( 'OutOfBoundsException' );
+               $info->getLabels( new ItemId( 'Q99' ) );
+       }
+
+       /**
+        * @dataProvider provideBlankInfo
+        */
+       public function testGetDescription_exception( $data ) {
+               $info = new EntityInfo( $data );
+
+               $this->setExpectedException( 'OutOfBoundsException' );
+               $info->getDescription( new ItemId( 'Q99' ), 'en' );
+       }
+
+       /**
+        * @dataProvider provideBlankInfo
+        */
+       public function testGetDescriptions_exception( $data ) {
+               $info = new EntityInfo( $data );
+
+               $this->setExpectedException( 'OutOfBoundsException' );
+               $info->getDescriptions( new ItemId( 'Q99' ) );
        }
 
 }
diff --git a/lib/tests/phpunit/store/EntityRetrievingTermLookupTest.php 
b/lib/tests/phpunit/store/EntityRetrievingTermLookupTest.php
index 6522410..6e8ec28 100644
--- a/lib/tests/phpunit/store/EntityRetrievingTermLookupTest.php
+++ b/lib/tests/phpunit/store/EntityRetrievingTermLookupTest.php
@@ -25,7 +25,7 @@
        public function testGetLabel_entityNotFound() {
                $termLookup = $this->getEntityTermLookup();
 
-               $this->setExpectedException( 
'\Wikibase\Lib\Store\StorageException' );
+               $this->setExpectedException( 'OutOfBoundsException' );
                $termLookup->getLabel( new ItemId( 'Q120' ), 'en' );
        }
 
diff --git a/lib/tests/phpunit/store/EntityTermLookupTest.php 
b/lib/tests/phpunit/store/EntityTermLookupTest.php
index 507a2dc..5fc8769 100644
--- a/lib/tests/phpunit/store/EntityTermLookupTest.php
+++ b/lib/tests/phpunit/store/EntityTermLookupTest.php
@@ -2,7 +2,6 @@
 
 namespace Wikibase\Test;
 
-use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\Lib\Store\EntityTermLookup;
 
@@ -40,15 +39,6 @@
                $this->assertEquals( $expected, $labels );
        }
 
-       public function testGetLabels_entityNotFoundThrowsStorageException() {
-               $termLookup = $this->getEntityTermLookup();
-
-               $this->setExpectedException( 
'Wikibase\Lib\Store\StorageException' );
-
-               $termLookup->getLabels( new ItemId( 'Q9999' ) );
-       }
-
-
        public function testGetDescription() {
                $termLookup = $this->getEntityTermLookup();
 
@@ -79,18 +69,8 @@
        }
 
        private function getEntityTermLookup() {
-               $entityLookup = $this->getMockBuilder( 
'Wikibase\Lib\Store\EntityLookup' )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
-               $entityLookup->expects( $this->any() )
-                       ->method( 'hasEntity' )
-                       ->will( $this->returnCallback( function( EntityId 
$entityId ) {
-                               return $entityId->getSerialization() === 'Q116';
-                       } ) );
-
                $termIndex = $this->getTermIndex();
-               return new EntityTermLookup( $termIndex, $entityLookup );
+               return new EntityTermLookup( $termIndex );
        }
 
        private function getTermIndex() {
diff --git a/lib/tests/phpunit/store/LanguageFallbackLabelLookupTest.php 
b/lib/tests/phpunit/store/LanguageFallbackLabelLookupTest.php
index a9ebdcb..386266e 100644
--- a/lib/tests/phpunit/store/LanguageFallbackLabelLookupTest.php
+++ b/lib/tests/phpunit/store/LanguageFallbackLabelLookupTest.php
@@ -29,7 +29,7 @@
 
                $labelLookup = new LanguageFallbackLabelLookup( $termLookup, 
$fallbackChain );
 
-               $this->setExpectedException( 
'Wikibase\Lib\Store\StorageException' );
+               $this->setExpectedException( 'OutOfBoundsException' );
                $labelLookup->getLabel( new ItemId( 'Q120' ) );
        }
 
@@ -62,9 +62,7 @@
        }
 
        private function getTermLookup() {
-               $entityLookup = new MockRepository();
-
-               return new EntityTermLookup( $this->getTermIndex(), 
$entityLookup );
+               return new EntityTermLookup( $this->getTermIndex() );
        }
 
        private function getTermIndex() {
diff --git a/lib/tests/phpunit/store/LanguageLabelLookupTest.php 
b/lib/tests/phpunit/store/LanguageLabelLookupTest.php
index c27b8d0..93a0c2b 100644
--- a/lib/tests/phpunit/store/LanguageLabelLookupTest.php
+++ b/lib/tests/phpunit/store/LanguageLabelLookupTest.php
@@ -26,7 +26,7 @@
                $termLookup = $this->getTermLookup();
                $labelLookup = new LanguageLabelLookup( $termLookup, 'en' );
 
-               $this->setExpectedException( 
'Wikibase\Lib\Store\StorageException' );
+               $this->setExpectedException( 'OutOfBoundsException' );
                $labelLookup->getLabel( new ItemId( 'Q120' ) );
        }
 
@@ -40,9 +40,7 @@
        }
 
        private function getTermLookup() {
-               $entityLookup = new MockRepository();
-
-               return new EntityTermLookup( $this->getTermIndex(), 
$entityLookup );
+               return new EntityTermLookup( $this->getTermIndex() );
        }
 
        private function getTermIndex() {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id8eb6ec021810350c59e7bbdb7c2b9bf5e608238
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[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

Reply via email to