Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/242850

Change subject: Add tests for StatementTransclusionInteractor
......................................................................

Add tests for StatementTransclusionInteractor

This covers more error cases and includes some
integration testing, using a RevisionBasedEntityLookup
as is done in the client for this.

and remove the wfLogWarning call

Bug: T114290
Change-Id: I6c6aec9d88d707a91bea29c590a77827cb564eee
---
M client/includes/DataAccess/StatementTransclusionInteractor.php
M 
client/tests/phpunit/includes/DataAccess/StatementTransclusionInteractorTest.php
2 files changed, 69 insertions(+), 37 deletions(-)


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

diff --git a/client/includes/DataAccess/StatementTransclusionInteractor.php 
b/client/includes/DataAccess/StatementTransclusionInteractor.php
index 28e9d8e..0ad127c 100644
--- a/client/includes/DataAccess/StatementTransclusionInteractor.php
+++ b/client/includes/DataAccess/StatementTransclusionInteractor.php
@@ -84,11 +84,6 @@
                try {
                        $entity = $this->entityLookup->getEntity( $entityId );
                } catch ( RevisionedUnresolvedRedirectException $ex ) {
-                       // We probably hit a double redirect
-                       wfLogWarning(
-                               'Encountered a UnresolvedRedirectException when 
trying to load ' . $entityId->getSerialization()
-                       );
-
                        return '';
                }
 
diff --git 
a/client/tests/phpunit/includes/DataAccess/StatementTransclusionInteractorTest.php
 
b/client/tests/phpunit/includes/DataAccess/StatementTransclusionInteractorTest.php
index e8b3205..f4265b1 100644
--- 
a/client/tests/phpunit/includes/DataAccess/StatementTransclusionInteractorTest.php
+++ 
b/client/tests/phpunit/includes/DataAccess/StatementTransclusionInteractorTest.php
@@ -10,12 +10,17 @@
 use Wikibase\Client\DataAccess\StatementTransclusionInteractor;
 use Wikibase\Client\PropertyLabelNotResolvedException;
 use Wikibase\Client\Usage\EntityUsage;
+use Wikibase\DataModel\Entity\EntityId;
 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\Snak\Snak;
+use Wikibase\EntityRevision;
 use Wikibase\Lib\SnakFormatter;
+use Wikibase\Lib\Store\RevisionBasedEntityLookup;
+use Wikibase\Lib\Store\RevisionedUnresolvedRedirectException;
 
 /**
  * @covers Wikibase\Client\DataAccess\StatementTransclusionInteractor
@@ -31,29 +36,6 @@
  */
 class StatementTransclusionInteractorTest extends PHPUnit_Framework_TestCase {
 
-       /**
-        * @param PropertyIdResolver $propertyIdResolver
-        * @param SnaksFinder $snaksFinder
-        * @param string $languageCode
-        *
-        * @return StatementTransclusionInteractor
-        */
-       private function getInteractor(
-               PropertyIdResolver $propertyIdResolver,
-               SnaksFinder $snaksFinder,
-               $languageCode
-       ) {
-               $targetLanguage = Language::factory( $languageCode );
-
-               return new StatementTransclusionInteractor(
-                       $targetLanguage,
-                       $propertyIdResolver,
-                       $snaksFinder,
-                       $this->getSnakFormatter(),
-                       $this->getEntityLookup()
-               );
-       }
-
        public function testRender() {
                $propertyId = new PropertyId( 'P1337' );
                $snaks = array(
@@ -63,8 +45,7 @@
 
                $renderer = $this->getInteractor(
                        $this->getPropertyIdResolver(),
-                       $this->getSnaksFinder( $snaks ),
-                       'en'
+                       $snaks
                );
 
                $q42 = new ItemId( 'Q42' );
@@ -77,13 +58,51 @@
        public function testRender_PropertyLabelNotResolvedException() {
                $renderer = $this->getInteractor(
                        $this->getPropertyIdResolverForPropertyNotFound(),
-                       $this->getSnaksFinder( array() ),
-                       'en'
+                       array()
                );
 
                $this->setExpectedException( 
'Wikibase\Client\PropertyLabelNotResolvedException' );
                $renderer->render( new ItemId( 'Q42' ), 'blah' );
        }
+
+       public function testRender_unresolvedRedirect() {
+               $renderer = $this->getInteractor(
+                       $this->getPropertyIdResolver(),
+                       array()
+               );
+
+               $this->assertEquals( '', $renderer->render( new ItemId( 'Q43' 
), 'P1337' ) );
+       }
+
+       public function testRender_unknownEntity() {
+               $renderer = $this->getInteractor(
+                       $this->getPropertyIdResolver(),
+                       array()
+               );
+
+               $this->assertEquals( '', $renderer->render( new ItemId( 
'Q43333' ), 'P1337' ) );
+       }
+
+    /**
+     * @param PropertyIdResolver $propertyIdResolver
+     * @param Snak[] $snaks
+     *
+     * @return StatementTransclusionInteractor
+     */
+    private function getInteractor(
+        PropertyIdResolver $propertyIdResolver,
+        array $snaks
+    ) {
+        $targetLanguage = Language::factory( 'en' );
+
+        return new StatementTransclusionInteractor(
+            $targetLanguage,
+            $propertyIdResolver,
+            $this->getSnaksFinder( $snaks ),
+            $this->getSnakFormatter(),
+            $this->getEntityLookup()
+        );
+    }
 
        /**
         * @param EntityUsage[] $expected
@@ -161,12 +180,30 @@
        }
 
        private function getEntityLookup() {
-               $lookup = $this->getMock( 
'Wikibase\DataModel\Services\Lookup\EntityLookup' );
+               return new RevisionBasedEntityLookup( 
$this->getEntityRevisionLookup() );
+       }
+
+       private function getEntityRevisionLookup() {
+               $lookup = $this->getMock( 
'Wikibase\Lib\Store\EntityRevisionLookup' );
+
                $lookup->expects( $this->any() )
-                       ->method( 'getEntity' )
-                       ->will( $this->returnValue(
-                               $this->getMock( 
'Wikibase\DataModel\StatementListProvider' )
-                       ) );
+                       ->method( 'getEntityRevision' )
+                       ->will( $this->returnCallback( function( EntityId 
$entityId ) {
+                if ( $entityId->getSerialization() === 'Q42' ) {
+                                       return new EntityRevision(
+                                               new Item( new ItemId( 'Q42' ) )
+                                       );
+                } elseif ( $entityId->getSerialization() === 'Q43' ) {
+                    // Unresolved redirect, derived from EntityLookupException
+                    throw new RevisionedUnresolvedRedirectException(
+                        $entityId,
+                        new ItemId( 'Q404' )
+                    );
+                } else {
+                    return null;
+                }
+                       } )
+               );
 
                return $lookup;
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c6aec9d88d707a91bea29c590a77827cb564eee
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to