|
Lines 2602-2644
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub {
Link Here
|
| 2602 |
|
2602 |
|
| 2603 |
|
2603 |
|
| 2604 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
2604 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
| 2605 |
plan tests => 6; |
2605 |
plan tests => 31; |
|
|
2606 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
| 2606 |
|
2607 |
|
| 2607 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
2608 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
| 2608 |
my $otherbranch = $builder->build( { source => 'Branch' } ); |
2609 |
my $holdingbranch = $builder->build( { source => 'Branch' } ); |
| 2609 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
2610 |
my $returnbranch = $builder->build( { source => 'Branch' } ); |
|
|
2611 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } ); |
| 2610 |
|
2612 |
|
| 2611 |
my $item = $builder->build_sample_item( |
2613 |
my $item = $builder->build_sample_item( |
| 2612 |
{ |
2614 |
{ |
| 2613 |
homebranch => $homebranch->{branchcode}, |
2615 |
homebranch => $homebranch->{branchcode}, |
| 2614 |
holdingbranch => $homebranch->{branchcode}, |
2616 |
holdingbranch => $holdingbranch->{branchcode}, |
| 2615 |
} |
2617 |
} |
| 2616 |
); |
2618 |
); |
| 2617 |
|
2619 |
|
| 2618 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2620 |
# Issue from holdingbranch |
| 2619 |
set_userenv($homebranch); |
2621 |
set_userenv($holdingbranch); |
| 2620 |
my $issue = AddIssue( $patron, $item->barcode ); |
2622 |
my $issue = AddIssue( $patron, $item->barcode ); |
| 2621 |
my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $otherbranch); |
2623 |
|
| 2622 |
is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to other is allowed'); |
2624 |
# 'Anywhere' + BranchTransferLimits |
|
|
2625 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2626 |
|
| 2627 |
# Attempt return at returnbranch (No limits defined) |
| 2628 |
my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2629 |
is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed'); |
| 2623 |
is ( undef , $message , 'without limits provides no message'); |
2630 |
is ( undef , $message , 'without limits provides no message'); |
| 2624 |
|
2631 |
|
| 2625 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
2632 |
# Set limit (Holding -> Return denied) |
| 2626 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
2633 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
| 2627 |
|
|
|
| 2628 |
# set limit |
| 2629 |
my $limit = Koha::Item::Transfer::Limit->new({ |
2634 |
my $limit = Koha::Item::Transfer::Limit->new({ |
| 2630 |
toBranch => $otherbranch->{branchcode}, |
2635 |
toBranch => $returnbranch->{branchcode}, |
| 2631 |
fromBranch => $item->homebranch, |
2636 |
fromBranch => $holdingbranch->{branchcode}, |
| 2632 |
itemtype => $item->effective_itemtype, |
2637 |
itemtype => $item->effective_itemtype, |
| 2633 |
})->store(); |
2638 |
})->store(); |
| 2634 |
|
2639 |
|
| 2635 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $otherbranch); |
2640 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Return limit)"); |
| 2636 |
is ( 0 , $allowed , 'With transfer limits cannot return to otherbranch'); |
2641 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2637 |
is ( $homebranch->{branchcode} , $message , 'With transfer limits asks return to homebranch'); |
2642 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
|
|
2643 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
| 2644 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2645 |
|
| 2646 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit)"); |
| 2647 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2648 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2649 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
| 2650 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
| 2651 |
|
| 2652 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit)"); |
| 2653 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2654 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2655 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
| 2656 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2657 |
|
| 2658 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Return limit)"); |
| 2659 |
# NOTE: This prevents receiving an item from a branch that is listed in |
| 2660 |
# the branchtransferlimits as not allowed to send to our returnbranch. |
| 2661 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2662 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2663 |
is ( 0 , $allowed , 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch'); |
| 2664 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2665 |
|
| 2666 |
# Set limit ( Return -> Home denied) |
| 2667 |
$limit->set( |
| 2668 |
{ |
| 2669 |
toBranch => $homebranch->{branchcode}, |
| 2670 |
fromBranch => $returnbranch->{branchcode} |
| 2671 |
} |
| 2672 |
)->store()->discard_changes; |
| 2673 |
|
| 2674 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Home limit)"); |
| 2675 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2676 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2677 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
| 2678 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2679 |
|
| 2680 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Home limit)"); |
| 2681 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2682 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2683 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
| 2684 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
| 2685 |
|
| 2686 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Home limit)"); |
| 2687 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2688 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2689 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
| 2690 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2691 |
|
| 2692 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Home limit)"); |
| 2693 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
| 2694 |
# to 'homebranch' (But we can transfer back to 'holdingbranch'). |
| 2695 |
# NOTE: This is the ONLY change that bug 7376 introduces currently. |
| 2696 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2697 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2698 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to from anywhere'); |
| 2699 |
|
| 2700 |
# Set limit ( Return -> Holding denied) |
| 2701 |
$limit->set( |
| 2702 |
{ |
| 2703 |
toBranch => $holdingbranch->{branchcode}, |
| 2704 |
fromBranch => $returnbranch->{branchcode} |
| 2705 |
} |
| 2706 |
)->store()->discard_changes; |
| 2707 |
|
| 2708 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Holding limit)"); |
| 2709 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2710 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2711 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
| 2712 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2713 |
|
| 2714 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit)"); |
| 2715 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2716 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2717 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
| 2718 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
| 2719 |
|
| 2720 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit)"); |
| 2721 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2722 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2723 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
| 2724 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2725 |
|
| 2726 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Holding limit)"); |
| 2727 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
| 2728 |
# to 'holdingbranch' (But we can transfer back to 'homebranch'). |
| 2729 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2730 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2731 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to from anywhere'); |
| 2732 |
|
| 2733 |
# Set limit ( Holding -> Home denied) |
| 2734 |
$limit->set( |
| 2735 |
{ |
| 2736 |
toBranch => $holdingbranch->{branchcode}, |
| 2737 |
fromBranch => $returnbranch->{branchcode} |
| 2738 |
} |
| 2739 |
)->store()->discard_changes; |
| 2740 |
|
| 2741 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Home limit)"); |
| 2742 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2743 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2744 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
| 2745 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2638 |
|
2746 |
|
| 2639 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $homebranch); |
2747 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit)"); |
| 2640 |
is ( 1 , $allowed , 'With transfer limits can return to homebranch'); |
2748 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2641 |
is ( undef , $message , 'With transfer limits and homebranch provides no message'); |
2749 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
|
|
2750 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
| 2751 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
| 2752 |
|
| 2753 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit)"); |
| 2754 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2755 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2756 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
| 2757 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2758 |
|
| 2759 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Home limit)"); |
| 2760 |
# NOTE: A return here can subsequently be transfered to back to homebranch |
| 2761 |
# or holdingbranch. |
| 2762 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2763 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2764 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to from anywhere'); |
| 2642 |
}; |
2765 |
}; |
| 2643 |
|
2766 |
|
| 2644 |
|
2767 |
|
| 2645 |
- |
|
|