public function testGetPropertyValuesFromCache()
 {
     $container = $this->getMockBuilder('\\Onoi\\BlobStore\\Container')->disableOriginalConstructor()->getMock();
     $container->expects($this->atLeastOnce())->method('has')->will($this->returnValue(true));
     $container->expects($this->once())->method('get')->with($this->stringContains('Bar:123'))->will($this->returnValue(1001));
     $this->blobStore->expects($this->atLeastOnce())->method('read')->will($this->returnValue($container));
     $instance = new CachedPropertyValuesPrefetcher($this->store, $this->blobStore);
     $this->assertEquals(1001, $instance->getPropertyValues(DIWikiPage::newFromText('Foo#123'), new DIProperty('Bar')));
 }
 private function tryFindMatchResultFor($hash, $dataValue)
 {
     $descriptionFactory = $this->queryFactory->newDescriptionFactory();
     $contextPage = $dataValue->getContextPage();
     // Exclude the current page from the result match to check whether another
     // page matches the condition and if so then the value can no longer be
     // assigned and is not unique
     $description = $descriptionFactory->newConjunction(array($descriptionFactory->newFromDataValue($dataValue), $descriptionFactory->newValueDescription($contextPage, null, SMW_CMP_NEQ)));
     $query = $this->queryFactory->newQuery($description);
     $query->setLimit(1);
     $dataItems = $this->cachedPropertyValuesPrefetcher->queryPropertyValuesFor($query);
     if (!is_array($dataItems) || $dataItems === array()) {
         // No other assignments were found therefore it is assumed that at
         // the time of the query request, the "contextPage" holds a unique
         // value for the property
         $page = $contextPage;
     } else {
         $page = end($dataItems);
     }
     // Create a linked list so that when the subject is altered or deleted
     // the related uniqueness container can be removed as well
     $blobStore = $this->cachedPropertyValuesPrefetcher->getBlobStore();
     $container = $blobStore->read($this->cachedPropertyValuesPrefetcher->getRootHashFrom($page));
     $container->addToLinkedList($hash);
     $blobStore->save($container);
     return $page;
 }
 /**
  * @since 2.4
  *
  * @param DIProperty|null $property
  */
 public function fetchCachedConversionData(DIProperty $property = null)
 {
     if ($property === null || ($propertyDiWikiPage = $property->getDiWikiPage()) === null) {
         return;
     }
     $blobStore = $this->cachedPropertyValuesPrefetcher->getBlobStore();
     // Ensure that when the property page is altered the cache gets
     // evicted
     $hash = $this->cachedPropertyValuesPrefetcher->getRootHashFrom($propertyDiWikiPage);
     $container = $blobStore->read($hash);
     $key = '--conv';
     if ($container->has($key)) {
         $data = $container->get($key);
         $this->unitIds = $data['ids'];
         $this->unitFactors = $data['factors'];
         $this->mainUnit = $data['main'];
         $this->prefixalUnitPreference = $data['prefix'];
         return;
     }
     $this->fetchConversionData($property);
     if ($this->errors !== array()) {
         return;
     }
     $data = array('ids' => $this->unitIds, 'factors' => $this->unitFactors, 'main' => $this->mainUnit, 'prefix' => $this->prefixalUnitPreference);
     $container->set($key, $data);
     $blobStore->save($container);
 }
 private function findPreferredPropertyLabel($property, $languageCode)
 {
     $text = '';
     $preferredProperty = new DIProperty('_PPLB');
     $dataItems = $this->cachedPropertyValuesPrefetcher->getPropertyValues($property->getCanonicalDiWikiPage(), $preferredProperty);
     if (($dataValue = $this->findTextValueByLanguage($dataItems, $preferredProperty, $languageCode)) !== null) {
         $text = $dataValue->getShortWikiText();
     }
     return $text;
 }