3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Test
::More tests
=> 3;
33 use t
::lib
::TestBuilder
;
35 my $schema = Koha
::Database
->schema;
36 $schema->storage->txn_begin;
37 my $builder = t
::lib
::TestBuilder
->new;
38 my $dbh = C4
::Context
->dbh;
39 $dbh->{RaiseError
} = 1;
41 $dbh->do("DELETE FROM reserves");
42 $dbh->do("DELETE FROM old_reserves");
44 my $branchcode = $builder->build( { source
=> 'Branch' } )->{branchcode
};
45 my $itemtype = $builder->build(
46 { source
=> 'Itemtype', value
=> { notforloan
=> undef } } )->{itemtype
};
48 local $SIG{__WARN__
} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
49 *C4
::Context
::userenv
= \
&Mock_userenv
;
52 my $userenv = { flags
=> 1, id
=> '1', branch
=> $branchcode };
56 my $borrowers_count = 3;
58 # Create a biblio instance
59 my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio
();
62 my $item_barcode = 'my_barcode';
63 my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem
(
64 { homebranch
=> $branchcode,
65 holdingbranch
=> $branchcode,
66 barcode
=> $item_barcode,
72 # Create some borrowers
73 my $patron_category = $builder->build({ source
=> 'Category' });
75 foreach my $i ( 1 .. $borrowers_count ) {
76 my $borrowernumber = AddMember
(
77 firstname
=> 'my firstname',
78 surname
=> 'my surname ' . $i,
79 categorycode
=> $patron_category->{categorycode
},
80 branchcode
=> $branchcode,
82 push @borrowernumbers, $borrowernumber;
85 my $biblionumber = $bibnum;
87 # Create five item level holds
88 foreach my $borrowernumber (@borrowernumbers) {
104 ModReserveAffect
( $itemnumber, $borrowernumbers[0] );
105 my $patron = Koha
::Patrons
->find( $borrowernumbers[1] )->unblessed;
106 C4
::Circulation
::AddIssue
( $patron,
107 $item_barcode, my $datedue, my $cancelreserve = 'revert' );
109 my $priorities = $dbh->selectall_arrayref(
110 "SELECT priority FROM reserves ORDER BY priority ASC");
111 ok
( scalar @
$priorities == 2, 'Only 2 holds remain in the reserves table' );
112 ok
( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' );
113 ok
( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
115 $schema->storage->txn_rollback;
117 # Helper method to set up a Biblio.
118 sub create_helper_biblio
{
119 my $bib = MARC
::Record
->new();
120 my $title = 'Silence in the library';
122 MARC
::Field
->new( '100', ' ', ' ', a
=> 'Moffat, Steven' ),
123 MARC
::Field
->new( '245', ' ', ' ', a
=> $title ),
125 return ( $bibnum, $title, $bibitemnum ) = AddBiblio
( $bib, '' );