|
Lines 2843-2888
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub {
Link Here
|
| 2843 |
}; |
2843 |
}; |
| 2844 |
|
2844 |
|
| 2845 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
2845 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
| 2846 |
plan tests => 6; |
2846 |
plan tests => 31; |
|
|
2847 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
| 2847 |
|
2848 |
|
| 2848 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
2849 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
| 2849 |
my $otherbranch = $builder->build( { source => 'Branch' } ); |
2850 |
my $holdingbranch = $builder->build( { source => 'Branch' } ); |
| 2850 |
my $patron = |
2851 |
my $returnbranch = $builder->build( { source => 'Branch' } ); |
| 2851 |
$builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
2852 |
my $patron = $builder->build_object( |
|
|
2853 |
{ class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } ); |
| 2852 |
|
2854 |
|
| 2853 |
my $item = $builder->build_sample_item( |
2855 |
my $item = $builder->build_sample_item( |
| 2854 |
{ |
2856 |
{ |
| 2855 |
homebranch => $homebranch->{branchcode}, |
2857 |
homebranch => $homebranch->{branchcode}, |
| 2856 |
holdingbranch => $homebranch->{branchcode}, |
2858 |
holdingbranch => $holdingbranch->{branchcode}, |
| 2857 |
} |
2859 |
} |
| 2858 |
); |
2860 |
); |
| 2859 |
|
2861 |
|
| 2860 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2862 |
# Issue from holdingbranch |
| 2861 |
set_userenv($homebranch); |
2863 |
set_userenv($holdingbranch); |
| 2862 |
my $issue = AddIssue( $patron, $item->barcode ); |
2864 |
my $issue = AddIssue( $patron, $item->barcode ); |
| 2863 |
my ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $otherbranch ); |
2865 |
|
| 2864 |
is( 1, $allowed, 'with AllowReturnToBranch = anywhere and no limits return to other is allowed' ); |
2866 |
# 'Anywhere' + BranchTransferLimits |
|
|
2867 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2868 |
|
| 2869 |
# Attempt return at returnbranch (No limits defined) |
| 2870 |
my ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2871 |
is( 1, $allowed, 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed' ); |
| 2865 |
is( undef, $message, 'without limits provides no message' ); |
2872 |
is( undef, $message, 'without limits provides no message' ); |
| 2866 |
|
2873 |
|
| 2867 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
2874 |
# Set limit (Holding -> Return denied) |
| 2868 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
2875 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
| 2869 |
|
|
|
| 2870 |
# set limit |
| 2871 |
my $limit = Koha::Item::Transfer::Limit->new( |
2876 |
my $limit = Koha::Item::Transfer::Limit->new( |
| 2872 |
{ |
2877 |
{ |
| 2873 |
toBranch => $otherbranch->{branchcode}, |
2878 |
toBranch => $returnbranch->{branchcode}, |
| 2874 |
fromBranch => $item->homebranch, |
2879 |
fromBranch => $holdingbranch->{branchcode}, |
| 2875 |
itemtype => $item->effective_itemtype, |
2880 |
itemtype => $item->effective_itemtype, |
| 2876 |
} |
2881 |
} |
| 2877 |
)->store(); |
2882 |
)->store(); |
| 2878 |
|
2883 |
|
| 2879 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $otherbranch ); |
2884 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Return limit)"); |
| 2880 |
is( 0, $allowed, 'With transfer limits cannot return to otherbranch' ); |
2885 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2881 |
is( $homebranch->{branchcode}, $message, 'With transfer limits asks return to homebranch' ); |
2886 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
|
|
2887 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
| 2888 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2889 |
|
| 2890 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit)"); |
| 2891 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2892 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2893 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
| 2894 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 2895 |
|
| 2896 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit)"); |
| 2897 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2898 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2899 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
| 2900 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2901 |
|
| 2902 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Return limit)"); |
| 2903 |
|
| 2904 |
# NOTE: This prevents receiving an item from a branch that is listed in |
| 2905 |
# the branchtransferlimits as not allowed to send to our returnbranch. |
| 2906 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2907 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2908 |
is( 0, $allowed, 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch' ); |
| 2909 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2910 |
|
| 2911 |
# Set limit ( Return -> Home denied) |
| 2912 |
$limit->set( |
| 2913 |
{ |
| 2914 |
toBranch => $homebranch->{branchcode}, |
| 2915 |
fromBranch => $returnbranch->{branchcode} |
| 2916 |
} |
| 2917 |
)->store()->discard_changes; |
| 2918 |
|
| 2919 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Home limit)"); |
| 2920 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2921 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2922 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
| 2923 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2924 |
|
| 2925 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Home limit)"); |
| 2926 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2927 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2928 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
| 2929 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 2882 |
|
2930 |
|
| 2883 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $homebranch ); |
2931 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Home limit)"); |
| 2884 |
is( 1, $allowed, 'With transfer limits can return to homebranch' ); |
2932 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2885 |
is( undef, $message, 'With transfer limits and homebranch provides no message' ); |
2933 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
|
|
2934 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
| 2935 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2936 |
|
| 2937 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Home limit)"); |
| 2938 |
|
| 2939 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
| 2940 |
# to 'homebranch' (But we can transfer back to 'holdingbranch'). |
| 2941 |
# NOTE: This is the ONLY change that bug 7376 introduces currently. |
| 2942 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2943 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2944 |
is( 1, $allowed, 'Allow return where returnbranch can be transfered to from anywhere' ); |
| 2945 |
|
| 2946 |
# Set limit ( Return -> Holding denied) |
| 2947 |
$limit->set( |
| 2948 |
{ |
| 2949 |
toBranch => $holdingbranch->{branchcode}, |
| 2950 |
fromBranch => $returnbranch->{branchcode} |
| 2951 |
} |
| 2952 |
)->store()->discard_changes; |
| 2953 |
|
| 2954 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Holding limit)"); |
| 2955 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2956 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2957 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
| 2958 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2959 |
|
| 2960 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit)"); |
| 2961 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2962 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2963 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
| 2964 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 2965 |
|
| 2966 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit)"); |
| 2967 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2968 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2969 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
| 2970 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2971 |
|
| 2972 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Holding limit)"); |
| 2973 |
|
| 2974 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
| 2975 |
# to 'holdingbranch' (But we can transfer back to 'homebranch'). |
| 2976 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2977 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2978 |
is( 1, $allowed, 'Allow return where returnbranch can be transfered to from anywhere' ); |
| 2979 |
|
| 2980 |
# Set limit ( Holding -> Home denied) |
| 2981 |
$limit->set( |
| 2982 |
{ |
| 2983 |
toBranch => $holdingbranch->{branchcode}, |
| 2984 |
fromBranch => $returnbranch->{branchcode} |
| 2985 |
} |
| 2986 |
)->store()->discard_changes; |
| 2987 |
|
| 2988 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Home limit)"); |
| 2989 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2990 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2991 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
| 2992 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2993 |
|
| 2994 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit)"); |
| 2995 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2996 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2997 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
| 2998 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 2999 |
|
| 3000 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit)"); |
| 3001 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 3002 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3003 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
| 3004 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 3005 |
|
| 3006 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Home limit)"); |
| 3007 |
|
| 3008 |
# NOTE: A return here can subsequently be transfered to back to homebranch |
| 3009 |
# or holdingbranch. |
| 3010 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 3011 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3012 |
is( 1, $allowed, 'Allow return where returnbranch can be transfered to from anywhere' ); |
| 2886 |
}; |
3013 |
}; |
| 2887 |
|
3014 |
|
| 2888 |
subtest 'Statistic patrons "X"' => sub { |
3015 |
subtest 'Statistic patrons "X"' => sub { |
| 2889 |
- |
|
|