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

(-)a/t/db_dependent/Koha/Patron/Restriction.t (-1 / +61 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2023 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>
19
20
use Modern::Perl;
21
22
use Test::More tests => 3;
23
use Test::Exception;
24
25
use Koha::Database;
26
use Koha::DateUtils qw( dt_from_string );
27
28
use t::lib::TestBuilder;
29
30
my $schema = Koha::Database->new->schema;
31
32
my $builder = t::lib::TestBuilder->new;
33
34
use_ok('Koha::Patron::Restriction');
35
use_ok('Koha::Patron::Restrictions');
36
37
subtest 'is_expired' => sub {
38
39
    plan tests => 4;
40
41
    $schema->storage->txn_begin;
42
43
    my $debarment = $builder->build({ source => 'BorrowerDebarment' });
44
    my $restriction = Koha::Patron::Restrictions->find( $debarment->{borrower_debarment_id} );
45
46
    $restriction->expiration( undef )->store->discard_changes;
47
    is( $restriction->is_expired, 0, 'Restriction should not be considered expired if dateexpiry is not set');
48
49
    $restriction->expiration( dt_from_string )->store->discard_changes;
50
    is( $restriction->is_expired, 0, 'Restriction should not be considered expired if dateexpiry is today');
51
52
    $restriction->expiration( dt_from_string->add( days => 1 ) )->store->discard_changes;
53
    is( $restriction->is_expired, 0, 'Restriction should not be considered expired if dateexpiry is tomorrow');
54
55
    $restriction->expiration( dt_from_string->add( days => -1 ) )->store->discard_changes;
56
    is( $restriction->is_expired, 1, 'Restriction should be considered expired if dateexpiry is yesterday');
57
58
    $schema->storage->txn_rollback;
59
};
60
61
1;

Return to bug 26053