9 use Test::More tests => 3;
18 use t::lib::TestBuilder;
20 my $schema = Koha::Database->schema;
21 $schema->storage->txn_begin;
22 my $builder = t::lib::TestBuilder->new;
23 my $dbh = C4::Context->dbh;
24 $dbh->{RaiseError} = 1;
26 $dbh->do("DELETE FROM reserves");
27 $dbh->do("DELETE FROM old_reserves");
29 my $library = $builder->build({
33 local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
34 *C4::Context::userenv = \&Mock_userenv;
37 my $userenv = { flags => 1, id => '1', branch => $library->{branchcode} };
41 my $borrowers_count = 3;
43 # Create a biblio instance
44 my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
47 my $item_barcode = 'my_barcode';
48 my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
49 { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, barcode => $item_barcode },
52 # Create some borrowers
54 foreach my $i ( 1 .. $borrowers_count ) {
55 my $borrowernumber = AddMember(
56 firstname => 'my firstname',
57 surname => 'my surname ' . $i,
59 branchcode => $library->{branchcode},
61 push @borrowernumbers, $borrowernumber;
64 my $biblionumber = $bibnum;
66 my $branchcode = Koha::Libraries->search->next->branchcode;
68 # Create five item level holds
69 foreach my $borrowernumber (@borrowernumbers) {
85 ModReserveAffect( $itemnumber, $borrowernumbers[0] );
86 C4::Circulation::AddIssue( GetMember( borrowernumber => $borrowernumbers[1] ),
87 $item_barcode, my $datedue, my $cancelreserve = 'revert' );
89 my $priorities = $dbh->selectall_arrayref(
90 "SELECT priority FROM reserves ORDER BY priority ASC");
91 ok( scalar @$priorities == 2, 'Only 2 holds remain in the reserves table' );
92 ok( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' );
93 ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
95 # Helper method to set up a Biblio.
96 sub create_helper_biblio {
97 my $bib = MARC::Record->new();
98 my $title = 'Silence in the library';
100 MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
101 MARC::Field->new( '245', ' ', ' ', a => $title ),
103 return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );