|
Lines 2898-2943
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub {
Link Here
|
| 2898 |
}; |
2898 |
}; |
| 2899 |
|
2899 |
|
| 2900 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
2900 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
| 2901 |
plan tests => 6; |
2901 |
plan tests => 31; |
|
|
2902 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
| 2902 |
|
2903 |
|
| 2903 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
2904 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
| 2904 |
my $otherbranch = $builder->build( { source => 'Branch' } ); |
2905 |
my $holdingbranch = $builder->build( { source => 'Branch' } ); |
| 2905 |
my $patron = |
2906 |
my $returnbranch = $builder->build( { source => 'Branch' } ); |
| 2906 |
$builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
2907 |
my $patron = $builder->build_object( |
|
|
2908 |
{ class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } ); |
| 2907 |
|
2909 |
|
| 2908 |
my $item = $builder->build_sample_item( |
2910 |
my $item = $builder->build_sample_item( |
| 2909 |
{ |
2911 |
{ |
| 2910 |
homebranch => $homebranch->{branchcode}, |
2912 |
homebranch => $homebranch->{branchcode}, |
| 2911 |
holdingbranch => $homebranch->{branchcode}, |
2913 |
holdingbranch => $holdingbranch->{branchcode}, |
| 2912 |
} |
2914 |
} |
| 2913 |
); |
2915 |
); |
| 2914 |
|
2916 |
|
| 2915 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2917 |
# Issue from holdingbranch |
| 2916 |
set_userenv($homebranch); |
2918 |
set_userenv($holdingbranch); |
| 2917 |
my $issue = AddIssue( $patron, $item->barcode ); |
2919 |
my $issue = AddIssue( $patron, $item->barcode ); |
| 2918 |
my ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $otherbranch ); |
2920 |
|
| 2919 |
is( 1, $allowed, 'with AllowReturnToBranch = anywhere and no limits return to other is allowed' ); |
2921 |
# 'Anywhere' + BranchTransferLimits |
|
|
2922 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2923 |
|
| 2924 |
# Attempt return at returnbranch (No limits defined) |
| 2925 |
my ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2926 |
is( 1, $allowed, 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed' ); |
| 2920 |
is( undef, $message, 'without limits provides no message' ); |
2927 |
is( undef, $message, 'without limits provides no message' ); |
| 2921 |
|
2928 |
|
| 2922 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
2929 |
# Set limit (Holding -> Return denied) |
| 2923 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
2930 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
| 2924 |
|
|
|
| 2925 |
# set limit |
| 2926 |
my $limit = Koha::Item::Transfer::Limit->new( |
2931 |
my $limit = Koha::Item::Transfer::Limit->new( |
| 2927 |
{ |
2932 |
{ |
| 2928 |
toBranch => $otherbranch->{branchcode}, |
2933 |
toBranch => $returnbranch->{branchcode}, |
| 2929 |
fromBranch => $item->homebranch, |
2934 |
fromBranch => $holdingbranch->{branchcode}, |
| 2930 |
itemtype => $item->effective_itemtype, |
2935 |
itemtype => $item->effective_itemtype, |
| 2931 |
} |
2936 |
} |
| 2932 |
)->store(); |
2937 |
)->store(); |
| 2933 |
|
2938 |
|
| 2934 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $otherbranch ); |
2939 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Return limit)"); |
| 2935 |
is( 0, $allowed, 'With transfer limits cannot return to otherbranch' ); |
2940 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2936 |
is( $homebranch->{branchcode}, $message, 'With transfer limits asks return to homebranch' ); |
2941 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
|
|
2942 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
| 2943 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2944 |
|
| 2945 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit)"); |
| 2946 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2947 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2948 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
| 2949 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 2950 |
|
| 2951 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit)"); |
| 2952 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2953 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2954 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
| 2955 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2956 |
|
| 2957 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Return limit)"); |
| 2958 |
|
| 2959 |
# NOTE: This prevents receiving an item from a branch that is listed in |
| 2960 |
# the branchtransferlimits as not allowed to send to our returnbranch. |
| 2961 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2962 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2963 |
is( 0, $allowed, 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch' ); |
| 2964 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2965 |
|
| 2966 |
# Set limit ( Return -> Home denied) |
| 2967 |
$limit->set( |
| 2968 |
{ |
| 2969 |
toBranch => $homebranch->{branchcode}, |
| 2970 |
fromBranch => $returnbranch->{branchcode} |
| 2971 |
} |
| 2972 |
)->store()->discard_changes; |
| 2973 |
|
| 2974 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Home limit)"); |
| 2975 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2976 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2977 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
| 2978 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2979 |
|
| 2980 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Home limit)"); |
| 2981 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2982 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2983 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
| 2984 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 2985 |
|
| 2986 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Home limit)"); |
| 2987 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2988 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2989 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
| 2990 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2991 |
|
| 2992 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Home limit)"); |
| 2993 |
|
| 2994 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
| 2995 |
# to 'homebranch' (But we can transfer back to 'holdingbranch'). |
| 2996 |
# NOTE: This is the ONLY change that bug 7376 introduces currently. |
| 2997 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2998 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2999 |
is( 1, $allowed, 'Allow return where returnbranch can be transfered to from anywhere' ); |
| 3000 |
|
| 3001 |
# Set limit ( Return -> Holding denied) |
| 3002 |
$limit->set( |
| 3003 |
{ |
| 3004 |
toBranch => $holdingbranch->{branchcode}, |
| 3005 |
fromBranch => $returnbranch->{branchcode} |
| 3006 |
} |
| 3007 |
)->store()->discard_changes; |
| 3008 |
|
| 3009 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Holding limit)"); |
| 3010 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 3011 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3012 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
| 3013 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 3014 |
|
| 3015 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit)"); |
| 3016 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 3017 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3018 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
| 3019 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 3020 |
|
| 3021 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit)"); |
| 3022 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 3023 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3024 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
| 3025 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2937 |
|
3026 |
|
| 2938 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $homebranch ); |
3027 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Holding limit)"); |
| 2939 |
is( 1, $allowed, 'With transfer limits can return to homebranch' ); |
3028 |
|
| 2940 |
is( undef, $message, 'With transfer limits and homebranch provides no message' ); |
3029 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
|
|
3030 |
# to 'holdingbranch' (But we can transfer back to 'homebranch'). |
| 3031 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 3032 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3033 |
is( 1, $allowed, 'Allow return where returnbranch can be transfered to from anywhere' ); |
| 3034 |
|
| 3035 |
# Set limit ( Holding -> Home denied) |
| 3036 |
$limit->set( |
| 3037 |
{ |
| 3038 |
toBranch => $holdingbranch->{branchcode}, |
| 3039 |
fromBranch => $returnbranch->{branchcode} |
| 3040 |
} |
| 3041 |
)->store()->discard_changes; |
| 3042 |
|
| 3043 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Home limit)"); |
| 3044 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 3045 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3046 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
| 3047 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 3048 |
|
| 3049 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit)"); |
| 3050 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 3051 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3052 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
| 3053 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 3054 |
|
| 3055 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit)"); |
| 3056 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 3057 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3058 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
| 3059 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 3060 |
|
| 3061 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Home limit)"); |
| 3062 |
|
| 3063 |
# NOTE: A return here can subsequently be transfered to back to homebranch |
| 3064 |
# or holdingbranch. |
| 3065 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 3066 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3067 |
is( 1, $allowed, 'Allow return where returnbranch can be transfered to from anywhere' ); |
| 2941 |
}; |
3068 |
}; |
| 2942 |
|
3069 |
|
| 2943 |
subtest 'Statistic patrons "X"' => sub { |
3070 |
subtest 'Statistic patrons "X"' => sub { |
| 2944 |
- |
|
|