| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
//////////////////////////////////////////////////////////////////////////////
|
| 5 |
// SPARQL unit tests (CIA Factbook)
|
| 6 |
|
| 7 |
class SPARQL_CIAFactbookTestCase extends DrupalWebTestCase {
|
| 8 |
const ENDPOINT = 'http://www4.wiwiss.fu-berlin.de/factbook/sparql';
|
| 9 |
const COUNTRY = 'http://www4.wiwiss.fu-berlin.de/factbook/ns#Country';
|
| 10 |
|
| 11 |
public function getInfo() {
|
| 12 |
return array(
|
| 13 |
'name' => t('CIA Factbook'),
|
| 14 |
'description' => t('Executes queries against the CIA Factbook\'s SPARQL endpoint, attempting to parse resultsets in both JSON and XML format.'),
|
| 15 |
'group' => t('SPARQL'),
|
| 16 |
);
|
| 17 |
}
|
| 18 |
|
| 19 |
function setup() {
|
| 20 |
parent::setup('rdf', 'sparql');
|
| 21 |
}
|
| 22 |
|
| 23 |
public function test_json_query() {
|
| 24 |
$this->query_classes(t('JSON'), array('format' => 'application/sparql-results+json', 'output' => 'json'));
|
| 25 |
}
|
| 26 |
|
| 27 |
public function test_xml_query() {
|
| 28 |
$this->query_classes(t('XML'), array('format' => 'application/sparql-results+xml', 'output' => 'xml'));
|
| 29 |
}
|
| 30 |
|
| 31 |
private function query_classes($format, array $options = array()) {
|
| 32 |
$results = $this->query('SELECT DISTINCT ?class WHERE { [] a ?class } ORDER BY ?class', $options);
|
| 33 |
$this->assertTrue(empty($this->errors), t('@format: No errors', array('@format' => $format)));
|
| 34 |
$this->assertNotNull($results, t('@format: Has results', array('@format' => $format)));
|
| 35 |
$this->assertEqual(count($results), 1, t('@format: Has one result', array('@format' => $format)));
|
| 36 |
$this->assertTrue(isset($results[0]['class']), t('@format: Contains ?class column', array('@format' => $format)));
|
| 37 |
$this->assertEqual((string)$results[0]['class'], self::COUNTRY, t('@format: Correct answer', array('@format' => $format)));
|
| 38 |
}
|
| 39 |
|
| 40 |
private function query($query, array $options = array()) {
|
| 41 |
$this->errors = array();
|
| 42 |
return sparql_query($query, array_merge(array('endpoint' => self::ENDPOINT), $options), $this->errors);
|
| 43 |
}
|
| 44 |
}
|