1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\SPARQLStore; |
4
|
|
|
|
5
|
|
|
use SMW\SPARQLStore\RepositoryConnectionProvider; |
6
|
|
|
use SMW\Tests\Utils\GlobalsProvider; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \SMW\SPARQLStore\RepositoryConnectionProvider |
10
|
|
|
* @group semantic-mediawiki |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 2.0 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class RepositoryConnectionProviderTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
private $globalsProvider; |
20
|
|
|
private $smwgSparqlDatabase; |
21
|
|
|
private $smwgSparqlDatabaseConnector; |
22
|
|
|
|
23
|
|
|
protected function setUp() { |
24
|
|
|
parent::setUp(); |
25
|
|
|
|
26
|
|
|
$this->globalsProvider = GlobalsProvider::getInstance(); |
27
|
|
|
|
28
|
|
|
$this->smwgSparqlDatabaseConnector = $this->globalsProvider->get( 'smwgSparqlDatabaseConnector' ); |
29
|
|
|
$this->smwgSparqlDatabase = $this->globalsProvider->get( 'smwgSparqlDatabase' ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function tearDown() { |
33
|
|
|
|
34
|
|
|
$this->globalsProvider->set( |
35
|
|
|
'smwgSparqlDatabaseConnector', |
36
|
|
|
$this->smwgSparqlDatabaseConnector |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$this->globalsProvider->set( |
40
|
|
|
'smwgSparqlDatabase', |
41
|
|
|
$this->smwgSparqlDatabase |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$this->globalsProvider->clear(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testCanConstruct() { |
48
|
|
|
|
49
|
|
|
$instance = new RepositoryConnectionProvider(); |
50
|
|
|
|
51
|
|
|
$this->assertInstanceOf( |
52
|
|
|
'\SMW\SPARQLStore\RepositoryConnectionProvider', |
53
|
|
|
$instance |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
$this->assertInstanceOf( |
57
|
|
|
'\SMW\DBConnectionProvider', |
58
|
|
|
$instance |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testGetDefaultConnection() { |
63
|
|
|
|
64
|
|
|
$instance = new RepositoryConnectionProvider( 'default' ); |
65
|
|
|
$instance->setHttpVersionTo( CURL_HTTP_VERSION_NONE ); |
66
|
|
|
|
67
|
|
|
$this->assertInstanceOf( |
68
|
|
|
'\SMWSparqlDatabase', |
69
|
|
|
$instance->getConnection() |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$connection = $instance->getConnection(); |
73
|
|
|
|
74
|
|
|
$this->assertSame( |
75
|
|
|
$connection, |
76
|
|
|
$instance->getConnection() |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$instance->releaseConnection(); |
80
|
|
|
|
81
|
|
|
$this->assertNotSame( |
82
|
|
|
$connection, |
83
|
|
|
$instance->getConnection() |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testGetFusekiConnection() { |
88
|
|
|
|
89
|
|
|
$instance = new RepositoryConnectionProvider( 'fuSEKi' ); |
90
|
|
|
|
91
|
|
|
$this->assertInstanceOf( |
92
|
|
|
'\SMW\SPARQLStore\RepositoryConnector\FusekiHttpRepositoryConnector', |
93
|
|
|
$instance->getConnection() |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testGetVirtuosoConnection() { |
98
|
|
|
|
99
|
|
|
$instance = new RepositoryConnectionProvider( 'virtuoso' ); |
100
|
|
|
|
101
|
|
|
$this->assertInstanceOf( |
102
|
|
|
'\SMW\SPARQLStore\RepositoryConnector\VirtuosoHttpRepositoryConnector', |
103
|
|
|
$instance->getConnection() |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
// Legacy |
107
|
|
|
$this->assertInstanceOf( |
108
|
|
|
'\SMWSparqlDatabaseVirtuoso', |
109
|
|
|
$instance->getConnection() |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testGet4StoreConnection() { |
114
|
|
|
|
115
|
|
|
$instance = new RepositoryConnectionProvider( '4STORE' ); |
116
|
|
|
|
117
|
|
|
$this->assertInstanceOf( |
118
|
|
|
'\SMW\SPARQLStore\RepositoryConnector\FourstoreHttpRepositoryConnector', |
119
|
|
|
$instance->getConnection() |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
// Legacy |
123
|
|
|
$this->assertInstanceOf( |
124
|
|
|
'\SMWSparqlDatabase4Store', |
125
|
|
|
$instance->getConnection() |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function testGetSesameConnection() { |
130
|
|
|
|
131
|
|
|
$instance = new RepositoryConnectionProvider( 'sesame' ); |
132
|
|
|
|
133
|
|
|
$this->assertInstanceOf( |
134
|
|
|
'\SMW\SPARQLStore\RepositoryConnector\GenericHttpRepositoryConnector', |
135
|
|
|
$instance->getConnection() |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function testGetGenericConnection() { |
140
|
|
|
|
141
|
|
|
$instance = new RepositoryConnectionProvider( 'generic' ); |
142
|
|
|
|
143
|
|
|
$this->assertInstanceOf( |
144
|
|
|
'\SMW\SPARQLStore\RepositoryConnector\GenericHttpRepositoryConnector', |
145
|
|
|
$instance->getConnection() |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function testGetDefaultConnectorForUnknownConnectorId() { |
150
|
|
|
|
151
|
|
|
$this->globalsProvider->set( |
152
|
|
|
'smwgSparqlDatabaseConnector', |
153
|
|
|
'default' |
154
|
|
|
); |
155
|
|
|
|
156
|
|
|
$instance = new RepositoryConnectionProvider( 'foo' ); |
157
|
|
|
|
158
|
|
|
$this->assertInstanceOf( |
159
|
|
|
'\SMWSparqlDatabase', |
160
|
|
|
$instance->getConnection() |
161
|
|
|
); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function testGetDefaultConnectorForEmptyConnectorId() { |
165
|
|
|
|
166
|
|
|
$this->globalsProvider->set( |
167
|
|
|
'smwgSparqlDatabaseConnector', |
168
|
|
|
'default' |
169
|
|
|
); |
170
|
|
|
|
171
|
|
|
$instance = new RepositoryConnectionProvider(); |
172
|
|
|
|
173
|
|
|
$this->assertInstanceOf( |
174
|
|
|
'\SMWSparqlDatabase', |
175
|
|
|
$instance->getConnection() |
176
|
|
|
); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function testGetDefaultConnectorForUnMappedId() { |
180
|
|
|
|
181
|
|
|
$this->globalsProvider->set( |
182
|
|
|
'smwgSparqlDatabaseConnector', |
183
|
|
|
'idThatCanNotBeMapped' |
184
|
|
|
); |
185
|
|
|
|
186
|
|
|
$instance = new RepositoryConnectionProvider(); |
187
|
|
|
|
188
|
|
|
$this->assertInstanceOf( |
189
|
|
|
'\SMWSparqlDatabase', |
190
|
|
|
$instance->getConnection() |
191
|
|
|
); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function testInvalidCustomClassConnectorThrowsException() { |
195
|
|
|
|
196
|
|
|
$this->globalsProvider->set( |
197
|
|
|
'smwgSparqlDatabase', |
198
|
|
|
'InvalidCustomClassConnector' |
199
|
|
|
); |
200
|
|
|
|
201
|
|
|
$instance = new RepositoryConnectionProvider( 'custom' ); |
202
|
|
|
|
203
|
|
|
$this->setExpectedException( 'RuntimeException' ); |
204
|
|
|
$instance->getConnection(); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function testInvalidCustomRespositoryConnectorThrowsException() { |
208
|
|
|
|
209
|
|
|
$this->globalsProvider->set( |
210
|
|
|
'smwgSparqlDatabase', |
211
|
|
|
'\SMW\Tests\Utils\Fixtures\InvalidCustomRespositoryConnector' |
212
|
|
|
); |
213
|
|
|
|
214
|
|
|
$instance = new RepositoryConnectionProvider( 'custom' ); |
215
|
|
|
|
216
|
|
|
$this->setExpectedException( 'RuntimeException' ); |
217
|
|
|
$instance->getConnection(); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
} |
221
|
|
|
|