public function getDataTypeForPropertyProvider()
 {
     $argLists = array();
     $emptyInfoStore = new MockPropertyInfoStore();
     $mockInfoStore = new MockPropertyInfoStore();
     $entityLookup = new MockRepository();
     $propertyDataTypeLookup = new EntityRetrievingDataTypeLookup($entityLookup);
     foreach ($this->propertiesAndTypes as $propertyId => $dataTypeId) {
         $id = new PropertyId($propertyId);
         // register property info
         $mockInfoStore->setPropertyInfo($id, array(PropertyInfoStore::KEY_DATA_TYPE => $dataTypeId));
         // register property as an entity, for the fallback
         $property = Property::newFromType($dataTypeId);
         $property->setId($id);
         $entityLookup->putEntity($property);
         // try with a working info store
         $argLists[] = array($mockInfoStore, null, $id, $dataTypeId);
         // try with via fallback
         $argLists[] = array($emptyInfoStore, $propertyDataTypeLookup, $id, $dataTypeId);
     }
     // try unknown property
     $id = new PropertyId('P23');
     // try with a working info store
     $argLists[] = array($mockInfoStore, null, $id, false);
     // try with via fallback
     $argLists[] = array($emptyInfoStore, $propertyDataTypeLookup, $id, false);
     return $argLists;
 }
Example #2
0
 public function testScript()
 {
     $dumpScript = new DumpRdf();
     $mockRepo = new MockRepository();
     $mockEntityPerPage = new MockEntityPerPage();
     $snakList = new SnakList();
     $snakList->addSnak(new PropertySomeValueSnak(new PropertyId('P12')));
     $snakList->addSnak(new PropertyValueSnak(new PropertyId('P12'), new StringValue('stringVal')));
     /** @var Entity[] $testEntities */
     $testEntities = array(new Item(new ItemId('Q1')), new Property(new PropertyId('P1'), null, 'string'), new Property(new PropertyId('P12'), null, 'string', new StatementList(array(new Statement(new PropertySomeValueSnak(new PropertyId('P999')), null, null, 'GUID1')))), new Item(new ItemId('Q2'), new Fingerprint(new TermList(array(new Term('en', 'en-label'), new Term('de', 'de-label'))), new TermList(array(new Term('fr', 'en-desc'), new Term('de', 'de-desc'))), new AliasGroupList(array(new AliasGroup('en', array('ali1', 'ali2')), new AliasGroup('dv', array('ali11', 'ali22'))))), new SiteLinkList(array(new SiteLink('enwiki', 'Berlin'), new SiteLink('dewiki', 'England', array(new ItemId('Q1'))))), new StatementList(array(new Statement(new PropertySomeValueSnak(new PropertyId('P12')), null, null, 'GUID1'), new Statement(new PropertySomeValueSnak(new PropertyId('P12')), $snakList, new ReferenceList(array(new Reference(array(new PropertyValueSnak(new PropertyId('P12'), new StringValue('refSnakVal')), new PropertyNoValueSnak(new PropertyId('P12')))))), 'GUID2')))));
     foreach ($testEntities as $key => $testEntity) {
         $mockRepo->putEntity($testEntity, $key, '20000101000000');
         $mockEntityPerPage->addEntityPage($testEntity->getId(), $key);
     }
     // Note: We are testing with the actual RDF bindings, so we can check for actual RDF output.
     $rdfBuilder = WikibaseRepo::getDefaultInstance()->getValueSnakRdfBuilderFactory();
     $dumpScript->setServices($mockEntityPerPage, new NullEntityPrefetcher(), MockSiteStore::newFromTestSites(), $this->getMockPropertyDataTypeLookup(), $rdfBuilder, $mockRepo, 'fooUri');
     $logFileName = tempnam(sys_get_temp_dir(), "Wikibase-DumpRdfTest");
     $outFileName = tempnam(sys_get_temp_dir(), "Wikibase-DumpRdfTest");
     $dumpScript->loadParamsAndArgs(null, array('log' => $logFileName, 'output' => $outFileName, 'format' => 'n-triples'));
     $dumpScript->execute();
     $expectedLog = file_get_contents(__DIR__ . '/../data/maintenance/dumpRdf-log.txt');
     $expectedOut = file_get_contents(__DIR__ . '/../data/maintenance/dumpRdf-out.txt');
     $actualOut = file_get_contents($outFileName);
     $actualOut = preg_replace('/<http:\\/\\/wikiba.se\\/ontology-beta#Dump> <http:\\/\\/schema.org\\/dateModified> "[^"]+"/', "<http://wikiba.se/ontology-beta#Dump> <http://schema.org/dateModified> \"2015-01-01T00:00:00Z\"", $actualOut);
     $this->assertEquals($this->fixLineEndings($expectedLog), $this->fixLineEndings(file_get_contents($logFileName)));
     $this->assertEquals($this->fixLineEndings($expectedOut), $this->fixLineEndings($actualOut));
 }
 /**
  * @return LangLinkHandler
  */
 private function getLangLinkHandler()
 {
     $this->mockRepo = new MockRepository();
     foreach ($this->getItems() as $item) {
         $this->mockRepo->putEntity($item);
     }
     $siteStore = new HashSiteStore(TestSites::getSites());
     return new LangLinkHandler($this->getLanguageLinkBadgeDisplay(), new NamespaceChecker(array(NS_TALK)), $this->mockRepo, $this->mockRepo, $siteStore, 'srwiki', 'wikipedia');
 }
 public function getEntityProvider()
 {
     $q10 = new ItemId('Q10');
     $q11 = new ItemId('Q11');
     $item10 = new Item($q10);
     $item10->setLabel('en', 'ten');
     $repo = new MockRepository();
     $repo->putEntity($item10);
     return array('found' => array($repo, $q10, $q10), 'not found' => array($repo, $q11, null));
 }
 private function getMockRepository()
 {
     $propertyId = new PropertyId('P1337');
     $property = Property::newFromType('string');
     $property->setId($propertyId);
     $property->setLabel('en', 'a kitten!');
     $mockRepository = new MockRepository();
     $mockRepository->putEntity($property);
     return $mockRepository;
 }
 /**
  * @return EntityLookup
  */
 private function getEntityLookup()
 {
     $q8 = new Item(new ItemId('Q8'));
     $p8 = Property::newFromType('string');
     $p8->setId(8);
     $entityLookup = new MockRepository();
     $entityLookup->putEntity($q8);
     $entityLookup->putEntity($p8);
     return $entityLookup;
 }
 /**
  * @param string[] $labels
  * @param string   $recache ignored
  *
  * @return EntityId[] a map of strings from $labels to the corresponding entity ID.
  */
 public function getPropertyIdsForLabels(array $labels, $recache = '')
 {
     $entityIds = array();
     foreach ($labels as $label) {
         $entity = $this->mockRepository->getPropertyByLabel($label, $this->languageCode);
         if ($entity !== null) {
             $entityIds[$label] = $entity->getId();
         }
     }
     return $entityIds;
 }
 public static function getMockRepository()
 {
     $mockRepository = new MockRepository();
     foreach (self::getEntityRevisions() as $entityRev) {
         $mockRepository->putEntity($entityRev->getEntity(), $entityRev->getRevisionId(), $entityRev->getTimestamp());
     }
     foreach (self::getEntityRedirects() as $entityRedir) {
         $mockRepository->putRedirect($entityRedir);
     }
     return $mockRepository;
 }
 /**
  * @param EntityDocument[] $entities
  *
  * @return EntityInfo
  */
 private function getEntityInfo(array $entities)
 {
     $entityRevisionLookup = new MockRepository();
     $ids = array();
     foreach ($entities as $entity) {
         $entityRevisionLookup->putEntity($entity);
         $ids[] = $entity->getId();
     }
     $builder = new GenericEntityInfoBuilder($ids, new BasicEntityIdParser(), $entityRevisionLookup);
     $builder->collectTerms();
     return $builder->getEntityInfo();
 }
 /**
  * @param array $ids
  *
  * @return GenericEntityInfoBuilder
  */
 protected function newEntityInfoBuilder(array $ids)
 {
     $idParser = new BasicEntityIdParser();
     $repo = new MockRepository();
     foreach ($this->getKnownEntities() as $entity) {
         $repo->putEntity($entity);
     }
     foreach ($this->getKnownRedirects() as $from => $toId) {
         $fromId = $idParser->parse($from);
         $repo->putRedirect(new EntityRedirect($fromId, $toId));
     }
     return new GenericEntityInfoBuilder($ids, $idParser, $repo);
 }
 /**
  * @return EntityRevisionLookup
  */
 private function getEntityRevisionLookup()
 {
     $repo = new MockRepository();
     $offsets = array('Q1' => 1100, 'Q2' => 1200);
     foreach ($offsets as $qid => $offset) {
         // entity 1, revision 1111
         $entity1 = new Item(new ItemId($qid));
         $entity1->setLabel('en', 'ORIGINAL');
         $entity1->getSiteLinkList()->addNewSiteLink('enwiki', 'Original');
         $repo->putEntity($entity1, $offset + 11);
         // entity 1, revision 1112
         $entity1->setLabel('de', 'HINZUGEFÃœGT');
         $repo->putEntity($entity1, $offset + 12);
         // entity 1, revision 1113
         $entity1->setLabel('nl', 'Addiert');
         $repo->putEntity($entity1, $offset + 13);
         // entity 1, revision 1114
         $entity1->getSiteLinkList()->addNewSiteLink('dewiki', 'Testen');
         $repo->putEntity($entity1, $offset + 14);
         // entity 1, revision 1117
         $entity1->getSiteLinkList()->setSiteLink(new SiteLink('enwiki', 'Spam', array(new ItemId('Q12345'))));
         $repo->putEntity($entity1, $offset + 17);
         // entity 1, revision 1118
         $entity1->getSiteLinkList()->setSiteLink(new SiteLink('enwiki', 'Spam', array(new ItemId('Q54321'))));
         $repo->putEntity($entity1, $offset + 18);
     }
     return $repo;
 }
 private function newValidatorBuilders()
 {
     $entityIdParser = new BasicEntityIdParser();
     $q8 = new Item(new ItemId('Q8'));
     $p8 = Property::newFromType('string');
     $p8->setId(new PropertyId('P8'));
     $entityLookup = new MockRepository();
     $entityLookup->putEntity($q8);
     $entityLookup->putEntity($p8);
     $urlSchemes = array('http', 'https', 'ftp', 'mailto');
     $contentLanguages = $this->getMock('Wikibase\\Lib\\ContentLanguages');
     $contentLanguages->expects($this->any())->method('getLanguages')->will($this->returnValue(array('contentlanguage')));
     $builders = new ValidatorBuilders($entityLookup, $entityIdParser, $urlSchemes, 'http://qudt.org/vocab/', $contentLanguages, $this->getCachingCommonsMediaFileNameLookup());
     return $builders;
 }
 /**
  * @dataProvider runProvider
  *
  * @param bool $expected
  * @param bool $titleExists
  * @param string $oldTitle
  */
 public function testRun($expected, $titleExists, $oldTitle)
 {
     $item = new Item();
     $item->getSiteLinkList()->addNewSiteLink('enwiki', 'Delete me', array(new ItemId('Q42')));
     $mockRepository = new MockRepository();
     $user = User::newFromName('UpdateRepo');
     // Needed as UpdateRepoOnDeleteJob instantiates a User object
     $user->addToDatabase();
     $mockRepository->saveEntity($item, 'UpdateRepoOnDeleteJobTest', $user, EDIT_NEW);
     $params = array('siteId' => 'enwiki', 'entityId' => $item->getId()->getSerialization(), 'title' => $oldTitle, 'user' => $user->getName());
     $job = new UpdateRepoOnDeleteJob(Title::newMainPage(), $params);
     $job->initServices($mockRepository, $mockRepository, $this->getSummaryFormatter(), $this->getSiteStore($titleExists), new EditEntityFactory($this->getEntityTitleLookup($item->getId()), $mockRepository, $mockRepository, $this->getEntityPermissionChecker(), $this->getMockEditFitlerHookRunner()));
     $job->run();
     $item = $mockRepository->getEntity($item->getId());
     $this->assertSame(!$expected, $item->getSiteLinkList()->hasLinkWithSiteId('enwiki'), 'Sitelink has been removed.');
 }
 /**
  * @dataProvider runProvider
  * @param string $expected
  * @param string $normalizedPageName
  * @param string $oldTitle
  */
 public function testRun($expected, $normalizedPageName, $oldTitle)
 {
     $user = User::newFromName('UpdateRepo');
     // Needed as UpdateRepoOnMoveJob instantiates a User object
     $user->addToDatabase();
     $item = new Item();
     $item->getSiteLinkList()->addNewSiteLink('enwiki', 'Old page name', array(new ItemId('Q42')));
     $mockRepository = new MockRepository();
     $mockRepository->saveEntity($item, 'UpdateRepoOnDeleteJobTest', $user, EDIT_NEW);
     $params = array('siteId' => 'enwiki', 'entityId' => $item->getId()->getSerialization(), 'oldTitle' => $oldTitle, 'newTitle' => 'New page name', 'user' => $user->getName());
     $job = new UpdateRepoOnMoveJob(Title::newMainPage(), $params);
     $job->initServices($mockRepository, $mockRepository, $this->getSummaryFormatter(), $this->getSiteStore($normalizedPageName), new EditEntityFactory($this->getEntityTitleLookup($item->getId()), $mockRepository, $mockRepository, $this->getEntityPermissionChecker(), $this->getMockEditFitlerHookRunner()));
     $job->run();
     /** @var Item $item */
     $item = $mockRepository->getEntity($item->getId());
     $this->assertSame($expected, $item->getSiteLinkList()->getBySiteId('enwiki')->getPageName(), 'Title linked on enwiki after the job ran');
     $this->assertEquals($item->getSiteLinkList()->getBySiteId('enwiki')->getBadges(), array(new ItemId('Q42')));
 }
 /**
  * @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 testScript()
 {
     $dumpScript = new DumpJson();
     $mockRepo = new MockRepository();
     $mockEntityPerPage = new MockEntityPerPage();
     $snakList = new SnakList();
     $snakList->addSnak(new PropertySomeValueSnak(new PropertyId('P12')));
     $snakList->addSnak(new PropertyValueSnak(new PropertyId('P12'), new StringValue('stringVal')));
     /** @var Entity[] $testEntities */
     $testEntities = array(new Item(new ItemId('Q1')), new Property(new PropertyId('P1'), null, 'string'), new Property(new PropertyId('P12'), null, 'string', new StatementList(array(new Statement(new PropertySomeValueSnak(new PropertyId('P999')), null, null, 'GUID1')))), new Item(new ItemId('Q2'), new Fingerprint(new TermList(array(new Term('en', 'en-label'), new Term('de', 'de-label'))), new TermList(array(new Term('fr', 'en-desc'), new Term('de', 'de-desc'))), new AliasGroupList(array(new AliasGroup('en', array('ali1', 'ali2')), new AliasGroup('dv', array('ali11', 'ali22'))))), new SiteLinkList(array(new SiteLink('enwiki', 'Berlin'), new SiteLink('dewiki', 'England', array(new ItemId('Q1'))))), new StatementList(array(new Statement(new PropertySomeValueSnak(new PropertyId('P12')), null, null, 'GUID1'), new Statement(new PropertySomeValueSnak(new PropertyId('P12')), $snakList, new ReferenceList(array(new Reference(array(new PropertyValueSnak(new PropertyId('P12'), new StringValue('refSnakVal')), new PropertyNoValueSnak(new PropertyId('P12')))))), 'GUID2')))));
     foreach ($testEntities as $key => $testEntity) {
         $mockRepo->putEntity($testEntity);
         $mockEntityPerPage->addEntityPage($testEntity->getId(), $key);
     }
     $dumpScript->setServices($mockEntityPerPage, new NullEntityPrefetcher(), $this->getMockPropertyDataTypeLookup(), $mockRepo);
     $logFileName = tempnam(sys_get_temp_dir(), "Wikibase-DumpJsonTest");
     $outFileName = tempnam(sys_get_temp_dir(), "Wikibase-DumpJsonTest");
     $dumpScript->loadParamsAndArgs(null, array('log' => $logFileName, 'output' => $outFileName));
     $dumpScript->execute();
     $expectedLog = file_get_contents(__DIR__ . '/../data/maintenance/dumpJson-log.txt');
     $expectedOut = file_get_contents(__DIR__ . '/../data/maintenance/dumpJson-out.txt');
     $this->assertEquals($this->fixLineEndings($expectedLog), $this->fixLineEndings(file_get_contents($logFileName)));
     $this->assertEquals($this->fixLineEndings($expectedOut), $this->fixLineEndings(file_get_contents($outFileName)));
 }
 /**
  * @param ItemId $id
  * @param string[] $labels
  * @param Statement[]|null $statements
  * @param SiteLink[]|null $siteLinks
  *
  * @return Item
  */
 private function createTestItem(ItemId $id, array $labels, array $statements = null, array $siteLinks = null)
 {
     $item = new Item($id);
     $item->getFingerprint()->setDescription('de', 'Description of ' . $id->getSerialization());
     foreach ($labels as $lang => $label) {
         $item->setLabel($lang, $label);
     }
     if ($statements !== null) {
         $item->setStatements(new StatementList($statements));
     }
     if ($siteLinks !== null) {
         $item->setSiteLinkList(new SiteLinkList($siteLinks));
     }
     $this->siteLinkLookup->putEntity($item);
     return $item;
 }
 /**
  * @dataProvider mergeProvider
  */
 public function testMergeItems($fromData, $toData, $expectedFrom, $expectedTo, $ignoreConflicts = array())
 {
     $interactor = $this->newInteractor();
     $fromId = new ItemId('Q1');
     $toId = new ItemId('Q2');
     $this->testHelper->putEntities(array('Q1' => $fromData, 'Q2' => $toData));
     if (is_string($ignoreConflicts)) {
         $ignoreConflicts = explode('|', $ignoreConflicts);
     }
     $interactor->mergeItems($fromId, $toId, $ignoreConflicts, 'CustomSummary');
     $actualTo = $this->testHelper->getEntity($toId);
     $this->testHelper->assertEntityEquals($expectedTo, $actualTo, 'modified target item');
     $this->assertRedirectWorks($expectedFrom, $fromId, $toId);
     $toRevId = $this->mockRepository->getLatestRevisionId($toId);
     $this->testHelper->assertRevisionSummary('@^/\\* *wbmergeitems-from:0\\|\\|Q1 *\\*/ *CustomSummary$@', $toRevId, 'summary for target item');
 }
 /**
  * Asserts that the revision with the given ID has a summary matching $regex
  *
  * @param string|string[] $regex The regex to match, or an array to build a regex from
  * @param int $revid
  * @param string $message
  */
 public function assertRevisionSummary($regex, $revid, $message = '')
 {
     if (is_array($regex)) {
         $r = '';
         foreach ($regex as $s) {
             if (strlen($r) > 0) {
                 $r .= '.*';
             }
             $r .= preg_quote($s, '!');
         }
         $regex = "!{$r}!";
     }
     $entry = $this->mockRepository->getLogEntry($revid);
     Assert::assertNotNull($entry, "revision not found: {$revid}");
     Assert::assertRegExp($regex, $entry['summary'], $message);
 }
 /**
  * Returns a MockRepository. The following entities are defined:
  *
  * - Items Q23
  * - Item Q42
  * - Redirect Q2233 -> Q23
  * - Redirect Q222333 -> Q23
  * - Property P5 (item reference)
  *
  * @return MockRepository
  */
 private function getMockRepository()
 {
     $mockRepo = new MockRepository();
     $p5 = new Property(new PropertyId('P5'), null, 'wikibase-item');
     $p5->getFingerprint()->setLabel('en', 'Label5');
     $mockRepo->putEntity($p5);
     $q23 = new Item(new ItemId('Q23'));
     $q23->getFingerprint()->setLabel('en', 'Label23');
     $mockRepo->putEntity($q23);
     $q2233 = new EntityRedirect(new ItemId('Q2233'), new ItemId('Q23'));
     $mockRepo->putRedirect($q2233);
     $q222333 = new EntityRedirect(new ItemId('Q222333'), new ItemId('Q23'));
     $mockRepo->putRedirect($q222333);
     $q42 = new Item(new ItemId('Q42'));
     $q42->getFingerprint()->setLabel('en', 'Label42');
     $snak = new PropertyValueSnak($p5->getId(), new EntityIdValue($q2233->getEntityId()));
     $q42->getStatements()->addNewStatement($snak, null, null, 'Q42$DEADBEEF');
     $mockRepo->putEntity($q42);
     return $mockRepo;
 }
 protected function setUp()
 {
     parent::setUp();
     $this->mockRepository = new MockRepository();
     // empty item
     $item = new Item(new ItemId('Q11'));
     $this->mockRepository->putEntity($item);
     // non-empty item
     $item->setLabel('en', 'Foo');
     $item->setId(new ItemId('Q12'));
     $this->mockRepository->putEntity($item);
     // a property
     $prop = Property::newFromType('string');
     $prop->setId(new PropertyId('P11'));
     $this->mockRepository->putEntity($prop);
     // another property
     $prop->setId(new PropertyId('P12'));
     $this->mockRepository->putEntity($prop);
     // redirect
     $redirect = new EntityRedirect(new ItemId('Q22'), new ItemId('Q12'));
     $this->mockRepository->putRedirect($redirect);
 }
 /**
  * @param MockRepository $mockRepository
  * @param array $pageNamesPerItemId Associative array of item id string => either Item object
  * or array of site id => page name.
  */
 private function updateMockRepository(MockRepository $mockRepository, array $pageNamesPerItemId)
 {
     foreach ($pageNamesPerItemId as $idString => $pageNames) {
         if (is_array($pageNames)) {
             $item = new Item(new ItemId($idString));
             foreach ($pageNames as $siteId => $pageName) {
                 if (!is_string($siteId)) {
                     $siteId = 'enwiki';
                 }
                 $item->getSiteLinkList()->addNewSiteLink($siteId, $pageName);
             }
         } else {
             $item = $pageNames;
         }
         $mockRepository->putEntity($item);
     }
 }
Example #23
0
 private function prepareItemForPermissionCheck(User $user, MockRepository $mockRepository, $create)
 {
     $item = new Item();
     if ($create) {
         $item->setLabel('de', 'Test');
         $mockRepository->putEntity($item, 0, 0, $user);
     }
     return $item;
 }
 public function testGetSiteLinkPageName_usage()
 {
     $item = $this->getItem();
     $entityLookup = new MockRepository();
     $entityLookup->putEntity($item);
     $siteLinkStore = new HashSiteLinkStore();
     $siteLinkStore->saveLinksOfItem($item);
     $usages = new HashUsageAccumulator();
     $wikibaseLuaBindings = $this->getWikibaseLuaBindings($entityLookup, $siteLinkStore, $usages);
     $itemId = $item->getId();
     $wikibaseLuaBindings->getSiteLinkPageName($itemId->getSerialization());
     $this->assertTrue($this->hasUsage($usages->getUsages(), $itemId, EntityUsage::TITLE_USAGE), 'title usage');
     $this->assertFalse($this->hasUsage($usages->getUsages(), $itemId, EntityUsage::LABEL_USAGE), 'label usage');
     $this->assertFalse($this->hasUsage($usages->getUsages(), $itemId, EntityUsage::ALL_USAGE), 'all usage');
 }
 /**
  * @param array[] $links
  *
  * @return MockRepository
  */
 private function getMockRepo(array $links)
 {
     $repo = new MockRepository();
     foreach ($links as $itemKey => $itemLinks) {
         $itemId = new ItemId($itemKey);
         $item = $this->newItem($itemId, $itemLinks);
         $repo->putEntity($item);
     }
     return $repo;
 }
 public function testFullEntityGetEntityResponse()
 {
     $item = new Item(new ItemId('Q123098'));
     //Basic
     $item->setLabel('de', 'foo-de');
     $item->setLabel('qu', 'foo-qu');
     $item->setAliases('en', array('bar', 'baz'));
     $item->setAliases('de-formal', array('bar', 'baz'));
     $item->setDescription('en', 'en-desc');
     $item->setDescription('pt', 'ptDesc');
     $item->getSiteLinkList()->addNewSiteLink('enwiki', 'Berlin', array(new ItemId('Q333')));
     $item->getSiteLinkList()->addNewSiteLink('zh_classicalwiki', 'User:Addshore', array());
     $snak = new PropertyValueSnak(65, new StringValue('snakStringValue'));
     $qualifiers = new SnakList();
     $qualifiers->addSnak(new PropertyValueSnak(65, new StringValue('string!')));
     $qualifiers->addSnak(new PropertySomeValueSnak(65));
     $references = new ReferenceList();
     $references->addNewReference(array(new PropertySomeValueSnak(65), new PropertySomeValueSnak(68)));
     $guid = 'imaguid';
     $item->getStatements()->addNewStatement($snak, $qualifiers, $references, $guid);
     $entityLookup = new MockRepository();
     $entityLookup->putEntity($item);
     $entityAccessor = $this->getEntityAccessor($entityLookup, null, 'qug');
     $expected = array('id' => 'Q123098', 'type' => 'item', 'labels' => array('de' => array('language' => 'de', 'value' => 'foo-de')), 'descriptions' => array('en' => array('language' => 'en', 'value' => 'en-desc')), 'aliases' => array('en' => array(1 => array('language' => 'en', 'value' => 'bar'), 2 => array('language' => 'en', 'value' => 'baz'))), 'claims' => array('P65' => array(1 => array('id' => 'imaguid', 'type' => 'statement', 'mainsnak' => array('snaktype' => 'value', 'property' => 'P65', 'datatype' => 'structured-cat', 'datavalue' => array('value' => 'snakStringValue', 'type' => 'string')), 'qualifiers' => array('P65' => array(1 => array('hash' => 'e95e866e7fa1c18bd06dae9b712cb99545107eb8', 'snaktype' => 'value', 'property' => 'P65', 'datavalue' => array('value' => 'string!', 'type' => 'string'), 'datatype' => 'structured-cat'), 2 => array('hash' => '210b00274bf03247a89de918f15b12142ebf9e56', 'snaktype' => 'somevalue', 'property' => 'P65', 'datatype' => 'structured-cat'))), 'rank' => 'normal', 'qualifiers-order' => array(1 => 'P65'), 'references' => array(1 => array('hash' => 'bdc5f7185904d6d3219e13b7443571dda8c4bee8', 'snaks' => array('P65' => array(1 => array('snaktype' => 'somevalue', 'property' => 'P65', 'datatype' => 'structured-cat')), 'P68' => array(1 => array('snaktype' => 'somevalue', 'property' => 'P68', 'datatype' => 'structured-cat'))), 'snaks-order' => array(1 => 'P65', 2 => 'P68')))))), 'sitelinks' => array('enwiki' => array('site' => 'enwiki', 'title' => 'Berlin', 'badges' => array(1 => 'Q333')), 'zh_classicalwiki' => array('site' => 'zh_classicalwiki', 'title' => 'User:Addshore', 'badges' => array())), 'schemaVersion' => 2);
     $this->assertEquals($expected, $entityAccessor->getEntity('Q123098'));
 }
 public function testUpdateBadgesProperty_inconsistentSiteLinkLookupNoSuchEntity()
 {
     $parserOutput = new ParserOutput();
     $title = Title::newFromText('Foo sr');
     $siteLinkLookup = new MockRepository();
     foreach ($this->getItems() as $item) {
         $siteLinkLookup->putEntity($item);
     }
     $parserOutputDataUpdater = new ClientParserOutputDataUpdater($this->getOtherProjectsSidebarGeneratorFactory(array()), $siteLinkLookup, new MockRepository(), 'srwiki');
     // Suppress warnings as this is supposed to throw one.
     \MediaWiki\suppressWarnings();
     $parserOutputDataUpdater->updateBadgesProperty($title, $parserOutput);
     \MediaWiki\restoreWarnings();
     // Stuff didn't blow up
     $this->assertTrue(true);
 }
 public function testEntityDeleted()
 {
     $mock = new MockRepository();
     $id = new ItemId('Q123');
     $item = new Item($id);
     $mock->putEntity($item, 11);
     $lookup = new CachingEntityRevisionLookup($mock, new HashBagOStuff());
     $lookup->setVerifyRevision(false);
     // fetch first revision, so it gets cached
     $lookup->getEntityRevision($id);
     // remove entity
     $mock->removeEntity($id);
     // now, notify the cache
     $lookup->entityDeleted($id);
     // make sure we get the new revision now
     $revId = $lookup->getLatestRevisionId($id);
     $this->assertFalse($revId, 'deletion should be detected after notification');
     $rev = $lookup->getEntityRevision($id);
     $this->assertNull($rev, 'deletion should be detected after notification');
 }
 /**
  * Construct mock repository matching the test data.
  *
  * @return MockRepository
  */
 public function getMockRepository()
 {
     static $repo;
     if (!empty($repo)) {
         return $repo;
     }
     $repo = new MockRepository();
     foreach (self::getTestProperties() as $prop) {
         list($id, $type) = $prop;
         $fingerprint = new Fingerprint();
         $fingerprint->setLabel('en', "Property{$id}");
         $entity = new Property(PropertyId::newFromNumber($id), $fingerprint, $type);
         $repo->putEntity($entity);
     }
     $q42 = new ItemId('Q42');
     $fingerprint = new Fingerprint();
     $fingerprint->setLabel('en', 'Item42');
     $entity = new Item($q42, $fingerprint);
     $repo->putEntity($entity);
     $repo->putRedirect(new EntityRedirect(new ItemId('Q4242'), $q42));
     return $repo;
 }
 public function testGetRedirectForEntityId()
 {
     $mock = new MockRepository();
     $q5 = new ItemId('Q5');
     $q55 = new ItemId('Q55');
     $q77 = new ItemId('Q77');
     $mock->putEntity(new Item($q5));
     $mock->putRedirect(new EntityRedirect($q55, $q5));
     $this->assertNull($mock->getRedirectForEntityId($q5), 'not a redirect');
     $this->assertEquals($q5, $mock->getRedirectForEntityId($q55));
     $this->setExpectedException('Wikibase\\DataModel\\Services\\Lookup\\EntityRedirectLookupException');
     $mock->getRedirectForEntityId($q77);
 }