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