/** * @param string|EntityId $id * @param bool $resolveRedirects * * @return null|EntityDocument */ public function getEntity($id, $resolveRedirects = false) { if (is_string($id)) { $id = $this->idParser->parse($id); } if ($resolveRedirects) { return $this->redirectResolvingEntityLookup->getEntity($id); } else { return $this->mockRepository->getEntity($id); } }
/** * @dataProvider createRedirectProvider_success */ public function testCreateRedirect_success(EntityId $fromId, EntityId $toId) { $interactor = $this->newInteractor($this->once()); $interactor->createRedirect($fromId, $toId, false); try { $this->mockRepository->getEntity($fromId); $this->fail('getEntity( ' . $fromId->getSerialization() . ' ) did not throw an UnresolvedRedirectException'); } catch (RevisionedUnresolvedRedirectException $ex) { $this->assertEquals($toId->getSerialization(), $ex->getRedirectTargetId()->getSerialization()); } }
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\\RevisionedUnresolvedRedirectException'); $this->repo->getEntity($q10); }