9 use Test::More tests => 3;
16 use t::lib::TestBuilder;
18 my $schema = Koha::Database->schema;
19 $schema->storage->txn_begin;
20 my $builder = t::lib::TestBuilder->new;
21 my $dbh = C4::Context->dbh;
22 $dbh->{RaiseError} = 1;
24 $dbh->do("DELETE FROM reserves");
25 $dbh->do("DELETE FROM old_reserves");
27 my $library = $builder->build({
31 local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
32 *C4::Context::userenv = \&Mock_userenv;
35 my $userenv = { flags => 1, id => '1', branch => $library->{branchcode} };
39 my $borrowers_count = 3;
41 # Create a biblio instance
42 my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
45 my $item_barcode = 'my_barcode';
46 my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
47 { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, barcode => $item_barcode },
50 # Create some borrowers
52 foreach my $i ( 1 .. $borrowers_count ) {
53 my $borrowernumber = AddMember(
54 firstname => 'my firstname',
55 surname => 'my surname ' . $i,
57 branchcode => $library->{branchcode},
59 push @borrowernumbers, $borrowernumber;
62 my $biblionumber = $bibnum;
64 my @branches = GetBranchesLoop();
65 my $branch = $branches[0][0]{value};
67 # Create five item level holds
68 foreach my $borrowernumber (@borrowernumbers) {
84 ModReserveAffect( $itemnumber, $borrowernumbers[0] );
85 C4::Circulation::AddIssue( GetMember( borrowernumber => $borrowernumbers[1] ),
86 $item_barcode, my $datedue, my $cancelreserve = 'revert' );
88 my $priorities = $dbh->selectall_arrayref(
89 "SELECT priority FROM reserves ORDER BY priority ASC");
90 ok( scalar @$priorities == 2, 'Only 2 holds remain in the reserves table' );
91 ok( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' );
92 ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
94 # Helper method to set up a Biblio.
95 sub create_helper_biblio {
96 my $bib = MARC::Record->new();
97 my $title = 'Silence in the library';
99 MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
100 MARC::Field->new( '245', ' ', ' ', a => $title ),
102 return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );