1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the sweetrdf/InMemoryStoreSqlite package and licensed under |
5
|
|
|
* the terms of the GPL-2 license. |
6
|
|
|
* |
7
|
|
|
* (c) Konrad Abicht <[email protected]> |
8
|
|
|
* (c) Benjamin Nowack |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Tests\Integration\Store\InMemoryStoreSqlite\Query; |
15
|
|
|
|
16
|
|
|
use simpleRdf\BlankNode; |
17
|
|
|
use simpleRdf\Literal; |
18
|
|
|
use simpleRdf\NamedNode; |
19
|
|
|
use sweetrdf\InMemoryStoreSqlite\NamespaceHelper; |
20
|
|
|
use sweetrdf\InMemoryStoreSqlite\Store\InMemoryStoreSqlite; |
21
|
|
|
use Tests\TestCase; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Tests for query method - focus on SELECT queries. |
25
|
|
|
* |
26
|
|
|
* Output format is: instances |
27
|
|
|
*/ |
28
|
|
|
class SelectQueryOutputInstancesTest extends TestCase |
29
|
|
|
{ |
30
|
|
|
protected function setUp(): void |
31
|
|
|
{ |
32
|
|
|
parent::setUp(); |
33
|
|
|
|
34
|
|
|
$this->subjectUnderTest = InMemoryStoreSqlite::createInstance(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testSelect1() |
38
|
|
|
{ |
39
|
|
|
// test data |
40
|
|
|
$this->subjectUnderTest->query('INSERT INTO <http://example.com/> { |
41
|
|
|
<http://s> <http://p1> "baz" . |
42
|
|
|
_:foo <http://p1> "baz"^^xsd:string . |
43
|
|
|
_:foo2 <p2> "baz"@de . |
44
|
|
|
}'); |
45
|
|
|
|
46
|
|
|
$result = $this->subjectUnderTest->query('SELECT * WHERE {?s ?p ?o.}', 'instances'); |
47
|
|
|
|
48
|
|
|
$this->assertEquals( |
49
|
|
|
[ |
50
|
|
|
[ |
51
|
|
|
's' => new NamedNode('http://s'), |
52
|
|
|
'p' => new NamedNode('http://p1'), |
53
|
|
|
'o' => new Literal('baz'), |
54
|
|
|
], |
55
|
|
|
[ |
56
|
|
|
's' => new BlankNode($result[1]['s']->getValue()), // dynamic value |
57
|
|
|
'p' => new NamedNode('http://p1'), |
58
|
|
|
'o' => new Literal('baz', null, 'http://www.w3.org/2001/XMLSchema#string'), |
59
|
|
|
], |
60
|
|
|
[ |
61
|
|
|
's' => new BlankNode($result[2]['s']->getValue()), // dynamic value |
62
|
|
|
'p' => new NamedNode(NamespaceHelper::BASE_NAMESPACE.'p2'), |
63
|
|
|
'o' => new Literal('baz', 'de'), |
64
|
|
|
], |
65
|
|
|
], |
66
|
|
|
$result |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|