From 381b158260feb2b14bc3b048c2ab3ef26475feec Mon Sep 17 00:00:00 2001 From: Yohann Dufour Date: Mon, 4 Aug 2014 16:09:53 +0200 Subject: [PATCH] [PASSED QA] Bug 8007: Discharge - Add unit tests Signed-off-by: Lucie Signed-off-by: Kyle M Hall --- t/db_dependent/Borrower_Discharge.t | 59 +++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) create mode 100644 t/db_dependent/Borrower_Discharge.t diff --git a/t/db_dependent/Borrower_Discharge.t b/t/db_dependent/Borrower_Discharge.t new file mode 100644 index 0000000..7d22b0b --- /dev/null +++ b/t/db_dependent/Borrower_Discharge.t @@ -0,0 +1,59 @@ +#!/usr/bin/perl; + +use Modern::Perl; +use Test::More; +use MARC::Record; + +use C4::Biblio qw( AddBiblio ); +use C4::Circulation qw( AddIssue AddReturn ); +use C4::Context; +use C4::Items qw( AddItem ); +use C4::Members qw( AddMember GetMember ); + +use Koha::Borrower::Discharge; + +my $dbh = C4::Context->dbh; +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + +$dbh->do(q|DELETE FROM discharges|); + +C4::Context->_new_userenv('xxx'); +C4::Context::set_userenv(0, 0, 0, 'firstname', 'surname', 'CPL', 'CPL', '', '', ''); + +my $borrowernumber = AddMember( + cardnumber => 'UTCARD1', + firstname => 'my firstname', + surname => 'my surname', + categorycode => 'S', + branchcode => 'CPL', +); +my $borrower = GetMember( borrowernumber => $borrowernumber ); + +# Discharge not possible with issues +my ( $biblionumber ) = AddBiblio( MARC::Record->new, ''); +my $barcode = 'BARCODE42'; +my ( undef, undef, $itemnumber ) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', barcode => $barcode }, $biblionumber); +AddIssue( $borrower, $barcode ); +is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrowernumber }), 0, 'A patron with issues cannot be discharged' ); + +is( Koha::Borrower::Discharge::request({ borrowernumber => $borrowernumber }), undef, 'No request done if patron has issues' ); +is( Koha::Borrower::Discharge::discharge({ borrowernumber => $borrowernumber }), undef, 'No discharge done if patron has issues' ); +is_deeply( Koha::Borrower::Discharge::get_pendings(), [], 'There is no pending discharge request' ); + +AddReturn( $barcode ); + +# Discharge possible without issue +is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrowernumber }), 1, 'A patron without issues can be discharged' ); + +# FIXME +# At this point, there is a problem with the AutoCommit off +# The transaction is bloked into DBIx::Class::Storage::DBI::_dbh_execute +# line my $rv = $sth->execute(); +# We are using 2 connections and the one used by Koha::Schema has the AutoCommit set to 1 +# Even if we switch off this flag, the connection will be blocked. +# The error is: +# DBIx::Class::ResultSet::create(): DBI Exception: DBD::mysql::st execute failed: Lock wait timeout exceeded; try restarting transaction [for Statement "INSERT INTO discharges ( borrower, needed, validated) VALUES ( ?, ?, ? )" with ParamValues: 0='121', 1='2014-01-08T16:38:29', 2=undef] at /home/koha/src/Koha/DataObject/Discharge.pm line 33 +#is( Koha::Service::Borrower::Discharge::request({ borrowernumber => $borrowernumber }), 1, 'Discharge request sent' ); + +done_testing; -- 1.7.2.5