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 # Setup Test------------------------
43 diag("Creating biblio instance for testing.");
44 my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
46 # Helper item for that biblio.
47 diag("Creating item instance for testing.");
48 my $item_barcode = 'my_barcode';
49 my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
50 { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, barcode => $item_barcode },
53 # Create some borrowers
55 foreach my $i ( 1 .. $borrowers_count ) {
56 my $borrowernumber = AddMember(
57 firstname => 'my firstname',
58 surname => 'my surname ' . $i,
60 branchcode => $library->{branchcode},
62 push @borrowernumbers, $borrowernumber;
65 my $biblionumber = $bibnum;
67 my @branches = GetBranchesLoop();
68 my $branch = $branches[0][0]{value};
70 # Create five item level holds
71 foreach my $borrowernumber (@borrowernumbers) {
87 ModReserveAffect( $itemnumber, $borrowernumbers[0] );
88 C4::Circulation::AddIssue( GetMember( borrowernumber => $borrowernumbers[1] ),
89 $item_barcode, my $datedue, my $cancelreserve = 'revert' );
91 my $priorities = $dbh->selectall_arrayref(
92 "SELECT priority FROM reserves ORDER BY priority ASC");
93 ok( scalar @$priorities == 2, 'Only 2 holds remain in the reserves table' );
94 ok( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' );
95 ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
97 # Helper method to set up a Biblio.
98 sub create_helper_biblio {
99 my $bib = MARC::Record->new();
100 my $title = 'Silence in the library';
102 MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
103 MARC::Field->new( '245', ' ', ' ', a => $title ),
105 return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );