Skip to content

Commit

Permalink
written more test to cover Store related code
Browse files Browse the repository at this point in the history
* SELECT queries:
* LIMIT and OFFSET
* AVG aggregate function (still buggy, but to catch current behavior)
* DESCRIBE queries:
* DESCRIBE <..>
* DESCRIBE ?s WHERE ...
* DESCRIBE * WHERE ...
* LOAD queries:
* LOAD <...>
* LOAD <...> INTO <...>
  • Loading branch information
k00ni committed May 7, 2018
1 parent b61379f commit 72bff77
Show file tree
Hide file tree
Showing 5 changed files with 329 additions and 1 deletion.
4 changes: 4 additions & 0 deletions phpunit.xml
Expand Up @@ -34,6 +34,10 @@
</logging>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./extractors</directory>
<directory suffix=".php">./parsers</directory>
<directory suffix=".php">./serializers</directory>
<directory suffix=".php">./sparqlscript</directory>
<directory suffix=".php">./store</directory>
</whitelist>
</filter>
Expand Down
101 changes: 101 additions & 0 deletions tests/integration/store/query/DescribeQueryTest.php
@@ -0,0 +1,101 @@
<?php

namespace Tests\integration\store\query;

use Tests\ARC2_TestCase;

/**
* Tests for query method - focus on DESCRIBE queries
*/
class DescribeQueryTest extends ARC2_TestCase
{
public function setUp()
{
parent::setUp();

$this->fixture = \ARC2::getStore($this->dbConfig);
$this->fixture->drop();
$this->fixture->setup();
}

public function testDescribeDefaultGraph()
{
// test data
$this->fixture->query('INSERT INTO <http://example.com/> {
<http://s> <http://p1> "baz" .
}');

$res = $this->fixture->query('DESCRIBE <http://s>');
$this->assertEquals(
[
'query_type' => 'describe',
'result' => [
'http://s' => [
'http://p1' => [
[
'value' => 'baz',
'type' => 'literal'
]
]
]
],
'query_time' => $res['query_time']
],
$res
);
}

public function testDescribeWhereDefaultGraph()
{
// test data
$this->fixture->query('INSERT INTO <http://example.com/> {
<http://s> <http://p1> "baz" .
}');

$res = $this->fixture->query('DESCRIBE ?s WHERE {?s ?p "baz".}');
$this->assertEquals(
[
'query_type' => 'describe',
'result' => [
'http://s' => [
'http://p1' => [
[
'value' => 'baz',
'type' => 'literal'
]
]
]
],
'query_time' => $res['query_time']
],
$res
);
}

public function testDescribeWhereDefaultGraph2()
{
// test data
$this->fixture->query('INSERT INTO <http://example.com/> {
<http://s> <http://p1> "baz" .
}');

$res = $this->fixture->query('DESCRIBE * WHERE {?s ?p "baz".}');
$this->assertEquals(
[
'query_type' => 'describe',
'result' => [
'http://s' => [
'http://p1' => [
[
'value' => 'baz',
'type' => 'literal'
]
]
]
],
'query_time' => $res['query_time']
],
$res
);
}
}
55 changes: 55 additions & 0 deletions tests/integration/store/query/LoadQueryTest.php
@@ -0,0 +1,55 @@
<?php

namespace Tests\integration\store\query;

use Tests\ARC2_TestCase;

/**
* Tests for query method - focus on LOAD queries
*/
class LoadQueryTest extends ARC2_TestCase
{
public function setUp()
{
parent::setUp();

$this->fixture = \ARC2::getStore($this->dbConfig);
$this->fixture->drop();
$this->fixture->setup();
}

public function testLoad()
{
// check that store is empty
$res = $this->fixture->query('SELECT * WHERE {?s ?p ?o.}');
$this->assertEquals(0, count($res['result']['rows']));

$filepath = 'https://raw.githubusercontent.com/semsol/arc2/'
.'master/tests/sparql11/w3c-tests/move/manifest.ttl';
$this->fixture->query('LOAD <'.$filepath.'>');

// check that triples were inserted
$res = $this->fixture->query('
SELECT *
FROM <https://raw.githubusercontent.com/semsol/arc2/'
.'master/tests/sparql11/w3c-tests/move/manifest.ttl>
WHERE {?s ?p ?o.}
');
$this->assertEquals(106, count($res['result']['rows']));
}

public function testLoadInto()
{
// check that store is empty
$res = $this->fixture->query('SELECT * FROM <http://load-example> WHERE {?s ?p ?o.}');
$this->assertEquals(0, count($res['result']['rows']));

$filepath = 'https://raw.githubusercontent.com/semsol/arc2/'
.'master/tests/sparql11/w3c-tests/move/manifest.ttl';
$this->fixture->query('LOAD <'.$filepath.'> INTO <http://load-example>');

// check that triples were inserted
$res = $this->fixture->query('SELECT * FROM <http://load-example> WHERE {?s ?p ?o.}');
$this->assertEquals(106, count($res['result']['rows']));
}
}
142 changes: 142 additions & 0 deletions tests/integration/store/query/SelectQueryTest.php
Expand Up @@ -160,6 +160,148 @@ public function testSelectGroupBy()
);
}

/*
* OFFSET and LIMIT
*/

public function testSelectOffset()
{
// test data
$this->fixture->query('INSERT INTO <http://example.com/> {
<http://person1> <http://id> "1" .
<http://person3> <http://id> "3" .
<http://person2> <http://id> "2" .
}');

$res = $this->fixture->query('
SELECT * WHERE { ?s ?p ?o . }
OFFSET 1
');

$this->assertEquals(
[
'query_type' => 'select',
'result' => [
'variables' => [
's', 'p', 'o'
],
'rows' => [
[
's' => 'http://person3',
's type' => 'uri',
'p' => 'http://id',
'p type' => 'uri',
'o' => '3',
'o type' => 'literal',
],
[
's' => 'http://person2',
's type' => 'uri',
'p' => 'http://id',
'p type' => 'uri',
'o' => '2',
'o type' => 'literal',
],
],
],
'query_time' => $res['query_time']
],
$res
);
}

public function testSelectOffsetLimit()
{
// test data
$this->fixture->query('INSERT INTO <http://example.com/> {
<http://person1> <http://id> "1" .
<http://person3> <http://id> "3" .
<http://person2> <http://id> "2" .
}');

$res = $this->fixture->query('
SELECT * WHERE { ?s ?p ?o . }
OFFSET 1 LIMIT 2
');

$this->assertEquals(
[
'query_type' => 'select',
'result' => [
'variables' => [
's', 'p', 'o'
],
'rows' => [
[
's' => 'http://person3',
's type' => 'uri',
'p' => 'http://id',
'p type' => 'uri',
'o' => '3',
'o type' => 'literal',
],
[
's' => 'http://person2',
's type' => 'uri',
'p' => 'http://id',
'p type' => 'uri',
'o' => '2',
'o type' => 'literal',
],
],
],
'query_time' => $res['query_time']
],
$res
);
}

public function testSelectLimit()
{
// test data
$this->fixture->query('INSERT INTO <http://example.com/> {
<http://person1> <http://id> "1" .
<http://person3> <http://id> "3" .
<http://person2> <http://id> "2" .
}');

$res = $this->fixture->query('
SELECT * WHERE { ?s ?p ?o . }
LIMIT 2
');

$this->assertEquals(
[
'query_type' => 'select',
'result' => [
'variables' => [
's', 'p', 'o'
],
'rows' => [
[
's' => 'http://person1',
's type' => 'uri',
'p' => 'http://id',
'p type' => 'uri',
'o' => '1',
'o type' => 'literal',
],
[
's' => 'http://person3',
's type' => 'uri',
'p' => 'http://id',
'p type' => 'uri',
'o' => '3',
'o type' => 'literal',
],
],
],
'query_time' => $res['query_time']
],
$res
);
}

/*
* ORDER BY
*/
Expand Down
28 changes: 27 additions & 1 deletion tests/sparql11/AggregatesTest.php
Expand Up @@ -25,8 +25,34 @@ public function setUp()

public function test_agg_avg_01()
{
$this->loadManifestFileIntoStore($this->w3cTestsFolderPath);

$testname = 'agg-avg-01';

// get test data
$data = $this->getTestData($this->testPref . $testname);

// load test data into graph
$this->store->insert($data, $this->dataGraphUri);

// get query to test
$testQuery = $this->getTestQuery($this->testPref . $testname);

// get expected result
$expectedResult = $this->getExpectedResult($this->testPref . $testname);

// get actual result for given test query
$actualResult = $this->store->query($testQuery);
$actualResultAsXml = $this->getXmlVersionOfResult($actualResult);

$this->assertEquals(
'2',
(string) $actualResultAsXml->results->result->binding->literal[0]
);

// remember current behavior, but skip test anyway to show developer here is still a problem.
$this->markTestSkipped(
'Test skipped, because of rounding bug in AVG function. See https://github.com/semsol/arc2/issues/99'
'Rounding bug in AVG function. See https://github.com/semsol/arc2/issues/99'
);
}

Expand Down

0 comments on commit 72bff77

Please sign in to comment.