Kyle M Hall
6b2d2abb19
This feature will allow libraries to specify that, when an item is returned, a local hold may be given priority for fulfillment even though it is of lower priority in the list of unfilled holds. This feature has three settings: * LocalHoldsPriority, which enables the feature * LocalHoldsPriorityPatronControl, which selects for either tha patron's home library, or the patron's pickup library for the hold * LocalHoldsPriorityItemControl, which selects for either the item's holding library, or home library. So, this feature can "give priority for filling holds to patrons whose (home library|pickup library) matches the item's (home library|holding library)" Test Plan: 1) Apply this patch 2) Run t/db_dependent/Holds/LocalHoldsPriority.t Signed-off-by: Joel Sasse <jsasse@plumcreeklibrary.net> Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
119 lines
3.7 KiB
Perl
Executable file
119 lines
3.7 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use t::lib::Mocks;
|
|
use C4::Context;
|
|
use C4::Branch;
|
|
|
|
use Test::More tests => 6;
|
|
use MARC::Record;
|
|
use C4::Biblio;
|
|
use C4::Items;
|
|
use C4::Members;
|
|
|
|
BEGIN {
|
|
use FindBin;
|
|
use lib $FindBin::Bin;
|
|
use_ok('C4::Reserves');
|
|
}
|
|
|
|
my $dbh = C4::Context->dbh;
|
|
|
|
# Start transaction
|
|
$dbh->{AutoCommit} = 0;
|
|
$dbh->{RaiseError} = 1;
|
|
|
|
my $borrowers_count = 5;
|
|
|
|
# Setup Test------------------------
|
|
# Helper biblio.
|
|
diag("Creating biblio instance for testing.");
|
|
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
|
|
|
|
# Helper item for that biblio.
|
|
diag("Creating item instance for testing.");
|
|
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
|
|
AddItem( { homebranch => 'MPL', holdingbranch => 'CPL' }, $bibnum );
|
|
|
|
my @branchcodes = qw{XXX RPL CPL MPL CPL MPL};
|
|
|
|
# Create some borrowers
|
|
diag("Creating borrowers.");
|
|
my @borrowernumbers;
|
|
foreach ( 1 .. $borrowers_count ) {
|
|
my $borrowernumber = AddMember(
|
|
firstname => 'my firstname',
|
|
surname => 'my surname ' . $_,
|
|
categorycode => 'S',
|
|
branchcode => $branchcodes[$_],
|
|
);
|
|
push @borrowernumbers, $borrowernumber;
|
|
}
|
|
|
|
my $biblionumber = $bibnum;
|
|
|
|
my @branches = GetBranchesLoop();
|
|
my $branch = $branches[0][0]{value};
|
|
|
|
# Create five item level holds
|
|
diag("Creating holds.");
|
|
my $i = 1;
|
|
foreach my $borrowernumber (@borrowernumbers) {
|
|
AddReserve(
|
|
$branchcodes[$i],
|
|
$borrowernumber,
|
|
$biblionumber,
|
|
my $constraint = 'a',
|
|
my $bibitems = q{},
|
|
my $priority = $i,
|
|
my $resdate,
|
|
my $expdate,
|
|
my $notes = q{},
|
|
$title,
|
|
my $checkitem,
|
|
my $found,
|
|
);
|
|
|
|
$i++;
|
|
}
|
|
|
|
my ($status, $reserve, $all_reserves);
|
|
|
|
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 0 );
|
|
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
|
|
ok( $reserve->{borrowernumber} eq $borrowernumbers[0], "Recieved expected results with LocalHoldsPriority disabled" );
|
|
|
|
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 );
|
|
|
|
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
|
|
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
|
|
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
|
|
ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with PickupLibrary/homebranch" );
|
|
|
|
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
|
|
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' );
|
|
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
|
|
ok( $reserve->{borrowernumber} eq $borrowernumbers[1], "Received expected results with PickupLibrary/holdingbranch" );
|
|
|
|
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
|
|
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' );
|
|
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
|
|
ok( $reserve->{borrowernumber} eq $borrowernumbers[1], "Received expected results with HomeLibrary/holdingbranch" );
|
|
|
|
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
|
|
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
|
|
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
|
|
ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with HomeLibrary/homebranch" );
|
|
|
|
# Helper method to set up a Biblio.
|
|
sub create_helper_biblio {
|
|
my $bib = MARC::Record->new();
|
|
my $title = 'Silence in the library';
|
|
$bib->append_fields(
|
|
MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
|
|
MARC::Field->new( '245', ' ', ' ', a => $title ),
|
|
);
|
|
return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );
|
|
}
|