public function getEntityTitleProvider()
 {
     $itemId = ItemId::newFromNumber(388);
     $propertyId = PropertyId::newFromNumber(472);
     $settings = $this->getRepoSettings();
     return array(array('Q388', $settings[0], $itemId), array('Item:Q388', $settings[2], $itemId), array('Property:P472', $settings[0], $propertyId));
 }
 /**
  * @param int $propertyId
  * @param string|null $guid
  * @param int $rank
  *
  * @return Statement
  */
 private function getStatement($propertyId, $guid, $rank = Statement::RANK_NORMAL)
 {
     $statement = $this->getMockBuilder('Wikibase\\DataModel\\Statement\\Statement')->disableOriginalConstructor()->getMock();
     $statement->expects($this->any())->method('getGuid')->will($this->returnValue($guid));
     $statement->expects($this->any())->method('getPropertyId')->will($this->returnValue(PropertyId::newFromNumber($propertyId)));
     $statement->expects($this->any())->method('getRank')->will($this->returnValue($rank));
     return $statement;
 }
 /**
  * @param string $entityType
  * @param int|float|string $numericId
  *
  * @return EntityId
  * @throws InvalidArgumentException
  */
 public static function newIdFromTypeAndNumber($entityType, $numericId)
 {
     if ($entityType === 'item') {
         return ItemId::newFromNumber($numericId);
     } elseif ($entityType === 'property') {
         return PropertyId::newFromNumber($numericId);
     }
     throw new InvalidArgumentException('Invalid entityType ' . $entityType);
 }
Example #4
0
 /**
  * Can be integer since 0.1.
  * Can be PropertyId since 0.5.
  * Can be null since 1.0.
  *
  * @param PropertyId|int|null $id
  *
  * @throws InvalidArgumentException
  */
 public function setId($id)
 {
     if ($id === null || $id instanceof PropertyId) {
         $this->id = $id;
     } elseif (is_int($id)) {
         $this->id = PropertyId::newFromNumber($id);
     } else {
         throw new InvalidArgumentException('$id must be an instance of PropertyId, an integer,' . ' or null');
     }
 }
 /**
  * @dataProvider newSnakProvider
  */
 public function testNewSnak($propertyId, $snakType, $rawValue, $expectedSnakClass, $expectedException = null)
 {
     if (is_int($propertyId)) {
         $propertyId = PropertyId::newFromNumber($propertyId);
     }
     if ($expectedException !== null) {
         $this->setExpectedException($expectedException);
     }
     $service = $this->newSnakConstructionService();
     $snak = $service->newSnak($propertyId, $snakType, $rawValue);
     $this->assertInstanceOf($expectedSnakClass, $snak);
 }
 public function testFilterSuggestions()
 {
     $p7 = PropertyId::newFromNumber(7);
     $p10 = PropertyId::newFromNumber(10);
     $p12 = PropertyId::newFromNumber(12);
     $p15 = PropertyId::newFromNumber(15);
     $p23 = PropertyId::newFromNumber(23);
     $suggestions = array(new Suggestion($p12, 0.9), new Suggestion($p23, 0.8), new Suggestion($p7, 0.7), new Suggestion($p15, 0.6));
     $resultSize = 2;
     $this->termIndex->expects($this->any())->method('getTopMatchingTerms')->will($this->returnValue($this->getTermIndexEntryArrayWithIds(array($p7, $p10, $p15, $p12))));
     $result = $this->suggestionGenerator->filterSuggestions($suggestions, 'foo', 'en', $resultSize);
     $this->assertEquals(array($suggestions[0], $suggestions[2]), $result);
 }
 /**
  * Construct mock repository matching the test data.
  *
  * @return MockRepository
  */
 public function getMockRepository()
 {
     static $repo;
     if (!empty($repo)) {
         return $repo;
     }
     $repo = new MockRepository();
     foreach (self::getTestProperties() as $prop) {
         list($id, $type) = $prop;
         $fingerprint = new Fingerprint();
         $fingerprint->setLabel('en', "Property{$id}");
         $entity = new Property(PropertyId::newFromNumber($id), $fingerprint, $type);
         $repo->putEntity($entity);
     }
     $q42 = new ItemId('Q42');
     $fingerprint = new Fingerprint();
     $fingerprint->setLabel('en', 'Item42');
     $entity = new Item($q42, $fingerprint);
     $repo->putEntity($entity);
     $repo->putRedirect(new EntityRedirect(new ItemId('Q4242'), $q42));
     return $repo;
 }
 /**
  * @param integer $offset Start to include at number of entries from the start title
  * @param integer $limit Stop at number of entries after start of inclusion
  *
  * @return PropertyId[]
  */
 protected function getResult($offset = 0, $limit = 0)
 {
     $propertyInfo = array_slice($this->getPropertyInfo(), $offset, $limit, true);
     $propertyIds = array();
     foreach ($propertyInfo as $numericId => $info) {
         $propertyIds[] = PropertyId::newFromNumber($numericId);
     }
     $this->bufferingTermLookup->prefetchTerms($propertyIds);
     return $propertyIds;
 }
Example #9
0
 /**
  * @see Serializable::unserialize
  *
  * @since 0.1
  *
  * @param string $serialized
  */
 public function unserialize($serialized)
 {
     $this->propertyId = PropertyId::newFromNumber(unserialize($serialized));
 }
 private function propertyInfoToPropertyListElement(PropertyInfo $propertyInfo) : PropertyListElement
 {
     $id = PropertyId::newFromNumber($propertyInfo->getNumericPropertyId());
     return new PropertyListElement($id, $propertyInfo->getPropertyType(), $this->urlBuilder->getWdEntityUrl($id), $this->urlBuilder->getApiPropertyUrl($id));
 }
 /**
  * Converts the rows of the SQL result to Suggestion objects
  *
  * @param ResultWrapper $res
  * @return Suggestion[]
  */
 protected function buildResult(ResultWrapper $res)
 {
     $resultArray = array();
     foreach ($res as $row) {
         $pid = PropertyId::newFromNumber((int) $row->pid);
         $suggestion = new Suggestion($pid, $row->prob);
         $resultArray[] = $suggestion;
     }
     return $resultArray;
 }
 public function testNotBuildExceptionIsThrownForByPropertyId()
 {
     $indexedArray = new ByPropertyIdArray();
     $this->setExpectedException('RuntimeException');
     $indexedArray->getByPropertyId(PropertyId::newFromNumber(9000));
 }
 /**
  * Rebuild the property info entries.
  * Use the rebuildPropertyInfo.php maintenance script to invoke this from the command line.
  *
  * Database updates a batched into multiple transactions. Do not call this
  * method within an (explicit) database transaction.
  *
  * @since 0.4
  */
 public function rebuildPropertyInfo()
 {
     $dbw = $this->propertyInfoTable->getWriteConnection();
     $rowId = $this->fromId - 1;
     $total = 0;
     $join = array();
     $tables = array('wb_entity_per_page');
     if (!$this->shouldUpdateAllEntities) {
         // Find properties in wb_entity_per_page with no corresponding
         // entry in wb_property_info.
         $piTable = $this->propertyInfoTable->getTableName();
         $tables[] = $piTable;
         $join[$piTable] = array('LEFT JOIN', array('pi_property_id = epp_entity_id'));
     }
     while (true) {
         // Make sure we are not running too far ahead of the slaves,
         // as that would cause the site to be rendered read only.
         wfWaitForSlaves();
         if ($this->useTransactions) {
             $dbw->begin();
         }
         //FIXME: use an EntityIdPager from EntityPerPage
         $props = $dbw->select($tables, array('epp_entity_id'), array('epp_entity_type = ' . $dbw->addQuotes(Property::ENTITY_TYPE), 'epp_entity_id > ' . (int) $rowId, 'epp_redirect_target IS NULL', $this->shouldUpdateAllEntities ? '1' : 'pi_property_id IS NULL'), __METHOD__, array('LIMIT' => $this->batchSize, 'ORDER BY' => 'epp_entity_id ASC', 'FOR UPDATE'), $join);
         $c = 0;
         foreach ($props as $row) {
             $id = PropertyId::newFromNumber((int) $row->epp_entity_id);
             $this->updatePropertyInfo($id);
             $rowId = $row->epp_entity_id;
             $c++;
         }
         if ($this->useTransactions) {
             $dbw->commit();
         }
         $this->reportMessage("Updated {$c} properties, up to ID {$rowId}.");
         $total += $c;
         if ($c < $this->batchSize) {
             // we are done.
             break;
         }
     }
     return $total;
 }
Example #14
0
 /**
  * @dataProvider invalidNumericIdProvider
  */
 public function testNewFromNumberWithInvalidNumericId($number)
 {
     $this->setExpectedException('InvalidArgumentException');
     PropertyId::newFromNumber($number);
 }
 /**
  * Injects data types from a DB result into the $entityInfo structure.
  *
  * @note: Keep in sync with ItemSerializer!
  *
  * @param ResultWrapper $dbResult
  *
  * @throws InvalidArgumentException
  */
 private function injectDataTypes(ResultWrapper $dbResult)
 {
     foreach ($dbResult as $row) {
         $id = PropertyId::newFromNumber((int) $row->pi_property_id);
         $key = $id->getSerialization();
         if (!isset($this->entityInfo[$key])) {
             continue;
         }
         $this->entityInfo[$key]['datatype'] = $row->pi_type;
     }
 }