forked from danielneis/oai_pmh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOAI2ServerTest.php
339 lines (287 loc) · 13.8 KB
/
OAI2ServerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<?php
class OAI2ServerTest extends PHPUnit_Framework_TestCase {
function setUp() {
$this->xml = new DomDocument("1.0", "UTF-8");
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>'.date('Y-m-d\TH:i:s\Z').'</responseDate>
</OAI-PMH>';
$this->xml->loadXML($xml);
$this->uri = 'test.oai_pmh';
}
function testIdentify() {
$xml = '<request verb="Identify">test.oai_pmh</request>
<Identify>
<repositoryName>OAI2 PMH Test</repositoryName>
<baseURL>http://198.199.108.242/~neis/oai_pmh/oai2.php</baseURL>
<protocolVersion>2.0</protocolVersion>
<adminEmail>danielneis@gmail.com</adminEmail>
<earliestDatestamp>2013-01-01T12:00:00Z</earliestDatestamp>
<deletedRecord>no</deletedRecord>
<granularity>YYYY-MM-DDThh:mm:ssZ</granularity>
</Identify>';
$f = $this->xml->createDocumentFragment();
$f->appendXML($xml);
$this->xml->documentElement->appendChild($f);
$return = true;
$uri = $this->uri;
$args = array('verb' => 'Identify');
$response = require('oai2.php');
$this->assertEqualXMLStructure($this->xml->firstChild, $response->firstChild);
}
function testIdentifyIllegalParameter() {
$verb = 'Identify';
$args = array('test' => 'test');
}
function testListMetadataFormats() {
$xml = '<request verb="ListMetadataFormats">test.oai_pmh</request>
<ListMetadataFormats>
<metadataFormat>
<metadataPrefix>rif</metadataPrefix>
<schema>http://services.ands.org.au/sandbox/orca/schemata/registryObjects.xsd</schema>
<metadataNamespace>http://ands.org.au/standards/rif-cs/registryObjects/</metadataNamespace>
</metadataFormat>
<metadataFormat>
<metadataPrefix>oai_dc</metadataPrefix>
<schema>http://www.openarchives.org/OAI/2.0/oai_dc.xsd</schema>
<metadataNamespace>http://www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace>
</metadataFormat>
</ListMetadataFormats>';
$f = $this->xml->createDocumentFragment();
$f->appendXML($xml);
$this->xml->documentElement->appendChild($f);
$return = true;
$uri = $this->uri;
$args = array('verb' => 'ListMetadataFormats');
$response = require('oai2.php');
$this->assertEqualXMLStructure($this->xml->firstChild, $response->firstChild);
}
function testListMetadataFormatsIdentifier() {
$verb = 'ListMetadataFormats';
$args = array('identifier' => 'a.b.c');
}
function testListMetadataFormatsIllegalIdentifier() {
$verb = 'ListMetadataFormats';
$args = array('identifier' => 'illegalIdentifier');
}
function testListSets() {
$xml = '<request verb="ListSets">test.oai_pmh</request>
<ListSets>
<set>
<setSpec>class:collection</setSpec>
<setName>Collections</setName>
</set>
<set>
<setSpec>math</setSpec>
<setName>Mathematics</setName>
</set>
<set>
<setSpec>phys</setSpec>
<setName>Physics</setName>
</set>
<set>
<setSpec>phdthesis</setSpec>
<setName>PHD Thesis</setName>
<setDescription>
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"> <dc:description>This set contains metadata describing electronic music recordings made during the 1950ies</dc:description> </oai_dc:dc>
</setDescription>
</set>
</ListSets>';
$f = $this->xml->createDocumentFragment();
$f->appendXML($xml);
$this->xml->documentElement->appendChild($f);
$return = true;
$uri = $this->uri;
$args = array('verb' => 'ListSets');
$response = require('oai2.php');
$this->assertEqualXMLStructure($this->xml->firstChild, $response->firstChild);
}
function testListSetsResumptionToken() {
$verb = 'ListSets';
$args = array('resumptionToken' => '????');
}
function testListIdentifiersMetadataPrefix() {
$xml = '<request verb="ListIdentifiers" metadataPrefix="oai_dc">test.oai_pmh</request>
<ListIdentifiers>
<header>
<identifier>dev.testing.pmh</identifier>
<datestamp>2013-05-14T18:41:00Z</datestamp>
<setSpec>class:activity</setSpec>
</header>
</ListIdentifiers>';
$f = $this->xml->createDocumentFragment();
$f->appendXML($xml);
$this->xml->documentElement->appendChild($f);
$return = true;
$uri = $this->uri;
$args = array('verb' => 'ListIdentifiers', 'metadataPrefix' => 'oai_dc');
$response = require('oai2.php');
$this->assertEqualXMLStructure($this->xml->firstChild, $response->firstChild);
}
function testListIdentifiers() {
$args = array('verb' => 'ListIdentifiers');
}
function testListIdentifiersResumptionToken() {
$args = array('verb' => 'ListIdentifiers', 'resumptionToken' => '????');
}
function testListIdentifiersResumptionTokenMetadataPrefix() {
$args = array('verb' => 'ListIdentifiers', 'resumptionToken' => '????', 'metadataPrefix' => 'oai_dc');
}
function testListIdentifiersMetadataPrefixSet() {
$args = array('verb' => 'ListIdentifiers', 'metadataPrefix' => 'oai_dc', 'set' => 'someSet');
}
function testListIdentifiersMetadataPrefixFromUntil() {
$args = array('verb' => 'ListIdentifiers', 'metadataPrefix' => 'oai_dc', 'from' => '2000-01-01', 'until' => '2000-01-01');
}
function testListIdentifiersMetadataPrefixSetFromUntil() {
$args = array('verb' => 'ListIdentifiers', 'metadataPrefix' => 'oai_dc',
'set' => '????', 'from' => '2000-01-01', 'until' => '2000-01-01');
}
function testListIdentifiersMetadataPrefixIllegalSetIllegalFromUntil() {
$args = array('verb' => 'ListIdentifiers', 'metadataPrefix' => 'oai_dc',
'set' => 'really_wrong_set',
'from' => 'some_random_from', 'until' => 'some_random_until');
}
function testListIdentifiersDifferentGranularity() {
$args = array('verb' => 'ListIdentifiers', 'resumptionToken' => '????', 'metadataPrefix' => 'oai_dc',
'from' => '2000-01-01', 'until' => '2000-01-01T00:00:00Z');
}
function testListIdentifiersFromGreaterThanUntil() {
$args = array('verb' => 'ListIdentifiers', 'resumptionToken' => '????', 'metadataPrefix' => 'oai_dc',
'from' => '2013-01-01', 'until' => '2000-01-01T00:00:00Z');
}
function testListIdentifiersIllegalMetadataPrefix() {
$args = array('verb' => 'ListIdentifiers', 'metadataPrefix' => 'illegalPrefix');
}
function testListIdentifiersMetadataPrefixMetadataPrefix() {
$args = array('verb' => 'ListIdentifiers', 'metadataPrefix' => 'oai_dc', 'metadataPrefix' => 'oai_dc');
}
function testListIdentifiersIllegalResumptionToken() {
$args = array('verb' => 'ListIdentifiers', 'resumptionToken' => 'illegalToken');
}
function testListIdentifiersMetadataPrefixFrom() {
$args = array('verb' => 'ListIdentifiers', 'metadataPrefix' => 'oai_dc', 'from' => '2001-01-01T00:00:00Z');
}
function testListIdentifiersMetadataPrefixFromYear() {
$args = array('verb' => 'ListIdentifiers', 'metadataPrefix' => 'oai_dc', 'from' => '2001');
}
function testListRecords() {
$verb = 'ListRecords';
$args = array('verb' => 'ListRecords');
}
function testListRecordsMetadataPrefix() {
$xml = '<request verb="ListRecords" metadataPrefix="oai_dc">test.oai_pmh</request>
<ListRecords>
<record>
<header>
<identifier>dev.testing.pmh</identifier>
<datestamp>2013-05-14T18:11:00Z</datestamp>
<setSpec>class:activity</setSpec>
</header>
<metadata>
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<dc:title>Testing records</dc:title>
<dc:author>Neis</dc:author>
</oai_dc:dc>
</metadata>
</record>
</ListRecords>';
$f = $this->xml->createDocumentFragment();
$f->appendXML($xml);
$this->xml->documentElement->appendChild($f);
$return = true;
$uri = $this->uri;
$args = array('verb' => 'ListRecords', 'metadataPrefix' => 'oai_dc');
$response = require('oai2.php');
$this->assertEqualXMLStructure($this->xml->firstChild, $response->firstChild);
}
function testListRecordsMetadataPrefixFromUntil() {
$args = array('verb' => 'ListRecords', 'metadataPrefix' => 'oai_dc', 'from' => '2000-01-01', 'until' => '2000-01-01');
}
function testListRecordsResumptionToken() {
$args = array('verb' => 'ListRecords', 'resumptionToken' => '????');
}
function testListRecordsMetadataPrefixIllegalSetIllegalFromUntil() {
$args = array('verb' => 'ListRecords', 'metadataPrefix' => 'oai_dc',
'set' => 'illegalSet',
'from' => 'some_random_from', 'until' => 'some_random_until');
}
function testListRecordsDifferentGranularity() {
$args = array('verb' => 'ListRecords', 'resumptionToken' => '????', 'metadataPrefix' => 'oai_dc',
'from' => '2000-01-01', 'until' => '2000-01-01T00:00:00Z');
}
function testListRecordsUntilBeforeEarliestDatestamp() {
$args = array('verb' => 'ListRecords', 'metadataPrefix' => 'oai_dc', 'until' => '1969-01-01T00:00:00Z');
}
function testListRecordsIllegalResumptionToken() {
$args = array('verb' => 'ListRecords', 'resumptionToken' => 'illegalToken');
}
function testGetRecord() {
$args = array('verb' => 'GetRecord');
}
function testGetRecordIdentifier() {
$args = array('verb' => 'GetRecord', 'identifier' => 'a.b.c');
}
function testGetRecordIdentifierMetadataPrefix() {
$xml = '<request verb="GetRecord" metadataPrefix="oai_dc" identifier="a.b.c">test.oai_pmh</request>
<GetRecord>
<record>
<header>
<identifier>a.b.c</identifier>
<datestamp>2013-05-14T18:08:00Z</datestamp>
<setSpec>class:activity</setSpec>
</header>
<metadata>
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<dc:title>Testing records</dc:title>
<dc:author>Neis</dc:author>
</oai_dc:dc>
</metadata>
</record>
</GetRecord>';
$f = $this->xml->createDocumentFragment();
$f->appendXML($xml);
$this->xml->documentElement->appendChild($f);
$return = true;
$uri = $this->uri;
$args = array('verb' => 'GetRecord', 'identifier' => 'a.b.c', 'metadataPrefix' => 'oai_dc');
$response = require('oai2.php');
$this->assertEqualXMLStructure($this->xml->firstChild, $response->firstChild);
}
function testGetRecordIdentifierIllegalMetadataPrefix() {
$args = array('verb' => 'GetRecord', 'identifier' => 'a.b.c', 'metadataPrefix' => 'illegalPrefix');
}
function testGetRecordMetadataPrefix() {
$args = array('verb' => 'GetRecord', 'metadataPrefix' => 'oai_dc');
}
function testGetRecordIllegalIdentifierMetadataPrefix() {
$args = array('verb' => 'GetRecord', 'identifier' => 'illegalID', 'metadataPrefix' => 'oai_dc');
}
function testGetRecordInvalidIdentifierMetadataPrefix() {
$args = array('verb' => 'GetRecord', 'identifier' => 'invalidID', 'metadataPrefix' => 'oai_dc');
}
function testIllegalVerb() {
$xml = '<request>test.oai_pmh</request>
<error code="badVerb">Illegal OAI verb</error>';
$f = $this->xml->createDocumentFragment();
$f->appendXML($xml);
$this->xml->documentElement->appendChild($f);
$return = true;
$uri = $this->uri;
$args = array('verb' => 'IllegalVerb');
$response = require('oai2.php');
$this->assertEqualXMLStructure($this->xml->firstChild, $response->firstChild);
}
function testNoVerb() {
$xml = '<request>test.oai_pmh</request>
<error code="badVerb">Illegal OAI verb</error>';
$f = $this->xml->createDocumentFragment();
$f->appendXML($xml);
$this->xml->documentElement->appendChild($f);
$return = true;
$uri = $this->uri;
$args = array();
$response = require('oai2.php');
$this->assertEqualXMLStructure($this->xml->firstChild, $response->firstChild);
}
}