Bug 18601: OAI/Sets.t mangles data due to truncate in ModOAISetsBiblios
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Mon, 15 May 2017 07:58:04 +0000 (09:58 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 13 Jun 2017 19:18:59 +0000 (16:18 -0300)
This patch replaces the TRUNCATE statement in ModOAISetsBiblios by a
DELETE statement. A truncate will cause an implicit commit and will
therefore commit the transaction started in the test script.

Also simplifying the module load in the test script.

Test plan:
Do not apply this patch and observe that biblio records are added to your
database by running t/db_dependent/OAI/Sets.t.
Apply this patch, run the test again and verify that it does no longer
add records to your biblio table.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
C4/OAI/Sets.pm
t/db_dependent/OAI/Sets.t

index e2d8586..62c98d8 100644 (file)
@@ -525,7 +525,7 @@ sub CalcOAISetsBiblio {
     };
     ModOAISetsBiblios($oai_sets_biblios);
 
-ModOAISetsBiblios truncate oai_sets_biblios table and call AddOAISetsBiblios.
+ModOAISetsBiblios deletes all records from oai_sets_biblios table and calls AddOAISetsBiblios.
 This table is then used in opac/oai.pl.
 
 =cut
@@ -537,7 +537,7 @@ sub ModOAISetsBiblios {
 
     my $dbh = C4::Context->dbh;
     my $query = qq{
-        TRUNCATE TABLE oai_sets_biblios
+        DELETE FROM oai_sets_biblios
     };
     my $sth = $dbh->prepare($query);
     $sth->execute;
index b1ce6ab..33b12e0 100644 (file)
 # with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
-use C4::Context;
-use Test::More tests => 148;
+
+use Test::More tests => 144;
 use Test::MockModule;
 use Test::Warn;
+use MARC::Record;
 
+use Koha::Database;
+use C4::Biblio;
+use C4::OAI::Sets;
 
-BEGIN {
-    use_ok('C4::OAI::Sets');
-    use_ok('MARC::Record');
-    use_ok('C4::Biblio');
-}
-can_ok(
-    'C4::OAI::Sets', qw(
-        GetOAISets
-        GetOAISet
-        GetOAISetBySpec
-        ModOAISet
-        DelOAISet
-        AddOAISet
-        GetOAISetsMappings
-        GetOAISetMappings
-        ModOAISetMappings
-        GetOAISetsBiblio
-        DelOAISetsBiblio
-        CalcOAISetsBiblio
-        ModOAISetsBiblios
-        UpdateOAISetsBiblio
-        AddOAISetsBiblios )
-);
-
-
+my $schema  = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
+
 $dbh->do('DELETE FROM oai_sets');
 $dbh->do('DELETE FROM oai_sets_descriptions');
 $dbh->do('DELETE FROM oai_sets_mappings');
@@ -632,4 +612,4 @@ sub create_helper_biblio {
     return $biblionumber;
 }
 
-$dbh->rollback;
\ No newline at end of file
+$schema->storage->txn_rollback;