|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use DateTime; |
| 21 |
use Time::HiRes qw/gettimeofday/; |
| 22 |
use C4::Members; |
| 23 |
use Koha::DateUtils; |
| 24 |
use t::lib::TestBuilder; |
| 25 |
use Test::More; |
| 26 |
|
| 27 |
subtest 'Tests for CanBookBeIssued related to dateexpiry' => sub { |
| 28 |
plan tests => 4; |
| 29 |
date_expiry(); |
| 30 |
}; |
| 31 |
|
| 32 |
sub date_expiry { |
| 33 |
my %a_borrower_data = ( |
| 34 |
firstname => 'Kyle', |
| 35 |
surname => 'Hall', |
| 36 |
categorycode => 'S', |
| 37 |
branchcode => 'CPL', |
| 38 |
); |
| 39 |
my $borrower = { |
| 40 |
branchcode => 'MPL', |
| 41 |
borrowernumber => AddMember( %a_borrower_data ), |
| 42 |
}; |
| 43 |
|
| 44 |
my $builder = t::lib::TestBuilder->new(); |
| 45 |
my $item = $builder->build( { source => 'Item' } ); |
| 46 |
my $patron = $builder->build( |
| 47 |
{ source => 'Borrower', |
| 48 |
value => { dateexpiry => '9999-12-31' } |
| 49 |
} |
| 50 |
); |
| 51 |
$patron->{flags} = C4::Members::patronflags( $borrower ); |
| 52 |
my $duration = gettimeofday(); |
| 53 |
my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} ); |
| 54 |
$duration = gettimeofday() - $duration; |
| 55 |
cmp_ok $duration, '<', 1, "CanBookBeIssued should not be take more than 1s if the patron is expired"; |
| 56 |
is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is 9999-*' ); |
| 57 |
|
| 58 |
$item = $builder->build( { source => 'Item' } ); |
| 59 |
$patron = $builder->build( |
| 60 |
{ source => 'Borrower', |
| 61 |
value => { dateexpiry => '0000-00-00' } |
| 62 |
} |
| 63 |
); |
| 64 |
$patron->{flags} = C4::Members::patronflags( $borrower ); |
| 65 |
( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} ); |
| 66 |
is( $issuingimpossible->{EXPIRED}, 1, 'The patron should be considered as expired if dateexpiry is 0000-00-00' ); |
| 67 |
|
| 68 |
my $tomorrow = dt_from_string->add_duration( DateTime::Duration->new( days => 1 ) ); |
| 69 |
$item = $builder->build( { source => 'Item' } ); |
| 70 |
$patron = $builder->build( |
| 71 |
{ source => 'Borrower', |
| 72 |
value => { dateexpiry => output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' } ) }, |
| 73 |
} |
| 74 |
); |
| 75 |
$patron->{flags} = C4::Members::patronflags($borrower); |
| 76 |
( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} ); |
| 77 |
is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is tomorrow' ); |
| 78 |
} |