|
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 sweetrdf\InMemoryStoreSqlite\Logger; |
|
17
|
|
|
use sweetrdf\InMemoryStoreSqlite\PDOSQLiteAdapter; |
|
18
|
|
|
use sweetrdf\InMemoryStoreSqlite\Store\InMemoryStoreSqlite; |
|
19
|
|
|
use Tests\TestCase; |
|
20
|
|
|
|
|
21
|
|
|
class InMemoryStoreSqliteTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
protected function setUp(): void |
|
24
|
|
|
{ |
|
25
|
|
|
parent::setUp(); |
|
26
|
|
|
|
|
27
|
|
|
$this->subjectUnderTest = new InMemoryStoreSqlite(new PDOSQLiteAdapter(), new Logger()); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/* |
|
31
|
|
|
* Tests for delete |
|
32
|
|
|
*/ |
|
33
|
|
|
|
|
34
|
|
|
public function testDelete() |
|
35
|
|
|
{ |
|
36
|
|
|
// test data |
|
37
|
|
|
$this->subjectUnderTest->query('INSERT INTO <http://example.com/> { |
|
38
|
|
|
<http://s> <http://p1> "baz" . |
|
39
|
|
|
<http://s> <http://xmlns.com/foaf/0.1/name> "label1" . |
|
40
|
|
|
}'); |
|
41
|
|
|
|
|
42
|
|
|
$res = $this->subjectUnderTest->query('SELECT * WHERE {?s ?p ?o.}'); |
|
43
|
|
|
$this->assertEquals(2, \count($res['result']['rows'])); |
|
44
|
|
|
|
|
45
|
|
|
// remove graph |
|
46
|
|
|
$this->subjectUnderTest->delete(false, 'http://example.com/'); |
|
47
|
|
|
|
|
48
|
|
|
$res = $this->subjectUnderTest->query('SELECT * WHERE {?s ?p ?o.}'); |
|
49
|
|
|
$this->assertEquals(0, \count($res['result']['rows'])); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/* |
|
53
|
|
|
* Tests for getDBVersion |
|
54
|
|
|
*/ |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* just check pattern |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testGetDBVersion() |
|
60
|
|
|
{ |
|
61
|
|
|
$pattern = '/[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}/'; |
|
62
|
|
|
$result = preg_match($pattern, $this->subjectUnderTest->getDBVersion(), $match); |
|
63
|
|
|
$this->assertEquals(1, $result); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* https://github.com/SaftIng/Saft/tree/master/src/Saft/Addition/ARC2 |
|
68
|
|
|
* |
|
69
|
|
|
* @group linux |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testInsertSaftRegressionTest1() |
|
72
|
|
|
{ |
|
73
|
|
|
$res = $this->subjectUnderTest->query('SELECT * FROM <http://example.com/> WHERE { ?s ?p ?o. } '); |
|
74
|
|
|
$this->assertEquals(0, \count($res['result']['rows'])); |
|
75
|
|
|
|
|
76
|
|
|
$this->subjectUnderTest->insert( |
|
77
|
|
|
file_get_contents($this->rootPath.'/data/nt/saft-arc2-addition-regression1.nt'), |
|
78
|
|
|
'http://example.com/' |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
$res1 = $this->subjectUnderTest->query('SELECT * FROM <http://example.com/> WHERE { ?s ?p ?o. } '); |
|
82
|
|
|
$this->assertEquals(442, \count($res1['result']['rows'])); |
|
83
|
|
|
|
|
84
|
|
|
$res2 = $this->subjectUnderTest->query('SELECT * WHERE { ?s ?p ?o. } '); |
|
85
|
|
|
$this->assertEquals(442, \count($res2['result']['rows'])); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* This test checks gathering of freshly created resources. |
|
90
|
|
|
*/ |
|
91
|
|
|
public function testInsertSaftRegressionTest2() |
|
92
|
|
|
{ |
|
93
|
|
|
$res = $this->subjectUnderTest->query('INSERT INTO <http://localhost/Saft/TestGraph/> {<http://foo/1> <http://foo/2> <http://foo/3> . }'); |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
$res1 = $this->subjectUnderTest->query('SELECT * FROM <http://localhost/Saft/TestGraph/> WHERE {?s ?p ?o.}'); |
|
96
|
|
|
$this->assertEquals(1, \count($res1['result']['rows'])); |
|
97
|
|
|
|
|
98
|
|
|
$res2 = $this->subjectUnderTest->query('SELECT * WHERE {?s ?p ?o.}'); |
|
99
|
|
|
$this->assertEquals(1, \count($res2['result']['rows'])); |
|
100
|
|
|
|
|
101
|
|
|
$res2 = $this->subjectUnderTest->query('SELECT ?s ?p ?o WHERE {?s ?p ?o.}'); |
|
102
|
|
|
$this->assertEquals(1, \count($res2['result']['rows'])); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* This test checks side effects of update operations on different graphs. |
|
107
|
|
|
* |
|
108
|
|
|
* We add 1 triple to 1 and another to another graph. |
|
109
|
|
|
* Afterwards first graph is removed. |
|
110
|
|
|
* In the end second graph still should contain its triples. |
|
111
|
|
|
*/ |
|
112
|
|
|
public function testInsertSaftRegressionTest3() |
|
113
|
|
|
{ |
|
114
|
|
|
$this->subjectUnderTest->query( |
|
115
|
|
|
'INSERT INTO <http://localhost/Saft/TestGraph/> {<http://localhost/Saft/TestGraph/> <http://localhost/Saft/TestGraph/> <http://localhost/Saft/TestGraph/> . }' |
|
116
|
|
|
); |
|
117
|
|
|
$this->subjectUnderTest->query( |
|
118
|
|
|
'INSERT INTO <http://second-graph/> {<http://second-graph/0> <http://second-graph/1> <http://second-graph/2> . }' |
|
119
|
|
|
); |
|
120
|
|
|
$this->subjectUnderTest->query( |
|
121
|
|
|
'DELETE FROM <http://localhost/Saft/TestGraph/>' |
|
122
|
|
|
); |
|
123
|
|
|
|
|
124
|
|
|
$res = $this->subjectUnderTest->query('SELECT * FROM <http://second-graph/> WHERE {?s ?p ?o.}'); |
|
125
|
|
|
$this->assertEquals(1, \count($res['result']['rows'])); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|