Bug 14549: Unit tests

To test:
1 - Apply just this patch
2 - prove -v t/db_dependent/Reserves.t
3 - Failure
4 - Apply second patch
5 - prove -v t/db_dependent/Reserves.t
6 - Success!

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 33bd28fb85)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Nick Clemens 2019-06-28 12:36:16 +00:00 committed by Fridolin Somers
parent 0b9c87f68c
commit 4569d1487f
1 changed files with 29 additions and 1 deletions

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 60;
use Test::More tests => 61;
use Test::MockModule;
use Test::Warn;
@ -739,6 +739,34 @@ subtest 'ChargeReserveFee tests' => sub {
is( $line->branchcode, $library->id , "Library id is picked from userenv and stored correctly" );
};
subtest 'MoveReserve additional test' => sub {
plan tests => 4;
# Create the items and patrons we need
my $biblio = $builder->build_sample_biblio();
my $itype = $builder->build_object({ class => "Koha::ItemTypes", value => { notforloan => 0 } });
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber,notforloan => 0, itype => $itype->itemtype });
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, notforloan => 0, itype => $itype->itemtype });
my $patron_1 = $builder->build_object({ class => "Koha::Patrons" });
my $patron_2 = $builder->build_object({ class => "Koha::Patrons" });
# Place a hold on the title for both patrons
my $reserve_1 = AddReserve( $item_1->homebranch, $patron_1->borrowernumber, $biblio->biblionumber, undef, 1 );
my $reserve_2 = AddReserve( $item_2->homebranch, $patron_2->borrowernumber, $biblio->biblionumber, undef, 1 );
is($patron_1->holds->next()->reserve_id, $reserve_1, "The 1st patron has a hold");
is($patron_2->holds->next()->reserve_id, $reserve_2, "The 2nd patron has a hold");
# Fake the holds queue
$dbh->do(q{INSERT INTO hold_fill_targets VALUES (?, ?, ?, ?, ?)},undef,($patron_1->borrowernumber,$biblio->biblionumber,$item_1->itemnumber,$item_1->homebranch,0));
# The 2nd hold should be filed even if the item is preselected for the first hold
MoveReserve($item_1->itemnumber,$patron_2->borrowernumber);
is($patron_2->holds->count, 0, "The 2nd patrons no longer has a hold");
is($patron_2->old_holds->next()->reserve_id, $reserve_2, "The 2nd patrons hold was filled and moved to old holds");
};
sub count_hold_print_messages {
my $message_count = $dbh->selectall_arrayref(q{
SELECT COUNT(*)