예제 #1
0
 public function testConstruction()
 {
     $entityId = new ItemId('Q123');
     $targetId = new ItemId('Q345');
     $redirect = new EntityRedirect($entityId, $targetId);
     $this->assertEquals($entityId, $redirect->getEntityId(), '$redirect->getEntityId()');
     $this->assertEquals($targetId, $redirect->getTargetId(), '$redirect->getTargetId()');
 }
 /**
  * Will return a new EntityContent representing the given EntityRedirect,
  * or null if the Content class does not support redirects (that is, if it does
  * not have a static newFromRedirect() function).
  *
  * @see makeRedirectContent()
  * @see supportsRedirects()
  *
  * @since 0.5
  *
  * @param EntityRedirect $redirect
  *
  * @return EntityContent|null
  */
 public function makeEntityRedirectContent(EntityRedirect $redirect)
 {
     $contentClass = $this->getContentClass();
     if (!$this->supportsRedirects()) {
         return null;
     } else {
         $title = $this->getTitleForId($redirect->getTargetId());
         return $contentClass::newFromRedirect($redirect, $title);
     }
 }
 /**
  * Encodes an EntityRedirect into a blob for storage.
  *
  * @see EntityHandler::serializeContent()
  *
  * @param EntityRedirect $redirect
  * @param string|null $format The desired serialization format.
  *
  * @throws InvalidArgumentException If the format is not supported.
  * @throws MWContentSerializationException
  * @return string A blob representing the given Entity.
  */
 public function encodeRedirect(EntityRedirect $redirect, $format)
 {
     // TODO: Use proper Serializer
     $data = array('entity' => $redirect->getEntityId()->getSerialization(), 'redirect' => $redirect->getTargetId()->getSerialization());
     return $this->encodeEntityContentData($data, $format);
 }
 /**
  * Puts a redirect into the mock repository. If there already is an entity with the same ID
  * in the mock repository, it is replaced with the redirect.
  *
  * @param EntityRedirect $redirect
  * @param int $revisionId
  * @param string|int $timestamp
  */
 public function putRedirect(EntityRedirect $redirect, $revisionId = 0, $timestamp = 0)
 {
     $key = $redirect->getEntityId()->getSerialization();
     if (isset($this->entities[$key])) {
         $this->removeEntity($redirect->getEntityId());
     }
     if ($revisionId === 0) {
         $revisionId = ++$this->maxRevisionId;
     }
     $this->maxEntityId = max($this->maxEntityId, $redirect->getTargetId()->getNumericId());
     $this->maxRevisionId = max($this->maxRevisionId, $revisionId);
     $this->redirects[$key] = new RedirectRevision(unserialize(serialize($redirect)), $revisionId, wfTimestamp(TS_MW, $timestamp));
 }
예제 #5
0
 /**
  * @param EntityRedirect|null $redirect
  *
  * @return RedirectCreationInteractor
  */
 public function getMockRedirectCreationInteractor(EntityRedirect $redirect = null)
 {
     $mock = $this->getMockBuilder('Wikibase\\Repo\\Interactors\\RedirectCreationInteractor')->disableOriginalConstructor()->getMock();
     if ($redirect) {
         $mock->expects($this->once())->method('createRedirect')->with($redirect->getEntityId(), $redirect->getTargetId())->will($this->returnCallback(function () use($redirect) {
             return $redirect;
         }));
     } else {
         $mock->expects($this->never())->method('createRedirect');
     }
     return $mock;
 }