From bafe14642dacea275af3c0a29f27748234aea85a Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 3 Feb 2016 17:10:37 +0000 Subject: [PATCH] Bug 9805 - Unit Tests --- t/db_dependent/Circulation/Renewal.t | 142 +++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100755 t/db_dependent/Circulation/Renewal.t diff --git a/t/db_dependent/Circulation/Renewal.t b/t/db_dependent/Circulation/Renewal.t new file mode 100755 index 0000000..5dc10e6 --- /dev/null +++ b/t/db_dependent/Circulation/Renewal.t @@ -0,0 +1,142 @@ +#!/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 C4::Biblio; +use C4::Items; +use Koha::Database; + +use t::lib::TestBuilder; + +use Test::More tests => 7; + +BEGIN { + use_ok('C4::Circulation'); +} + +my $schema = Koha::Database->schema; +$schema->storage->txn_begin; +my $builder = t::lib::TestBuilder->new; +my $dbh = C4::Context->dbh; + +# Start transaction +$dbh->{RaiseError} = 1; + +# Start with a clean slate +$dbh->do('DELETE FROM issues'); + +my $library = $builder->build( + { + source => 'Branch', + } +); + +my $borrower = $builder->build( + { + source => 'Borrower', + } +); + +# Now, set a userenv +C4::Context->_new_userenv('xxx'); +C4::Context->set_userenv( + 0, 0, 0, 'firstname', 'surname', + $library->{branchcode}, + 'Midway Public Library', + '', '', '' +); +is( C4::Context->userenv->{branch}, $library->{branchcode}, 'userenv set' ); + +my $biblio = MARC::Record->new(); +my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' ); + +my $barcode = '1234'; +my ( undef, undef, $itemnumber ) = AddItem( + { + homebranch => $library->{branchcode}, + holdingbranch => $library->{branchcode}, + barcode => $barcode, + }, + $biblionumber +); + +$dbh->do('DELETE FROM issuingrules'); +$schema->resultset('Issuingrule')->create( + { + categorycode => '*', + branchcode => '*', + itemtype => '*', + maxissueqty => 20, + issuelength => 14, + lengthunit => 'days', + renewalsallowed => 99, + renewalperiod => 7, + } +); + +my $issue = AddIssue( $borrower, $barcode ); + +my $item = Koha::Items->find($itemnumber); +$item->itemlost(1)->store(); + +$dbh->do('DELETE FROM default_branch_circ_rules'); + +$dbh->do('DELETE FROM default_circ_rules'); +$schema->resultset('DefaultCircRule')->create( + { + renew_lost_allowed => 0, + renew_lost_found => 0, + } +); + +my ( $ok, $error ); +( $ok, $error ) = CanBookBeRenewed( $borrower->{borrowernumber}, $itemnumber ); + +is( $ok, 0, "Lost item cannot be renewed" ); +is( $error, 'item_lost', "Lost item cannot be renewed, error is item_lost" ); + +$dbh->do('DELETE FROM default_circ_rules'); +$schema->resultset('DefaultCircRule')->create( + { + renew_lost_allowed => 1, + renew_lost_found => 0, + } +); +( $ok, $error ) = CanBookBeRenewed( $borrower->{borrowernumber}, $itemnumber ); + +is( $ok, 1, "Lost item can be renewed" ); + +AddRenewal( $borrower->{borrowernumber}, $itemnumber, $library->{branchcode} ); +$item = Koha::Items->find($itemnumber); +is( $item->itemlost, 1, + "Item still lost after renewal with renew_lost_found = 0" ); + +$dbh->do('DELETE FROM default_circ_rules'); +$schema->resultset('DefaultCircRule')->create( + { + renew_lost_allowed => 1, + renew_lost_found => 1, + } +); + +AddRenewal( $borrower->{borrowernumber}, $itemnumber, $library->{branchcode} ); +$item = Koha::Items->find($itemnumber); +is( $item->itemlost, 0, + "Item no longer lost after renewal with renew_lost_found = 1" ); + +1; -- 2.1.4