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

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

Return to bug 14494