From d248a6b233a303cadd7c144f59e7a38c52884743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Demians?= Date: Mon, 24 Oct 2016 15:17:50 +0000 Subject: [PATCH] Fix OAI Server tests Tests introduced by bug 17493 must be amended to accomodate the new resumption tokens (with time) returned by OAI Server. https://bugs.koha-community.org/show_bug.cgi?id=15108 --- Koha/OAI/Server/ResumptionToken.pm | 5 +-- t/db_dependent/OAI/Server.t | 66 +++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/Koha/OAI/Server/ResumptionToken.pm b/Koha/OAI/Server/ResumptionToken.pm index 5fbf9cb..a6a6f03 100644 --- a/Koha/OAI/Server/ResumptionToken.pm +++ b/Koha/OAI/Server/ResumptionToken.pm @@ -41,10 +41,12 @@ sub new { my $self = $class->SUPER::new(%args); - my ($metadata_prefix, $offset, $from, $until, $set, $deleted); + my ($metadata_prefix, $offset, $from, $until, $set); + my $deleted = defined $args{ deleted } ? $args{ deleted } : 1; if ( $args{ resumptionToken } ) { ($metadata_prefix, $offset, $from, $until, $set, $deleted) = split( '/', $args{resumptionToken} ); + $deleted = 1 unless defined $deleted; } else { $metadata_prefix = $args{ metadataPrefix }; @@ -59,7 +61,6 @@ sub new { $until .= 'T23:59:59Z' if length($until) == 10; $offset = $args{ offset } || 0; $set = $args{ set } || ''; - $deleted = defined $args{ deleted } ? $args{ deleted } : 1; } $self->{ metadata_prefix } = $metadata_prefix; diff --git a/t/db_dependent/OAI/Server.t b/t/db_dependent/OAI/Server.t index 2763207..66df9e5 100644 --- a/t/db_dependent/OAI/Server.t +++ b/t/db_dependent/OAI/Server.t @@ -21,8 +21,7 @@ use Modern::Perl; use C4::Context; use C4::Biblio; -<<<<<<< HEAD -use Test::More tests => 27; +use Test::More tests => 28; use Test::MockModule; use Test::Warn; use DateTime; @@ -37,6 +36,7 @@ BEGIN { use_ok('Koha::OAI::Server::Description'); use_ok('Koha::OAI::Server::GetRecord'); use_ok('Koha::OAI::Server::Identify'); + use_ok('Koha::OAI::Server::ListBase'); use_ok('Koha::OAI::Server::ListIdentifiers'); use_ok('Koha::OAI::Server::ListMetadataFormats'); use_ok('Koha::OAI::Server::ListRecords'); @@ -50,7 +50,7 @@ BEGIN { # Mocked CGI module in order to be able to send CGI parameters to OAI Server my %param; my $module = Test::MockModule->new('CGI'); - $module->mock('Vars', sub { %param; }); +$module->mock('Vars', sub { %param; }); my $schema = Koha::Database->schema; $schema->storage->txn_begin; @@ -59,23 +59,27 @@ my $dbh = C4::Context->dbh; my $builder = t::lib::TestBuilder->new; $dbh->do('SET FOREIGN_KEY_CHECKS = 0'); +$dbh->do("SET time_zone='+00:00'"); $dbh->do('TRUNCATE biblio'); $dbh->do('TRUNCATE biblioitems'); $dbh->do('TRUNCATE issues'); # Add 10 biblio records -our $tz = DateTime::TimeZone->new( name => 'local' ); -my $date_added = DateTime->now(time_zone =>$tz) . 'Z'; +my $date_added = DateTime->now() . 'Z'; my $date_to = substr($date_added, 0, 10) . 'T23:59:59Z'; my (@header, @marcxml, @oaidc); +my $sth = $dbh->prepare('SELECT timestamp FROM biblioitems WHERE biblionumber=?'); map { my $record = MARC::Record->new(); $record->append_fields( MARC::Field->new('245', '', '', 'a' => "Title $_" ) ); my ($biblionumber) = AddBiblio($record, ''); + $sth->execute($biblionumber); + my $timestamp = $sth->fetchrow_array . 'Z'; + $timestamp =~ s/ /T/; $record = GetMarcBiblio($biblionumber); $record = XMLin($record->as_xml_record); - $header[$biblionumber] = { datestamp => $date_added, identifier => "TEST:$biblionumber" }; + $header[$biblionumber] = { datestamp => $timestamp, identifier => "TEST:$biblionumber" }; delete $record->{$_} for (('xmlns','xmlns:xsi','xsi:schemaLocation')); $oaidc[$biblionumber] = { header => $header[$biblionumber], @@ -110,6 +114,7 @@ map { }, }, }; + sleep 2; $biblionumber => undef; } (1..10); @@ -155,7 +160,7 @@ sub test_query { diag "PARAM:" . Dump($param) . "EXPECTED:" . Dump(\%full_expected) . - "RESPONSE:" . Dump($response); + "RESPONSE:" . Dump($response); } } @@ -170,6 +175,11 @@ test_query('ListMetadataFormats', {verb => 'ListMetadataFormats'}, { }, { metadataNamespace => 'http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim', + metadataPrefix => 'marc21', + schema => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd', + }, + { + metadataNamespace => 'http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim', metadataPrefix => 'marcxml', schema => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd', }, @@ -189,7 +199,7 @@ test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'mar ListIdentifiers => { header => [ @header[1..3] ], resumptionToken => { - content => "marcxml/3/1970-01-01T00:00:00Z/$date_to/", + content => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0", cursor => 3, }, }, @@ -199,7 +209,7 @@ test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'mar ListIdentifiers => { header => [ @header[1..3] ], resumptionToken => { - content => "marcxml/3/1970-01-01T00:00:00Z/$date_to/", + content => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0", cursor => 3, }, }, @@ -207,12 +217,12 @@ test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'mar test_query( 'ListIdentifiers with resumptionToken 1', - { verb => 'ListIdentifiers', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to/" }, + { verb => 'ListIdentifiers', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0" }, { ListIdentifiers => { header => [ @header[4..6] ], resumptionToken => { - content => "marcxml/6/1970-01-01T00:00:00Z/$date_to/", + content => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0", cursor => 6, }, }, @@ -222,12 +232,12 @@ test_query( test_query( 'ListIdentifiers with resumptionToken 2', - { verb => 'ListIdentifiers', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to/" }, + { verb => 'ListIdentifiers', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0" }, { ListIdentifiers => { header => [ @header[7..9] ], resumptionToken => { - content => "marcxml/9/1970-01-01T00:00:00Z/$date_to/", + content => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0", cursor => 9, }, }, @@ -237,7 +247,7 @@ test_query( test_query( 'ListIdentifiers with resumptionToken 3, response without resumption', - { verb => 'ListIdentifiers', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to/" }, + { verb => 'ListIdentifiers', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0" }, { ListIdentifiers => { header => $header[10], @@ -246,11 +256,7 @@ test_query( }, ); -<<<<<<< HEAD test_query('ListRecords marcxml without metadataPrefix', {verb => 'ListRecords'}, { -======= -test_query('ListRecords without metadataPrefix', {verb => 'ListRecords'}, { ->>>>>>> 523f474... Bug 17493 Improve OAI Server tests error => { code => 'badArgument', content => "Required argument 'metadataPrefix' was undefined", @@ -261,7 +267,7 @@ test_query('ListRecords marcxml', {verb => 'ListRecords', metadataPrefix => 'mar ListRecords => { record => [ @marcxml[1..3] ], resumptionToken => { - content => "marcxml/3/1970-01-01T00:00:00Z/$date_to/", + content => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0", cursor => 3, }, }, @@ -269,11 +275,11 @@ test_query('ListRecords marcxml', {verb => 'ListRecords', metadataPrefix => 'mar test_query( 'ListRecords marcxml with resumptionToken 1', - { verb => 'ListRecords', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to/" }, + { verb => 'ListRecords', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0" }, { ListRecords => { record => [ @marcxml[4..6] ], resumptionToken => { - content => "marcxml/6/1970-01-01T00:00:00Z/$date_to/", + content => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0", cursor => 6, }, }, @@ -281,11 +287,11 @@ test_query( test_query( 'ListRecords marcxml with resumptionToken 2', - { verb => 'ListRecords', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to/" }, + { verb => 'ListRecords', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0" }, { ListRecords => { record => [ @marcxml[7..9] ], resumptionToken => { - content => "marcxml/9/1970-01-01T00:00:00Z/$date_to/", + content => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0", cursor => 9, }, }, @@ -294,7 +300,7 @@ test_query( # Last record, so no resumption token test_query( 'ListRecords marcxml with resumptionToken 3, response without resumption', - { verb => 'ListRecords', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to/" }, + { verb => 'ListRecords', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0" }, { ListRecords => { record => $marcxml[10], }, @@ -304,7 +310,7 @@ test_query('ListRecords oai_dc', {verb => 'ListRecords', metadataPrefix => 'oai_ ListRecords => { record => [ @oaidc[1..3] ], resumptionToken => { - content => "oai_dc/3/1970-01-01T00:00:00Z/$date_to/", + content => "oai_dc/3/1970-01-01T00:00:00Z/$date_to//0", cursor => 3, }, }, @@ -312,11 +318,11 @@ test_query('ListRecords oai_dc', {verb => 'ListRecords', metadataPrefix => 'oai_ test_query( 'ListRecords oai_dc with resumptionToken 1', - { verb => 'ListRecords', resumptionToken => "oai_dc/3/1970-01-01T00:00:00Z/$date_to/" }, + { verb => 'ListRecords', resumptionToken => "oai_dc/3/1970-01-01T00:00:00Z/$date_to//0" }, { ListRecords => { record => [ @oaidc[4..6] ], resumptionToken => { - content => "oai_dc/6/1970-01-01T00:00:00Z/$date_to/", + content => "oai_dc/6/1970-01-01T00:00:00Z/$date_to//0", cursor => 6, }, }, @@ -324,11 +330,11 @@ test_query( test_query( 'ListRecords oai_dc with resumptionToken 2', - { verb => 'ListRecords', resumptionToken => "oai_dc/6/1970-01-01T00:00:00Z/$date_to/" }, + { verb => 'ListRecords', resumptionToken => "oai_dc/6/1970-01-01T00:00:00Z/$date_to//0" }, { ListRecords => { record => [ @oaidc[7..9] ], resumptionToken => { - content => "oai_dc/9/1970-01-01T00:00:00Z/$date_to/", + content => "oai_dc/9/1970-01-01T00:00:00Z/$date_to//0", cursor => 9, }, }, @@ -337,7 +343,7 @@ test_query( # Last record, so no resumption token test_query( 'ListRecords oai_dc with resumptionToken 3, response without resumption', - { verb => 'ListRecords', resumptionToken => "oai_dc/9/1970-01-01T00:00:00Z/$date_to/" }, + { verb => 'ListRecords', resumptionToken => "oai_dc/9/1970-01-01T00:00:00Z/$date_to//0" }, { ListRecords => { record => $oaidc[10], }, -- 2.9.2