From 30ebf4a0c8b43a77bad137ff5ccacce52af658b8 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 9 Jul 2015 09:52:28 +0100 Subject: [PATCH] Bug 14494: Unit test Content-Type: text/plain; charset=utf-8 Signed-off-by: Marcel de Rooy Moved the test on its own. Nicer than adding TestBuilder in the final part of the test. No warnings/errors from TestBuilder, no dependency.. --- t/db_dependent/Circulation_dateexpiry.t | 78 +++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 t/db_dependent/Circulation_dateexpiry.t diff --git a/t/db_dependent/Circulation_dateexpiry.t b/t/db_dependent/Circulation_dateexpiry.t new file mode 100644 index 0000000..6ff3dee --- /dev/null +++ b/t/db_dependent/Circulation_dateexpiry.t @@ -0,0 +1,78 @@ +#!/usr/bin/perl + +# 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 DateTime; +use Time::HiRes qw/gettimeofday/; +use C4::Members; +use Koha::DateUtils; +use t::lib::TestBuilder; +use Test::More; + +subtest 'Tests for CanBookBeIssued related to dateexpiry' => sub { + plan tests => 4; + date_expiry(); +}; + +sub date_expiry { + my %a_borrower_data = ( + firstname => 'Kyle', + surname => 'Hall', + categorycode => 'S', + branchcode => 'CPL', + ); + my $borrower = { + branchcode => 'MPL', + borrowernumber => AddMember( %a_borrower_data ), + }; + + my $builder = t::lib::TestBuilder->new(); + my $item = $builder->build( { source => 'Item' } ); + my $patron = $builder->build( + { source => 'Borrower', + value => { dateexpiry => '9999-12-31' } + } + ); + $patron->{flags} = C4::Members::patronflags( $borrower ); + my $duration = gettimeofday(); + my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} ); + $duration = gettimeofday() - $duration; + cmp_ok $duration, '<', 1, "CanBookBeIssued should not be take more than 1s if the patron is expired"; + is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is 9999-*' ); + + $item = $builder->build( { source => 'Item' } ); + $patron = $builder->build( + { source => 'Borrower', + value => { dateexpiry => '0000-00-00' } + } + ); + $patron->{flags} = C4::Members::patronflags( $borrower ); + ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} ); + is( $issuingimpossible->{EXPIRED}, 1, 'The patron should be considered as expired if dateexpiry is 0000-00-00' ); + + my $tomorrow = dt_from_string->add_duration( DateTime::Duration->new( days => 1 ) ); + $item = $builder->build( { source => 'Item' } ); + $patron = $builder->build( + { source => 'Borrower', + value => { dateexpiry => output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' } ) }, + } + ); + $patron->{flags} = C4::Members::patronflags($borrower); + ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} ); + is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is tomorrow' ); +} -- 1.7.10.4