8 use Test::More tests => 6;
15 use t::lib::TestBuilder;
19 use lib $FindBin::Bin;
20 use_ok('C4::Reserves');
23 my $schema = Koha::Database->schema;
24 $schema->storage->txn_begin;
26 my $builder = t::lib::TestBuilder->new;
28 my $library1 = $builder->build({
31 my $library2 = $builder->build({
34 my $library3 = $builder->build({
37 my $library4 = $builder->build({
41 my $borrowers_count = 5;
43 # Create a helper biblio
44 my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
45 # Create a helper item for the biblio.
46 my ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
47 AddItem( { homebranch => $library4->{branchcode}, holdingbranch => $library3->{branchcode} }, $bibnum );
49 my @branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode}, $library4->{branchcode}, $library3->{branchcode}, $library4->{branchcode} );
51 # Create some borrowers
53 foreach ( 1 .. $borrowers_count ) {
54 my $borrowernumber = AddMember(
55 firstname => 'my firstname',
56 surname => 'my surname ' . $_,
58 branchcode => $branchcodes[$_],
60 push @borrowernumbers, $borrowernumber;
63 my $biblionumber = $bibnum;
65 # Create five item level holds
67 foreach my $borrowernumber (@borrowernumbers) {
85 my ($status, $reserve, $all_reserves);
87 t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 0 );
88 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
89 ok( $reserve->{borrowernumber} eq $borrowernumbers[0], "Received expected results with LocalHoldsPriority disabled" );
91 t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 );
93 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
94 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
95 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
96 ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with PickupLibrary/homebranch" );
98 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
99 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' );
100 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
101 ok( $reserve->{borrowernumber} eq $borrowernumbers[1], "Received expected results with PickupLibrary/holdingbranch" );
103 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
104 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' );
105 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
106 ok( $reserve->{borrowernumber} eq $borrowernumbers[1], "Received expected results with HomeLibrary/holdingbranch" );
108 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
109 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
110 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
111 ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with HomeLibrary/homebranch" );
113 # Helper method to set up a Biblio.
114 sub create_helper_biblio {
115 my $bib = MARC::Record->new();
116 my $title = 'Silence in the library';
118 MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
119 MARC::Field->new( '245', ' ', ' ', a => $title ),
121 return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );