jenkins-bot has submitted this change and it was merged. Change subject: Better handing for redirects in MockRepositors ......................................................................
Better handing for redirects in MockRepositors Also adds more tests. Change-Id: I9ac1493f3b57962fa12ecb6483c9081eeddea637 --- M lib/tests/phpunit/MockRepository.php M lib/tests/phpunit/MockRepositoryTest.php 2 files changed, 53 insertions(+), 5 deletions(-) Approvals: WikidataJenkins: Verified Thiemo Mättig (WMDE): Looks good to me, approved jenkins-bot: Verified diff --git a/lib/tests/phpunit/MockRepository.php b/lib/tests/phpunit/MockRepository.php index 1da87d5..74709d0 100644 --- a/lib/tests/phpunit/MockRepository.php +++ b/lib/tests/phpunit/MockRepository.php @@ -354,6 +354,8 @@ $rev->user = $user; } + unset( $this->redirects[$key] ); + $this->entities[$key][$revision] = $rev; ksort( $this->entities[$key] ); @@ -368,6 +370,11 @@ */ public function putRedirect( EntityRedirect $redirect ) { $key = $redirect->getEntityId()->getSerialization(); + + if ( isset( $this->entities[$key] ) ) { + $this->removeEntity( $redirect->getEntityId() ); + } + $this->redirects[$key] = $redirect; } @@ -379,15 +386,20 @@ * @return Entity */ public function removeEntity( EntityId $id ) { - $oldEntity = $this->getEntity( $id ); + try { + $oldEntity = $this->getEntity( $id ); - if ( $oldEntity && ( $oldEntity instanceof Item ) ) { - // clean up old sitelinks - $this->unregisterSiteLinks( $oldEntity ); + if ( $oldEntity && ( $oldEntity instanceof Item ) ) { + // clean up old sitelinks + $this->unregisterSiteLinks( $oldEntity ); + } + } catch ( StorageException $ex ) { + $oldEntity = null; // ignore } $key = $id->getPrefixedId(); unset( $this->entities[$key] ); + unset( $this->redirects[$key] ); return $oldEntity; } diff --git a/lib/tests/phpunit/MockRepositoryTest.php b/lib/tests/phpunit/MockRepositoryTest.php index f080c4c..7328836 100644 --- a/lib/tests/phpunit/MockRepositoryTest.php +++ b/lib/tests/phpunit/MockRepositoryTest.php @@ -551,7 +551,13 @@ $this->setExpectedException( $error ); } - $rev = $this->repo->saveEntity( $entity, '', $GLOBALS['wgUser'], $flags, $baseRevId ); + $rev = $this->repo->saveEntity( $entity, 'f00', $GLOBALS['wgUser'], $flags, $baseRevId ); + + $logEntry = $this->repo->getLogEntry( $rev->getRevision() ); + $this->assertNotNull( $logEntry ); + $this->assertEquals( $rev->getRevision(), $logEntry['revision'] ); + $this->assertEquals( $entity->getId()->getSerialization(), $logEntry['entity'] ); + $this->assertEquals( 'f00', $logEntry['summary'] ); $this->assertEquals( $entity->getLabels(), $rev->getEntity()->getLabels() ); $this->assertEquals( $entity->getLabels(), $this->repo->getEntity( $entity->getId() )->getLabels() ); @@ -559,7 +565,29 @@ // test we can't mess with entities in the repo $entity->setLabel( 'en', 'STRANGE' ); $entity = $this->repo->getEntity( $entity->getId() ); + $this->assertNotNull( $entity ); $this->assertNotEquals( 'STRANGE', $entity->getLabel( 'en' ) ); + } + + public function testSaveRedirect() { + $this->setupGetEntities(); + + $q10 = new ItemId( 'Q10' ); + $q1 = new ItemId( 'Q1' ); + + $redirect = new EntityRedirect( $q10, $q1 ); + $revId = $this->repo->saveRedirect( $redirect, 'redirected Q10 to Q1', $GLOBALS['wgUser'] ); + + $this->assertGreaterThan( 0, $revId ); + + $logEntry = $this->repo->getLogEntry( $revId ); + $this->assertNotNull( $logEntry ); + $this->assertEquals( $revId, $logEntry['revision'] ); + $this->assertEquals( $redirect->getEntityId()->getSerialization(), $logEntry['entity'] ); + $this->assertEquals( 'redirected Q10 to Q1', $logEntry['summary'] ); + + $this->setExpectedException( 'Wikibase\Lib\Store\UnresolvedRedirectException' ); + $this->repo->getEntity( $q10 ); } public function testGetLogEntry() { @@ -619,6 +647,14 @@ $this->assertFalse( $this->repo->hasEntity( $item->getId() ) ); } + public function testDeleteRedirect( ) { + $redirect = new EntityRedirect( new ItemId( 'Q11' ), new ItemId( 'Q1' ) ); + $this->repo->putRedirect( $redirect ); + + $this->repo->deleteEntity( $redirect->getEntityId(), 'testing', $GLOBALS['wgUser'] ); + $this->assertNull( $this->repo->getEntity( $redirect->getEntityId() ) ); + } + public function testUpdateWatchlist() { $user = User::newFromName( "WikiPageEntityStoreTestUser2" ); -- To view, visit https://gerrit.wikimedia.org/r/151149 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I9ac1493f3b57962fa12ecb6483c9081eeddea637 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: WikidataJenkins <wikidata-servi...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits