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

Change subject: Fix WikiPageEntityRedirectLookup::getRedirectForEntityId for 
items in main NS
......................................................................


Fix WikiPageEntityRedirectLookup::getRedirectForEntityId for items in main NS

Also added test case for this.

Bug: T111342
Change-Id: Ia9ee92c18c225b99b155d366a0fbef351acee225
---
M repo/includes/store/sql/WikiPageEntityRedirectLookup.php
M repo/tests/phpunit/includes/store/sql/WikiPageEntityRedirectLookupTest.php
2 files changed, 71 insertions(+), 1 deletion(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  Jeroen De Dauw: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/repo/includes/store/sql/WikiPageEntityRedirectLookup.php 
b/repo/includes/store/sql/WikiPageEntityRedirectLookup.php
index 5ad3224..85c9e6a 100644
--- a/repo/includes/store/sql/WikiPageEntityRedirectLookup.php
+++ b/repo/includes/store/sql/WikiPageEntityRedirectLookup.php
@@ -128,7 +128,7 @@
                        return false;
                }
 
-               if ( !$row->rd_namespace ) {
+               if ( $row->rd_namespace === null ) {
                        return null;
                }
 
diff --git 
a/repo/tests/phpunit/includes/store/sql/WikiPageEntityRedirectLookupTest.php 
b/repo/tests/phpunit/includes/store/sql/WikiPageEntityRedirectLookupTest.php
index 68f5137..585bda0 100644
--- a/repo/tests/phpunit/includes/store/sql/WikiPageEntityRedirectLookupTest.php
+++ b/repo/tests/phpunit/includes/store/sql/WikiPageEntityRedirectLookupTest.php
@@ -4,6 +4,8 @@
 
 use LoadBalancer;
 use MediaWikiTestCase;
+use Title;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\EntityRedirect;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Entity\ItemId;
@@ -81,6 +83,74 @@
                $this->assertNull( $res );
        }
 
+       public function testGetRedirectForEntityId_itemsInMainNamespace() {
+               $row = array(
+                       'page_id' => 10,
+                       'rd_namespace' => NS_MAIN,
+                       'rd_title' => 'Q10'
+               );
+
+               $entityRedirectLookup = new WikiPageEntityRedirectLookup(
+                       $this->getMockEntityTitleLookup(),
+                       $this->getMockEntityIdLookup(),
+                       $this->getMockLoadBalancer( $row )
+               );
+
+               $redirect = $entityRedirectLookup->getRedirectForEntityId( new 
ItemId( 'Q2' ) );
+
+               $this->assertEquals( new ItemId( 'Q10' ), $redirect );
+       }
+
+       private function getMockEntityTitleLookup() {
+               $entityTitleLookup = $this->getMock( 
'\Wikibase\Lib\Store\EntityTitleLookup' );
+
+               $entityTitleLookup->expects( $this->any() )
+                       ->method( 'getTitleForId' )
+                       ->will( $this->returnCallback( function( EntityId 
$entityId ) {
+                               return Title::makeTitle( NS_MAIN, 
$entityId->getSerialization() );
+                       } ) );
+
+               return $entityTitleLookup;
+       }
+
+       private function getMockEntityIdLookup() {
+               $entityIdLookup = $this->getMock( 
'Wikibase\Store\EntityIdLookup' );
+
+               $entityIdLookup->expects( $this->any() )
+                       ->method( 'getEntityIdForTitle' )
+                       ->will( $this->returnCallback( function( Title $title ) 
{
+                               return new ItemId( $title->getText() );
+                       } ) );
+
+               return $entityIdLookup;
+       }
+
+       private function getMockLoadBalancer( array $row ) {
+               $db = $this->getMockDatabase( $row );
+
+               $loadBalancer = $this->getMockBuilder( 'LoadBalancer' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $loadBalancer->expects( $this->any() )
+                       ->method( 'getConnection' )
+                       ->will( $this->returnValue( $db ) );
+
+               return $loadBalancer;
+       }
+
+       private function getMockDatabase( array $row ) {
+               $db = $this->getMockBuilder( 'DatabaseMysql' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $db->expects( $this->any() )
+                       ->method( 'selectRow' )
+                       ->will( $this->returnValue( (object)$row ) );
+
+               return $db;
+       }
+
        public function testGetRedirectIds() {
                $res = 
$this->getWikiPageEntityRedirectLookup()->getRedirectIds( $this->itemId );
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia9ee92c18c225b99b155d366a0fbef351acee225
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to