|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 27; |
22 |
use Test::More tests => 28; |
| 23 |
use DateTime; |
23 |
use DateTime; |
| 24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
| 25 |
use Test::Warn; |
25 |
use Test::Warn; |
|
Lines 37-42
BEGIN {
Link Here
|
| 37 |
use_ok('Koha::OAI::Server::Description'); |
37 |
use_ok('Koha::OAI::Server::Description'); |
| 38 |
use_ok('Koha::OAI::Server::GetRecord'); |
38 |
use_ok('Koha::OAI::Server::GetRecord'); |
| 39 |
use_ok('Koha::OAI::Server::Identify'); |
39 |
use_ok('Koha::OAI::Server::Identify'); |
|
|
40 |
use_ok('Koha::OAI::Server::ListBase'); |
| 40 |
use_ok('Koha::OAI::Server::ListIdentifiers'); |
41 |
use_ok('Koha::OAI::Server::ListIdentifiers'); |
| 41 |
use_ok('Koha::OAI::Server::ListMetadataFormats'); |
42 |
use_ok('Koha::OAI::Server::ListMetadataFormats'); |
| 42 |
use_ok('Koha::OAI::Server::ListRecords'); |
43 |
use_ok('Koha::OAI::Server::ListRecords'); |
|
Lines 56-78
$schema->storage->txn_begin;
Link Here
|
| 56 |
my $dbh = C4::Context->dbh; |
57 |
my $dbh = C4::Context->dbh; |
| 57 |
|
58 |
|
| 58 |
$dbh->do('SET FOREIGN_KEY_CHECKS = 0'); |
59 |
$dbh->do('SET FOREIGN_KEY_CHECKS = 0'); |
|
|
60 |
$dbh->do("SET time_zone='+00:00'"); |
| 59 |
$dbh->do('TRUNCATE biblio'); |
61 |
$dbh->do('TRUNCATE biblio'); |
| 60 |
$dbh->do('TRUNCATE biblioitems'); |
62 |
$dbh->do('TRUNCATE biblioitems'); |
| 61 |
$dbh->do('TRUNCATE issues'); |
63 |
$dbh->do('TRUNCATE issues'); |
| 62 |
|
64 |
|
| 63 |
our $tz = DateTime::TimeZone->new( name => 'local' ); |
65 |
my $date_added = DateTime->now() . 'Z'; |
| 64 |
my $date_added = DateTime->now(time_zone =>$tz) . 'Z'; |
|
|
| 65 |
my $date_to = substr($date_added, 0, 10) . 'T23:59:59Z'; |
66 |
my $date_to = substr($date_added, 0, 10) . 'T23:59:59Z'; |
| 66 |
my (@header, @marcxml, @oaidc); |
67 |
my (@header, @marcxml, @oaidc); |
|
|
68 |
my $sth = $dbh->prepare('SELECT timestamp FROM biblioitems WHERE biblionumber=?'); |
| 67 |
|
69 |
|
| 68 |
# Add 10 biblio records |
70 |
# Add 10 biblio records |
| 69 |
foreach( 1..10 ) { |
71 |
foreach( 1..10 ) { |
| 70 |
my $record = MARC::Record->new(); |
72 |
my $record = MARC::Record->new(); |
| 71 |
$record->append_fields( MARC::Field->new('245', '', '', 'a' => "Title $_" ) ); |
73 |
$record->append_fields( MARC::Field->new('245', '', '', 'a' => "Title $_" ) ); |
| 72 |
my ($biblionumber) = AddBiblio($record, ''); |
74 |
my ($biblionumber) = AddBiblio($record, ''); |
|
|
75 |
$sth->execute($biblionumber); |
| 76 |
my $timestamp = $sth->fetchrow_array . 'Z'; |
| 77 |
$timestamp =~ s/ /T/; |
| 73 |
$record = GetMarcBiblio($biblionumber); |
78 |
$record = GetMarcBiblio($biblionumber); |
| 74 |
$record = XMLin($record->as_xml_record); |
79 |
$record = XMLin($record->as_xml_record); |
| 75 |
$header[$biblionumber] = { datestamp => $date_added, identifier => "TEST:$biblionumber" }; |
80 |
$header[$biblionumber] = { datestamp => $timestamp, identifier => "TEST:$biblionumber" }; |
| 76 |
delete $record->{$_} for (('xmlns','xmlns:xsi','xsi:schemaLocation')); |
81 |
delete $record->{$_} for (('xmlns','xmlns:xsi','xsi:schemaLocation')); |
| 77 |
$oaidc[$biblionumber] = { |
82 |
$oaidc[$biblionumber] = { |
| 78 |
header => $header[$biblionumber], |
83 |
header => $header[$biblionumber], |
|
Lines 107-112
foreach( 1..10 ) {
Link Here
|
| 107 |
}, |
112 |
}, |
| 108 |
}, |
113 |
}, |
| 109 |
}; |
114 |
}; |
|
|
115 |
sleep 2; # FIXME Why do we need this sleep? |
| 110 |
} |
116 |
} |
| 111 |
|
117 |
|
| 112 |
my $syspref = { |
118 |
my $syspref = { |
|
Lines 163-174
test_query('ListMetadataFormats', {verb => 'ListMetadataFormats'}, {
Link Here
|
| 163 |
}, |
169 |
}, |
| 164 |
{ |
170 |
{ |
| 165 |
metadataNamespace => 'http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim', |
171 |
metadataNamespace => 'http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim', |
|
|
172 |
metadataPrefix => 'marc21', |
| 173 |
schema => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd', |
| 174 |
}, |
| 175 |
{ |
| 176 |
metadataNamespace => 'http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim', |
| 166 |
metadataPrefix => 'marcxml', |
177 |
metadataPrefix => 'marcxml', |
| 167 |
schema => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd', |
178 |
schema => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd', |
| 168 |
}, |
179 |
}, |
| 169 |
], |
180 |
], |
| 170 |
}, |
181 |
}, |
| 171 |
} ); |
182 |
}); |
| 172 |
|
183 |
|
| 173 |
test_query('ListIdentifiers without metadataPrefix', {verb => 'ListIdentifiers'}, { |
184 |
test_query('ListIdentifiers without metadataPrefix', {verb => 'ListIdentifiers'}, { |
| 174 |
error => { |
185 |
error => { |
|
Lines 182-188
test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'mar
Link Here
|
| 182 |
ListIdentifiers => { |
193 |
ListIdentifiers => { |
| 183 |
header => [ @header[1..3] ], |
194 |
header => [ @header[1..3] ], |
| 184 |
resumptionToken => { |
195 |
resumptionToken => { |
| 185 |
content => "marcxml/3/1970-01-01T00:00:00Z/$date_to/", |
196 |
content => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0", |
| 186 |
cursor => 3, |
197 |
cursor => 3, |
| 187 |
}, |
198 |
}, |
| 188 |
}, |
199 |
}, |
|
Lines 192-198
test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'mar
Link Here
|
| 192 |
ListIdentifiers => { |
203 |
ListIdentifiers => { |
| 193 |
header => [ @header[1..3] ], |
204 |
header => [ @header[1..3] ], |
| 194 |
resumptionToken => { |
205 |
resumptionToken => { |
| 195 |
content => "marcxml/3/1970-01-01T00:00:00Z/$date_to/", |
206 |
content => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0", |
| 196 |
cursor => 3, |
207 |
cursor => 3, |
| 197 |
}, |
208 |
}, |
| 198 |
}, |
209 |
}, |
|
Lines 200-211
test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'mar
Link Here
|
| 200 |
|
211 |
|
| 201 |
test_query( |
212 |
test_query( |
| 202 |
'ListIdentifiers with resumptionToken 1', |
213 |
'ListIdentifiers with resumptionToken 1', |
| 203 |
{ verb => 'ListIdentifiers', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to/" }, |
214 |
{ verb => 'ListIdentifiers', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0" }, |
| 204 |
{ |
215 |
{ |
| 205 |
ListIdentifiers => { |
216 |
ListIdentifiers => { |
| 206 |
header => [ @header[4..6] ], |
217 |
header => [ @header[4..6] ], |
| 207 |
resumptionToken => { |
218 |
resumptionToken => { |
| 208 |
content => "marcxml/6/1970-01-01T00:00:00Z/$date_to/", |
219 |
content => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0", |
| 209 |
cursor => 6, |
220 |
cursor => 6, |
| 210 |
}, |
221 |
}, |
| 211 |
}, |
222 |
}, |
|
Lines 215-226
test_query(
Link Here
|
| 215 |
|
226 |
|
| 216 |
test_query( |
227 |
test_query( |
| 217 |
'ListIdentifiers with resumptionToken 2', |
228 |
'ListIdentifiers with resumptionToken 2', |
| 218 |
{ verb => 'ListIdentifiers', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to/" }, |
229 |
{ verb => 'ListIdentifiers', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0" }, |
| 219 |
{ |
230 |
{ |
| 220 |
ListIdentifiers => { |
231 |
ListIdentifiers => { |
| 221 |
header => [ @header[7..9] ], |
232 |
header => [ @header[7..9] ], |
| 222 |
resumptionToken => { |
233 |
resumptionToken => { |
| 223 |
content => "marcxml/9/1970-01-01T00:00:00Z/$date_to/", |
234 |
content => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0", |
| 224 |
cursor => 9, |
235 |
cursor => 9, |
| 225 |
}, |
236 |
}, |
| 226 |
}, |
237 |
}, |
|
Lines 230-236
test_query(
Link Here
|
| 230 |
|
241 |
|
| 231 |
test_query( |
242 |
test_query( |
| 232 |
'ListIdentifiers with resumptionToken 3, response without resumption', |
243 |
'ListIdentifiers with resumptionToken 3, response without resumption', |
| 233 |
{ verb => 'ListIdentifiers', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to/" }, |
244 |
{ verb => 'ListIdentifiers', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0" }, |
| 234 |
{ |
245 |
{ |
| 235 |
ListIdentifiers => { |
246 |
ListIdentifiers => { |
| 236 |
header => $header[10], |
247 |
header => $header[10], |
|
Lines 250-256
test_query('ListRecords marcxml', {verb => 'ListRecords', metadataPrefix => 'mar
Link Here
|
| 250 |
ListRecords => { |
261 |
ListRecords => { |
| 251 |
record => [ @marcxml[1..3] ], |
262 |
record => [ @marcxml[1..3] ], |
| 252 |
resumptionToken => { |
263 |
resumptionToken => { |
| 253 |
content => "marcxml/3/1970-01-01T00:00:00Z/$date_to/", |
264 |
content => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0", |
| 254 |
cursor => 3, |
265 |
cursor => 3, |
| 255 |
}, |
266 |
}, |
| 256 |
}, |
267 |
}, |
|
Lines 258-268
test_query('ListRecords marcxml', {verb => 'ListRecords', metadataPrefix => 'mar
Link Here
|
| 258 |
|
269 |
|
| 259 |
test_query( |
270 |
test_query( |
| 260 |
'ListRecords marcxml with resumptionToken 1', |
271 |
'ListRecords marcxml with resumptionToken 1', |
| 261 |
{ verb => 'ListRecords', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to/" }, |
272 |
{ verb => 'ListRecords', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0" }, |
| 262 |
{ ListRecords => { |
273 |
{ ListRecords => { |
| 263 |
record => [ @marcxml[4..6] ], |
274 |
record => [ @marcxml[4..6] ], |
| 264 |
resumptionToken => { |
275 |
resumptionToken => { |
| 265 |
content => "marcxml/6/1970-01-01T00:00:00Z/$date_to/", |
276 |
content => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0", |
| 266 |
cursor => 6, |
277 |
cursor => 6, |
| 267 |
}, |
278 |
}, |
| 268 |
}, |
279 |
}, |
|
Lines 270-280
test_query(
Link Here
|
| 270 |
|
281 |
|
| 271 |
test_query( |
282 |
test_query( |
| 272 |
'ListRecords marcxml with resumptionToken 2', |
283 |
'ListRecords marcxml with resumptionToken 2', |
| 273 |
{ verb => 'ListRecords', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to/" }, |
284 |
{ verb => 'ListRecords', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0" }, |
| 274 |
{ ListRecords => { |
285 |
{ ListRecords => { |
| 275 |
record => [ @marcxml[7..9] ], |
286 |
record => [ @marcxml[7..9] ], |
| 276 |
resumptionToken => { |
287 |
resumptionToken => { |
| 277 |
content => "marcxml/9/1970-01-01T00:00:00Z/$date_to/", |
288 |
content => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0", |
| 278 |
cursor => 9, |
289 |
cursor => 9, |
| 279 |
}, |
290 |
}, |
| 280 |
}, |
291 |
}, |
|
Lines 283-289
test_query(
Link Here
|
| 283 |
# Last record, so no resumption token |
294 |
# Last record, so no resumption token |
| 284 |
test_query( |
295 |
test_query( |
| 285 |
'ListRecords marcxml with resumptionToken 3, response without resumption', |
296 |
'ListRecords marcxml with resumptionToken 3, response without resumption', |
| 286 |
{ verb => 'ListRecords', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to/" }, |
297 |
{ verb => 'ListRecords', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0" }, |
| 287 |
{ ListRecords => { |
298 |
{ ListRecords => { |
| 288 |
record => $marcxml[10], |
299 |
record => $marcxml[10], |
| 289 |
}, |
300 |
}, |
|
Lines 293-299
test_query('ListRecords oai_dc', {verb => 'ListRecords', metadataPrefix => 'oai_
Link Here
|
| 293 |
ListRecords => { |
304 |
ListRecords => { |
| 294 |
record => [ @oaidc[1..3] ], |
305 |
record => [ @oaidc[1..3] ], |
| 295 |
resumptionToken => { |
306 |
resumptionToken => { |
| 296 |
content => "oai_dc/3/1970-01-01T00:00:00Z/$date_to/", |
307 |
content => "oai_dc/3/1970-01-01T00:00:00Z/$date_to//0", |
| 297 |
cursor => 3, |
308 |
cursor => 3, |
| 298 |
}, |
309 |
}, |
| 299 |
}, |
310 |
}, |
|
Lines 301-311
test_query('ListRecords oai_dc', {verb => 'ListRecords', metadataPrefix => 'oai_
Link Here
|
| 301 |
|
312 |
|
| 302 |
test_query( |
313 |
test_query( |
| 303 |
'ListRecords oai_dc with resumptionToken 1', |
314 |
'ListRecords oai_dc with resumptionToken 1', |
| 304 |
{ verb => 'ListRecords', resumptionToken => "oai_dc/3/1970-01-01T00:00:00Z/$date_to/" }, |
315 |
{ verb => 'ListRecords', resumptionToken => "oai_dc/3/1970-01-01T00:00:00Z/$date_to//0" }, |
| 305 |
{ ListRecords => { |
316 |
{ ListRecords => { |
| 306 |
record => [ @oaidc[4..6] ], |
317 |
record => [ @oaidc[4..6] ], |
| 307 |
resumptionToken => { |
318 |
resumptionToken => { |
| 308 |
content => "oai_dc/6/1970-01-01T00:00:00Z/$date_to/", |
319 |
content => "oai_dc/6/1970-01-01T00:00:00Z/$date_to//0", |
| 309 |
cursor => 6, |
320 |
cursor => 6, |
| 310 |
}, |
321 |
}, |
| 311 |
}, |
322 |
}, |
|
Lines 313-323
test_query(
Link Here
|
| 313 |
|
324 |
|
| 314 |
test_query( |
325 |
test_query( |
| 315 |
'ListRecords oai_dc with resumptionToken 2', |
326 |
'ListRecords oai_dc with resumptionToken 2', |
| 316 |
{ verb => 'ListRecords', resumptionToken => "oai_dc/6/1970-01-01T00:00:00Z/$date_to/" }, |
327 |
{ verb => 'ListRecords', resumptionToken => "oai_dc/6/1970-01-01T00:00:00Z/$date_to//0" }, |
| 317 |
{ ListRecords => { |
328 |
{ ListRecords => { |
| 318 |
record => [ @oaidc[7..9] ], |
329 |
record => [ @oaidc[7..9] ], |
| 319 |
resumptionToken => { |
330 |
resumptionToken => { |
| 320 |
content => "oai_dc/9/1970-01-01T00:00:00Z/$date_to/", |
331 |
content => "oai_dc/9/1970-01-01T00:00:00Z/$date_to//0", |
| 321 |
cursor => 9, |
332 |
cursor => 9, |
| 322 |
}, |
333 |
}, |
| 323 |
}, |
334 |
}, |
|
Lines 326-332
test_query(
Link Here
|
| 326 |
# Last record, so no resumption token |
337 |
# Last record, so no resumption token |
| 327 |
test_query( |
338 |
test_query( |
| 328 |
'ListRecords oai_dc with resumptionToken 3, response without resumption', |
339 |
'ListRecords oai_dc with resumptionToken 3, response without resumption', |
| 329 |
{ verb => 'ListRecords', resumptionToken => "oai_dc/9/1970-01-01T00:00:00Z/$date_to/" }, |
340 |
{ verb => 'ListRecords', resumptionToken => "oai_dc/9/1970-01-01T00:00:00Z/$date_to//0" }, |
| 330 |
{ ListRecords => { |
341 |
{ ListRecords => { |
| 331 |
record => $oaidc[10], |
342 |
record => $oaidc[10], |
| 332 |
}, |
343 |
}, |
| 333 |
- |
|
|