Lines 2212-2254
subtest 'AddIssue & illrequests.due_date' => sub {
Link Here
|
2212 |
}; |
2212 |
}; |
2213 |
|
2213 |
|
2214 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
2214 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
2215 |
plan tests => 6; |
2215 |
plan tests => 31; |
|
|
2216 |
|
2217 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
2216 |
|
2218 |
|
2217 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
2219 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
2218 |
my $otherbranch = $builder->build( { source => 'Branch' } ); |
2220 |
my $holdingbranch = $builder->build( { source => 'Branch' } ); |
|
|
2221 |
my $returnbranch = $builder->build( { source => 'Branch' } ); |
2219 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
2222 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
2220 |
|
2223 |
|
2221 |
my $item = $builder->build_sample_item( |
2224 |
my $item = $builder->build_sample_item( |
2222 |
{ |
2225 |
{ |
2223 |
homebranch => $homebranch->{branchcode}, |
2226 |
homebranch => $homebranch->{branchcode}, |
2224 |
holdingbranch => $homebranch->{branchcode}, |
2227 |
holdingbranch => $holdingbranch->{branchcode}, |
2225 |
} |
2228 |
} |
2226 |
); |
2229 |
); |
2227 |
|
2230 |
|
2228 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2231 |
# Issue from holdingbranch |
2229 |
set_userenv($homebranch); |
2232 |
set_userenv($holdingbranch); |
2230 |
my $issue = AddIssue( $patron, $item->barcode ); |
2233 |
my $issue = AddIssue( $patron, $item->barcode ); |
2231 |
my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $otherbranch); |
2234 |
|
2232 |
is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to other is allowed'); |
2235 |
# 'Anywhere' + BranchTransferLimits |
|
|
2236 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2237 |
|
2238 |
# Attempt return at returnbranch (No limits defined) |
2239 |
my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2240 |
is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed'); |
2233 |
is ( undef , $message , 'without limits provides no message'); |
2241 |
is ( undef , $message , 'without limits provides no message'); |
2234 |
|
2242 |
|
2235 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
2243 |
# Set limit (Holding -> Return denied) |
2236 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
2244 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
2237 |
|
|
|
2238 |
# set limit |
2239 |
my $limit = Koha::Item::Transfer::Limit->new({ |
2245 |
my $limit = Koha::Item::Transfer::Limit->new({ |
2240 |
toBranch => $otherbranch->{branchcode}, |
2246 |
toBranch => $returnbranch->{branchcode}, |
2241 |
fromBranch => $item->homebranch, |
2247 |
fromBranch => $holdingbranch->{branchcode}, |
2242 |
itemtype => $item->effective_itemtype, |
2248 |
itemtype => $item->effective_itemtype, |
2243 |
})->store(); |
2249 |
})->store(); |
2244 |
|
2250 |
|
2245 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $otherbranch); |
2251 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Return limit)"); |
2246 |
is ( 0 , $allowed , 'With transfer limits cannot return to otherbranch'); |
2252 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
2247 |
is ( $homebranch->{branchcode} , $message , 'With transfer limits asks return to homebranch'); |
2253 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
|
|
2254 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
2255 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
2256 |
|
2257 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit)"); |
2258 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
2259 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2260 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
2261 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
2262 |
|
2263 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit)"); |
2264 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
2265 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2266 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
2267 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
2268 |
|
2269 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Return limit)"); |
2270 |
# NOTE: This prevents receiving an item from a branch that is listed in |
2271 |
# the branchtransferlimits as not allowed to send to our returnbranch. |
2272 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2273 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2274 |
is ( 0 , $allowed , 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch'); |
2275 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
2276 |
|
2277 |
# Set limit ( Return -> Home denied) |
2278 |
$limit->set( |
2279 |
{ |
2280 |
toBranch => $homebranch->{branchcode}, |
2281 |
fromBranch => $returnbranch->{branchcode} |
2282 |
} |
2283 |
)->store()->discard_changes; |
2248 |
|
2284 |
|
2249 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $homebranch); |
2285 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Home limit)"); |
2250 |
is ( 1 , $allowed , 'With transfer limits can return to homebranch'); |
2286 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
2251 |
is ( undef , $message , 'With transfer limits and homebranch provides no message'); |
2287 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
|
|
2288 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
2289 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
2290 |
|
2291 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Home limit)"); |
2292 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
2293 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2294 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
2295 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
2296 |
|
2297 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Home limit)"); |
2298 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
2299 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2300 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
2301 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
2302 |
|
2303 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Home limit)"); |
2304 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
2305 |
# to 'homebranch' (But we can transfer back to 'holdingbranch'). |
2306 |
# NOTE: This is the ONLY change that bug 7376 introduces currently. |
2307 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2308 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2309 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to from anywhere'); |
2310 |
|
2311 |
# Set limit ( Return -> Holding denied) |
2312 |
$limit->set( |
2313 |
{ |
2314 |
toBranch => $holdingbranch->{branchcode}, |
2315 |
fromBranch => $returnbranch->{branchcode} |
2316 |
} |
2317 |
)->store()->discard_changes; |
2318 |
|
2319 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Holding limit)"); |
2320 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
2321 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2322 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
2323 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
2324 |
|
2325 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit)"); |
2326 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
2327 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2328 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
2329 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
2330 |
|
2331 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit)"); |
2332 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
2333 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2334 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
2335 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
2336 |
|
2337 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Holding limit)"); |
2338 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
2339 |
# to 'holdingbranch' (But we can transfer back to 'homebranch'). |
2340 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2341 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2342 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to from anywhere'); |
2343 |
|
2344 |
# Set limit ( Holding -> Home denied) |
2345 |
$limit->set( |
2346 |
{ |
2347 |
toBranch => $holdingbranch->{branchcode}, |
2348 |
fromBranch => $returnbranch->{branchcode} |
2349 |
} |
2350 |
)->store()->discard_changes; |
2351 |
|
2352 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Home limit)"); |
2353 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
2354 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2355 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
2356 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
2357 |
|
2358 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit)"); |
2359 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
2360 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2361 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
2362 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
2363 |
|
2364 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit)"); |
2365 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
2366 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2367 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
2368 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
2369 |
|
2370 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Home limit)"); |
2371 |
# NOTE: A return here can subsequently be transfered to back to homebranch |
2372 |
# or holdingbranch. |
2373 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2374 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2375 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to from anywhere'); |
2252 |
}; |
2376 |
}; |
2253 |
|
2377 |
|
2254 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
2378 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
2255 |
- |
|
|