View | Details | Raw Unified | Return to bug 15108
Collapse All | Expand All

(-)a/Koha/OAI/Server/ResumptionToken.pm (-2 / +3 lines)
Lines 41-50 sub new { Link Here
41
41
42
    my $self = $class->SUPER::new(%args);
42
    my $self = $class->SUPER::new(%args);
43
43
44
    my ($metadata_prefix, $offset, $from, $until, $set, $deleted);
44
    my ($metadata_prefix, $offset, $from, $until, $set);
45
    my $deleted = defined $args{ deleted } ? $args{ deleted } : 1;
45
    if ( $args{ resumptionToken } ) {
46
    if ( $args{ resumptionToken } ) {
46
        ($metadata_prefix, $offset, $from, $until, $set, $deleted)
47
        ($metadata_prefix, $offset, $from, $until, $set, $deleted)
47
            = split( '/', $args{resumptionToken} );
48
            = split( '/', $args{resumptionToken} );
49
        $deleted = 1 unless defined $deleted;
48
    }
50
    }
49
    else {
51
    else {
50
        $metadata_prefix = $args{ metadataPrefix };
52
        $metadata_prefix = $args{ metadataPrefix };
Lines 59-65 sub new { Link Here
59
        $until .= 'T23:59:59Z' if length($until) == 10;
61
        $until .= 'T23:59:59Z' if length($until) == 10;
60
        $offset = $args{ offset } || 0;
62
        $offset = $args{ offset } || 0;
61
        $set = $args{ set } || '';
63
        $set = $args{ set } || '';
62
        $deleted = defined $args{ deleted } ? $args{ deleted } : 1;
63
    }
64
    }
64
65
65
    $self->{ metadata_prefix } = $metadata_prefix;
66
    $self->{ metadata_prefix } = $metadata_prefix;
(-)a/t/db_dependent/OAI/Server.t (-31 / +36 lines)
Lines 21-28 Link Here
21
use Modern::Perl;
21
use Modern::Perl;
22
use C4::Context;
22
use C4::Context;
23
use C4::Biblio;
23
use C4::Biblio;
24
<<<<<<< HEAD
24
use Test::More tests => 28;
25
use Test::More tests => 27;
26
use Test::MockModule;
25
use Test::MockModule;
27
use Test::Warn;
26
use Test::Warn;
28
use DateTime;
27
use DateTime;
Lines 37-42 BEGIN { Link Here
37
    use_ok('Koha::OAI::Server::Description');
36
    use_ok('Koha::OAI::Server::Description');
38
    use_ok('Koha::OAI::Server::GetRecord');
37
    use_ok('Koha::OAI::Server::GetRecord');
39
    use_ok('Koha::OAI::Server::Identify');
38
    use_ok('Koha::OAI::Server::Identify');
39
    use_ok('Koha::OAI::Server::ListBase');
40
    use_ok('Koha::OAI::Server::ListIdentifiers');
40
    use_ok('Koha::OAI::Server::ListIdentifiers');
41
    use_ok('Koha::OAI::Server::ListMetadataFormats');
41
    use_ok('Koha::OAI::Server::ListMetadataFormats');
42
    use_ok('Koha::OAI::Server::ListRecords');
42
    use_ok('Koha::OAI::Server::ListRecords');
Lines 50-56 BEGIN { Link Here
50
# Mocked CGI module in order to be able to send CGI parameters to OAI Server
50
# Mocked CGI module in order to be able to send CGI parameters to OAI Server
51
my %param;
51
my %param;
52
my $module = Test::MockModule->new('CGI');
52
my $module = Test::MockModule->new('CGI');
53
    $module->mock('Vars', sub { %param; });
53
$module->mock('Vars', sub { %param; });
54
54
55
my $schema = Koha::Database->schema;
55
my $schema = Koha::Database->schema;
56
$schema->storage->txn_begin;
56
$schema->storage->txn_begin;
Lines 59-81 my $dbh = C4::Context->dbh; Link Here
59
my $builder = t::lib::TestBuilder->new;
59
my $builder = t::lib::TestBuilder->new;
60
60
61
$dbh->do('SET FOREIGN_KEY_CHECKS = 0');
61
$dbh->do('SET FOREIGN_KEY_CHECKS = 0');
62
$dbh->do("SET time_zone='+00:00'");
62
$dbh->do('TRUNCATE biblio');
63
$dbh->do('TRUNCATE biblio');
63
$dbh->do('TRUNCATE biblioitems');
64
$dbh->do('TRUNCATE biblioitems');
64
$dbh->do('TRUNCATE issues');
65
$dbh->do('TRUNCATE issues');
65
66
66
# Add 10 biblio records
67
# Add 10 biblio records
67
our $tz = DateTime::TimeZone->new( name => 'local' );
68
my $date_added = DateTime->now() . 'Z';
68
my $date_added = DateTime->now(time_zone =>$tz) . 'Z';
69
my $date_to = substr($date_added, 0, 10) . 'T23:59:59Z';
69
my $date_to = substr($date_added, 0, 10) . 'T23:59:59Z';
70
70
71
my (@header, @marcxml, @oaidc);
71
my (@header, @marcxml, @oaidc);
72
my $sth = $dbh->prepare('SELECT timestamp FROM biblioitems WHERE biblionumber=?');
72
map {
73
map {
73
    my $record = MARC::Record->new();
74
    my $record = MARC::Record->new();
74
    $record->append_fields( MARC::Field->new('245', '', '', 'a' => "Title $_" ) );
75
    $record->append_fields( MARC::Field->new('245', '', '', 'a' => "Title $_" ) );
75
    my ($biblionumber) = AddBiblio($record, '');
76
    my ($biblionumber) = AddBiblio($record, '');
77
    $sth->execute($biblionumber);
78
    my $timestamp = $sth->fetchrow_array . 'Z';
79
    $timestamp =~ s/ /T/;
76
    $record = GetMarcBiblio($biblionumber);
80
    $record = GetMarcBiblio($biblionumber);
77
    $record = XMLin($record->as_xml_record);
81
    $record = XMLin($record->as_xml_record);
78
    $header[$biblionumber] = { datestamp => $date_added, identifier => "TEST:$biblionumber" };
82
    $header[$biblionumber] = { datestamp => $timestamp, identifier => "TEST:$biblionumber" };
79
    delete $record->{$_} for (('xmlns','xmlns:xsi','xsi:schemaLocation'));
83
    delete $record->{$_} for (('xmlns','xmlns:xsi','xsi:schemaLocation'));
80
    $oaidc[$biblionumber] = {
84
    $oaidc[$biblionumber] = {
81
        header => $header[$biblionumber],
85
        header => $header[$biblionumber],
Lines 110-115 map { Link Here
110
            },
114
            },
111
        },
115
        },
112
    };
116
    };
117
    sleep 2;
113
    $biblionumber => undef;
118
    $biblionumber => undef;
114
} (1..10);
119
} (1..10);
115
120
Lines 155-161 sub test_query { Link Here
155
        diag
160
        diag
156
            "PARAM:" . Dump($param) .
161
            "PARAM:" . Dump($param) .
157
            "EXPECTED:" . Dump(\%full_expected) .
162
            "EXPECTED:" . Dump(\%full_expected) .
158
            "RESPONSE:" . Dump($response); 
163
            "RESPONSE:" . Dump($response);
159
    }
164
    }
160
}
165
}
161
166
Lines 170-175 test_query('ListMetadataFormats', {verb => 'ListMetadataFormats'}, { Link Here
170
            },
175
            },
171
            {
176
            {
172
                metadataNamespace => 'http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim',
177
                metadataNamespace => 'http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim',
178
                metadataPrefix => 'marc21',
179
                schema => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
180
            },
181
            {
182
                metadataNamespace => 'http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim',
173
                metadataPrefix => 'marcxml',
183
                metadataPrefix => 'marcxml',
174
                schema => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
184
                schema => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
175
            },
185
            },
Lines 189-195 test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'mar Link Here
189
    ListIdentifiers => {
199
    ListIdentifiers => {
190
        header => [ @header[1..3] ],
200
        header => [ @header[1..3] ],
191
        resumptionToken => {
201
        resumptionToken => {
192
            content => "marcxml/3/1970-01-01T00:00:00Z/$date_to/",
202
            content => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0",
193
            cursor  => 3,
203
            cursor  => 3,
194
        },
204
        },
195
    },
205
    },
Lines 199-205 test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'mar Link Here
199
    ListIdentifiers => {
209
    ListIdentifiers => {
200
        header => [ @header[1..3] ],
210
        header => [ @header[1..3] ],
201
        resumptionToken => {
211
        resumptionToken => {
202
            content => "marcxml/3/1970-01-01T00:00:00Z/$date_to/",
212
            content => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0",
203
            cursor  => 3,
213
            cursor  => 3,
204
        },
214
        },
205
    },
215
    },
Lines 207-218 test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'mar Link Here
207
217
208
test_query(
218
test_query(
209
    'ListIdentifiers with resumptionToken 1',
219
    'ListIdentifiers with resumptionToken 1',
210
    { verb => 'ListIdentifiers', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to/" },
220
    { verb => 'ListIdentifiers', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0" },
211
    {
221
    {
212
        ListIdentifiers => {
222
        ListIdentifiers => {
213
            header => [ @header[4..6] ],
223
            header => [ @header[4..6] ],
214
            resumptionToken => {
224
            resumptionToken => {
215
              content => "marcxml/6/1970-01-01T00:00:00Z/$date_to/",
225
              content => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0",
216
              cursor  => 6,
226
              cursor  => 6,
217
            },
227
            },
218
          },
228
          },
Lines 222-233 test_query( Link Here
222
232
223
test_query(
233
test_query(
224
    'ListIdentifiers with resumptionToken 2',
234
    'ListIdentifiers with resumptionToken 2',
225
    { verb => 'ListIdentifiers', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to/" },
235
    { verb => 'ListIdentifiers', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0" },
226
    {
236
    {
227
        ListIdentifiers => {
237
        ListIdentifiers => {
228
            header => [ @header[7..9] ],
238
            header => [ @header[7..9] ],
229
            resumptionToken => {
239
            resumptionToken => {
230
              content => "marcxml/9/1970-01-01T00:00:00Z/$date_to/",
240
              content => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0",
231
              cursor  => 9,
241
              cursor  => 9,
232
            },
242
            },
233
          },
243
          },
Lines 237-243 test_query( Link Here
237
247
238
test_query(
248
test_query(
239
    'ListIdentifiers with resumptionToken 3, response without resumption',
249
    'ListIdentifiers with resumptionToken 3, response without resumption',
240
    { verb => 'ListIdentifiers', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to/" },
250
    { verb => 'ListIdentifiers', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0" },
241
    {
251
    {
242
        ListIdentifiers => {
252
        ListIdentifiers => {
243
            header => $header[10],
253
            header => $header[10],
Lines 246-256 test_query( Link Here
246
    },
256
    },
247
);
257
);
248
258
249
<<<<<<< HEAD
250
test_query('ListRecords marcxml without metadataPrefix', {verb => 'ListRecords'}, {
259
test_query('ListRecords marcxml without metadataPrefix', {verb => 'ListRecords'}, {
251
=======
252
test_query('ListRecords without metadataPrefix', {verb => 'ListRecords'}, {
253
>>>>>>> 523f474... Bug 17493 Improve OAI Server tests
254
    error => {
260
    error => {
255
        code => 'badArgument',
261
        code => 'badArgument',
256
        content => "Required argument 'metadataPrefix' was undefined",
262
        content => "Required argument 'metadataPrefix' was undefined",
Lines 261-267 test_query('ListRecords marcxml', {verb => 'ListRecords', metadataPrefix => 'mar Link Here
261
    ListRecords => {
267
    ListRecords => {
262
        record => [ @marcxml[1..3] ],
268
        record => [ @marcxml[1..3] ],
263
        resumptionToken => {
269
        resumptionToken => {
264
          content => "marcxml/3/1970-01-01T00:00:00Z/$date_to/",
270
          content => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0",
265
          cursor  => 3,
271
          cursor  => 3,
266
        },
272
        },
267
    },
273
    },
Lines 269-279 test_query('ListRecords marcxml', {verb => 'ListRecords', metadataPrefix => 'mar Link Here
269
275
270
test_query(
276
test_query(
271
    'ListRecords marcxml with resumptionToken 1',
277
    'ListRecords marcxml with resumptionToken 1',
272
    { verb => 'ListRecords', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to/" },
278
    { verb => 'ListRecords', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0" },
273
    { ListRecords => {
279
    { ListRecords => {
274
        record => [ @marcxml[4..6] ],
280
        record => [ @marcxml[4..6] ],
275
        resumptionToken => {
281
        resumptionToken => {
276
          content => "marcxml/6/1970-01-01T00:00:00Z/$date_to/",
282
          content => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0",
277
          cursor  => 6,
283
          cursor  => 6,
278
        },
284
        },
279
    },
285
    },
Lines 281-291 test_query( Link Here
281
287
282
test_query(
288
test_query(
283
    'ListRecords marcxml with resumptionToken 2',
289
    'ListRecords marcxml with resumptionToken 2',
284
    { verb => 'ListRecords', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to/" },
290
    { verb => 'ListRecords', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0" },
285
    { ListRecords => {
291
    { ListRecords => {
286
        record => [ @marcxml[7..9] ],
292
        record => [ @marcxml[7..9] ],
287
        resumptionToken => {
293
        resumptionToken => {
288
          content => "marcxml/9/1970-01-01T00:00:00Z/$date_to/",
294
          content => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0",
289
          cursor  => 9,
295
          cursor  => 9,
290
        },
296
        },
291
    },
297
    },
Lines 294-300 test_query( Link Here
294
# Last record, so no resumption token
300
# Last record, so no resumption token
295
test_query(
301
test_query(
296
    'ListRecords marcxml with resumptionToken 3, response without resumption',
302
    'ListRecords marcxml with resumptionToken 3, response without resumption',
297
    { verb => 'ListRecords', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to/" },
303
    { verb => 'ListRecords', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0" },
298
    { ListRecords => {
304
    { ListRecords => {
299
        record => $marcxml[10],
305
        record => $marcxml[10],
300
    },
306
    },
Lines 304-310 test_query('ListRecords oai_dc', {verb => 'ListRecords', metadataPrefix => 'oai_ Link Here
304
    ListRecords => {
310
    ListRecords => {
305
        record => [ @oaidc[1..3] ],
311
        record => [ @oaidc[1..3] ],
306
        resumptionToken => {
312
        resumptionToken => {
307
          content => "oai_dc/3/1970-01-01T00:00:00Z/$date_to/",
313
          content => "oai_dc/3/1970-01-01T00:00:00Z/$date_to//0",
308
          cursor  => 3,
314
          cursor  => 3,
309
        },
315
        },
310
    },
316
    },
Lines 312-322 test_query('ListRecords oai_dc', {verb => 'ListRecords', metadataPrefix => 'oai_ Link Here
312
318
313
test_query(
319
test_query(
314
    'ListRecords oai_dc with resumptionToken 1',
320
    'ListRecords oai_dc with resumptionToken 1',
315
    { verb => 'ListRecords', resumptionToken => "oai_dc/3/1970-01-01T00:00:00Z/$date_to/" },
321
    { verb => 'ListRecords', resumptionToken => "oai_dc/3/1970-01-01T00:00:00Z/$date_to//0" },
316
    { ListRecords => {
322
    { ListRecords => {
317
        record => [ @oaidc[4..6] ],
323
        record => [ @oaidc[4..6] ],
318
        resumptionToken => {
324
        resumptionToken => {
319
          content => "oai_dc/6/1970-01-01T00:00:00Z/$date_to/",
325
          content => "oai_dc/6/1970-01-01T00:00:00Z/$date_to//0",
320
          cursor  => 6,
326
          cursor  => 6,
321
        },
327
        },
322
    },
328
    },
Lines 324-334 test_query( Link Here
324
330
325
test_query(
331
test_query(
326
    'ListRecords oai_dc with resumptionToken 2',
332
    'ListRecords oai_dc with resumptionToken 2',
327
    { verb => 'ListRecords', resumptionToken => "oai_dc/6/1970-01-01T00:00:00Z/$date_to/" },
333
    { verb => 'ListRecords', resumptionToken => "oai_dc/6/1970-01-01T00:00:00Z/$date_to//0" },
328
    { ListRecords => {
334
    { ListRecords => {
329
        record => [ @oaidc[7..9] ],
335
        record => [ @oaidc[7..9] ],
330
        resumptionToken => {
336
        resumptionToken => {
331
          content => "oai_dc/9/1970-01-01T00:00:00Z/$date_to/",
337
          content => "oai_dc/9/1970-01-01T00:00:00Z/$date_to//0",
332
          cursor  => 9,
338
          cursor  => 9,
333
        },
339
        },
334
    },
340
    },
Lines 337-343 test_query( Link Here
337
# Last record, so no resumption token
343
# Last record, so no resumption token
338
test_query(
344
test_query(
339
    'ListRecords oai_dc with resumptionToken 3, response without resumption',
345
    'ListRecords oai_dc with resumptionToken 3, response without resumption',
340
    { verb => 'ListRecords', resumptionToken => "oai_dc/9/1970-01-01T00:00:00Z/$date_to/" },
346
    { verb => 'ListRecords', resumptionToken => "oai_dc/9/1970-01-01T00:00:00Z/$date_to//0" },
341
    { ListRecords => {
347
    { ListRecords => {
342
        record => $oaidc[10],
348
        record => $oaidc[10],
343
    },
349
    },
344
- 

Return to bug 15108