/** * @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'); }
/** * @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; }
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; }
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; }
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)); }
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; }
/** * 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; }
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(); }
/** * @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; }
/** * @param array|Entity $entity * @param EntityId|string|null $id Overrides any id in $entity */ public function putEntity($entity, $id = null) { if (is_array($entity)) { $entity = $this->unserializeEntity($entity, $id); } if ($id !== null) { if (is_string($id)) { $id = $this->idParser->parse($id); } $entity->setId($id); } $this->mockRepository->putEntity($entity); }
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 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); }
/** * @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; }
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))); }
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')); }
/** * 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 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'); }
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); }
/** * @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); } }