|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
=head TESTING PLAN |
| 4 |
|
| 5 |
PRECONDITIONS| |
| 6 |
-------------+ |
| 7 |
UseBranchTranferLimits itemtype DVD |
| 8 |
IPT -> CPL -> FFL -> IPT |
| 9 |
no transfers into LPL |
| 10 |
|
| 11 |
TransportCostMatrix in use |
| 12 |
Allow all, cost 1 |
| 13 |
|
| 14 |
-> pickup branch IPT <- |
| 15 |
-> Borrowers homebranch LPL <- |
| 16 |
|
| 17 |
|
| 18 |
Biblio1 Items |
| 19 |
Item barcode holdingbranch transferOK? itemtype |
| 20 |
cpl11 CPL 0 DVD |
| 21 |
cpl12 CPL 1 BK |
| 22 |
ffl11 FFL 1 DVD |
| 23 |
ffl12 FFL 1 BK |
| 24 |
|
| 25 |
Biblio2 Items |
| 26 |
Item barcode holdingbranch transferOK? itemtype |
| 27 |
cpl21 CPL 0 DVD |
| 28 |
cpl22 CPL 0 DVD |
| 29 |
|
| 30 |
Biblio3 Items |
| 31 |
Item barcode holdingbranch transferOK? itemtype |
| 32 |
ffl31 FFL 1 DVD |
| 33 |
ffl32 FFL 1 BK |
| 34 |
|
| 35 |
--------------------- |
| 36 |
--- HoldsQueue.pm --- |
| 37 |
--------------------- |
| 38 |
|
| 39 |
CASE1: Title-level multi_hold on all Biblios, pickup location IPT |
| 40 |
|
| 41 |
Expected: |
| 42 |
Hold for Biblio1 gets satisfied with Items cpl12, ipt11, ipt12 or ffl1. |
| 43 |
Hold for Biblio2 fails to satisfy, no messages given. |
| 44 |
Hold for Biblio3 is satisfied with ffl31. |
| 45 |
|
| 46 |
|
| 47 |
CASE2: Item-level holds, pickup location IPT |
| 48 |
|
| 49 |
Expected: |
| 50 |
Item to hold hold satisfied? |
| 51 |
cpl1 0 |
| 52 |
cpl12 1 |
| 53 |
ipt11 1 |
| 54 |
ipt12 1 |
| 55 |
ffl1 1 |
| 56 |
cpl21 0 |
| 57 |
cpl22 0 |
| 58 |
cpl23 1 |
| 59 |
ffl31 1 |
| 60 |
ffl32 1 |
| 61 |
|
| 62 |
|
| 63 |
=cut |
| 64 |
|
| 65 |
use Modern::Perl; |
| 66 |
|
| 67 |
use C4::Context; |
| 68 |
|
| 69 |
use Test::More tests => 9; |
| 70 |
|
| 71 |
use C4::Circulation; |
| 72 |
use C4::Record; |
| 73 |
use C4::HoldsQueue; |
| 74 |
use C4::Reserves; |
| 75 |
use C4::HoldsQueue; |
| 76 |
|
| 77 |
# Start transaction |
| 78 |
my $dbh = C4::Context->dbh; |
| 79 |
$dbh->{AutoCommit} = 0; |
| 80 |
$dbh->{RaiseError} = 1; |
| 81 |
|
| 82 |
|
| 83 |
##########################xxxxxxxxxxxxxxxxxxxxxxxxx########################### |
| 84 |
### xxxxxxxxxxxxxxxxxxxxxxxxxx Set up the stage xxxxxxxxxxxxxxxxxxxxxxxxxx ### |
| 85 |
##########################xxxxxxxxxxxxxxxxxxxxxxxxx########################### |
| 86 |
|
| 87 |
## Set branches |
| 88 |
my $desiredBranches = ['IPT', 'CPL', 'FFL', 'LPL']; |
| 89 |
my $branches = C4::Branch::GetBranches; |
| 90 |
|
| 91 |
foreach my $branchCode (@$desiredBranches) { |
| 92 |
if (exists $branches->{$branchCode}) { |
| 93 |
#Alls well and the library is here yay! |
| 94 |
} |
| 95 |
else { |
| 96 |
#le fuu! who is not using the default libraries? |
| 97 |
my $branchwhatever = C4::SQLHelper::InsertInTable("branches",{branchcode=>"$branchCode",branchname=>"Yet another branch",city=>" ",zipcode=>" "},1); |
| 98 |
print $branchwhatever; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
my %data = ( |
| 103 |
cardnumber => 'CARDNUMBER42', |
| 104 |
firstname => 'my firstname', |
| 105 |
surname => 'my surname', |
| 106 |
categorycode => 'S', |
| 107 |
branchcode => 'LPL', |
| 108 |
); |
| 109 |
|
| 110 |
my $borrowernumber = C4::Members::AddMember(%data); |
| 111 |
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); |
| 112 |
|
| 113 |
|
| 114 |
## Itemtypes |
| 115 |
my $itemTypes = { map {$_->{itemtype} => 1} C4::ItemType->all() }; |
| 116 |
if (! (exists $itemTypes->{'BK'})) { |
| 117 |
$dbh->do("INSERT INTO `kohadata`.`itemtypes` (`itemtype`, `description`, `rentalcharge`, `notforloan`, `imageurl`, `summary`, `checkinmsg`, `checkinmsgtype`) VALUES ('BK', NULL, '0', NULL, NULL, NULL, NULL, 'message');"); |
| 118 |
} |
| 119 |
if (! (exists $itemTypes->{'DVD'})) { |
| 120 |
$dbh->do("INSERT INTO `kohadata`.`itemtypes` (`itemtype`, `description`, `rentalcharge`, `notforloan`, `imageurl`, `summary`, `checkinmsg`, `checkinmsgtype`) VALUES ('DVD', NULL, '0', NULL, NULL, NULL, NULL, 'message');"); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
## Add example Bibliographic records |
| 126 |
|
| 127 |
my ( $biblioNumber1, $biblioNumber2, $biblioNumber3, $discardBiblioitemnumber); |
| 128 |
my $bibFramework = ''; #Using the default bibliographic framework. |
| 129 |
|
| 130 |
my $marcxml=qq(<?xml version="1.0" encoding="UTF-8"?> |
| 131 |
<record format="MARC21" type="Bibliographic"> |
| 132 |
<leader>00000cim a22000004a 4500</leader> |
| 133 |
<controlfield tag="007">ss||||j|||||||</controlfield> |
| 134 |
<controlfield tag="008"> uuuu xxk|||||||||||||||||eng|c</controlfield> |
| 135 |
<datafield tag="245" ind1="1" ind2="4"> |
| 136 |
<subfield code="a">BIBLIO1</subfield> |
| 137 |
</datafield> |
| 138 |
</record> |
| 139 |
); |
| 140 |
my $record=C4::Record::marcxml2marc($marcxml); |
| 141 |
( $biblioNumber1, $discardBiblioitemnumber ) = C4::Biblio::AddBiblio( $record, $bibFramework, { defer_marc_save => 1 } ); |
| 142 |
|
| 143 |
$marcxml=qq(<?xml version="1.0" encoding="UTF-8"?> |
| 144 |
<record format="MARC21" type="Bibliographic"> |
| 145 |
<leader>00000cim a22000004a 4500</leader> |
| 146 |
<controlfield tag="007">ss||||j|||||||</controlfield> |
| 147 |
<controlfield tag="008"> uuuu xxk|||||||||||||||||eng|c</controlfield> |
| 148 |
<datafield tag="245" ind1="1" ind2="4"> |
| 149 |
<subfield code="a">BIBLIO2</subfield> |
| 150 |
</datafield> |
| 151 |
</record> |
| 152 |
); |
| 153 |
$record=C4::Record::marcxml2marc($marcxml); |
| 154 |
( $biblioNumber2, $discardBiblioitemnumber ) = C4::Biblio::AddBiblio( $record, $bibFramework, { defer_marc_save => 1 } ); |
| 155 |
|
| 156 |
$marcxml=qq(<?xml version="1.0" encoding="UTF-8"?> |
| 157 |
<record format="MARC21" type="Bibliographic"> |
| 158 |
<leader>00000cim a22000004a 4500</leader> |
| 159 |
<controlfield tag="007">ss||||j|||||||</controlfield> |
| 160 |
<controlfield tag="008"> uuuu xxk|||||||||||||||||eng|c</controlfield> |
| 161 |
<datafield tag="245" ind1="1" ind2="4"> |
| 162 |
<subfield code="a">BIBLIO3</subfield> |
| 163 |
</datafield> |
| 164 |
</record> |
| 165 |
); |
| 166 |
$record=C4::Record::marcxml2marc($marcxml); |
| 167 |
( $biblioNumber3, $discardBiblioitemnumber ) = C4::Biblio::AddBiblio( $record, $bibFramework, { defer_marc_save => 1 } ); |
| 168 |
|
| 169 |
## Add items to the mix |
| 170 |
my ($discardThis, $discardThat); # Not needing biblionumber or biblioitemnumber for the added items |
| 171 |
my ($cpl11, $cpl12, $ffl11, $ffl12, $cpl21, $cpl22, $ffl31, $ffl32); |
| 172 |
|
| 173 |
($discardThis, $discardThat, $cpl11) = C4::Items::AddItem({ barcode => 'cpl11', homebranch => 'CPL', holdingbranch => 'CPL', itype => 'DVD', notforloan => '0' }, $biblioNumber1); |
| 174 |
($discardThis, $discardThat, $cpl12) = C4::Items::AddItem({ barcode => 'cpl12', homebranch => 'CPL', holdingbranch => 'CPL', itype => 'BK' , notforloan => '0' }, $biblioNumber1); |
| 175 |
($discardThis, $discardThat, $ffl11) = C4::Items::AddItem({ barcode => 'ffl11', homebranch => 'FFL', holdingbranch => 'FFL', itype => 'DVD', notforloan => '0' }, $biblioNumber1); |
| 176 |
($discardThis, $discardThat, $ffl12) = C4::Items::AddItem({ barcode => 'ffl12', homebranch => 'FFL', holdingbranch => 'FFL', itype => 'BK' , notforloan => '0' }, $biblioNumber1); |
| 177 |
|
| 178 |
($discardThis, $discardThat, $cpl21) = C4::Items::AddItem({ barcode => 'cpl21', homebranch => 'CPL', holdingbranch => 'CPL', itype => 'DVD', notforloan => '0' }, $biblioNumber2); |
| 179 |
($discardThis, $discardThat, $cpl22) = C4::Items::AddItem({ barcode => 'cpl22', homebranch => 'CPL', holdingbranch => 'CPL', itype => 'DVD', notforloan => '0' }, $biblioNumber2); |
| 180 |
|
| 181 |
($discardThis, $discardThat, $ffl31) = C4::Items::AddItem({ barcode => 'ffl31', homebranch => 'FFL', holdingbranch => 'FFL', itype => 'DVD', notforloan => '0' }, $biblioNumber3); |
| 182 |
($discardThis, $discardThat, $ffl32) = C4::Items::AddItem({ barcode => 'ffl32', homebranch => 'FFL', holdingbranch => 'FFL', itype => 'BK' , notforloan => '0' }, $biblioNumber3); |
| 183 |
|
| 184 |
|
| 185 |
## Sysprefs and cost matrix |
| 186 |
C4::Context->set_preference('UseTransportCostMatrix', 1); |
| 187 |
C4::Context->set_preference('item-level_itypes', 1); |
| 188 |
C4::Context->set_preference("BranchTransferLimitsType", 'itemtype'); |
| 189 |
C4::Context->set_preference('StaticHoldsQueueWeight', 0); |
| 190 |
C4::Context->set_preference('RandomizeHoldsQueueWeight', 0); |
| 191 |
|
| 192 |
|
| 193 |
C4::HoldsQueue::UpdateTransportCostMatrix( [ |
| 194 |
{frombranch => 'IPT', tobranch => 'CPL', cost => 1, disable_transfer => 0}, |
| 195 |
{frombranch => 'IPT', tobranch => 'FFL', cost => 1, disable_transfer => 0}, |
| 196 |
{frombranch => 'IPT', tobranch => 'LPL', cost => 1, disable_transfer => 0}, |
| 197 |
{frombranch => 'CPL', tobranch => 'FFL', cost => 1, disable_transfer => 0}, |
| 198 |
{frombranch => 'CPL', tobranch => 'IPT', cost => 0.2, disable_transfer => 0}, |
| 199 |
{frombranch => 'CPL', tobranch => 'LPL', cost => 1, disable_transfer => 0}, |
| 200 |
{frombranch => 'FFL', tobranch => 'IPT', cost => 1, disable_transfer => 0}, |
| 201 |
{frombranch => 'FFL', tobranch => 'CPL', cost => 1, disable_transfer => 0}, |
| 202 |
{frombranch => 'FFL', tobranch => 'LPL', cost => 1, disable_transfer => 0}, |
| 203 |
] ); |
| 204 |
|
| 205 |
|
| 206 |
C4::Circulation::DeleteBranchTransferLimits( 'IPT' ); |
| 207 |
C4::Circulation::DeleteBranchTransferLimits( 'CPL' ); |
| 208 |
C4::Circulation::DeleteBranchTransferLimits( 'FFL' ); |
| 209 |
C4::Circulation::DeleteBranchTransferLimits( 'LPL' ); |
| 210 |
# CreateBranchTransferLimit( to , from, code ); Block these transfers! |
| 211 |
C4::Circulation::CreateBranchTransferLimit( 'IPT', 'CPL', 'DVD' ); |
| 212 |
C4::Circulation::CreateBranchTransferLimit( 'CPL', 'FFL', 'DVD' ); |
| 213 |
C4::Circulation::CreateBranchTransferLimit( 'FFL', 'IPT', 'DVD' ); |
| 214 |
C4::Circulation::CreateBranchTransferLimit( 'LPL', 'IPT', 'DVD' ); |
| 215 |
C4::Circulation::CreateBranchTransferLimit( 'LPL', 'CPL', 'DVD' ); |
| 216 |
C4::Circulation::CreateBranchTransferLimit( 'LPL', 'FFL', 'DVD' ); |
| 217 |
|
| 218 |
|
| 219 |
#############################xxxxxxxxxxxxxxxxxxxxxxxxx########################### |
| 220 |
### xxxxxxxxxxxxxxxxxxxxxxxxxx Start running tests xxxxxxxxxxxxxxxxxxxxxxxxxx ### |
| 221 |
#############################xxxxxxxxxxxxxxxxxxxxxxxxx########################### |
| 222 |
|
| 223 |
|
| 224 |
############# |
| 225 |
### CASE1: Title-level multi_hold on all Biblios, pickup location IPT ### |
| 226 |
############# |
| 227 |
|
| 228 |
## Remove existing reserves, makes debugging easier |
| 229 |
$dbh->do("DELETE FROM reserves"); |
| 230 |
|
| 231 |
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber1, 'a', '', '1' ); |
| 232 |
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber2, 'a', '', '1' ); |
| 233 |
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber3, 'a', '', '1' ); |
| 234 |
|
| 235 |
$dbh->do("UPDATE reserves SET reservedate = DATE_SUB( reservedate, INTERVAL 1 DAY )"); |
| 236 |
|
| 237 |
## Item cpl11 is a DVD and transferring it from CPL to IPT is strictly forbidden. |
| 238 |
## Transport matrix favours CPL -> IPT transports, so we should get either the BK or DVD. |
| 239 |
my $testOk = 0; |
| 240 |
my $branches_to_use = undef; #Testing only with Transport cost matrix since it is the future! |
| 241 |
my $transport_cost_matrix = C4::HoldsQueue::TransportCostMatrix(); |
| 242 |
my $hold_requests = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblioNumber1); |
| 243 |
my $available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblioNumber1, $branches_to_use); |
| 244 |
my $item_map = C4::HoldsQueue::MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix); |
| 245 |
my $rib = (C4::Items::GetItem( (keys %$item_map)[0] ))->{barcode}; #Reserved Item's barcode |
| 246 |
$testOk = 1 if ($rib eq 'cpl12'); |
| 247 |
is($testOk, 1, 'Title-level hold, mixed material, Biblio1'); |
| 248 |
=head |
| 249 |
## Should fail, requesting DVD's from a transfer-denied branch. |
| 250 |
$testOk = 0; |
| 251 |
$branches_to_use = undef; #Testing only with Transport cost matrix since it is the future! |
| 252 |
$transport_cost_matrix = C4::HoldsQueue::TransportCostMatrix(); |
| 253 |
$hold_requests = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblioNumber2); |
| 254 |
$available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblioNumber2, $branches_to_use); |
| 255 |
$item_map = C4::HoldsQueue::MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix); |
| 256 |
$testOk = %$item_map; #This time we should have no results |
| 257 |
is($testOk, 0, 'Title-level hold, transfer denied, Biblio2'); |
| 258 |
|
| 259 |
## Should succeed, no transfer blocks |
| 260 |
$testOk = 0; |
| 261 |
$branches_to_use = undef; #Testing only with Transport cost matrix since it is the future! |
| 262 |
$transport_cost_matrix = C4::HoldsQueue::TransportCostMatrix(); |
| 263 |
$hold_requests = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblioNumber3); |
| 264 |
$available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblioNumber3, $branches_to_use); |
| 265 |
$item_map = C4::HoldsQueue::MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix); |
| 266 |
$testOk = keys %$item_map; #This time any result will do |
| 267 |
is($testOk, 1, 'Title-level hold, transfer allowed, Biblio3'); |
| 268 |
=cut |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
############# |
| 273 |
### CASE2: Item-level holds, pickup location IPT ### |
| 274 |
############# |
| 275 |
|
| 276 |
## Remove existing reserves, makes debugging easier |
| 277 |
$dbh->do("DELETE FROM reserves"); |
| 278 |
|
| 279 |
#$branch, $borrowernumber, $biblionumber, $constraint, $bibitems, $priority, $resdate, $expdate, $notes, $title, $checkitem, $found |
| 280 |
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber1, undef, undef, '1', undef, undef, undef, undef, $cpl11, undef ); |
| 281 |
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber1, undef, undef, '1', undef, undef, undef, undef, $cpl12, undef ); |
| 282 |
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber1, undef, undef, '1', undef, undef, undef, undef, $ffl11, undef ); |
| 283 |
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber1, undef, undef, '1', undef, undef, undef, undef, $ffl12, undef ); |
| 284 |
|
| 285 |
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber2, undef, undef, '1', undef, undef, undef, undef, $cpl21, undef ); |
| 286 |
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber2, undef, undef, '1', undef, undef, undef, undef, $cpl22, undef ); |
| 287 |
|
| 288 |
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber3, undef, undef, '1', undef, undef, undef, undef, $ffl31, undef ); |
| 289 |
C4::Reserves::AddReserve ( 'IPT', $borrowernumber, $biblioNumber3, undef, undef, '1', undef, undef, undef, undef, $ffl32, undef ); |
| 290 |
|
| 291 |
$dbh->do("UPDATE reserves SET reservedate = DATE_SUB( reservedate, INTERVAL 1 DAY )"); |
| 292 |
|
| 293 |
## Transfer of cpl11 should be blocked, other 3 Items are mapped |
| 294 |
$testOk = 0; |
| 295 |
$branches_to_use = undef; #Testing only with Transport cost matrix since it is the future! |
| 296 |
$transport_cost_matrix = C4::HoldsQueue::TransportCostMatrix(); |
| 297 |
$hold_requests = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblioNumber1); |
| 298 |
$available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblioNumber1, $branches_to_use); |
| 299 |
$item_map = C4::HoldsQueue::MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix); |
| 300 |
is( (exists $item_map->{$cpl11}) , '', 'Item cpl11 transfer denied'); |
| 301 |
is( (exists $item_map->{$cpl12}) , 1, 'Item cpl12 transfer allowed'); |
| 302 |
is( (exists $item_map->{$ffl11}) , 1, 'Item cpl11 transfer allowed'); |
| 303 |
is( (exists $item_map->{$ffl12}) , 1, 'Item cpl11 transfer allowed'); |
| 304 |
|
| 305 |
## All items should fail their transfer |
| 306 |
$testOk = 0; |
| 307 |
$branches_to_use = undef; #Testing only with Transport cost matrix since it is the future! |
| 308 |
$transport_cost_matrix = C4::HoldsQueue::TransportCostMatrix(); |
| 309 |
$hold_requests = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblioNumber2); |
| 310 |
$available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblioNumber2, $branches_to_use); |
| 311 |
$item_map = C4::HoldsQueue::MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix); |
| 312 |
is( (exists $item_map->{$cpl21}) , '', 'Item cpl21 transfer denied'); |
| 313 |
is( (exists $item_map->{$cpl22}) , '', 'Item cpl22 transfer denied'); |
| 314 |
|
| 315 |
## Should succeed, no transfer blocks |
| 316 |
$testOk = 0; |
| 317 |
$branches_to_use = undef; #Testing only with Transport cost matrix since it is the future! |
| 318 |
$transport_cost_matrix = C4::HoldsQueue::TransportCostMatrix(); |
| 319 |
$hold_requests = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblioNumber3); |
| 320 |
$available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblioNumber3, $branches_to_use); |
| 321 |
$item_map = C4::HoldsQueue::MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix); |
| 322 |
is( (exists $item_map->{$ffl31}) , 1, 'Item ffl31 transfer allowed'); |
| 323 |
is( (exists $item_map->{$ffl32}) , 1, 'Item ffl32 transfer allowed'); |
| 324 |
|
| 325 |
# Cleanup |
| 326 |
$dbh->rollback(); |