/**
  * @dataProvider extractStringComparatorProvider
  */
 public function testExtractComparatorFromString($string, $expectedString, $expectedComparator)
 {
     $comparatorList = '';
     $instance = new QueryComparator($comparatorList, true);
     $this->assertEquals($expectedComparator, $instance->extractComparatorFromString($string));
     $this->assertEquals($expectedString, $string);
 }
 private function addListenersToCollection()
 {
     $this->eventListenerCollection->registerCallback('factbox.cache.delete', function ($dispatchContext) {
         if ($dispatchContext->has('subject')) {
             $title = $dispatchContext->get('subject')->getTitle();
         } else {
             $title = $dispatchContext->get('title');
         }
         $applicationFactory = ApplicationFactory::getInstance();
         $applicationFactory->getCache()->delete($applicationFactory->newCacheFactory()->getFactboxCacheKey($title->getArticleID()));
     });
     $this->eventListenerCollection->registerCallback('exporter.reset', function () {
         Exporter::getInstance()->clear();
     });
     $this->eventListenerCollection->registerCallback('query.comparator.reset', function () {
         QueryComparator::getInstance()->clear();
     });
     /**
      * Emitted during NewRevisionFromEditComplete, UpdateJob, ArticleDelete
      */
     $this->eventListenerCollection->registerCallback('cached.propertyvalues.prefetcher.reset', function ($dispatchContext) {
         if ($dispatchContext->has('title')) {
             $subject = DIWikiPage::newFromTitle($dispatchContext->get('title'));
         } else {
             $subject = $dispatchContext->get('subject');
         }
         wfDebugLog('smw', 'Clear CachedPropertyValuesPrefetcher for ' . $subject->getHash());
         $applicationFactory = ApplicationFactory::getInstance();
         $applicationFactory->getCachedPropertyValuesPrefetcher()->resetCacheBy($subject);
         $dispatchContext->set('propagationstop', true);
     });
     $this->registerStateChangeEvents();
     return $this->eventListenerCollection;
 }
 private function addListenersToCollection()
 {
     $this->eventListenerCollection->registerCallback('factbox.cache.delete', function ($dispatchContext) {
         $title = $dispatchContext->get('title');
         $cache = ApplicationFactory::getInstance()->getCache();
         $cache->delete(ApplicationFactory::getInstance()->newCacheFactory()->getFactboxCacheKey($title->getArticleID()));
     });
     $this->eventListenerCollection->registerCallback('exporter.reset', function () {
         Exporter::getInstance()->clear();
     });
     $this->eventListenerCollection->registerCallback('query.comparator.reset', function () {
         QueryComparator::getInstance()->clear();
     });
     $this->eventListenerCollection->registerCallback('property.spec.change', function ($dispatchContext) {
         $subject = $dispatchContext->get('subject');
         $updateDispatcherJob = ApplicationFactory::getInstance()->newJobFactory()->newUpdateDispatcherJob($subject->getTitle());
         $updateDispatcherJob->run();
         Exporter::getInstance()->resetCacheFor($subject);
         $dispatchContext->set('propagationstop', true);
     });
     return $this->eventListenerCollection;
 }
 /**
  * Helper function for DescriptionDeserializer::deserialize that prepares a
  * single value string, possibly extracting comparators. $value is changed
  * to consist only of the remaining effective value string (without the
  * comparator).
  *
  * @param string $value
  * @param string|integer $comparator
  */
 protected function prepareValue(&$value, &$comparator)
 {
     $comparator = QueryComparator::getInstance()->extractComparatorFromString($value);
 }
Exemplo n.º 5
0
 /**
  * Helper function for DescriptionDeserializer::deserialize that prepares a
  * single value string, possibly extracting comparators. $value is changed
  * to consist only of the remaining effective value string (without the
  * comparator).
  *
  * @param string $value
  * @param string|integer $comparator
  */
 protected function prepareValue(&$value, &$comparator)
 {
     // Loop over the comparators to determine which one is used and what the actual value is.
     foreach (QueryComparator::getInstance()->getComparatorStrings() as $string) {
         if (strpos($value, $string) === 0) {
             $comparator = QueryComparator::getInstance()->getComparatorFromString(substr($value, 0, strlen($string)));
             $value = substr($value, strlen($string));
             break;
         }
     }
 }
Exemplo n.º 6
0
 /**
  * @dataProvider stringComparatorProvider
  */
 public function testGetStringForComparator($stringComparator, $comparator)
 {
     $comparatorList = '';
     $instance = new QueryComparator($comparatorList, false);
     $this->assertEquals($stringComparator, $instance->getStringForComparator($comparator));
 }
 /**
  * @param bool $asValue
  *
  * @return string
  */
 public function getQueryString($asValue = false)
 {
     $comparator = QueryComparator::getInstance()->getStringForComparator($this->comparator);
     $dataValue = DataValueFactory::getInstance()->newDataItemValue($this->dataItem, $this->property);
     if ($asValue) {
         return $comparator . $dataValue->getWikiValue();
     }
     // this only is possible for values of Type:Page
     if ($comparator === '') {
         // some extra care for Category: pages
         return '[[:' . $dataValue->getWikiValue() . ']]';
     }
     return '[[' . $comparator . $dataValue->getWikiValue() . ']]';
 }
 /**
  * @param bool $asValue
  *
  * @return string
  */
 public function getQueryString($asValue = false)
 {
     $comparator = QueryComparator::getInstance()->getStringForComparator($this->comparator);
     $dataValue = DataValueFactory::getInstance()->newDataValueByItem($this->dataItem, $this->property);
     // Signals that we don't want any precision limitation
     $dataValue->setOption('value.description', true);
     if ($asValue) {
         return $comparator . $dataValue->getWikiValue();
     }
     // this only is possible for values of Type:Page
     if ($comparator === '') {
         // some extra care for Category: pages
         return '[[:' . $dataValue->getWikiValue() . ']]';
     }
     return '[[' . $comparator . $dataValue->getWikiValue() . ']]';
 }
 /**
  * @dataProvider containsComparatorProvider
  */
 public function testContainsComparator($string, $comparator, $expected)
 {
     $comparatorList = '';
     $instance = new QueryComparator($comparatorList, true);
     $this->assertEquals($expected, $instance->containsComparator($string, $comparator));
 }