From 99e8fe8ab98e26720dad9ca5d1943cba2618a9d9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 7 Dec 2018 14:14:06 -0300 Subject: [PATCH] Bug 14334: Remove AutoCommit from tests Content-Type: text/plain; charset=utf-8 And use a DBIx transaction instead. Test plan: prove that the test files modified by this patch are passing Signed-off-by: Josef Moravec Signed-off-by: Marcel de Rooy --- t/db_dependent/Acquisition/FillWithDefaultValues.t | 6 +++--- t/db_dependent/AdditionalField.t | 8 +++----- t/db_dependent/Auth_with_cas.t | 11 +++-------- t/db_dependent/BackgroundJob.t | 8 ++++---- t/db_dependent/Charset.t | 8 ++++---- t/db_dependent/Circulation/CheckIfIssuedToPatron.t | 8 +------- t/db_dependent/Circulation/CheckValidBarcode.t | 8 +++----- t/db_dependent/Circulation/GetHardDueDate.t | 9 +++------ t/db_dependent/Circulation/OfflineOperation.t | 9 +++------ t/db_dependent/ColumnsSettings.t | 8 ++++---- t/db_dependent/Contract.t | 7 +++---- t/db_dependent/Fines.t | 7 ++----- t/db_dependent/Koha/GetDailyQuote.t | 9 +++------ t/db_dependent/Koha/Item/Search/Field.t | 7 +++---- t/db_dependent/Koha_Misc_Files.t | 8 +++----- t/db_dependent/Labels/t_Batch.t | 8 +++----- t/db_dependent/Languages.t | 10 ++++------ t/db_dependent/Letters/GetLetterTemplates.t | 5 +++-- t/db_dependent/Letters/GetLettersAvailableForALibrary.t | 5 +++-- t/db_dependent/LibraryGroups.t | 7 ++++--- t/db_dependent/MarcModificationTemplates.t | 5 +++-- t/db_dependent/MungeMarcPrice.t | 13 ++++--------- t/db_dependent/NewsChannels.t | 9 +++------ t/db_dependent/Overdues.t | 5 +++-- t/db_dependent/Record.t | 7 +++---- t/db_dependent/Record/marcrecord2csv.t | 5 +++-- t/db_dependent/RotatingCollections.t | 10 +++------- t/db_dependent/Serials.t | 10 +++------- t/db_dependent/Serials/Claims.t | 5 +++-- t/db_dependent/Serials/Frequency.t | 7 +++---- t/db_dependent/Serials/GetNextSeq.t | 8 +++----- t/db_dependent/Serials/Numberpattern.t | 12 ++++++------ t/db_dependent/Stats.t | 9 +++------ t/db_dependent/Virtualshelves.t | 4 +++- t/db_dependent/XISBN.t | 8 +++----- t/db_dependent/sysprefs.t | 8 +++----- 36 files changed, 114 insertions(+), 167 deletions(-) diff --git a/t/db_dependent/Acquisition/FillWithDefaultValues.t b/t/db_dependent/Acquisition/FillWithDefaultValues.t index 531aa78..f70ae1e 100755 --- a/t/db_dependent/Acquisition/FillWithDefaultValues.t +++ b/t/db_dependent/Acquisition/FillWithDefaultValues.t @@ -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'; diff --git a/t/db_dependent/AdditionalField.t b/t/db_dependent/AdditionalField.t index 93121db..2a3a680 100644 --- a/t/db_dependent/AdditionalField.t +++ b/t/db_dependent/AdditionalField.t @@ -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| ); @@ -290,6 +291,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; diff --git a/t/db_dependent/Auth_with_cas.t b/t/db_dependent/Auth_with_cas.t index d15bf5e..bb001ec 100755 --- a/t/db_dependent/Auth_with_cas.t +++ b/t/db_dependent/Auth_with_cas.t @@ -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; - diff --git a/t/db_dependent/BackgroundJob.t b/t/db_dependent/BackgroundJob.t index 7005594..ae5c25a 100644 --- a/t/db_dependent/BackgroundJob.t +++ b/t/db_dependent/BackgroundJob.t @@ -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; diff --git a/t/db_dependent/Charset.t b/t/db_dependent/Charset.t index ea649ae..99837c2 100644 --- a/t/db_dependent/Charset.t +++ b/t/db_dependent/Charset.t @@ -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; diff --git a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t b/t/db_dependent/Circulation/CheckIfIssuedToPatron.t index b06d0c3..bd39895 100644 --- a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t +++ b/t/db_dependent/Circulation/CheckIfIssuedToPatron.t @@ -30,13 +30,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(); - diff --git a/t/db_dependent/Circulation/CheckValidBarcode.t b/t/db_dependent/Circulation/CheckValidBarcode.t index 505955f..527a133 100644 --- a/t/db_dependent/Circulation/CheckValidBarcode.t +++ b/t/db_dependent/Circulation/CheckValidBarcode.t @@ -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(); - diff --git a/t/db_dependent/Circulation/GetHardDueDate.t b/t/db_dependent/Circulation/GetHardDueDate.t index fe126ca..22531af 100644 --- a/t/db_dependent/Circulation/GetHardDueDate.t +++ b/t/db_dependent/Circulation/GetHardDueDate.t @@ -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|); @@ -397,6 +397,3 @@ is_deeply( ], "GetHardDueDate returns the duedate and the duedatecompare" ); - -#End transaction -$dbh->rollback; diff --git a/t/db_dependent/Circulation/OfflineOperation.t b/t/db_dependent/Circulation/OfflineOperation.t index c50524d..fb11b6f 100644 --- a/t/db_dependent/Circulation/OfflineOperation.t +++ b/t/db_dependent/Circulation/OfflineOperation.t @@ -3,6 +3,7 @@ use Modern::Perl; use C4::Circulation; +use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Library; @@ -21,10 +22,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|); @@ -99,6 +99,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; diff --git a/t/db_dependent/ColumnsSettings.t b/t/db_dependent/ColumnsSettings.t index da75931..ebf5272 100644 --- a/t/db_dependent/ColumnsSettings.t +++ b/t/db_dependent/ColumnsSettings.t @@ -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; diff --git a/t/db_dependent/Contract.t b/t/db_dependent/Contract.t index 9ca0e18..1a6bafd 100644 --- a/t/db_dependent/Contract.t +++ b/t/db_dependent/Contract.t @@ -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; diff --git a/t/db_dependent/Fines.t b/t/db_dependent/Fines.t index 1f273ba..7a0ede4 100644 --- a/t/db_dependent/Fines.t +++ b/t/db_dependent/Fines.t @@ -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|); diff --git a/t/db_dependent/Koha/GetDailyQuote.t b/t/db_dependent/Koha/GetDailyQuote.t index 7bb4869..a2f5514 100644 --- a/t/db_dependent/Koha/GetDailyQuote.t +++ b/t/db_dependent/Koha/GetDailyQuote.t @@ -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"); @@ -83,5 +82,3 @@ $dbh->do(q|INSERT INTO `quotes` VALUES $quote = GetDailyQuote(); is( $quote->{id}, 6, ' GetDailyQuote returns the only existing quote' ); - -$dbh->rollback; diff --git a/t/db_dependent/Koha/Item/Search/Field.t b/t/db_dependent/Koha/Item/Search/Field.t index 1cbb544..9e73880 100755 --- a/t/db_dependent/Koha/Item/Search/Field.t +++ b/t/db_dependent/Koha/Item/Search/Field.t @@ -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; diff --git a/t/db_dependent/Koha_Misc_Files.t b/t/db_dependent/Koha_Misc_Files.t index 18fbab0..689fb52 100755 --- a/t/db_dependent/Koha_Misc_Files.t +++ b/t/db_dependent/Koha_Misc_Files.t @@ -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; - diff --git a/t/db_dependent/Labels/t_Batch.t b/t/db_dependent/Labels/t_Batch.t index cbf8ea3..b74917b 100644 --- a/t/db_dependent/Labels/t_Batch.t +++ b/t/db_dependent/Labels/t_Batch.t @@ -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' } }) @@ -120,5 +120,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; diff --git a/t/db_dependent/Languages.t b/t/db_dependent/Languages.t index 8e8d372..5afdd80 100755 --- a/t/db_dependent/Languages.t +++ b/t/db_dependent/Languages.t @@ -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; diff --git a/t/db_dependent/Letters/GetLetterTemplates.t b/t/db_dependent/Letters/GetLetterTemplates.t index fd74285..65d05f8 100644 --- a/t/db_dependent/Letters/GetLetterTemplates.t +++ b/t/db_dependent/Letters/GetLetterTemplates.t @@ -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|); diff --git a/t/db_dependent/Letters/GetLettersAvailableForALibrary.t b/t/db_dependent/Letters/GetLettersAvailableForALibrary.t index 8ebc4fe..ded8985 100644 --- a/t/db_dependent/Letters/GetLettersAvailableForALibrary.t +++ b/t/db_dependent/Letters/GetLettersAvailableForALibrary.t @@ -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|); diff --git a/t/db_dependent/LibraryGroups.t b/t/db_dependent/LibraryGroups.t index eb800dd..69f9e9d 100644 --- a/t/db_dependent/LibraryGroups.t +++ b/t/db_dependent/LibraryGroups.t @@ -7,6 +7,7 @@ use List::MoreUtils 'any'; use Test::More tests => 20; use t::lib::TestBuilder; +use Koha::Database; BEGIN { use FindBin; @@ -15,9 +16,9 @@ BEGIN { use_ok('Koha::Library::Groups'); } -our $dbh = C4::Context->dbh; -$dbh->{AutoCommit} = 0; -$dbh->{RaiseError} = 1; +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; +my $dbh = C4::Context->dbh; $dbh->do(q|DELETE FROM issues|); $dbh->do(q|DELETE FROM library_groups|); diff --git a/t/db_dependent/MarcModificationTemplates.t b/t/db_dependent/MarcModificationTemplates.t index a820ede..6865fa8 100644 --- a/t/db_dependent/MarcModificationTemplates.t +++ b/t/db_dependent/MarcModificationTemplates.t @@ -2,15 +2,16 @@ use Modern::Perl; use Test::More tests => 115; +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|); diff --git a/t/db_dependent/MungeMarcPrice.t b/t/db_dependent/MungeMarcPrice.t index 78a599f..12a3d6a 100755 --- a/t/db_dependent/MungeMarcPrice.t +++ b/t/db_dependent/MungeMarcPrice.t @@ -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; diff --git a/t/db_dependent/NewsChannels.t b/t/db_dependent/NewsChannels.t index ce15247..928ddd5 100644 --- a/t/db_dependent/NewsChannels.t +++ b/t/db_dependent/NewsChannels.t @@ -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; diff --git a/t/db_dependent/Overdues.t b/t/db_dependent/Overdues.t index bb5265f..30ca444 100644 --- a/t/db_dependent/Overdues.t +++ b/t/db_dependent/Overdues.t @@ -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|); diff --git a/t/db_dependent/Record.t b/t/db_dependent/Record.t index 2d839f3..613e5ea 100755 --- a/t/db_dependent/Record.t +++ b/t/db_dependent/Record.t @@ -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{} ); diff --git a/t/db_dependent/Record/marcrecord2csv.t b/t/db_dependent/Record/marcrecord2csv.t index 3f2c951..c937887 100644 --- a/t/db_dependent/Record/marcrecord2csv.t +++ b/t/db_dependent/Record/marcrecord2csv.t @@ -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'); diff --git a/t/db_dependent/RotatingCollections.t b/t/db_dependent/RotatingCollections.t index e00410c..a83adba 100644 --- a/t/db_dependent/RotatingCollections.t +++ b/t/db_dependent/RotatingCollections.t @@ -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 |); @@ -330,7 +330,3 @@ is( $countcollection + 1, "Two Collections have been deleted" ); - -#End transaction -$dbh->rollback; - diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index 4c0f56a..323e821 100755 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -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 @@ -348,8 +346,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( diff --git a/t/db_dependent/Serials/Claims.t b/t/db_dependent/Serials/Claims.t index 3acb2d3..6458497 100644 --- a/t/db_dependent/Serials/Claims.t +++ b/t/db_dependent/Serials/Claims.t @@ -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|); diff --git a/t/db_dependent/Serials/Frequency.t b/t/db_dependent/Serials/Frequency.t index e57ff34..ac58981 100644 --- a/t/db_dependent/Serials/Frequency.t +++ b/t/db_dependent/Serials/Frequency.t @@ -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; diff --git a/t/db_dependent/Serials/GetNextSeq.t b/t/db_dependent/Serials/GetNextSeq.t index fc6e3f2..4b277d0 100644 --- a/t/db_dependent/Serials/GetNextSeq.t +++ b/t/db_dependent/Serials/GetNextSeq.t @@ -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; diff --git a/t/db_dependent/Serials/Numberpattern.t b/t/db_dependent/Serials/Numberpattern.t index c964ee9..f703cd4 100644 --- a/t/db_dependent/Serials/Numberpattern.t +++ b/t/db_dependent/Serials/Numberpattern.t @@ -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; diff --git a/t/db_dependent/Stats.t b/t/db_dependent/Stats.t index 4ec1bce..76e9735 100644 --- a/t/db_dependent/Stats.t +++ b/t/db_dependent/Stats.t @@ -2,6 +2,7 @@ use Modern::Perl; use C4::Stats; +use Koha::Database; use Test::More tests => 19; @@ -13,10 +14,9 @@ can_ok( qw(UpdateStats) ); -#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 @@ -163,6 +163,3 @@ is( $line->{location}, undef, "UpdateStats sets location to NULL if undef is passed in." ); # More tests to write! - -#End transaction -$dbh->rollback; diff --git a/t/db_dependent/Virtualshelves.t b/t/db_dependent/Virtualshelves.t index ce521ad..9f830fb 100644 --- a/t/db_dependent/Virtualshelves.t +++ b/t/db_dependent/Virtualshelves.t @@ -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 { diff --git a/t/db_dependent/XISBN.t b/t/db_dependent/XISBN.t index b544c2b..803743a 100755 --- a/t/db_dependent/XISBN.t +++ b/t/db_dependent/XISBN.t @@ -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'); @@ -62,8 +62,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 diff --git a/t/db_dependent/sysprefs.t b/t/db_dependent/sysprefs.t index 340e89a..c6853b9 100755 --- a/t/db_dependent/sysprefs.t +++ b/t/db_dependent/sysprefs.t @@ -21,11 +21,11 @@ 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; -- 2.1.4