From b703d978168b462453fed0c3830ec85fa201546c Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Fri, 29 Sep 2023 09:27:30 -1000 Subject: [PATCH] Bug 26053: Add unit test for Koha::Patron::Restriction Run: prove t/db_dependent/Koha/Patron/Restriction.t Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Patron/Restriction.t | 61 ++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 t/db_dependent/Koha/Patron/Restriction.t diff --git a/t/db_dependent/Koha/Patron/Restriction.t b/t/db_dependent/Koha/Patron/Restriction.t new file mode 100755 index 0000000000..4c95dcf70c --- /dev/null +++ b/t/db_dependent/Koha/Patron/Restriction.t @@ -0,0 +1,61 @@ +#!/usr/bin/perl + +# Copyright 2023 Koha Development team +# +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see + +use Modern::Perl; + +use Test::More tests => 3; +use Test::Exception; + +use Koha::Database; +use Koha::DateUtils qw( dt_from_string ); + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; + +my $builder = t::lib::TestBuilder->new; + +use_ok('Koha::Patron::Restriction'); +use_ok('Koha::Patron::Restrictions'); + +subtest 'is_expired' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $debarment = $builder->build( { source => 'BorrowerDebarment' } ); + my $restriction = Koha::Patron::Restrictions->find( $debarment->{borrower_debarment_id} ); + + $restriction->expiration(undef)->store->discard_changes; + is( $restriction->is_expired, 0, 'Restriction should not be considered expired if dateexpiry is not set' ); + + $restriction->expiration( dt_from_string->add( days => 1 ) )->store->discard_changes; + is( $restriction->is_expired, 0, 'Restriction should not be considered expired if dateexpiry is tomorrow' ); + + $restriction->expiration(dt_from_string)->store->discard_changes; + is( $restriction->is_expired, 1, 'Restriction should be considered expired if dateexpiry is today' ); + + $restriction->expiration( dt_from_string->add( days => -1 ) )->store->discard_changes; + is( $restriction->is_expired, 1, 'Restriction should be considered expired if dateexpiry is yesterday' ); + + $schema->storage->txn_rollback; +}; + +1;