View | Details | Raw Unified | Return to bug 14494
Collapse All | Expand All

(-)a/t/db_dependent/Circulation_dateexpiry.t (-1 / +68 lines)
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 tests => 1;
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 $builder = t::lib::TestBuilder->new();
34
    my $item    = $builder->build( { source => 'Item' } );
35
    my $patron  = $builder->build(
36
        {   source => 'Borrower',
37
            value  => { dateexpiry => '9999-12-31' }
38
        }
39
    );
40
    $patron->{flags} = C4::Members::patronflags( $patron );
41
    my $duration = gettimeofday();
42
    my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
43
    $duration = gettimeofday() - $duration;
44
    cmp_ok $duration, '<', 1, "CanBookBeIssued should not be take more than 1s if the patron is expired";
45
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is 9999-*' );
46
47
    $item = $builder->build( { source => 'Item' } );
48
    $patron = $builder->build(
49
        {   source => 'Borrower',
50
            value  => { dateexpiry => '0000-00-00' }
51
        }
52
    );
53
    $patron->{flags} = C4::Members::patronflags( $patron );
54
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
55
    is( $issuingimpossible->{EXPIRED}, 1, 'The patron should be considered as expired if dateexpiry is 0000-00-00' );
56
57
    my $tomorrow = dt_from_string->add_duration( DateTime::Duration->new( days => 1 ) );
58
    $item = $builder->build( { source => 'Item' } );
59
    $patron = $builder->build(
60
        {   source => 'Borrower',
61
            value  => { dateexpiry => output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' } ) },
62
        }
63
    );
64
    $patron->{flags} = C4::Members::patronflags( $patron );
65
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
66
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is tomorrow' );
67
68
}

Return to bug 14494