コード例 #1
0
 /**
  * @param EntityId|Item|Property $target
  *
  * @throws UnexpectedValueException
  * @return EntityId|SiteLink
  *
  * @todo Fix duplicated code
  */
 private function getEntityIdentifierFromTarget($target)
 {
     if ($target instanceof Item || $target instanceof Property) {
         return $target->getId();
     } else {
         return $target;
     }
 }
コード例 #2
0
 /**
  * @param Property $property
  *
  * @return array[]
  */
 private function toDiffArray(Property $property)
 {
     $array = array();
     $array['aliases'] = $property->getFingerprint()->getAliasGroups()->toTextArray();
     $array['label'] = $property->getFingerprint()->getLabels()->toTextArray();
     $array['description'] = $property->getFingerprint()->getDescriptions()->toTextArray();
     return $array;
 }
コード例 #3
0
 /**
  * @see PropertyInfoTable::setPropertyInfo
  *
  * @param Property $property
  *
  * @return array Information to be stored in the "pi_info" column of the "wb_property_info"
  * table. Must be an array and can contain anything that can be encoded by json_encode.
  */
 public function buildPropertyInfo(Property $property)
 {
     $info = array(PropertyInfoStore::KEY_DATA_TYPE => $property->getDataTypeId());
     $formatterUrl = $this->getFormatterUrl($property->getStatements());
     if ($formatterUrl !== null) {
         $info[PropertyInfoStore::KEY_FORMATTER_URL] = $formatterUrl;
     }
     return $info;
 }
コード例 #4
0
 public function testGivenKnownPropertyId_propertyLabelIsReturned()
 {
     $property = new Property(new PropertyId('P1337'), null, 'string');
     $property->getFingerprint()->setLabel('en', 'postal code');
     $this->testEnvironment->insertProperty($property);
     $client = $this->createClient();
     $client->request('GET', '/properties/P1337/label');
     $this->assertSuccessResponse('postal code', $client->getResponse());
 }
コード例 #5
0
 public function testGivenKnownPropertyId_propertyDescriptionIsReturned()
 {
     $property = new Property(new PropertyId('P1337'), null, 'string');
     $property->getFingerprint()->setDescription('en', 'foo bar baz');
     $this->testEnvironment->insertProperty($property);
     $client = $this->createClient();
     $client->request('GET', '/properties/P1337/description');
     $this->assertSuccessResponse('foo bar baz', $client->getResponse());
 }
コード例 #6
0
 public function testGivenKnownPropertyId_propertyLabelIsReturned()
 {
     $property = new Property(new PropertyId('P1337'), null, 'string');
     $property->getFingerprint()->setAliasGroup('en', ['foo', 'bar', 'baz']);
     $this->testEnvironment->insertProperty($property);
     $client = $this->createClient();
     $client->request('GET', '/properties/P1337/aliases');
     $this->assertSuccessResponse(['foo', 'bar', 'baz'], $client->getResponse());
 }
コード例 #7
0
 private function newCountryProperty()
 {
     $fingerprint = new Fingerprint();
     $fingerprint->setLabel('en', 'country');
     $fingerprint->setLabel('nl', 'land');
     $fingerprint->setDescription('en', 'sovereign state of this item');
     $countryProperty = new Property(new PropertyId('P17'), $fingerprint, 'wikibase-item');
     $countryProperty->getStatements()->addNewStatement(new PropertyValueSnak(42, new StringValue('foobar')));
     return $countryProperty;
 }
 /**
  * @param PropertyId $id
  * @param string $dataTypeId
  * @param string $label
  *
  * @return Property
  */
 private function getTestProperty(PropertyId $id, $dataTypeId, $label)
 {
     $property = Property::newFromType($dataTypeId);
     $property->setId($id);
     $property->setLabel('de', $label);
     return $property;
 }
コード例 #9
0
 public function testValidConstruction()
 {
     $property = Property::newFromType('string');
     $content = new PropertyContent($property);
     $this->assertEquals($property, $content->getData());
     $this->assertInternalType('string', $content->getHash());
 }
コード例 #10
0
 private function newProperty()
 {
     $property = Property::newFromType('kittens');
     $property->setId(1337);
     $property->setFingerprint($this->newFingerprint());
     return $property;
 }
 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));
 }
コード例 #12
0
 public function setup()
 {
     parent::setup();
     if (!isset(self::$hasSetup)) {
         $wikibaseRepo = WikibaseRepo::getDefaultInstance();
         $store = $wikibaseRepo->getEntityStore();
         $prop = Property::newFromType('string');
         $store->saveEntity($prop, 'EditEntityTestP56', $GLOBALS['wgUser'], EDIT_NEW);
         self::$idMap['%P56%'] = $prop->getId()->getSerialization();
         self::$idMap['%StringProp%'] = $prop->getId()->getSerialization();
         $prop = Property::newFromType('string');
         $store->saveEntity($prop, 'EditEntityTestP72', $GLOBALS['wgUser'], EDIT_NEW);
         self::$idMap['%P72%'] = $prop->getId()->getSerialization();
         $this->initTestEntities(array('Berlin'), self::$idMap);
         self::$idMap['%Berlin%'] = EntityTestHelper::getId('Berlin');
         $p56 = self::$idMap['%P56%'];
         $berlinData = EntityTestHelper::getEntityOutput('Berlin');
         self::$idMap['%BerlinP56%'] = $berlinData['claims'][$p56][0]['id'];
         $badge = new Item();
         $store->saveEntity($badge, 'EditEntityTestQ42', $GLOBALS['wgUser'], EDIT_NEW);
         self::$idMap['%Q42%'] = $badge->getId()->getSerialization();
         $badge = new Item();
         $store->saveEntity($badge, 'EditEntityTestQ149', $GLOBALS['wgUser'], EDIT_NEW);
         self::$idMap['%Q149%'] = $badge->getId()->getSerialization();
         $badge = new Item();
         $store->saveEntity($badge, 'EditEntityTestQ32', $GLOBALS['wgUser'], EDIT_NEW);
         self::$idMap['%Q32%'] = $badge->getId()->getSerialization();
         $wikibaseRepo->getSettings()->setSetting('badgeItems', array(self::$idMap['%Q42%'] => '', self::$idMap['%Q149%'] => '', 'Q99999' => ''));
     }
     self::$hasSetup = true;
 }
コード例 #13
0
 public function testIsStub_nonStubProperty()
 {
     $Property = Property::newFromType('foo');
     $Property->getStatements()->addNewStatement(new PropertyNoValueSnak(42));
     $content = PropertyContent::newFromProperty($Property);
     $this->assertFalse($content->isStub());
 }
 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;
 }
コード例 #15
0
 /**
  * @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);
 }
コード例 #16
0
 protected function storeNewProperty()
 {
     global $wgUser;
     $store = WikibaseRepo::getDefaultInstance()->getEntityStore();
     $property = Property::newFromType('string');
     $entityRevision = $store->saveEntity($property, 'testing', $wgUser, EDIT_NEW);
     $this->lastPropertyId = $entityRevision->getEntity()->getId();
 }
コード例 #17
0
 /**
  * @param EntityId $id
  * @param Statement[] $statements
  *
  * @return Entity
  */
 protected function makeEntity(EntityId $id, array $statements = array())
 {
     $property = Property::newFromType('string');
     $property->setId($id);
     $property->setLabel('en', "label:{$id}");
     $property->setDescription('en', "description:{$id}");
     $property->setStatements(new StatementList($statements));
     return $property;
 }
コード例 #18
0
 protected static function getNewItemAndProperty()
 {
     $store = WikibaseRepo::getDefaultInstance()->getEntityStore();
     $item = new Item();
     $store->saveEntity($item, 'test', $GLOBALS['wgUser'], EDIT_NEW);
     $property = Property::newFromType('commonsMedia');
     $store->saveEntity($property, 'test', $GLOBALS['wgUser'], EDIT_NEW);
     return array($item, $property);
 }
コード例 #19
0
 protected function newEntity(EntityId $id = null)
 {
     if (!$id) {
         $id = new PropertyId('P7');
     }
     $property = Property::newFromType('string');
     $property->setId($id);
     return $property;
 }
コード例 #20
0
 public function testClaimsAreDiffed()
 {
     $firstProperty = Property::newFromType('kittens');
     $secondProperty = Property::newFromType('kittens');
     $secondProperty->getStatements()->addNewStatement(new PropertySomeValueSnak(42), null, null, 'guid');
     $differ = new PropertyDiffer();
     $diff = $differ->diffProperties($firstProperty, $secondProperty);
     $this->assertCount(1, $diff->getClaimsDiff()->getAdditions());
 }
コード例 #21
0
 /**
  * @return EntityDocument[]
  */
 private function getNewEntities()
 {
     $property = Property::newFromType('string');
     $this->save($property);
     $propertyId = $property->getId();
     $item = new Item();
     $this->addStatements($item, $propertyId);
     $this->save($item);
     return array($property, $item);
 }
コード例 #22
0
 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;
 }
 public function provideBuildPropertyInfo()
 {
     $cases = array();
     $cases[] = array(Property::newFromType('foo'), array('type' => 'foo'));
     $property = Property::newFromType('foo');
     $snak = new PropertyValueSnak(new PropertyId('P42'), new StringValue('test'));
     $property->getStatements()->addNewStatement($snak);
     $cases[] = array($property, array('type' => 'foo', 'formatterURL' => 'test'));
     return $cases;
 }
コード例 #25
0
 /**
  * @return EntityLookup
  */
 private function newEntityLookup()
 {
     $lookup = new InMemoryEntityLookup();
     foreach ($this->propertiesAndTypes as $propertyId => $dataTypeId) {
         $property = Property::newFromType($dataTypeId);
         $property->setId(new PropertyId($propertyId));
         $lookup->addEntity($property);
     }
     return $lookup;
 }
コード例 #26
0
 private function getSimpleEntities()
 {
     $item = new Item();
     $item->setLabel('en', 'Item');
     $item->setDescription('en', 'Item description');
     $property = Property::newFromType('string');
     $property->setLabel('en', 'Property');
     $property->setDescription('en', 'Property description');
     return array($item, $property);
 }
 /**
  * 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;
 }
コード例 #28
0
 private static function newEntity($entityType)
 {
     switch ($entityType) {
         case Item::ENTITY_TYPE:
             return new Item();
         case Property::ENTITY_TYPE:
             return Property::newFromType('string');
         default:
             throw new \RuntimeException("unknown entity type: {$entityType}");
     }
 }
コード例 #29
0
 /**
  * @param EntityId $id
  *
  * @throws InvalidArgumentException
  * @return Item|Property
  */
 protected function makeEntity(EntityId $id)
 {
     if ($id instanceof ItemId) {
         $entity = new Item($id);
         $entity->getSiteLinkList()->addNewSiteLink('test', 'Foo');
     } elseif ($id instanceof PropertyId) {
         $entity = new Property($id, null, 'wibblywobbly');
     } else {
         throw new InvalidArgumentException('Unsupported entity type ' . $id->getEntityType());
     }
     $entity->setLabel('en', 'label:' . $id->getSerialization());
     return $entity;
 }
 /**
  * @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;
 }