Example #1
0
 private function setIdFromSerialization(array $serialization, Item $item)
 {
     if (!array_key_exists('id', $serialization)) {
         return;
     }
     $item->setId($this->entityIdDeserializer->deserialize($serialization['id']));
 }
 /**
  * @depends testCreateItem
  */
 public function testEmptyItem()
 {
     $factory = $factory = TestEnvironment::newDefault()->getFactory();
     self::$localItem = new Item();
     self::$localItem->setId(self::$itemId);
     $newItem = $factory->newRevisionSaver()->save(new Revision(new ItemContent(self::$localItem)));
     $this->assertTrue(self::$localItem->equals($newItem));
 }
 private function newItem()
 {
     $item = new Item();
     $item->setId(1337);
     $item->setFingerprint($this->newFingerprint());
     $item->setSiteLinkList($this->newSiteLinks());
     $this->addStatements($item);
     return $item;
 }
 public function testAttemptSave()
 {
     $mockApiBase = $this->getMockApiBase();
     $mockApiBase->expects($this->once())->method('isWriteMode')->will($this->returnValue(true));
     $mockApiBase->expects($this->atLeastOnce())->method('getContext')->will($this->returnValue($this->newContext()));
     $mockApiBase->expects($this->atLeastOnce())->method('extractRequestParams')->will($this->returnValue(array()));
     $helper = new EntitySavingHelper($mockApiBase, $this->getMockErrorReporter(), $this->getMockSummaryFormatter(), $this->getMockEditEntityFactory(1));
     $entity = new Item();
     $entity->setId(new ItemId('Q444'));
     $entity->getFingerprint()->setLabel('en', 'Foo');
     $entity->getSiteLinkList()->addNewSiteLink('enwiki', 'APage');
     $entity->getStatements()->addNewStatement(new PropertyNoValueSnak(new PropertyId('P8')));
     $summary = 'A String Summary';
     $flags = 0;
     $status = $helper->attemptSaveEntity($entity, $summary, $flags);
     $this->assertTrue($status->isGood());
 }
 public function serializationProvider()
 {
     $provider = array(array(array('type' => 'item', 'labels' => array(), 'descriptions' => array(), 'aliases' => array(), 'sitelinks' => array(), 'claims' => array()), new Item()));
     $entity = new Item();
     $entity->setId(42);
     $provider[] = array(array('type' => 'item', 'id' => 'Q42', 'claims' => array(), 'labels' => array(), 'descriptions' => array(), 'aliases' => array(), 'sitelinks' => array()), $entity);
     $entity = new Item();
     $entity->getFingerprint()->setLabel('en', 'foo');
     $provider[] = array(array('type' => 'item', 'claims' => array(), 'labels' => array('en' => array('lang' => 'en', 'value' => 'foo')), 'descriptions' => array(), 'aliases' => array(), 'sitelinks' => array()), $entity);
     $entity = new Item();
     $entity->getFingerprint()->setDescription('en', 'foo');
     $provider[] = array(array('type' => 'item', 'claims' => array(), 'labels' => array(), 'descriptions' => array('en' => array('lang' => 'en', 'value' => 'foo')), 'aliases' => array(), 'sitelinks' => array()), $entity);
     $entity = new Item();
     $entity->getFingerprint()->setAliasGroup('en', array('foo', 'bar'));
     $provider[] = array(array('type' => 'item', 'claims' => array(), 'labels' => array(), 'descriptions' => array(), 'aliases' => array('en' => array('lang' => 'en', 'values' => array('foo', 'bar'))), 'sitelinks' => array()), $entity);
     $entity = new Item();
     $entity->getStatements()->addNewStatement(new PropertyNoValueSnak(42), null, null, 'test');
     $provider[] = array(array('type' => 'item', 'claims' => array('P42' => array(array('mainsnak' => array('snaktype' => 'novalue', 'property' => 'P42'), 'type' => 'statement', 'rank' => 'normal'))), 'labels' => array(), 'descriptions' => array(), 'aliases' => array(), 'sitelinks' => array()), $entity);
     $item = new Item();
     $item->addSiteLink(new SiteLink('enwiki', 'Nyan Cat'));
     $provider[] = array(array('type' => 'item', 'sitelinks' => array('enwiki' => array('site' => 'enwiki', 'title' => 'Nyan Cat', 'badges' => array())), 'labels' => array(), 'descriptions' => array(), 'aliases' => array(), 'claims' => array()), $item);
     return $provider;
 }
 private function setUpEntities()
 {
     global $wgUser;
     static $setup = false;
     if ($setup) {
         return;
     }
     $setup = true;
     $store = WikibaseRepo::getDefaultInstance()->getStore()->getEntityStore();
     // remove entities we care about
     $idsToDelete = array(new ItemId('Q404'), new ItemId('Q23'));
     foreach ($idsToDelete as $id) {
         try {
             $store->deleteEntity($id, 'test', $wgUser);
         } catch (StorageException $ex) {
             // ignore
         }
     }
     // set up Q23
     $item = new Item();
     $item->setId(new ItemId('Q23'));
     $item->getFingerprint()->setLabel('en', 'George Washington');
     $store->saveEntity($item, 'testing', $wgUser, EDIT_NEW);
 }
 public function testExceptionThrownWhenNormalizingSiteNotFound()
 {
     $from = new Item();
     $from->setId(new ItemId('Q111'));
     $from->getSiteLinkList()->addNewSiteLink('enwiki', 'FOo');
     $to = new Item();
     $to->setId(new ItemId('Q222'));
     $to->getSiteLinkList()->addNewSiteLink('enwiki', 'Foo');
     $changeOps = $this->makeChangeOpsMerge($from, $to, array(), new MockSiteStore());
     $this->setExpectedException('\\Wikibase\\ChangeOp\\ChangeOpException', 'Conflicting sitelinks for enwiki, Failed to normalize');
     $changeOps->apply();
 }
 /**
  * @dataProvider provideGetPermissionStatusForEntity
  */
 public function testGetPermissionStatusForEntity($action, array $permissions, $id, array $expectations)
 {
     global $wgUser;
     $entity = new Item();
     if ($id) {
         // "exists"
         $entity->setId(new ItemId($id));
     }
     $this->stashMwGlobals('wgUser');
     $this->stashMwGlobals('wgGroupPermissions');
     PermissionsHelper::applyPermissions(array('*' => $permissions, 'user' => $permissions, 'autoconfirmed' => $permissions, 'emailconfirmed' => $permissions), array());
     $factory = $this->newFactory();
     if (isset($expectations['getPermissionStatusForEntity'])) {
         $status = $factory->getPermissionStatusForEntity($wgUser, $action, $entity);
         $this->assertEquals($expectations['getPermissionStatusForEntity'], $status->isOK());
     }
     if (isset($expectations['getPermissionStatusForEntityType'])) {
         $status = $factory->getPermissionStatusForEntityType($wgUser, $action, $entity->getType());
         $this->assertEquals($expectations['getPermissionStatusForEntityType'], $status->isOK());
     }
     if (isset($expectations['getPermissionStatusForEntityId'])) {
         $status = $factory->getPermissionStatusForEntityId($wgUser, $action, $entity->getId());
         $this->assertEquals($expectations['getPermissionStatusForEntityId'], $status->isOK());
     }
 }
Example #9
0
 public function testSetIdUsingNumber()
 {
     $item = new Item();
     $item->setId(42);
     $this->assertEquals(new ItemId('Q42'), $item->getId());
 }