public function testFormatDebugOutputWithQuery() { $description = $this->getMockBuilder('\\SMW\\Query\\Language\\Description')->disableOriginalConstructor()->getMockForAbstractClass(); $query = $this->getMockBuilder('\\SMWQuery')->disableOriginalConstructor()->getMock(); $query->expects($this->any())->method('getDescription')->will($this->returnValue($description)); $query->expects($this->any())->method('getErrors')->will($this->returnValue(array())); $instance = new DebugOutputFormatter(); $this->assertInternalType('string', $instance->formatOutputFor('foo', array(), $query)); }
/** * Using a preprocessed internal query description referenced by $rootid, compute * the proper debug output for the given query. * * @param Query $query * @param integer $rootid * * @return string */ private function getDebugQueryResult(Query $query, $rootid) { $qobj = $this->querySegmentList[$rootid]; $entries = array(); $sqlOptions = $this->getSQLOptions($query, $rootid); $entries['SQL Query'] = ''; $entries['SQL Explain'] = ''; if (isset($qobj->joinfield) && $qobj->joinfield !== '') { $this->doPrepareDebugQueryResult($qobj, $sqlOptions, $entries); } else { $entries['SQL Query'] = 'Empty result, no SQL query created.'; } $auxtables = ''; foreach ($this->querySegmentListProcessor->getListOfResolvedQueries() as $table => $log) { $auxtables .= "<li>Temporary table {$table}"; foreach ($log as $q) { $auxtables .= "<br />  <tt>{$q}</tt>"; } $auxtables .= '</li>'; } if ($auxtables) { $entries['Auxilliary Tables Used'] = "<ul>{$auxtables}</ul>"; } else { $entries['Auxilliary Tables Used'] = 'No auxilliary tables used.'; } return DebugOutputFormatter::formatOutputFor('SQLStore', $entries, $query); }
private function getDebugQueryResult(Query $query, Condition $compoundCondition) { $entries = array(); if ($this->isSingletonConditionWithElementMatch($compoundCondition)) { if ($compoundCondition->condition === '') { // all URIs exist, no querying $sparql = 'None (no conditions).'; } else { $condition = $this->compoundConditionBuilder->convertConditionToString($compoundCondition); $namespaces = $compoundCondition->namespaces; $sparql = $this->connection->getSparqlForAsk($condition, $namespaces); } } elseif ($compoundCondition instanceof FalseCondition) { $sparql = 'None (conditions can not be satisfied by anything).'; } else { $condition = $this->compoundConditionBuilder->convertConditionToString($compoundCondition); $namespaces = $compoundCondition->namespaces; $options = $this->getOptions($query, $compoundCondition); $options['DISTINCT'] = true; $sparql = $this->connection->getSparqlForSelect('?' . self::RESULT_VARIABLE, $condition, $options, $namespaces); } $sparql = str_replace(array('[', ':', ' '), array('[', ':', ' '), $sparql); $entries['SPARQL Query'] = '<div class="smwpre">' . $sparql . '</div>'; return DebugOutputFormatter::formatOutputFor('SPARQLStore', $entries, $query); }