1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the sweetrdf/InMemoryStoreSqlite package and licensed under |
5
|
|
|
* the terms of the GPL-3 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; |
15
|
|
|
|
16
|
|
|
use simpleRdf\DataFactory; |
17
|
|
|
use sweetrdf\InMemoryStoreSqlite\KeyValueBag; |
18
|
|
|
use sweetrdf\InMemoryStoreSqlite\Log\LoggerPool; |
19
|
|
|
use sweetrdf\InMemoryStoreSqlite\NamespaceHelper; |
20
|
|
|
use sweetrdf\InMemoryStoreSqlite\PDOSQLiteAdapter; |
21
|
|
|
use sweetrdf\InMemoryStoreSqlite\Store\InMemoryStoreSqlite; |
22
|
|
|
use sweetrdf\InMemoryStoreSqlite\StringReader; |
23
|
|
|
use Tests\TestCase; |
24
|
|
|
|
25
|
|
|
class InMemoryStoreSqliteTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
protected function setUp(): void |
28
|
|
|
{ |
29
|
|
|
parent::setUp(); |
30
|
|
|
|
31
|
|
|
$this->subjectUnderTest = InMemoryStoreSqlite::createInstance(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/* |
35
|
|
|
* Tests for createInstance |
36
|
|
|
*/ |
37
|
|
|
|
38
|
|
|
public function testCreateInstance() |
39
|
|
|
{ |
40
|
|
|
$expected = new InMemoryStoreSqlite( |
41
|
|
|
new PDOSQLiteAdapter(), |
42
|
|
|
new DataFactory(), |
43
|
|
|
new NamespaceHelper(), |
44
|
|
|
new LoggerPool(), |
45
|
|
|
new KeyValueBag(), |
46
|
|
|
new StringReader() |
47
|
|
|
); |
48
|
|
|
$this->assertEquals($expected, InMemoryStoreSqlite::createInstance()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/* |
52
|
|
|
* Tests for getDBVersion |
53
|
|
|
*/ |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* just check pattern |
57
|
|
|
*/ |
58
|
|
|
public function testGetDBVersion() |
59
|
|
|
{ |
60
|
|
|
$pattern = '/[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}/'; |
61
|
|
|
$result = preg_match($pattern, $this->subjectUnderTest->getDBVersion(), $match); |
62
|
|
|
$this->assertEquals(1, $result); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* This test checks gathering of freshly created resources. |
67
|
|
|
*/ |
68
|
|
|
public function testInsertSaftRegressionTest2() |
69
|
|
|
{ |
70
|
|
|
$res = $this->subjectUnderTest->query('INSERT INTO <http://localhost/Saft/TestGraph/> {<http://foo/1> <http://foo/2> <http://foo/3> . }'); |
|
|
|
|
71
|
|
|
|
72
|
|
|
$res1 = $this->subjectUnderTest->query('SELECT * FROM <http://localhost/Saft/TestGraph/> WHERE {?s ?p ?o.}'); |
73
|
|
|
$this->assertEquals(1, \count($res1['result']['rows'])); |
74
|
|
|
|
75
|
|
|
$res2 = $this->subjectUnderTest->query('SELECT * WHERE {?s ?p ?o.}'); |
76
|
|
|
$this->assertEquals(1, \count($res2['result']['rows'])); |
77
|
|
|
|
78
|
|
|
$res2 = $this->subjectUnderTest->query('SELECT ?s ?p ?o WHERE {?s ?p ?o.}'); |
79
|
|
|
$this->assertEquals(1, \count($res2['result']['rows'])); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* This test checks side effects of update operations on different graphs. |
84
|
|
|
* |
85
|
|
|
* We add 1 triple to 1 and another to another graph. |
86
|
|
|
* Afterwards first graph is removed. |
87
|
|
|
* In the end second graph still should contain its triples. |
88
|
|
|
*/ |
89
|
|
|
public function testInsertSaftRegressionTest3() |
90
|
|
|
{ |
91
|
|
|
$this->subjectUnderTest->query( |
92
|
|
|
'INSERT INTO <http://localhost/Saft/TestGraph/> {<http://localhost/Saft/TestGraph/> <http://localhost/Saft/TestGraph/> <http://localhost/Saft/TestGraph/> . }' |
93
|
|
|
); |
94
|
|
|
$this->subjectUnderTest->query( |
95
|
|
|
'INSERT INTO <http://second-graph/> {<http://second-graph/0> <http://second-graph/1> <http://second-graph/2> . }' |
96
|
|
|
); |
97
|
|
|
$this->subjectUnderTest->query( |
98
|
|
|
'DELETE FROM <http://localhost/Saft/TestGraph/>' |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$res = $this->subjectUnderTest->query('SELECT * FROM <http://second-graph/> WHERE {?s ?p ?o.}'); |
102
|
|
|
$this->assertEquals(1, \count($res['result']['rows'])); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testAddQuads() |
106
|
|
|
{ |
107
|
|
|
// check data at the beginning |
108
|
|
|
$res = $this->subjectUnderTest->query('SELECT * WHERE {?s ?p ?o.}'); |
109
|
|
|
$this->assertCount(0, $res['result']['rows']); |
110
|
|
|
|
111
|
|
|
/* |
112
|
|
|
* add quads |
113
|
|
|
*/ |
114
|
|
|
$df = new DataFactory(); |
115
|
|
|
$graph = 'http://graph'; |
116
|
|
|
|
117
|
|
|
// q1 |
118
|
|
|
$q1 = $df->quad( |
119
|
|
|
$df->namedNode('http://a'), |
120
|
|
|
$df->namedNode('http://b'), |
121
|
|
|
$df->namedNode('http://c'), |
122
|
|
|
$df->namedNode($graph) |
123
|
|
|
); |
124
|
|
|
|
125
|
|
|
// q2 |
126
|
|
|
$q2 = $df->quad( |
127
|
|
|
$df->blankNode('123'), |
128
|
|
|
$df->namedNode('http://b'), |
129
|
|
|
$df->literal('foobar', 'de'), |
130
|
|
|
$df->namedNode($graph) |
131
|
|
|
); |
132
|
|
|
|
133
|
|
|
$quads = [$q1, $q2]; |
134
|
|
|
|
135
|
|
|
$this->subjectUnderTest->addQuads($quads); |
136
|
|
|
|
137
|
|
|
// check after quads were added |
138
|
|
|
$res = $this->subjectUnderTest->query('SELECT * FROM <'.$graph.'> WHERE {?s ?p ?o.}'); |
139
|
|
|
$this->assertEquals( |
140
|
|
|
[ |
141
|
|
|
[ |
142
|
|
|
's' => 'http://a', |
143
|
|
|
's type' => 'uri', |
144
|
|
|
'p' => 'http://b', |
145
|
|
|
'p type' => 'uri', |
146
|
|
|
'o' => 'http://c', |
147
|
|
|
'o type' => 'uri', |
148
|
|
|
], |
149
|
|
|
[ |
150
|
|
|
's' => $res['result']['rows'][1]['s'], // dynamic value |
151
|
|
|
's type' => 'bnode', |
152
|
|
|
'p' => 'http://b', |
153
|
|
|
'p type' => 'uri', |
154
|
|
|
'o' => 'foobar', |
155
|
|
|
'o type' => 'literal', |
156
|
|
|
'o lang' => 'de', |
157
|
|
|
], |
158
|
|
|
], |
159
|
|
|
$res['result']['rows'] |
160
|
|
|
); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|