/** * @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 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; }
/** * @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; }
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)); }
public function testValidConstruction() { $property = Property::newFromType('string'); $content = new PropertyContent($property); $this->assertEquals($property, $content->getData()); $this->assertInternalType('string', $content->getHash()); }
public function testIsStub_nonStubProperty() { $Property = Property::newFromType('foo'); $Property->getStatements()->addNewStatement(new PropertyNoValueSnak(42)); $content = PropertyContent::newFromProperty($Property); $this->assertFalse($content->isStub()); }
private function newProperty() { $property = Property::newFromType('kittens'); $property->setId(1337); $property->setFingerprint($this->newFingerprint()); return $property; }
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; }
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(); }
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); }
protected function newEntity(EntityId $id = null) { if (!$id) { $id = new PropertyId('P7'); } $property = Property::newFromType('string'); $property->setId($id); return $property; }
/** * @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; }
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()); }
/** * @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; }
/** * @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); }
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; }
/** * @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; }
/** * @param array $serialization * * @return Property */ private function getDeserialized(array $serialization) { $this->requireAttribute($serialization, 'datatype'); $this->assertAttributeInternalType($serialization, 'datatype', 'string'); $property = Property::newFromType($serialization['datatype']); $this->setIdFromSerialization($serialization, $property); $this->setTermsFromSerialization($serialization, $property); $this->setStatementListFromSerialization($serialization, $property); return $property; }
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; }
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); }
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}"); } }
/** * @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; }
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 validEntityProvider() { $cases = array(); foreach ($this->validFingerprintProvider() as $name => $fingerprintCase) { // if the case has a non-null languageCodes or a strange entityId param, skip it if (isset($fingerprintCase[2]) || !$fingerprintCase[1] instanceof PropertyId) { continue; } $id = $fingerprintCase[1]; $cases[$name] = $this->fingerprintCaseToEntityCase($fingerprintCase, $id); } // check validation without entity id $cases["no id"] = array(Property::newFromType('string')); return $cases; }
public function testStatementsArePatched() { $s1337 = new Statement(new PropertyNoValueSnak(1337)); $s1337->setGuid('s1337'); $s23 = new Statement(new PropertyNoValueSnak(23)); $s23->setGuid('s23'); $s42 = new Statement(new PropertyNoValueSnak(42)); $s42->setGuid('s42'); $patch = new EntityDiff(array('claim' => new Diff(array('s42' => new DiffOpRemove($s42), 's23' => new DiffOpAdd($s23))))); $property = Property::newFromType('kittens'); $property->getStatements()->addStatement($s1337); $property->getStatements()->addStatement($s42); $expectedProperty = Property::newFromType('kittens'); $expectedProperty->getStatements()->addStatement($s1337); $expectedProperty->getStatements()->addStatement($s23); $this->assertEquals($expectedProperty, $this->getPatchedProperty($property, $patch)); }
protected function setUp() { parent::setUp(); $wikibaseRepo = WikibaseRepo::getDefaultInstance(); $store = $wikibaseRepo->getEntityStore(); if (!self::$propertyIds) { self::$propertyIds = array(); for ($i = 0; $i < 4; $i++) { $property = Property::newFromType('string'); $store->saveEntity($property, '', $GLOBALS['wgUser'], EDIT_NEW); self::$propertyIds[] = $property->getId(); } $this->initTestEntities(array('StringProp', 'Berlin')); } $this->serializerFactory = new SerializerFactory(new DataValueSerializer(), SerializerFactory::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH); $this->deserializerFactory = new DeserializerFactory($wikibaseRepo->getDataValueDeserializer(), $wikibaseRepo->getEntityIdParser()); }
protected function getTestItem() { static $item = null; if (!$item) { $store = WikibaseRepo::getDefaultInstance()->getEntityStore(); $newItem = new Item(); $store->saveEntity($newItem, '', $GLOBALS['wgUser'], EDIT_NEW); $prop = Property::newFromType('string'); $propId = $this->makeProperty($prop)->getId(); $snak = new PropertyValueSnak($propId, new StringValue('^_^')); $guidGenerator = new GuidGenerator(); $guid = $guidGenerator->newGuid($newItem->getId()); $newItem->getStatements()->addNewStatement($snak, null, null, $guid); $store->saveEntity($newItem, '', $GLOBALS['wgUser'], EDIT_UPDATE); $item = $newItem; } return $item; }
private function initProperties() { $infos = array(array(PropertyInfoStore::KEY_DATA_TYPE => 'string', 'test' => 'one'), array(PropertyInfoStore::KEY_DATA_TYPE => 'string', 'test' => 'two', PropertyInfoStore::KEY_FORMATTER_URL => 'foo'), array(PropertyInfoStore::KEY_DATA_TYPE => 'time', 'test' => 'three'), array(PropertyInfoStore::KEY_DATA_TYPE => 'time', 'test' => 'four'), array(PropertyInfoStore::KEY_DATA_TYPE => 'string', 'test' => 'five', PropertyInfoStore::KEY_FORMATTER_URL => 'bar')); $store = WikibaseRepo::getDefaultInstance()->getEntityStore(); $properties = array(); foreach ($infos as $info) { $property = Property::newFromType($info[PropertyInfoStore::KEY_DATA_TYPE]); $property->setDescription('en', $info['test']); if (isset($info[PropertyInfoStore::KEY_FORMATTER_URL])) { $mainSnak = new PropertyValueSnak(1630, new StringValue($info[PropertyInfoStore::KEY_FORMATTER_URL])); $property->getStatements()->addNewStatement($mainSnak); } $revision = $store->saveEntity($property, "test", $GLOBALS['wgUser'], EDIT_NEW); $id = $revision->getEntity()->getId()->getSerialization(); $properties[$id] = $info; } return $properties; }
public function addDBData() { if (!self::$hasSetup) { $store = WikibaseRepo::getDefaultInstance()->getEntityStore(); $prop = Property::newFromType('string'); $store->saveEntity($prop, 'EditEntityTestP56', $GLOBALS['wgUser'], EDIT_NEW); self::$idMap['%P56%'] = $prop->getId()->getSerialization(); $prop = Property::newFromType('string'); $store->saveEntity($prop, 'EditEntityTestP72', $GLOBALS['wgUser'], EDIT_NEW); self::$idMap['%P72%'] = $prop->getId()->getSerialization(); self::$hasSetup = true; } $p56 = self::$idMap['%P56%']; $p72 = self::$idMap['%P72%']; $ip56 = (int) substr($p56, 1); $ip72 = (int) substr($p72, 1); $row = array('pid1' => $ip56, 'qid1' => 0, 'pid2' => $ip72, 'count' => 1, 'probability' => 0.3, 'context' => 'item'); $this->db->insert('wbs_propertypairs', array($row)); }
public function serializationProvider() { $property = Property::newFromType('string'); $provider = array(array(array('type' => 'property', 'datatype' => 'string', 'labels' => array(), 'descriptions' => array(), 'aliases' => array(), 'claims' => array()), $property)); $property = Property::newFromType(''); $property->setId(42); $provider[] = array(array('type' => 'property', 'id' => 'P42', 'datatype' => '', 'claims' => array(), 'labels' => array(), 'descriptions' => array(), 'aliases' => array()), $property); $property = Property::newFromType(''); $property->getFingerprint()->setLabel('en', 'foo'); $provider[] = array(array('type' => 'property', 'datatype' => '', 'claims' => array(), 'labels' => array('en' => array('lang' => 'en', 'value' => 'foo')), 'descriptions' => array(), 'aliases' => array()), $property); $property = Property::newFromType(''); $property->getFingerprint()->setDescription('en', 'foo'); $provider[] = array(array('type' => 'property', 'datatype' => '', 'claims' => array(), 'labels' => array(), 'descriptions' => array('en' => array('lang' => 'en', 'value' => 'foo')), 'aliases' => array()), $property); $property = Property::newFromType(''); $property->getFingerprint()->setAliasGroup('en', array('foo', 'bar')); $provider[] = array(array('type' => 'property', 'datatype' => '', 'claims' => array(), 'labels' => array(), 'descriptions' => array(), 'aliases' => array('en' => array('lang' => 'en', 'values' => array('foo', 'bar')))), $property); $property = Property::newFromType(''); $property->getStatements()->addNewStatement(new PropertyNoValueSnak(42), null, null, 'test'); $provider[] = array(array('type' => 'property', 'datatype' => '', 'claims' => array('P42' => array(array('mainsnak' => array('snaktype' => 'novalue', 'property' => 'P42'), 'type' => 'statement', 'rank' => 'normal'))), 'labels' => array(), 'descriptions' => array(), 'aliases' => array()), $property); return $provider; }