Skip to content

Commit

Permalink
Merge 3a3f59a into 13279b2
Browse files Browse the repository at this point in the history
  • Loading branch information
ailintom committed Mar 23, 2020
2 parents 13279b2 + 3a3f59a commit b034108
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
6 changes: 3 additions & 3 deletions store/ARC2_StoreEndpoint.php
Expand Up @@ -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]).'"';
Expand Down
67 changes: 67 additions & 0 deletions tests/unit/store/ARC2_StoreEndpointTest.php
@@ -0,0 +1,67 @@
<?php

namespace Tests\unit\store;

use Tests\ARC2_TestCase;


//Tests ARC2_StoreEndpoint functions
class ARC2_StoreEndpointTest extends ARC2_TestCase
{

public function setUp(): void
{
parent::setUp();
$this->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');
}
}

0 comments on commit b034108

Please sign in to comment.