/** * @return EntityDocument[] */ protected function getKnownEntities() { $q1 = new Item(new ItemId('Q1')); $q1->setLabel('en', 'label:Q1/en'); $q1->setLabel('de', 'label:Q1/de'); $q1->setDescription('en', 'description:Q1/en'); $q1->setDescription('de', 'description:Q1/de'); $q1->setAliases('en', array('alias:Q1/en#1')); $q1->setAliases('de', array('alias:Q1/de#1', 'alias:Q1/de#2')); $q2 = new Item(new ItemId('Q2')); $q2->setLabel('en', 'label:Q2/en'); $q2->setLabel('de', 'label:Q2/de'); $q2->setAliases('en', array('alias:Q2/en#1')); $q2->setAliases('de', array('alias:Q2/de#1', 'alias:Q2/de#2')); $p2 = Property::newFromType('string'); $p2->setId(new PropertyId('P2')); $p2->setLabel('en', 'label:P2/en'); $p2->setLabel('de', 'label:P2/de'); $p2->setDescription('en', 'description:P2/en'); $p2->setDescription('de', 'description:P2/de'); $p2->setAliases('en', array('alias:P2/en#1')); $p2->setAliases('de', array('alias:P2/de#1', 'alias:P2/de#2')); $p3 = Property::newFromType('string'); $p3->setId(new PropertyId('P3')); $p3->setLabel('en', 'label:P3/en'); $p3->setLabel('de', 'label:P3/de'); $p3->setDescription('en', 'description:P3/en'); $p3->setDescription('de', 'description:P3/de'); return array($q1, $q2, $p2, $p3); }
public function generateProvider() { $item = new Item(); $item->setLabel('en', 'Test'); $item->setLabel('de', 'Testen'); $item->setDescription('en', 'city in Spain'); $item->setAliases('en', array('abc', 'cde')); $item->setAliases('de', array('xyz', 'uvw')); $item->getSiteLinkList()->addNewSiteLink('dewiki', 'Berlin'); $item->getSiteLinkList()->addNewSiteLink('enwiki', 'Rome'); $patterns = array('/^Test$/', '/^Testen$/', '/^city in Spain$/', '/^abc$/', '/^cde$/', '/^uvw$/', '/^xyz$/', '/^(?!abcde).*$/', '/^Berlin$/', '/^Rome$/'); return array(array($item, $patterns)); }
public function testSerialize() { $item = new Item(); $item->setLabel('de', 'German'); $item->setDescription('de', 'German'); $item->setAliases('de', array('German')); $item->setAliases('en', array('English')); $item->getStatements()->addNewStatement(new PropertyNoValueSnak(1)); $instance = $this->newInstance(); $serialization = $instance->serialize($item); $expected = array('type' => 'item', 'labels' => array('en' => array('source-language' => '<SOURCE>')), 'descriptions' => array('en' => array('source-language' => '<SOURCE>')), 'aliases' => array('en' => array(array('language' => 'en', 'value' => 'English'))), 'claims' => array('P1' => array(array('mainsnak' => array('snaktype' => 'novalue', 'property' => 'P1', 'datatype' => '<DATATYPE>'), 'type' => 'statement', 'rank' => 'normal')))); $this->assertSame($expected, $serialization); }
public function itemProvider() { $emptyItem = new Item(new ItemId('Q1')); $item = new Item(new ItemId('Q11')); $item->setDescription('en', 'ohi there'); $item->setLabel('de', 'o_O'); $item->setAliases('nl', array('foo', 'bar')); $item2 = new Item(new ItemId('Q12')); $item2->setLabel('de', 'o_O'); $item2->setLabel('en', 'O_o'); $item2->setAliases('nl', array('daaaah')); $redirect = new EntityRedirect(new ItemId('Q11'), new ItemId('Q21')); $redirect2 = new EntityRedirect(new ItemId('Q11'), new ItemId('Q22')); $insTags = array('has <td>label / de</td>' => array('tag' => 'td', 'content' => 'label / de'), 'has <ins>foo</ins>' => array('tag' => 'ins', 'content' => 'foo'), 'has <td>aliases / nl / 0</td>' => array('tag' => 'td', 'content' => 'aliases / nl / 0'), 'has <ins>bar</ins>' => array('tag' => 'ins', 'content' => 'bar'), 'has <td>description / en</td>' => array('tag' => 'td', 'content' => 'description / en'), 'has <ins>ohi there</ins>' => array('tag' => 'ins', 'content' => 'ohi there')); $delTags = array('has <td>label / de</td>' => array('tag' => 'td', 'content' => 'label / de'), 'has <del>foo</del>' => array('tag' => 'del', 'content' => 'foo'), 'has <td>aliases / nl / 0</td>' => array('tag' => 'td', 'content' => 'aliases / nl / 0'), 'has <del>bar</del>' => array('tag' => 'del', 'content' => 'bar'), 'has <td>description / en</td>' => array('tag' => 'td', 'content' => 'description / en'), 'has <del>ohi there</del>' => array('tag' => 'del', 'content' => 'ohi there')); $changeTags = array('has <td>label / en</td>' => array('tag' => 'td', 'content' => 'label / en'), 'has <ins>O_o</ins>' => array('tag' => 'ins', 'content' => 'O_o'), 'has <td>aliases / nl / 0</td>' => array('tag' => 'td', 'content' => 'aliases / nl / 0'), 'has <ins>daaaah</ins>' => array('tag' => 'ins', 'content' => 'daaaah'), 'has <td>aliases / nl / 1</td>' => array('tag' => 'td', 'content' => 'aliases / nl / 1'), 'has <del>foo</del>' => array('tag' => 'del', 'content' => 'foo'), 'has <td>aliases / nl / 2</td>' => array('tag' => 'td', 'content' => 'aliases / nl / 2'), 'has <del>bar</del>' => array('tag' => 'del', 'content' => 'bar'), 'has <td>description / en</td>' => array('tag' => 'td', 'content' => 'description / en'), 'has <del>ohi there</del>' => array('tag' => 'del', 'content' => 'ohi there')); $fromRedirTags = array('has <td>label / de</td>' => array('tag' => 'td', 'content' => 'label / de'), 'has <ins>foo</ins>' => array('tag' => 'ins', 'content' => 'foo'), 'has <td>redirect</td>' => array('tag' => 'td', 'content' => 'redirect'), 'has <del>Q21</del>' => array('tag' => 'del', 'content' => 'Q21')); $toRedirTags = array('has <td>label / de</td>' => array('tag' => 'td', 'content' => 'label / de'), 'has <del>foo</del>' => array('tag' => 'del', 'content' => 'foo'), 'has <td>redirect</td>' => array('tag' => 'td', 'content' => 'redirect'), 'has <ins>Q21</ins>' => array('tag' => 'ins', 'content' => 'Q21')); $changeRedirTags = array('has <td>redirect</td>' => array('tag' => 'td', 'content' => 'redirect'), 'has <del>Q21</del>' => array('tag' => 'del', 'content' => 'Q21'), 'has <ins>Q22</del>' => array('tag' => 'ins', 'content' => 'Q22')); $empty = ItemContent::newFromItem($emptyItem); $itemContent = ItemContent::newFromItem($item); $itemContent2 = ItemContent::newFromItem($item2); $redirectContent = ItemContent::newFromRedirect($redirect, Title::newFromText($redirect->getEntityId()->getSerialization())); $redirectContent2 = ItemContent::newFromRedirect($redirect2, Title::newFromText($redirect2->getEntityId()->getSerialization())); return array('empty' => array($empty, $empty, array('empty' => '/^$/')), 'same' => array($itemContent, $itemContent, array('empty' => '/^$/')), 'from emtpy' => array($empty, $itemContent, $insTags), 'to empty' => array($itemContent, $empty, $delTags), 'changed' => array($itemContent, $itemContent2, $changeTags), 'to redirect' => array($itemContent, $redirectContent, $toRedirTags), 'from redirect' => array($redirectContent, $itemContent, $fromRedirTags), 'redirect changed' => array($redirectContent, $redirectContent2, $changeRedirTags)); }
/** * Creates a new item and returns its id. * * @return string */ private function createNewItem() { $item = new Item(); // add data and check if it is shown in the form $item->setLabel('de', 'foo'); $item->setDescription('de', 'foo'); $item->setAliases('de', array('foo')); // save the item $store = WikibaseRepo::getDefaultInstance()->getEntityStore(); $store->saveEntity($item, "testing", $GLOBALS['wgUser'], EDIT_NEW | EntityContent::EDIT_IGNORE_CONSTRAINTS); // return the id return $item->getId()->getSerialization(); }
public function entityProvider() { $entities = array(); $entity = new Item(new ItemId('Q42')); $entities[] = array($entity); $entity = new Item(); $entity->setLabels(array('en' => 'Nyan Cat', 'fr' => 'Nyan Cat')); $entities[] = array($entity); $entity = new Item(); $entity->setDescriptions(array('en' => 'A Nyan Cat', 'fr' => 'A Nyan Cat')); $entities[] = array($entity); $entity = new Item(); $entity->setAliases('en', array('Cat', 'My cat')); $entity->setAliases('fr', array('Cat')); $entities[] = array($entity); $entity = new Item(); $entity->getStatements()->addNewStatement(new PropertyNoValueSnak(42), null, null, 'guid'); $entities[] = array($entity); $item = new Item(); $item->addSiteLink(new SiteLink('enwiki', 'Nyan Cat')); $entities[] = array($item); $entities[] = array(Property::newFromType('string')); return $entities; }
public function itemProvider() { $items = array(); $items[] = new Item(); $item = new Item(); $item->setDescription('en', 'foo'); $items[] = $item; $item = new Item(); $item->setDescription('en', 'foo'); $item->setDescription('de', 'foo'); $item->setLabel('en', 'foo'); $item->setAliases('de', array('bar', 'baz')); $items[] = $item; /** @var Item $item */ $item = $item->copy(); $item->getStatements()->addNewStatement(new PropertyNoValueSnak(new PropertyId('P42'))); $items[] = $item; $argLists = array(); foreach ($items as $item) { $argLists[] = array($item); } return $argLists; }
public function testGetTermsOfEntities() { $lookup = $this->getTermIndex(); $item1 = new Item(new ItemId('Q568234314')); $item1->setLabel('en', 'abc'); $item1->setLabel('de', 'def'); $item1->setLabel('nl', 'ghi'); $item1->setDescription('en', 'one description'); $item1->setAliases('fr', array('o', '_', 'O')); $item2 = new Item(new ItemId('Q87236423')); $item2->setLabel('en', 'xyz'); $item2->setLabel('de', 'uvw'); $item2->setLabel('nl', 'rst'); $item2->setDescription('en', 'another description'); $item2->setAliases('fr', array('X', '~', 'x')); $this->assertTrue($lookup->saveTermsOfEntity($item1)); $this->assertTrue($lookup->saveTermsOfEntity($item2)); $itemIds = array($item1->getId(), $item2->getId()); $labelTerms = $lookup->getTermsOfEntities($itemIds, array(TermIndexEntry::TYPE_LABEL)); $this->assertEquals(6, count($labelTerms), "expected 3 labels"); $englishTerms = $lookup->getTermsOfEntities($itemIds, null, array('en')); $this->assertEquals(4, count($englishTerms), "expected 2 English terms"); $englishTerms = $lookup->getTermsOfEntities(array($item1->getId()), null, array('en')); $this->assertEquals(2, count($englishTerms), "expected 2 English terms"); $germanLabelTerms = $lookup->getTermsOfEntities($itemIds, array(TermIndexEntry::TYPE_LABEL), array('de')); $this->assertEquals(2, count($germanLabelTerms), "expected 1 German label"); $noTerms = $lookup->getTermsOfEntities($itemIds, array(TermIndexEntry::TYPE_LABEL), array()); $this->assertEmpty($noTerms, "expected no labels"); $noTerms = $lookup->getTermsOfEntities($itemIds, array(), array('de')); $this->assertEmpty($noTerms, "expected no labels"); $terms = $lookup->getTermsOfEntities($itemIds); $this->assertEquals(14, count($terms), "expected 7 terms for item"); // make list of strings for easy checking $term_keys = array(); foreach ($terms as $t) { $term_keys[] = $t->getType() . '/' . $t->getLanguage() . '/' . $t->getText(); } $k = TermIndexEntry::TYPE_LABEL . '/en/abc'; $this->assertContains($k, $term_keys, "expected to find {$k} in terms for item"); $k = TermIndexEntry::TYPE_LABEL . '/en/xyz'; $this->assertContains($k, $term_keys, "expected to find {$k} in terms for item"); $k = TermIndexEntry::TYPE_DESCRIPTION . '/en/another description'; $this->assertContains($k, $term_keys, "expected to find {$k} in terms for item"); $k = TermIndexEntry::TYPE_ALIAS . '/fr/x'; $this->assertContains($k, $term_keys, "expected to find {$k} in terms for item"); }
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')); }
/** * @dataProvider provideTestAddEntityRevision */ public function testAddEntityRevision($addMetaData, array $expected) { $result = $this->getDefaultResult(); $item = new Item(new ItemId('Q123098')); //Basic $item->setLabel('de', 'foo'); $item->setLabel('zh_classical', 'Longer Label'); $item->setAliases('en', array('bar', 'baz')); $item->setAliases('zh', array('????????')); $item->setDescription('pt', 'ptDesc'); $item->setDescription('pl', 'Longer Description For An Item'); $item->getSiteLinkList()->addNewSiteLink('enwiki', 'Berlin', array(new ItemId('Q333'))); $item->getSiteLinkList()->addNewSiteLink('zh_classicalwiki', 'User:Addshore', array()); $snak = new PropertyValueSnak(new PropertyId('P65'), new StringValue('snakStringValue')); $qualifiers = new SnakList(); $qualifiers->addSnak(new PropertyValueSnak(new PropertyId('P65'), new StringValue('string!'))); $qualifiers->addSnak(new PropertySomeValueSnak(new PropertyId('P65'))); $references = new ReferenceList(); $referenceSnaks = new SnakList(); $referenceSnaks->addSnak(new PropertySomeValueSnak(new PropertyId('P65'))); $referenceSnaks->addSnak(new PropertySomeValueSnak(new PropertyId('P68'))); $references->addReference(new Reference($referenceSnaks)); $guid = 'imaguid'; $item->getStatements()->addNewStatement($snak, $qualifiers, $references, $guid); $entityRevision = new EntityRevision($item, 33, '20131126202923'); $resultBuilder = $this->getResultBuilder($result, $addMetaData); $resultBuilder->addEntityRevision('Q1230000', $entityRevision); $data = $result->getResultData(); $this->assertEquals($expected, $data); }
/** * @param ItemId $id * @param string $languageCode * @param string[] $aliases * * @return Item */ private function getItemWithAliases(ItemId $id, $languageCode, array $aliases) { $item = new Item($id); $item->setAliases($languageCode, $aliases); return $item; }