From 5d7625d8ff661b77966f508ff5b89319de13a384 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 | 51 ++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 21 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 7fee298..43332e6 100644 --- a/t/db_dependent/OAI/Server.t +++ b/t/db_dependent/OAI/Server.t @@ -52,7 +52,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; @@ -61,23 +61,26 @@ 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, @metadata, @record); +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')); $metadata[$biblionumber] = { collection => { record => $record, @@ -89,6 +92,7 @@ map { header => $header[$biblionumber], metadata => $metadata[$biblionumber], }; + sleep 2; $biblionumber => undef; } (1..10); @@ -130,7 +134,11 @@ sub test_query { $response = XMLin($stdout); } - is_deeply($response, \%full_expected, $test); + unless (is_deeply($response, \%full_expected, $test)) { + diag "PARAM:" . Dump($param) . + "EXPECTED: " . Dump(\%full_expected) . + "RESPONSE: " . Dump($response); + } } @@ -144,6 +152,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', }, @@ -163,7 +176,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, }, }, @@ -173,7 +186,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, }, }, @@ -181,12 +194,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, }, }, @@ -196,12 +209,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, }, }, @@ -211,7 +224,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], @@ -231,7 +244,7 @@ test_query('ListRecords', {verb => 'ListRecords', metadataPrefix => 'marcxml'}, ListRecords => { record => [ @record[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, }, }, @@ -239,11 +252,11 @@ test_query('ListRecords', {verb => 'ListRecords', metadataPrefix => 'marcxml'}, test_query( 'ListRecords 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 => [ @record[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, }, }, @@ -251,11 +264,11 @@ test_query( test_query( 'ListRecords 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 => [ @record[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, }, }, @@ -264,7 +277,7 @@ test_query( # Last record, so no resumption token test_query( 'ListRecords 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 => $record[10], }, -- 2.9.2