diff --git a/store/ARC2_StoreEndpoint.php b/store/ARC2_StoreEndpoint.php index 864f80af..0dea2933 100755 --- a/store/ARC2_StoreEndpoint.php +++ b/store/ARC2_StoreEndpoint.php @@ -429,13 +429,13 @@ public function getSPARQLJSONSelectResultDoc($r) $r .= ' "'.$var.'": {'; if ('uri' == $row[$var.' type']) { $r .= $nl.' "type": "uri",'; - $r .= $nl.' "value": "'.$this->store->a['db_object']->escape($row[$var]).'"'; + $r .= $nl.' "value": "'.$this->a['db_object']->escape($row[$var]).'"'; } elseif ('bnode' == $row[$var.' type']) { $r .= $nl.' "type": "bnode",'; $r .= $nl.' "value": "'.substr($row[$var], 2).'"'; } else { - $dt = isset($row[$var.' datatype']) ? ','.$nl.' "datatype": "'.$this->store->a['db_object']->escape($row[$var.' datatype']).'"' : ''; - $lang = isset($row[$var.' lang']) ? ','.$nl.' "xml:lang": "'.$this->store->a['db_object']->escape($row[$var.' lang']).'"' : ''; + $dt = isset($row[$var.' datatype']) ? ','.$nl.' "datatype": "'.$this->a['db_object']->escape($row[$var.' datatype']).'"' : ''; + $lang = isset($row[$var.' lang']) ? ','.$nl.' "xml:lang": "'.$this->a['db_object']->escape($row[$var.' lang']).'"' : ''; $type = $dt ? 'typed-literal' : 'literal'; $r .= $nl.' "type": "'.$type.'",'; $r .= $nl.' "value": "'.$this->jsonEscape($row[$var]).'"'; diff --git a/tests/unit/store/ARC2_StoreEndpointTest.php b/tests/unit/store/ARC2_StoreEndpointTest.php new file mode 100644 index 00000000..471199d4 --- /dev/null +++ b/tests/unit/store/ARC2_StoreEndpointTest.php @@ -0,0 +1,67 @@ +endpoint = \ARC2::getStoreEndpoint($this->dbConfig); + $this->endpoint->createDBCon(); + } + public function testJSON() + { + + $data = array( + 'result' => array( + 'variables' => array( + 'a', + 'b', + 'c' + ), + 'rows' => array( + array( + 'a' => 'http://de.dbpedia.org/resource/Johann_von_Pont', + 'a type' => 'uri', + 'b' => 'http://dbpedia.org/ontology/deathPlace', + 'b type' => 'uri', + 'c' => 'http://de.dbpedia.org/resource/Aachen', + 'c type' => 'uri' + ), + array( + 'a' => 'http://de.dbpedia.org/resource/Aachen', + 'a type' => 'uri', + 'b' => 'http://dbpedia.org/ontology/elevation', + 'b type' => 'uri', + 'c' => '173.0', + 'c type' => 'literal', + 'c datatype' => 'http://www.w3.org/2001/XMLSchema#double' + ), + array( + 'a' => 'http://de.dbpedia.org/resource/Aachen', + 'a type' => 'uri', + 'b' => 'http://dbpedia.org/ontology/leaderTitle', + 'b type' => 'uri', + 'c' => 'Oberbürgermeister', + 'c type' => 'literal', + 'c lang' => 'de' + ) + ) + ), + 'query_time' => 1 + ); + $res = json_decode($this->endpoint->getSPARQLJSONSelectResultDoc($data), true); + $this->assertArrayHasKey('head', $res); + $this->assertArrayHasKey('results', $res); + $this->assertEquals($res['head']['vars'][0], 'a'); + $this->assertEquals($res['results']['bindings'][0]['a']['value'], 'http://de.dbpedia.org/resource/Johann_von_Pont'); + $this->assertEquals($res['results']['bindings'][1]['c']['type'], 'typed-literal'); + $this->assertEquals($res['results']['bindings'][2]['c']['type'], 'literal'); + } +}