コード例 #1
0
ファイル: QueryEngineTest.php プロジェクト: Rikuforever/wiki
 public function testConditionBuilderReturnsErrors()
 {
     $condition = $this->getMockForAbstractClass('\\SMW\\SPARQLStore\\QueryEngine\\Condition\\Condition');
     $connection = $this->getMockBuilder('\\SMW\\SPARQLStore\\RepositoryConnection')->disableOriginalConstructor()->getMockForAbstractClass();
     $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
     $compoundConditionBuilder = $this->getMockBuilder('\\SMW\\SPARQLStore\\QueryEngine\\CompoundConditionBuilder')->disableOriginalConstructor()->getMock();
     $compoundConditionBuilder->expects($this->any())->method('getErrors')->will($this->returnValue(array('bogus-error')));
     $compoundConditionBuilder->expects($this->atLeastOnce())->method('buildCondition')->will($this->returnValue($condition));
     $description = $this->getMockForAbstractClass('\\SMW\\Query\\Language\\Description');
     $engineOptions = new EngineOptions();
     $engineOptions->set('smwgIgnoreQueryErrors', false);
     $instance = new QueryEngine($connection, $compoundConditionBuilder, new QueryResultFactory($store), $engineOptions);
     $query = new Query($description);
     $this->assertInstanceOf('\\SMWQueryResult', $instance->getQueryResult($query));
     $this->assertEmpty($instance->getQueryResult($query)->getResults());
     $this->assertEquals(array('bogus-error'), $query->getErrors());
 }
コード例 #2
0
 /**
  * @since 2.3
  *
  * @param integer $queryFeatureFlag
  *
  * @return boolean
  */
 public function canUseQFeature($queryFeatureFlag)
 {
     $canUse = true;
     // Adhere additional condition
     if ($queryFeatureFlag === SMW_SPARQL_QF_SUBP) {
         $canUse = $this->engineOptions->get('smwgQSubpropertyDepth') > 0;
     }
     if ($queryFeatureFlag === SMW_SPARQL_QF_SUBC) {
         $canUse = $this->engineOptions->get('smwgQSubcategoryDepth') > 0;
     }
     return $this->engineOptions->get('smwgSparqlQFeatures') === ($this->engineOptions->get('smwgSparqlQFeatures') | $queryFeatureFlag) && $canUse;
 }
コード例 #3
0
 /**
  * Get a SPARQL option array for the given query.
  *
  * @param Query $query
  * @param Condition $compoundCondition (storing order by variable names)
  *
  * @return array
  */
 protected function getOptions(Query $query, Condition $compoundCondition)
 {
     $result = array('LIMIT' => $query->getLimit() + 1, 'OFFSET' => $query->getOffset());
     // Build ORDER BY options using discovered sorting fields.
     if ($this->engineOptions->get('smwgQSortingSupport')) {
         $orderByString = '';
         foreach ($query->sortkeys as $propkey => $order) {
             if (!is_string($propkey)) {
                 throw new RuntimeException("Expected a string value as sortkey");
             }
             if ($order != 'RANDOM' && array_key_exists($propkey, $compoundCondition->orderVariables)) {
                 $orderByString .= "{$order}(?" . $compoundCondition->orderVariables[$propkey] . ") ";
             } elseif ($order == 'RANDOM' && $this->engineOptions->get('smwgQRandSortingSupport')) {
                 // not supported in SPARQL; might be possible via function calls in some stores
             }
         }
         if ($orderByString !== '') {
             $result['ORDER BY'] = $orderByString;
         }
     }
     return $result;
 }
コード例 #4
0
 public function testUnregisteredKeyThrowsException()
 {
     $instance = new EngineOptions();
     $this->setExpectedException('InvalidArgumentException');
     $instance->get('Foo');
 }