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
|
|
|
|