From fbcb17eaf38f16b17b37f72f4bc6280ce4057286 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 9 Dec 2016 14:14:49 +0100 Subject: [PATCH] Bug 15108: [QA Follow-up] Remove truncate Content-Type: text/plain; charset=utf-8 Truncate operations cause an implicit commit, and so cannot be rolled back. So we need to replace it by a DELETE and adjust the code so that it does not assume numbering biblionumbers from 1, etc. Signed-off-by: Marcel de Rooy --- t/db_dependent/OAI/Server.t | 53 ++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/t/db_dependent/OAI/Server.t b/t/db_dependent/OAI/Server.t index 8a177c0..cd643b7 100644 --- a/t/db_dependent/OAI/Server.t +++ b/t/db_dependent/OAI/Server.t @@ -56,11 +56,11 @@ my $schema = Koha::Database->schema; $schema->storage->txn_begin; my $dbh = C4::Context->dbh; -$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'); +$dbh->do('DELETE FROM biblio'); +$dbh->do('DELETE FROM deletedbiblio'); +$dbh->do('DELETE FROM deletedbiblioitems'); +$dbh->do('DELETE FROM deleteditems'); my $date_added = DateTime->now() . 'Z'; my $date_to = substr($date_added, 0, 10) . 'T23:59:59Z'; @@ -68,24 +68,24 @@ my (@header, @marcxml, @oaidc); my $sth = $dbh->prepare('SELECT timestamp FROM biblioitems WHERE biblionumber=?'); # Add 10 biblio records -foreach( 1..10 ) { +foreach my $index ( 0..9 ) { my $record = MARC::Record->new(); - $record->append_fields( MARC::Field->new('245', '', '', 'a' => "Title $_" ) ); + $record->append_fields( MARC::Field->new('245', '', '', 'a' => "Title $index" ) ); 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 => $timestamp, identifier => "TEST:$biblionumber" }; + push @header, { datestamp => $timestamp, identifier => "TEST:$biblionumber" }; delete $record->{$_} for (('xmlns','xmlns:xsi','xsi:schemaLocation')); - $oaidc[$biblionumber] = { - header => $header[$biblionumber], + push @oaidc, { + header => $header[$index], metadata => { 'oai_dc:dcCollection' => { 'oai_dc:dc' => { 'dc:title' => { - 'content' => "Title $biblionumber", + 'content' => "Title $index", 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/' }, 'dc:language' => { @@ -101,11 +101,11 @@ foreach( 1..10 ) { }, }, }; - $marcxml[$biblionumber] = { - header => $header[$biblionumber], + push @marcxml, { + header => $header[$index], metadata => { collection => { - record => $record, + record => $record, "xmlns" => "http://www.loc.gov/MARC21/slim", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation" => "http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd", @@ -188,10 +188,9 @@ test_query('ListIdentifiers without metadataPrefix', {verb => 'ListIdentifiers'} }, }); - test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'marcxml'}, { ListIdentifiers => { - header => [ @header[1..3] ], + header => [ @header[0..2] ], resumptionToken => { content => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0", cursor => 3, @@ -201,7 +200,7 @@ test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'mar test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'marcxml'}, { ListIdentifiers => { - header => [ @header[1..3] ], + header => [ @header[0..2] ], resumptionToken => { content => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0", cursor => 3, @@ -214,7 +213,7 @@ test_query( { verb => 'ListIdentifiers', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0" }, { ListIdentifiers => { - header => [ @header[4..6] ], + header => [ @header[3..5] ], resumptionToken => { content => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0", cursor => 6, @@ -229,7 +228,7 @@ test_query( { verb => 'ListIdentifiers', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0" }, { ListIdentifiers => { - header => [ @header[7..9] ], + header => [ @header[6..8] ], resumptionToken => { content => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0", cursor => 9, @@ -244,7 +243,7 @@ test_query( { verb => 'ListIdentifiers', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0" }, { ListIdentifiers => { - header => $header[10], + header => $header[9], }, }, @@ -259,7 +258,7 @@ test_query('ListRecords marcxml without metadataPrefix', {verb => 'ListRecords'} test_query('ListRecords marcxml', {verb => 'ListRecords', metadataPrefix => 'marcxml'}, { ListRecords => { - record => [ @marcxml[1..3] ], + record => [ @marcxml[0..2] ], resumptionToken => { content => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0", cursor => 3, @@ -271,7 +270,7 @@ test_query( 'ListRecords marcxml with resumptionToken 1', { verb => 'ListRecords', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to//0" }, { ListRecords => { - record => [ @marcxml[4..6] ], + record => [ @marcxml[3..5] ], resumptionToken => { content => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0", cursor => 6, @@ -283,7 +282,7 @@ test_query( 'ListRecords marcxml with resumptionToken 2', { verb => 'ListRecords', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to//0" }, { ListRecords => { - record => [ @marcxml[7..9] ], + record => [ @marcxml[6..8] ], resumptionToken => { content => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0", cursor => 9, @@ -296,13 +295,13 @@ test_query( 'ListRecords marcxml with resumptionToken 3, response without resumption', { verb => 'ListRecords', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to//0" }, { ListRecords => { - record => $marcxml[10], + record => $marcxml[9], }, }); test_query('ListRecords oai_dc', {verb => 'ListRecords', metadataPrefix => 'oai_dc'}, { ListRecords => { - record => [ @oaidc[1..3] ], + record => [ @oaidc[0..2] ], resumptionToken => { content => "oai_dc/3/1970-01-01T00:00:00Z/$date_to//0", cursor => 3, @@ -314,7 +313,7 @@ test_query( 'ListRecords oai_dc with resumptionToken 1', { verb => 'ListRecords', resumptionToken => "oai_dc/3/1970-01-01T00:00:00Z/$date_to//0" }, { ListRecords => { - record => [ @oaidc[4..6] ], + record => [ @oaidc[3..5] ], resumptionToken => { content => "oai_dc/6/1970-01-01T00:00:00Z/$date_to//0", cursor => 6, @@ -326,7 +325,7 @@ test_query( 'ListRecords oai_dc with resumptionToken 2', { verb => 'ListRecords', resumptionToken => "oai_dc/6/1970-01-01T00:00:00Z/$date_to//0" }, { ListRecords => { - record => [ @oaidc[7..9] ], + record => [ @oaidc[6..8] ], resumptionToken => { content => "oai_dc/9/1970-01-01T00:00:00Z/$date_to//0", cursor => 9, @@ -339,7 +338,7 @@ test_query( 'ListRecords oai_dc with resumptionToken 3, response without resumption', { verb => 'ListRecords', resumptionToken => "oai_dc/9/1970-01-01T00:00:00Z/$date_to//0" }, { ListRecords => { - record => $oaidc[10], + record => $oaidc[9], }, }); -- 2.1.4