Bug 22789: Add tests

Signed-off-by: Lisette Scheer <lisettes@latahlibrary.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Agustin Moyano 2020-08-19 15:50:22 -03:00 committed by Jonathan Druart
parent e7910c6740
commit ee50e86784
2 changed files with 79 additions and 1 deletions

View file

@ -7,19 +7,21 @@ use t::lib::TestBuilder;
use C4::Context; use C4::Context;
use Test::More tests => 66; use Test::More tests => 67;
use MARC::Record; use MARC::Record;
use C4::Biblio; use C4::Biblio;
use C4::Calendar; use C4::Calendar;
use C4::Items; use C4::Items;
use C4::Reserves; use C4::Reserves;
use C4::Circulation;
use Koha::Biblios; use Koha::Biblios;
use Koha::CirculationRules; use Koha::CirculationRules;
use Koha::Database; use Koha::Database;
use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::DateUtils qw( dt_from_string output_pref );
use Koha::Holds; use Koha::Holds;
use Koha::Checkout;
use Koha::Item::Transfer::Limits; use Koha::Item::Transfer::Limits;
use Koha::Items; use Koha::Items;
use Koha::Libraries; use Koha::Libraries;
@ -1251,3 +1253,76 @@ subtest 'CanItemBeReserved / pickup_not_in_hold_group' => sub {
$schema->storage->txn_rollback; $schema->storage->txn_rollback;
}; };
subtest 'non priority holds' => sub {
plan tests => 4;
$schema->storage->txn_begin;
# Cleanup database
Koha::Holds->search->delete;
$dbh->do('DELETE FROM issues');
Koha::CirculationRules->set_rules(
{
branchcode => undef,
categorycode => undef,
itemtype => undef,
rules => {
renewalsallowed => 5,
reservesallowed => 5,
}
}
);
my $item = $builder->build_sample_item;
my $patron1 = $builder->build_object(
{
class => 'Koha::Patrons',
value => { branchcode => $item->homebranch }
}
);
my $patron2 = $builder->build_object(
{
class => 'Koha::Patrons',
value => { branchcode => $item->homebranch }
}
);
Koha::Checkout->new(
{
borrowernumber => $patron1->borrowernumber,
itemnumber => $item->itemnumber,
branchcode => $item->homebranch
}
)->store;
my $hid = AddReserve(
{
branchcode => $item->homebranch,
borrowernumber => $patron2->borrowernumber,
biblionumber => $item->biblionumber,
priority => 1,
itemnumber => $item->itemnumber,
}
);
my ( $ok, $err ) =
CanBookBeRenewed( $patron1->borrowernumber, $item->itemnumber );
ok( !$ok, 'Cannot renew' );
is( $err, 'on_reserve', 'Item is on hold' );
my $hold = Koha::Holds->find($hid);
$hold->non_priority(1)->store;
( $ok, $err ) =
CanBookBeRenewed( $patron1->borrowernumber, $item->itemnumber );
ok( $ok, 'Can renew' );
is( $err, undef, 'Item is on non priority hold' );
$schema->storage->txn_rollback;
};

View file

@ -563,6 +563,9 @@ sub _gen_default_values {
Branch => { Branch => {
pickup_location => 0, pickup_location => 0,
}, },
Reserve => {
non_priority => 0,
},
Itemtype => { Itemtype => {
rentalcharge => 0, rentalcharge => 0,
rentalcharge_daily => 0, rentalcharge_daily => 0,