Skip to content

Commit

Permalink
Merge pull request #142 from ailintom/patch-1
Browse files Browse the repository at this point in the history
Fixed store/ARC2_StoreEndpoint.php: $this has no property named $store
  • Loading branch information
k00ni authored Mar 24, 2020
2 parents 13279b2 + 7709770 commit 65238a4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ before_script:
# Install composer packages, will also trigger dump-autoload
- travis_retry composer install --no-interaction --prefer-dist
# Install coveralls.phar
- wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.1.0/coveralls.phar
- travis_retry wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.1.0/coveralls.phar
- chmod +x coveralls.phar
- php coveralls.phar --version

Expand Down
6 changes: 3 additions & 3 deletions store/ARC2_StoreEndpoint.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 65238a4

Please sign in to comment.