9 use Test::More tests => 6;
16 use t::lib::TestBuilder;
20 use lib $FindBin::Bin;
21 use_ok('C4::Reserves');
24 my $schema = Koha::Database->schema;
25 $schema->storage->txn_begin;
27 my $builder = t::lib::TestBuilder->new;
29 my $library1 = $builder->build({
32 my $library2 = $builder->build({
35 my $library3 = $builder->build({
38 my $library4 = $builder->build({
42 my $borrowers_count = 5;
44 # Create a helper biblio
45 my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
46 # Create a helper item for the biblio.
47 my ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
48 AddItem( { homebranch => $library4->{branchcode}, holdingbranch => $library3->{branchcode} }, $bibnum );
50 my @branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode}, $library4->{branchcode}, $library3->{branchcode}, $library4->{branchcode} );
52 # Create some borrowers
54 foreach ( 1 .. $borrowers_count ) {
55 my $borrowernumber = AddMember(
56 firstname => 'my firstname',
57 surname => 'my surname ' . $_,
59 branchcode => $branchcodes[$_],
61 push @borrowernumbers, $borrowernumber;
64 my $biblionumber = $bibnum;
66 # Create five item level holds
68 foreach my $borrowernumber (@borrowernumbers) {
86 my ($status, $reserve, $all_reserves);
88 t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 0 );
89 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
90 ok( $reserve->{borrowernumber} eq $borrowernumbers[0], "Received expected results with LocalHoldsPriority disabled" );
92 t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 );
94 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
95 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
96 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
97 ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with PickupLibrary/homebranch" );
99 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
100 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' );
101 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
102 ok( $reserve->{borrowernumber} eq $borrowernumbers[1], "Received expected results with PickupLibrary/holdingbranch" );
104 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
105 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' );
106 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
107 ok( $reserve->{borrowernumber} eq $borrowernumbers[1], "Received expected results with HomeLibrary/holdingbranch" );
109 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
110 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
111 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
112 ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with HomeLibrary/homebranch" );
114 # Helper method to set up a Biblio.
115 sub create_helper_biblio {
116 my $bib = MARC::Record->new();
117 my $title = 'Silence in the library';
119 MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
120 MARC::Field->new( '245', ' ', ' ', a => $title ),
122 return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );