diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 7a0951173e..258421c350 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3245,13 +3245,13 @@ $code is either itemtype or collection code depending on what the pref BranchTra sub CreateBranchTransferLimit { my ( $toBranch, $fromBranch, $code ) = @_; - + return unless ($toBranch && $fromBranch); my $limitType = C4::Context->preference("BranchTransferLimitsType"); my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("INSERT INTO branch_transfer_limits ( $limitType, toBranch, fromBranch ) VALUES ( ?, ?, ? )"); - $sth->execute( $code, $toBranch, $fromBranch ); + return $sth->execute( $code, $toBranch, $fromBranch ); } =head2 DeleteBranchTransferLimits diff --git a/t/db_dependent/Circulation_transfers.t b/t/db_dependent/Circulation_transfers.t index 927b87cd64..5724f4fa56 100644 --- a/t/db_dependent/Circulation_transfers.t +++ b/t/db_dependent/Circulation_transfers.t @@ -9,7 +9,7 @@ use C4::Circulation; use Koha::DateUtils; use DateTime::Duration; -use Test::More tests => 12; +use Test::More tests => 15; BEGIN { use_ok('C4::Circulation'); @@ -129,8 +129,15 @@ is( 1, "A Branch TransferLimit has been added" ); -#FIXME :The following test should pass but doesn't because currently the routine CreateBranchTransferLimit returns nothing -#is(CreateBranchTransferLimit(),undef,"Without parameters CreateBranchTransferLimit returns undef"); +is(CreateBranchTransferLimit(),undef, + "Without parameters CreateBranchTransferLimit returns undef"); +is(CreateBranchTransferLimit($samplebranch2->{branchcode}),undef, + "With only tobranch CreateBranchTransferLimit returns undef"); +is(CreateBranchTransferLimit(undef,$samplebranch2->{branchcode}),undef, + "With only frombranch CreateBranchTransferLimit returns undef"); +#FIXME: Currently, we can add a transferlimit even to nonexistent branches because in the database, +#branch_transfer_limits.toBranch and branch_transfer_limits.fromBranch aren't foreign keys +#is(CreateBranchTransferLimit(-1,-1,'CODE'),0,"With wrong CreateBranchTransferLimit returns 0 - No transfertlimit added"); #Test GetTransfers my $dt_today = dt_from_string( undef, 'sql', undef );