From aa284f2efb2915514f77791cdc1bc73d54561057 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 16 Jun 2015 16:30:01 +0200 Subject: [PATCH] Bug 14334: Add a Database module for db dependent tests --- t/db_dependent/Acquisition.t | 10 ++-------- t/lib/Database.pm | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 t/lib/Database.pm diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 83486d2..e73e848 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -20,7 +20,7 @@ use Modern::Perl; use POSIX qw(strftime); use Test::More tests => 87; -use Koha::Database; +use t::lib::Database; BEGIN { use_ok('C4::Acquisition'); @@ -118,11 +118,7 @@ sub _check_fields_of_orders { } -my $schema = Koha::Database->new()->schema(); -$schema->storage->txn_begin(); - -my $dbh = C4::Context->dbh; -$dbh->{RaiseError} = 1; +my $dbh = t::lib::Database::dbh; # Creating some orders my $booksellerid = C4::Bookseller::AddBookseller( @@ -920,5 +916,3 @@ ok((defined $order4->{datecancellationprinted}), "order is cancelled"); ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \"foobar\""); ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anymore"); # End of tests for DelOrder - -$schema->storage->txn_rollback(); diff --git a/t/lib/Database.pm b/t/lib/Database.pm new file mode 100644 index 0000000..2106d61 --- /dev/null +++ b/t/lib/Database.pm @@ -0,0 +1,19 @@ +package t::lib::Database; + +use C4::Context; +use Koha::Database; + +sub dbh { + my $dbh = C4::Context->dbh; + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + $dbh->{RaiseError} = 1; + return $dbh; +} + +END { + my $schema = Koha::Database->new->schema; + $schema->storage->txn_rollback; +}; + +1; -- 2.1.0