private function getBadgeItem()
 {
     $item = new Item(new ItemId('Q17'));
     $item->setLabel('de', 'exzellent');
     $item->setLabel('en', 'featured');
     return $item;
 }
 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));
 }
 /**
  * @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));
 }
 /**
  * @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;
 }
 /**
  * @return EntityRevision[]
  */
 public static function getEntityRevisions()
 {
     $item = new Item(new ItemId('Q42'));
     $item->setLabel('en', 'Raarrr!');
     $itemRev = new EntityRevision($item, 4242, '20131211100908');
     return array($itemRev);
 }
 /**
  * @dataProvider termProvider
  */
 public function testRebuildSearchKey($languageCode, $termText, $searchText, $matches)
 {
     /* @var TermSqlIndex $termCache */
     $termCache = WikibaseRepo::getDefaultInstance()->getStore()->getTermIndex();
     // make term in item
     $item = new Item(new ItemId('Q42'));
     $item->setLabel($languageCode, $termText);
     // save term
     $termCache->clear();
     $termCache->saveTermsOfEntity($item);
     // remove search key
     $dbw = wfGetDB(DB_MASTER);
     $dbw->update($termCache->getTableName(), array('term_search_key' => ''), array(), __METHOD__);
     // rebuild search key
     $builder = new TermSearchKeyBuilder($termCache);
     $builder->setRebuildAll(true);
     $builder->rebuildSearchKey();
     // remove search key
     $term = new TermIndexEntry();
     $term->setLanguage($languageCode);
     $term->setText($searchText);
     $options = array('caseSensitive' => false);
     $obtainedTerms = $termCache->getMatchingTerms(array($term), TermIndexEntry::TYPE_LABEL, Item::ENTITY_TYPE, $options);
     $this->assertEquals($matches ? 1 : 0, count($obtainedTerms));
     if ($matches) {
         $obtainedTerm = array_shift($obtainedTerms);
         $this->assertEquals($termText, $obtainedTerm->getText());
     }
 }
 public function entityProvider()
 {
     $empty = new Item(new ItemId('Q1'));
     $simple = new Item(new ItemId('Q1'));
     $simple->setLabel('en', 'Test');
     return array('Property' => array(Property::newFromType('string'), null), 'empty' => array($empty, null), 'empty json' => array($empty, CONTENT_FORMAT_JSON), 'simple' => array($simple, null), 'simple json' => array($simple, CONTENT_FORMAT_JSON), 'simple php' => array($simple, CONTENT_FORMAT_SERIALIZED));
 }
 /**
  * @param array $pageNamesPerItemId
  *
  * @return SiteLinkLookup
  */
 private function getSiteLinkLookup(array $pageNamesPerItemId)
 {
     $repo = new MockRepository();
     // entity 1, revision 11
     $entity1 = new Item(new ItemId('Q1'));
     $entity1->setLabel('en', 'one');
     $repo->putEntity($entity1, 11);
     // entity 1, revision 12
     $entity1->setLabel('de', 'eins');
     $repo->putEntity($entity1, 12);
     // entity 1, revision 13
     $entity1->setLabel('it', 'uno');
     $repo->putEntity($entity1, 13);
     // entity 1, revision 1111
     $entity1->setDescription('en', 'the first');
     $repo->putEntity($entity1, 1111);
     // entity 2, revision 21
     $entity1 = new Item(new ItemId('Q2'));
     $entity1->setLabel('en', 'two');
     $repo->putEntity($entity1, 21);
     // entity 2, revision 22
     $entity1->setLabel('de', 'zwei');
     $repo->putEntity($entity1, 22);
     // entity 2, revision 23
     $entity1->setLabel('it', 'due');
     $repo->putEntity($entity1, 23);
     // entity 2, revision 1211
     $entity1->setDescription('en', 'the second');
     $repo->putEntity($entity1, 1211);
     $this->updateMockRepository($repo, $pageNamesPerItemId);
     return $repo;
 }
 protected function makeEntity(EntityId $id, array $statements = array())
 {
     $item = new Item($id);
     $item->setLabel('en', "label:{$id}");
     $item->setDescription('en', "description:{$id}");
     $item->setStatements(new StatementList($statements));
     return $item;
 }
 private function createEntity($label)
 {
     $entity = new Item();
     $entity->setLabel('en', $label);
     $store = WikibaseRepo::getDefaultInstance()->getEntityStore();
     $rev = $store->saveEntity($entity, 'GetEntitiesRedirectTest', $GLOBALS['wgUser'], EDIT_NEW);
     $id = $rev->getEntity()->getId();
     return $id;
 }
 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));
 }
 public function itemProvider()
 {
     $items = array();
     $item = new Item(new ItemId('Q1'));
     $item->setLabel('en', 'Beer');
     $siteLinks = array('cswiki' => 'Pivo', 'enwiki' => 'Beer', 'jawiki' => 'ビール');
     foreach ($siteLinks as $siteId => $pageName) {
         $item->getSiteLinkList()->addNewSiteLink($siteId, $pageName);
     }
     $items[] = $item;
     return array($items);
 }
 public function testNewFromUpdate_add()
 {
     $itemId = new ItemId('Q1');
     $item = new Item($itemId);
     $item->setLabel('en', 'kitten');
     $factory = $this->getEntityChangeFactory();
     $change = $factory->newFromUpdate(EntityChange::ADD, null, $item);
     $this->assertEquals($itemId, $change->getEntityId(), 'entity id');
     $this->assertEquals('q1', $change->getObjectId(), 'object id');
     $this->assertEquals('wikibase-item~add', $change->getType(), 'type');
     $this->assertEquals(new Diff(array('en' => new DiffOpAdd('kitten'))), $change->getDiff()->getLabelsDiff(), 'diff');
 }
 /**
  * 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();
 }
 /**
  * @return EntityRevision[]
  */
 protected function getTestRevisions()
 {
     $entities = array();
     $item = new Item(new ItemId('Q42'));
     $entities[11] = new EntityRevision($item, 11, '20130101001100');
     $item = new Item(new ItemId('Q42'));
     $item->setLabel('en', "Foo");
     $entities[12] = new EntityRevision($item, 12, '20130101001200');
     $prop = Property::newFromType("string");
     $prop->setId(753);
     $entities[13] = new EntityRevision($prop, 13, '20130101001300');
     return $entities;
 }
 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);
 }
 private function createItems()
 {
     $store = WikibaseRepo::getDefaultInstance()->getEntityStore();
     $badge = new Item();
     $badge->setLabel('de', 'Guter Artikel');
     $store->saveEntity($badge, "testing", $GLOBALS['wgUser'], EDIT_NEW);
     $item = new Item();
     $item->getSiteLinkList()->addNewSiteLink('dewiki', 'Wikidata', array($badge->getId()));
     $store->saveEntity($item, "testing", $GLOBALS['wgUser'], EDIT_NEW);
     $redirect = new EntityRedirect(new ItemId('Q12345678'), $item->getId());
     $store->saveRedirect($redirect, "testing", $GLOBALS['wgUser'], EDIT_NEW);
     self::$badgeId = $badge->getId()->getSerialization();
     self::$itemId = $item->getId()->getSerialization();
     self::$redirectId = $redirect->getEntityId()->getSerialization();
 }
 /**
  * @group API
  */
 public function testEditItemDirectly()
 {
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $store = $wikibaseRepo->getEntityStore();
     $item = new Item();
     //@todo: do this with all kinds of entities.
     $item->setLabel("en", "EditPageTest");
     $store->saveEntity($item, 'testing', $GLOBALS['wgUser'], EDIT_NEW);
     $item->setLabel("de", "EditPageTest");
     $data = $wikibaseRepo->getInternalEntitySerializer()->serialize($item);
     $text = json_encode($data);
     $title = $wikibaseRepo->getEntityTitleLookup()->getTitleForId($item->getId());
     // try to update the item with valid data via the edit action
     $this->setExpectedException('UsageException');
     $this->doApiRequestWithToken(array('action' => 'edit', 'pageid' => $title->getArticleID(), 'text' => $text));
 }
 /**
  * @dataProvider termProvider
  */
 public function testGetMatchingTerms2($languageCode, $termText, $searchText, $matches)
 {
     $termIndex = $this->getTermIndex();
     $termIndex->clear();
     $item = new Item(new ItemId('Q42'));
     $item->setLabel($languageCode, $termText);
     $termIndex->saveTermsOfEntity($item);
     $term = new TermIndexEntry();
     $term->setLanguage($languageCode);
     $term->setText($searchText);
     $options = array('caseSensitive' => false);
     //FIXME: test with arrays for term types and entity types!
     $obtainedTerms = $termIndex->getMatchingTerms(array($term), TermIndexEntry::TYPE_LABEL, Item::ENTITY_TYPE, $options);
     $this->assertEquals($matches ? 1 : 0, count($obtainedTerms));
     if ($matches) {
         $obtainedTerm = array_shift($obtainedTerms);
         $this->assertEquals($termText, $obtainedTerm->getText());
     }
 }
 private function getItems()
 {
     $items = array();
     $item = new Item(new ItemId('Q1'));
     $item->setLabel('en', 'Foo');
     $links = $item->getSiteLinkList();
     $links->addNewSiteLink('dewiki', 'Foo de');
     $links->addNewSiteLink('enwiki', 'Foo en', array(new ItemId('Q17')));
     $links->addNewSiteLink('srwiki', 'Foo sr');
     $links->addNewSiteLink('dewiktionary', 'Foo de word');
     $links->addNewSiteLink('enwiktionary', 'Foo en word');
     $items[] = $item;
     $item = new Item(new ItemId('Q2'));
     $item->setLabel('en', 'Talk:Foo');
     $links = $item->getSiteLinkList();
     $links->addNewSiteLink('dewiki', 'Talk:Foo de');
     $links->addNewSiteLink('enwiki', 'Talk:Foo en');
     $links->addNewSiteLink('srwiki', 'Talk:Foo sr');
     $items[] = $item;
     return $items;
 }
Example #22
0
 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");
 }
Example #24
0
 /**
  * @dataProvider provideAttemptSaveWatch
  */
 public function testAttemptSaveWatch($watchdefault, $watchcreations, $new, $watched, $watch, $expected)
 {
     $repo = $this->getMockRepository();
     $user = $this->getUser('EditEntityTestUser2');
     if ($user->getId() === 0) {
         $user->addToDatabase();
     }
     $user->setOption('watchdefault', $watchdefault);
     $user->setOption('watchcreations', $watchcreations);
     $item = new Item();
     $item->setLabel("en", "Test");
     if (!$new) {
         $repo->putEntity($item);
         $repo->updateWatchlist($user, $item->getId(), $watched);
     }
     $titleLookup = $this->getEntityTitleLookup();
     $edit = $this->makeEditEntity($repo, $item, $titleLookup, $user);
     $status = $edit->attemptSave("testing", $new ? EDIT_NEW : EDIT_UPDATE, false, $watch);
     $this->assertTrue($status->isOK(), "edit failed: " . $status->getWikiText());
     // sanity
     $this->assertEquals($expected, $repo->isWatching($user, $item->getId()), "watched");
 }
 private function newItem()
 {
     $item = new Item(new ItemId('Q7799929'));
     $item->setLabel('en', 'kitten item');
     $statements = $item->getStatements();
     $statements->addNewStatement(new PropertyValueSnak(42, new StringValue('http://an.url.com')));
     $statements->addNewStatement(new PropertyValueSnak(42, new StringValue('https://another.url.org')));
     $statements->addNewStatement(new PropertyValueSnak(10, new StringValue('File:This is a file.pdf')));
     $statements->addNewStatement(new PropertyValueSnak(10, new StringValue('File:Selfie.jpg')));
     return $item;
 }
Example #26
0
 private function makeTestItemData()
 {
     $items = array();
     $item = new Item();
     $item->setLabel('de', 'Berlin');
     $item->setDescription('de', 'Stadt in Deutschland');
     $items['Berlin'][] = $item;
     $item = new Item();
     $item->setLabel('de', 'Berlin');
     $item->setLabel('en', 'Berlin');
     $item->setDescription('de', 'Stadt in Brandenburg');
     $item->setDescription('en', 'City in Germany');
     $items['Berlin'][] = $item;
     $item = new Item();
     $item->setLabel('de', 'Berlin');
     $item->setLabel('en', 'Berlin');
     $item->setDescription('de', 'Hauptstadt von Deutschland');
     $item->setDescription('en', 'City in Germany');
     $items['Berlin'][] = $item;
     $item = new Item();
     $item->setLabel('en', 'London');
     $items['London'][] = $item;
     $item = new Item();
     $item->setLabel('en', 'London');
     $item->setLabel('de', 'London');
     $items['London'][] = $item;
     $item = new Item();
     $item->setLabel('de', 'Oslo');
     $item->setLabel('en', 'Oslo');
     $items['Oslo'][] = $item;
     if ($this->shouldTestRedirects()) {
         $item = new Item();
         $item->setLabel('de', 'Berlin');
         $items['Berlin2'][] = $item;
         // HACK: this revision is a redirect
         $items['Berlin2'][] = 'Berlin';
     }
     return $items;
 }
 /**
  * @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);
 }
 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'));
 }
 private function getItem()
 {
     $item = new Item(new ItemId('Q23'));
     $item->setLabel('en', 'Moskow');
     $item->setLabel('de', 'Moskau');
     $item->setDescription('de', 'Hauptstadt Russlands');
     return $item;
 }
 public function testUserWasLastToEdit()
 {
     /* @var WikiPageEntityStore $store */
     /* @var EntityRevisionLookup $lookup */
     list($store, $lookup) = $this->createStoreAndLookup();
     $anonUser = User::newFromId(0);
     $anonUser->setName('127.0.0.1');
     $user = User::newFromName("EditEntityTestUser");
     $item = new Item();
     // check for default values, last revision by anon --------------------
     $item->setLabel('en', "Test Anon default");
     $store->saveEntity($item, 'testing', $anonUser, EDIT_NEW);
     $itemId = $item->getId();
     $res = $store->userWasLastToEdit($anonUser, $itemId, false);
     $this->assertFalse($res);
     // check for default values, last revision by sysop --------------------
     $item->setLabel('en', "Test SysOp default");
     $store->saveEntity($item, 'Test SysOp default', $user, EDIT_UPDATE);
     $res = $store->userWasLastToEdit($anonUser, $itemId, false);
     $this->assertFalse($res);
     // check for default values, last revision by anon --------------------
     $item->setLabel('en', "Test Anon with user");
     $store->saveEntity($item, 'Test Anon with user', $anonUser, EDIT_UPDATE);
     $res = $store->userWasLastToEdit($anonUser, $itemId, false);
     $this->assertFalse($res);
     // check for default values, last revision by sysop --------------------
     $item->setLabel('en', "Test SysOp with user");
     $store->saveEntity($item, 'Test SysOp with user', $user, EDIT_UPDATE);
     $res = $store->userWasLastToEdit($user, $itemId, false);
     $this->assertFalse($res);
     // create an edit and check if the anon user is last to edit --------------------
     $lastRevId = $lookup->getLatestRevisionId($itemId, EntityRevisionLookup::LATEST_FROM_MASTER);
     $item->setLabel('en', "Test Anon");
     $store->saveEntity($item, 'Test Anon', $anonUser, EDIT_UPDATE);
     $res = $store->userWasLastToEdit($anonUser, $itemId, $lastRevId);
     $this->assertTrue($res);
     // also check that there is a failure if we use the sysop user
     $res = $store->userWasLastToEdit($user, $itemId, $lastRevId);
     $this->assertFalse($res);
     // create an edit and check if the sysop user is last to edit --------------------
     $lastRevId = $lookup->getLatestRevisionId($itemId, EntityRevisionLookup::LATEST_FROM_MASTER);
     $item->setLabel('en', "Test SysOp");
     $store->saveEntity($item, 'Test SysOp', $user, EDIT_UPDATE);
     $res = $store->userWasLastToEdit($user, $itemId, $lastRevId);
     $this->assertTrue($res);
     // also check that there is a failure if we use the anon user
     $res = $store->userWasLastToEdit($anonUser, $itemId, $lastRevId);
     $this->assertFalse($res);
 }