5f18793461
Fixes problem where if the IssuingInProcess preference is ON, the operator is always required to confirm a checkout if the patron has had any fine transactions at all, even if the patron's balance is 0. Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
132 lines
6.5 KiB
Perl
132 lines
6.5 KiB
Perl
package KohaTest::Circulation::AddIssue;
|
|
use base qw(KohaTest::Circulation);
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Test::More;
|
|
|
|
=head2 basic_usage
|
|
|
|
basic usage of C4::Circulation::AddIssue
|
|
|
|
Note: This logic is repeated in
|
|
KohaTest::Circulation::checkout_first_item, but without tests. This
|
|
includes tests at each step to make it easier to track down what's
|
|
broken as we go along.
|
|
|
|
=cut
|
|
|
|
sub basic_usage : Test( 13 ) {
|
|
my $self = shift;
|
|
|
|
my $borrowernumber = $self->{'memberid'};
|
|
ok( $borrowernumber, "we're going to work with borrower: $borrowernumber" );
|
|
|
|
my $borrower = C4::Members::GetMemberDetails( $borrowernumber );
|
|
ok( $borrower, '...and we were able to look up that borrower' );
|
|
is( $borrower->{'borrowernumber'}, $borrowernumber, '...and they have the right borrowernumber' );
|
|
|
|
my $itemnumber = $self->{'items'}[0]{'itemnumber'};
|
|
ok( $itemnumber, "We're going to checkout itemnumber $itemnumber" );
|
|
my $barcode = $self->get_barcode_from_itemnumber($itemnumber);
|
|
ok( $barcode, "...which has barcode $barcode" );
|
|
|
|
my $before_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
|
|
# Note that we can't check for $before_issues as undef because GetItemIssue always returns a populated hashref
|
|
ok( ! defined $before_issues->{'borrowernumber'}, '...and is not currently checked out' )
|
|
or diag( Data::Dumper->Dump( [ $before_issues ], [ 'before_issues' ] ) );
|
|
|
|
my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $borrower, $barcode );
|
|
is( scalar keys %$issuingimpossible, 0, 'the item CanBookBeIssued' )
|
|
or diag( Data::Dumper->Dump( [ $issuingimpossible, $needsconfirmation ], [ qw( issuingimpossible needsconfirmation ) ] ) );
|
|
is( scalar keys %$needsconfirmation, 0, '...and the transaction does not needsconfirmation' )
|
|
or diag( Data::Dumper->Dump( [ $issuingimpossible, $needsconfirmation ], [ qw( issuingimpossible needsconfirmation ) ] ) );
|
|
|
|
# bug 2758 don't ask for confirmation if patron has $0.00 account balance
|
|
# and IssuingInProcess is on
|
|
my $orig_issuing_in_process = C4::Context->preference('IssuingInProcess');
|
|
my $dbh = C4::Context->dbh;
|
|
$dbh->do("UPDATE systempreferences SET value = 1 WHERE variable = 'IssuingInProcess'");
|
|
C4::Context->clear_syspref_cache(); # FIXME not needed after a syspref mutator is written
|
|
( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $borrower, $barcode );
|
|
is( scalar keys %$issuingimpossible, 0, 'the item CanBookBeIssued with IssuingInProcess ON (bug 2758)' )
|
|
or diag( Data::Dumper->Dump( [ $issuingimpossible, $needsconfirmation ], [ qw( issuingimpossible needsconfirmation ) ] ) );
|
|
is( scalar keys %$needsconfirmation, 0,
|
|
'...and the transaction does not needsconfirmation with IssuingInProcess ON (bug 2758)' )
|
|
or diag( Data::Dumper->Dump( [ $issuingimpossible, $needsconfirmation ], [ qw( issuingimpossible needsconfirmation ) ] ) );
|
|
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'IssuingInProcess'", {}, $orig_issuing_in_process);
|
|
C4::Context->clear_syspref_cache(); # FIXME not needed after a syspref mutator is written
|
|
|
|
my $datedue = C4::Circulation::AddIssue( $borrower, $barcode );
|
|
ok( $datedue, "the item has been issued and it is due: $datedue" );
|
|
|
|
my $after_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
|
|
is( $after_issues->{'borrowernumber'}, $borrowernumber, '...and now it is checked out to our borrower' )
|
|
or diag( Data::Dumper->Dump( [ $after_issues ], [ 'after_issues' ] ) );
|
|
|
|
my $loanlength = Date::Calc::Delta_Days( split( /-/, $after_issues->{'issuedate'} ), split( /-/, $after_issues->{'date_due'} ) );
|
|
ok( $loanlength, "the loanlength is $loanlength days" );
|
|
|
|
# save this here since we refer to it in set_issuedate.
|
|
$self->{'loanlength'} = $loanlength;
|
|
|
|
}
|
|
|
|
=head2 set_issuedate
|
|
|
|
Make sure that we can set the issuedate of an issue.
|
|
|
|
Also, since we are specifying an issuedate and not a due date, the due
|
|
date should be calculated from the issuedate, not today.
|
|
|
|
=cut
|
|
|
|
sub set_issuedate : Test( 7 ) {
|
|
my $self = shift;
|
|
|
|
my $before_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
|
|
ok( ! defined $before_issues->{'borrowernumber'}, 'At this beginning, this item was not checked out.' )
|
|
or diag( Data::Dumper->Dump( [ $before_issues ], [ 'before_issues' ] ) );
|
|
|
|
my $issuedate = $self->random_date();
|
|
ok( $issuedate, "Check out an item on $issuedate" );
|
|
my $datedue = $self->checkout_first_item( { issuedate => $issuedate } );
|
|
ok( $datedue, "...and it's due on $datedue" );
|
|
|
|
my $after_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
|
|
is( $after_issues->{'borrowernumber'}, $self->{'memberid'}, 'We found this item checked out to our member.' )
|
|
or diag( Data::Dumper->Dump( [ $after_issues ], [ 'issues' ] ) );
|
|
is( $after_issues->{'issuedate'}, $issuedate, "...and it was issued on $issuedate" )
|
|
or diag( Data::Dumper->Dump( [ $after_issues ], [ 'after_issues' ] ) );
|
|
|
|
my $loanlength = Date::Calc::Delta_Days( split( /-/, $after_issues->{'issuedate'} ), split( /-/, $after_issues->{'date_due'} ) );
|
|
ok( $loanlength, "the loanlength is $loanlength days" );
|
|
is( $loanlength, $self->{'loanlength'} );
|
|
}
|
|
|
|
sub set_lastreneweddate_on_renewal : Test( 6 ) {
|
|
my $self = shift;
|
|
|
|
my $before_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
|
|
ok( ! defined $before_issues->{'borrowernumber'}, 'At this beginning, this item was not checked out.' )
|
|
or diag( Data::Dumper->Dump( [ $before_issues ], [ 'before_issues' ] ) );
|
|
|
|
my $datedue = $self->checkout_first_item( { issuedate => $self->yesterday() } );
|
|
ok( $datedue, "The item is checked out and it's due on $datedue" );
|
|
|
|
my $issuedate = $self->random_date();
|
|
ok( $issuedate, "Check out an item again on $issuedate" );
|
|
# This will actually be a renewal
|
|
$datedue = $self->checkout_first_item( { issuedate => $issuedate } );
|
|
ok( $datedue, "...and it's due on $datedue" );
|
|
|
|
my $after_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
|
|
is( $after_issues->{'borrowernumber'}, $self->{'memberid'}, 'We found this item checked out to our member.' )
|
|
or diag( Data::Dumper->Dump( [ $after_issues ], [ 'issues' ] ) );
|
|
is( $after_issues->{'lastreneweddate'}, $issuedate, "...and it was renewed on $issuedate" )
|
|
or diag( Data::Dumper->Dump( [ $after_issues ], [ 'after_issues' ] ) );
|
|
|
|
}
|
|
|
|
1;
|