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 my @branches = GetBranchesLoop();
67 my $branch = $branches[0][0]{value};
69 # Create five item level holds
71 foreach my $borrowernumber (@borrowernumbers) {
89 my ($status, $reserve, $all_reserves);
91 t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 0 );
92 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
93 ok( $reserve->{borrowernumber} eq $borrowernumbers[0], "Received expected results with LocalHoldsPriority disabled" );
95 t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 );
97 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
98 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
99 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
100 ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with PickupLibrary/homebranch" );
102 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
103 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' );
104 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
105 ok( $reserve->{borrowernumber} eq $borrowernumbers[1], "Received expected results with PickupLibrary/holdingbranch" );
107 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
108 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' );
109 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
110 ok( $reserve->{borrowernumber} eq $borrowernumbers[1], "Received expected results with HomeLibrary/holdingbranch" );
112 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
113 t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
114 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
115 ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with HomeLibrary/homebranch" );
117 # Helper method to set up a Biblio.
118 sub create_helper_biblio {
119 my $bib = MARC::Record->new();
120 my $title = 'Silence in the library';
122 MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
123 MARC::Field->new( '245', ' ', ' ', a => $title ),
125 return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );