Bug 14334: Remove AutoCommit from tests
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 7 Dec 2018 17:14:06 +0000 (14:14 -0300)
committerFridolin Somers <fridolin.somers@biblibre.com>
Wed, 2 Jan 2019 10:20:36 +0000 (11:20 +0100)
And use a DBIx transaction instead.

Test plan:
prove that the test files modified by this patch are passing

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 64242cabea21e9ee7673666cad88eb403d1053d6)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 10148dc26ba801d3f86401dc24a3fb5b6618a02b)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 61784f5e2607afaa1a89ee3a4384ea0155bacba0)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

35 files changed:
t/db_dependent/Acquisition/FillWithDefaultValues.t
t/db_dependent/AdditionalField.t
t/db_dependent/Auth_with_cas.t
t/db_dependent/BackgroundJob.t
t/db_dependent/Charset.t
t/db_dependent/Circulation/CheckIfIssuedToPatron.t
t/db_dependent/Circulation/CheckValidBarcode.t
t/db_dependent/Circulation/GetHardDueDate.t
t/db_dependent/Circulation/OfflineOperation.t
t/db_dependent/ColumnsSettings.t
t/db_dependent/Contract.t
t/db_dependent/Fines.t
t/db_dependent/Koha/GetDailyQuote.t
t/db_dependent/Koha/Item/Search/Field.t
t/db_dependent/Koha_Misc_Files.t
t/db_dependent/Labels/t_Batch.t
t/db_dependent/Languages.t
t/db_dependent/Letters/GetLetterTemplates.t
t/db_dependent/Letters/GetLettersAvailableForALibrary.t
t/db_dependent/MarcModificationTemplates.t
t/db_dependent/MungeMarcPrice.t
t/db_dependent/NewsChannels.t
t/db_dependent/Overdues.t
t/db_dependent/Record.t
t/db_dependent/Record/marcrecord2csv.t
t/db_dependent/RotatingCollections.t
t/db_dependent/Serials.t
t/db_dependent/Serials/Claims.t
t/db_dependent/Serials/Frequency.t
t/db_dependent/Serials/GetNextSeq.t
t/db_dependent/Serials/Numberpattern.t
t/db_dependent/Stats.t
t/db_dependent/Virtualshelves.t
t/db_dependent/XISBN.t
t/db_dependent/sysprefs.t

index 531aa78..f70ae1e 100755 (executable)
@@ -7,10 +7,10 @@ use MARC::Field;
 
 use C4::Context;
 use C4::Acquisition qw( FillWithDefaultValues );
+use Koha::Database;
 
-my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 
 my $biblio_module  = Test::MockModule->new('C4::Biblio');
 my $default_author = 'default author';
index 0a56ce0..2a77eda 100644 (file)
@@ -5,10 +5,11 @@ use Test::More tests => 40;
 
 use C4::Context;
 use Koha::AdditionalField;
+use Koha::Database;
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 $dbh->do( q|DELETE FROM additional_fields| );
 $dbh->do( q|DELETE FROM additional_field_values| );
@@ -289,6 +290,3 @@ is_deeply ( $af1->values, {$subscriptionid2 => qq|value_for_af1_$subscriptionid2
 $af1->delete_values;
 $af1->fetch_values;
 is_deeply ( $af1->values, {}, "fetch_values: no values" );
-
-
-$dbh->rollback;
index d15bf5e..bb001ec 100755 (executable)
@@ -22,6 +22,7 @@ use CGI;
 
 use t::lib::Mocks;
 use C4::Context;
+use Koha::Database;
 
 BEGIN {
     use_ok('C4::Auth_with_cas');
@@ -34,10 +35,9 @@ BEGIN {
             /);
 }
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-# Start transaction
-$dbh->{ AutoCommit } = 0;
-$dbh->{ RaiseError } = 1;
 
 C4::Context->disable_syspref_cache();
 t::lib::Mocks::mock_preference('OPACBaseURL','http://localhost');
@@ -63,8 +63,3 @@ $ENV{SCRIPT_NAME} = '/cgi-bin/koha/circ/circulation-home.pl';
 is(C4::Auth_with_cas::_url_with_get_params($cgi, 'intranet'),
     "$staff_base_url/cgi-bin/koha/circ/circulation-home.pl?bar=baz",
    "Intranet URL should be returned when using intranet login (Bug 13507)");
-
-
-
-$dbh->rollback;
-
index 7005594..ae5c25a 100644 (file)
@@ -5,15 +5,15 @@ use C4::Auth;
 use CGI qw ( -utf8 );
 use Test::More tests => 18;
 
+use Koha::Database;
+
 BEGIN {
     use_ok('C4::BackgroundJob');
 }
 my $query = new CGI;
 
-# Generate a session id
-my $dbh     = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 
 my $session = C4::Auth::get_session;
 $session->flush;
index ea649ae..99837c2 100644 (file)
@@ -6,9 +6,11 @@ use C4::Biblio qw( AddBiblio GetMarcFromKohaField );
 use C4::Context;
 use C4::Charset qw( SanitizeRecord );
 
+use Koha::Database;
+
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 my $frameworkcode = q||;
 
@@ -47,5 +49,3 @@ $record->append_fields(
 ( $sanitized_record, $has_been_modified ) = C4::Charset::SanitizeRecord( $record, $biblionumber );
 is( $has_been_modified, 1, 'SanitizeRecord: the record has been modified' );
 is( $url, $sanitized_record->subfield($url_field, $url_subfield), 'SanitizeRecord: the url has not been modified');
-
-$dbh->rollback;
index d51e4ba..cf0d60b 100644 (file)
@@ -31,13 +31,10 @@ use MARC::Record;
 
 my $schema = Koha::Database->schema;
 $schema->storage->txn_begin;
+my $dbh = C4::Context->dbh;
 
 my $builder = t::lib::TestBuilder->new;
 
-my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
-
 $dbh->do(q|DELETE FROM issues|);
 $dbh->do(q|DELETE FROM items|);
 $dbh->do(q|DELETE FROM borrowers|);
@@ -125,6 +122,3 @@ $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $bib
 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
 is( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' );
-
-$dbh->rollback();
-
index 505955f..527a133 100644 (file)
@@ -22,6 +22,7 @@ use Test::More tests => 10;
 use C4::Circulation;
 use C4::Biblio;
 use C4::Items;
+use Koha::Database;
 use Koha::Library;
 
 
@@ -29,9 +30,9 @@ BEGIN {
     use_ok('C4::Circulation');
 }
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 $dbh->do(q|DELETE FROM issues|);
 $dbh->do(q|DELETE FROM items|);
@@ -81,6 +82,3 @@ $check_valid_barcode = C4::Circulation::CheckValidBarcode($barcode3);
 is( $check_valid_barcode, 1, 'CheckValidBarcode returns true' );
 $check_valid_barcode = C4::Circulation::CheckValidBarcode('wrong barcode');
 is( $check_valid_barcode, 0, 'CheckValidBarcode with an invalid barcode returns false' );
-
-$dbh->rollback();
-
index 9cbf5b1..fd54439 100644 (file)
@@ -3,6 +3,7 @@
 use Modern::Perl;
 use C4::Context;
 use DateTime;
+use Koha::Database;
 use Koha::DateUtils;
 use Koha::IssuingRules;
 use Koha::Library;
@@ -20,10 +21,9 @@ can_ok(
       )
 );
 
-#Start transaction
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 $dbh->do(q|DELETE FROM issues|);
 $dbh->do(q|DELETE FROM items|);
@@ -395,6 +395,3 @@ is_deeply(
     ],
     "GetHardDueDate returns the duedate and the duedatecompare"
 );
-
-#End transaction
-$dbh->rollback;
index 387ae64..df5b713 100644 (file)
@@ -2,6 +2,7 @@
 
 use Modern::Perl;
 use C4::Circulation;
+use Koha::Database;
 use Koha::Library;
 
 use Test::More tests => 7;
@@ -19,10 +20,9 @@ can_ok(
       )
 );
 
-#Start transaction
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 $dbh->do(q|DELETE FROM issues|);
 $dbh->do(q|DELETE FROM borrowers|);
@@ -94,6 +94,3 @@ is( DeleteOfflineOperation($offline_id),
 
 #is (DeleteOfflineOperation(), undef, 'DeleteOfflineOperation without id returns undef');
 #is (DeleteOfflineOperation(-1),undef, 'DeleteOfflineOperation with a wrong id returns undef');#FIXME
-
-#End transaction
-$dbh->rollback;
index da75931..ebf5272 100644 (file)
@@ -6,9 +6,11 @@ use Test::MockModule;
 
 use C4::Context;
 use C4::Utils::DataTables::ColumnsSettings;
+use Koha::Database;
+
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 $dbh->do(q|DELETE FROM columns_settings|);
 
@@ -180,5 +182,3 @@ for my $m ( keys %$modules ) {
         }
     }
 }
-
-$dbh->rollback;
index 9ca0e18..1a6bafd 100644 (file)
@@ -20,6 +20,7 @@
 use Modern::Perl;
 
 use C4::Context;
+use Koha::Database;
 use Koha::DateUtils;
 use Koha::Acquisition::Booksellers;
 
@@ -31,9 +32,9 @@ BEGIN {
     use_ok('C4::Contract');
 }
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 $dbh->do(q|DELETE FROM aqbasket|);
 $dbh->do(q|DELETE FROM aqcontract|);
@@ -148,5 +149,3 @@ $del_status = DelContract( { contractnumber => $my_contract_id2 } );
 is( $del_status, 1, 'DelContract returns true' );
 $contracts = GetContracts();
 is( @$contracts, 0, 'DelContract deletes a contract' );
-
-$dbh->rollback;
index 1f273ba..7a0ede4 100644 (file)
@@ -9,12 +9,9 @@ use Koha::DateUtils;
 
 use Test::More tests => 5;
 
-#Start transaction
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-my $schema = Koha::Database->new()->schema();
-
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 $dbh->do(q|DELETE FROM issuingrules|);
 
index 08ec0bb..f15a927 100644 (file)
@@ -21,6 +21,7 @@ use Test::More tests => 12;
 
 use C4::Koha qw( GetDailyQuote );
 use DateTime::Format::MySQL;
+use Koha::Database;
 use Koha::DateUtils qw(dt_from_string);
 
 BEGIN {
@@ -29,12 +30,10 @@ BEGIN {
 
 can_ok('C4::Koha', qw( GetDailyQuote ));
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
 
-# Start transaction
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
-
 # Setup stage
 $dbh->do("DELETE FROM quotes");
 
@@ -84,5 +83,3 @@ $dbh->do(q|INSERT INTO `quotes` VALUES
 
 $quote = GetDailyQuote();
 is( $quote->{id}, 6, ' GetDailyQuote returns the only existing quote' );
-
-$dbh->rollback;
index 1cbb544..9e73880 100755 (executable)
@@ -4,13 +4,14 @@ use Modern::Perl;
 use Test::More tests => 11;
 
 use C4::Context;
+use Koha::Database;
 
 use_ok('Koha::Item::Search::Field');
 import Koha::Item::Search::Field qw(AddItemSearchField ModItemSearchField
     DelItemSearchField GetItemSearchField GetItemSearchFields);
 
-my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 
 # Start with empty table.
 foreach my $field (GetItemSearchFields()) {
@@ -35,5 +36,3 @@ is_deeply($field, {name => 'foo', label => 'Foo', tagfield => '001', tagsubfield
 ok((defined ModItemSearchField({name => 'foo', label => 'Foobar', tagfield => '100', 'tagsubfield' => 'a'})), "successful mod");
 $field = GetItemSearchField('foo');
 is_deeply($field, {name => 'foo', label => 'Foobar', tagfield => '100', tagsubfield => 'a', authorised_values_category => undef});
-
-$dbh->rollback;
index 18fbab0..689fb52 100755 (executable)
@@ -5,15 +5,16 @@
 
 use Modern::Perl;
 use C4::Context;
+use Koha::Database;
 use Test::More tests => 30;
 
 BEGIN {
     use_ok('Koha::Misc::Files');
 }
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 ## new() parameter handling check
 is(Koha::Misc::Files->new(), undef, "new() param check test/0");
@@ -84,6 +85,3 @@ is(scalar @$files_a_123_infos, 0, "GetFilesInfo() result count after DelAllFiles
 my $number_of_deleted_files_b_221 = $mf_b_221->DelAllFiles();
 is( $number_of_deleted_files_b_221, 1, "DelAllFiles returns the number of deleted files/2" );
 is(scalar @{$mf_b_221->GetFilesInfo()}, 0, "GetFilesInfo() result count after DelAllFiles()/2");
-
-$dbh->rollback;
-
index 4992946..3052692 100644 (file)
@@ -29,16 +29,16 @@ use t::lib::TestBuilder;
 use C4::Context;
 use C4::Items;
 use C4::Biblio;
+use Koha::Database;
 use Koha::Libraries;
 
 BEGIN {
     use_ok('C4::Labels::Batch');
 }
 
-# Start transaction
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 my $builder = t::lib::TestBuilder->new;
 $builder->build({ source => 'Branch', value => { branchcode => 'CPL' } })
@@ -119,5 +119,3 @@ is_deeply($updated_batch, $batch, "Updated batch object is correct.");
 # Testing Batch->delete() method.
 my $del_results = $batch->delete();
 ok($del_results eq 0, "Batch->delete() success.");
-
-$dbh->rollback;
index 8e8d372..5afdd80 100755 (executable)
@@ -3,22 +3,22 @@
 # This Koha test module is a stub!  
 # Add more tests here!!!
 
-use strict;
-use warnings;
+use Modern::Perl;
 
 use Test::More tests => 17;
 use List::Util qw(first);
 use Data::Dumper;
 use Test::Warn;
 use t::lib::Mocks;
+use Koha::Database;
 
 BEGIN {
     use_ok('C4::Languages');
 }
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 isnt(C4::Languages::_get_themes(), undef, 'testing _get_themes doesnt return undef');
 
@@ -94,5 +94,3 @@ $sth->execute();
 my $LangRfc4646 = $sth->fetchall_arrayref({});
 
 is(scalar(@$LangRfc4646),scalar(@$DistinctLangRfc4646),"No unexpected language_rfc4646_to_iso639 duplicates.");
-
-$dbh->rollback;
index fd74285..65d05f8 100644 (file)
@@ -3,10 +3,11 @@ use Test::More tests => 7;
 
 use C4::Context;
 use C4::Letters qw( GetLetterTemplates );
+use Koha::Database;
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 $dbh->do(q|DELETE FROM letter|);
 
index 4649a33..97513a3 100644 (file)
@@ -3,10 +3,11 @@ use Test::More tests => 19;
 
 use C4::Context;
 use C4::Letters qw( GetLettersAvailableForALibrary DelLetter );
+use Koha::Database;
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 $dbh->do(q|DELETE FROM letter|);
 
index d2fcffc..fc8ffb4 100644 (file)
@@ -2,15 +2,16 @@ use Modern::Perl;
 
 use Test::More tests => 96;
 
+use Koha::Database;
 use Koha::SimpleMARC;
 
 use_ok("MARC::Field");
 use_ok("MARC::Record");
 use_ok("C4::MarcModificationTemplates");
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 $dbh->do(q|DELETE FROM marc_modification_templates|);
 
index 78a599f..12a3d6a 100755 (executable)
@@ -1,20 +1,18 @@
 #!/usr/bin/perl
 
-use strict;
-use warnings;
+use Modern::Perl;
 use C4::Biblio;
+use Koha::Database;
 use Koha::Acquisition::Currencies;
 use Test::More;
-use utf8;
 
 # work around wide character warnings
 binmode Test::More->builder->output, ":encoding(UTF-8)";
 binmode Test::More->builder->failure_output, ":encoding(UTF-8)";
 
-# start transaction
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 # set some test price strings and expected output
 my @prices2test=( { string => '25,5 £, $34,55, $LD35',       expected => '34.55' },
@@ -69,6 +67,3 @@ foreach my $price (@prices2test) {
         "got expected price from $price->{'string'} (using ISO code as currency name)",
     );
 }
-
-# Cleanup
-$dbh->rollback;
index ce15247..928ddd5 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 
 use Modern::Perl;
+use Koha::Database;
 use Koha::DateUtils;
 use Koha::Libraries;
 
@@ -10,12 +11,10 @@ BEGIN {
     use_ok('C4::NewsChannels');
 }
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
 
-# Start transaction
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
-
 # Add LIB1, if it doesn't exist.
 my $addbra = 'LIB1';
 unless ( Koha::Libraries->find($addbra) ) {
@@ -226,5 +225,3 @@ subtest 'Regression tests on author title, firstname, and surname.', sub {
     ok($check==3,'Both with and without author data tested');
     done_testing();
 };
-
-$dbh->rollback;
index bb5265f..30ca444 100644 (file)
@@ -4,14 +4,15 @@ use Modern::Perl;
 use Test::More tests => 16;
 
 use C4::Context;
+use Koha::Database;
 use Koha::Libraries;
 use_ok('C4::Overdues');
 can_ok('C4::Overdues', 'GetOverdueMessageTransportTypes');
 can_ok('C4::Overdues', 'GetBranchcodesWithOverdueRules');
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 $dbh->do(q|DELETE FROM letter|);
 $dbh->do(q|DELETE FROM message_queue|);
index 62c1564..ae56dcd 100755 (executable)
@@ -7,15 +7,14 @@ use MARC::Record;
 
 use t::lib::Mocks;
 use C4::Context;
+use Koha::Database;
 
 BEGIN {
         use_ok('C4::Record');
 }
 
-my $dbh = C4::Context->dbh;
-# Start transaction
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 
 t::lib::Mocks::mock_preference( "BibtexExportAdditionalFields", q{} );
 
index e5cf0d3..45f1f94 100644 (file)
@@ -10,12 +10,13 @@ use Text::CSV::Encoded;
 use C4::Biblio qw( AddBiblio );
 use C4::Context;
 use C4::Record;
+use Koha::Database;
 
 use t::lib::TestBuilder;
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 my $builder = t::lib::TestBuilder->new;
 my $module_biblio = Test::MockModule->new('C4::Biblio');
index bdf3801..5496498 100644 (file)
@@ -21,6 +21,7 @@ use Test::More tests => 51;
 use C4::Context;
 use C4::RotatingCollections;
 use C4::Biblio;
+use Koha::Database;
 use Koha::Library;
 
 BEGIN {
@@ -44,10 +45,9 @@ can_ok(
       )
 );
 
-#Start transaction
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 #Start Tests
 $dbh->do(q|DELETE FROM issues |);
@@ -331,7 +331,3 @@ is(
     $countcollection + 1,
     "Two Collections have been deleted"
 );
-
-#End transaction
-$dbh->rollback;
-
index de623fe..c1ab854 100755 (executable)
@@ -6,7 +6,6 @@
 use Modern::Perl;
 use YAML;
 
-use CGI qw ( -utf8 );
 use C4::Serials;
 use C4::Serials::Frequency;
 use C4::Serials::Numberpattern;
@@ -14,6 +13,7 @@ use C4::Debug;
 use C4::Biblio;
 use C4::Budgets;
 use C4::Items;
+use Koha::Database;
 use Koha::DateUtils;
 use Koha::Acquisition::Booksellers;
 use t::lib::Mocks;
@@ -24,12 +24,10 @@ BEGIN {
     use_ok('C4::Serials');
 }
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
 
-# Start transaction
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
-
 my $builder = t::lib::TestBuilder->new();
 
 # This could/should be used for all untested methods
@@ -351,8 +349,6 @@ subtest "Do not generate an expected if one already exists" => sub {
     is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and not create another if exists" );
 };
 
-$dbh->rollback;
-
 sub get_biblio {
     my $bib = MARC::Record->new();
     $bib->append_fields(
index 3acb2d3..6458497 100644 (file)
@@ -3,14 +3,15 @@ use Test::More tests => 17;
 
 use C4::Acquisition;
 use C4::Budgets;
+use Koha::Database;
 use Koha::Acquisition::Booksellers;
 use_ok('C4::Serials');
 
 use Koha::DateUtils qw( dt_from_string output_pref );
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 $dbh->do(q|DELETE FROM issues|);
 $dbh->do(q|DELETE FROM subscription|);
index e57ff34..ac58981 100644 (file)
@@ -1,12 +1,13 @@
 #!/usr/bin/perl
 
 use C4::Context;
+use Koha::Database;
 use Test::More tests => 27;
 use Modern::Perl;
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 use C4::Serials::Frequency;
 
@@ -86,5 +87,3 @@ is(scalar @frequencies, 1, "There is one frequency");
 DelSubscriptionFrequency($id2);
 @frequencies = GetSubscriptionFrequencies();
 is(scalar @frequencies, 0, "There is no frequency");
-
-$dbh->rollback;
index fc6e3f2..4b277d0 100644 (file)
@@ -3,10 +3,11 @@
 use C4::Context;
 use Test::More tests => 32;
 use Modern::Perl;
+use Koha::Database;
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 use C4::Serials::Frequency;
 use C4::Serials;
@@ -264,9 +265,6 @@ $publisheddate = GetNextDate($subscription, $publisheddate);
 $seq = _next_seq($subscription, $pattern, $publisheddate);
 is($seq, 'Z: 4, Y: 5, X: 1');
 
-
-$dbh->rollback;
-
 sub _next_seq {
     my ($subscription, $pattern, $publisheddate) = @_;
     my $seq;
index 6a05325..88da43f 100644 (file)
@@ -1,12 +1,14 @@
 #!/usr/bin/perl
 
-use C4::Context;
-use Test::More tests => 95;
 use Modern::Perl;
+use Test::More tests => 95;
 
+use C4::Context;
+use Koha::Database;
+
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 use C4::Serials::Numberpattern;
 
@@ -99,5 +101,3 @@ is(scalar @numberpatterns, 1, "There is one numberpattern");
 DelSubscriptionNumberpattern($id2);
 @numberpatterns = GetSubscriptionNumberpatterns();
 is(scalar @numberpatterns, 0, "There is no numberpattern");
-
-$dbh->rollback;
index 7675a16..c03bbc4 100644 (file)
@@ -2,6 +2,7 @@
 
 use Modern::Perl;
 use C4::Stats;
+use Koha::Database;
 
 use Test::More tests => 20;
 
@@ -15,10 +16,9 @@ can_ok(
       )
 );
 
-#Start transaction
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 #
 # Test UpdateStats
@@ -170,6 +170,3 @@ is( $line->{location}, undef,
 
 is (TotalPaid (),undef,"TotalPaid returns undef if no params are given");
 # More tests to write!
-
-#End transaction
-$dbh->rollback;
index 8bc51c6..c617776 100644 (file)
@@ -5,6 +5,7 @@ use Test::More tests => 6;
 use DateTime::Duration;
 
 use C4::Context;
+use Koha::Database;
 use Koha::DateUtils;
 use Koha::Virtualshelves;
 use Koha::Virtualshelfshares;
@@ -15,8 +16,9 @@ use t::lib::TestBuilder;
 
 my $builder = t::lib::TestBuilder->new;
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
 teardown();
 
 subtest 'CRUD' => sub {
index c656a38..fd9a223 100755 (executable)
@@ -11,6 +11,7 @@ use C4::Biblio;
 use C4::XISBN;
 use C4::Context;
 use C4::Search;
+use Koha::Database;
 use t::lib::Mocks;
 use Test::MockModule;
 
@@ -18,9 +19,8 @@ BEGIN {
     use_ok('C4::XISBN');
 }
 
-my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 
 my $search_module = new Test::MockModule('C4::Search');
 
@@ -67,8 +67,6 @@ SKIP: {
         "Gets correct biblionumber from a book with a similar isbn using ThingISBN." );
 }
 
-$dbh->rollback;
-
 # Util subs
 
 # Add new biblio with isbn and return biblionumber
index 340e89a..c6853b9 100755 (executable)
 use Modern::Perl;
 use Test::More tests => 8;
 use C4::Context;
+use Koha::Database;
 
-# Start transaction
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 my $opacheader    = C4::Context->preference('opacheader');
 my $newopacheader = "newopacheader";
@@ -59,5 +59,3 @@ $dbh->do("DELETE FROM systempreferences WHERE variable='testpreference'");
 is(C4::Context->preference('testpreference'), 'def', 'caching preferences');
 C4::Context->clear_syspref_cache();
 is(C4::Context->preference('testpreference'), undef, 'clearing preference cache');
-
-$dbh->rollback;