|
Lines 1925-1932
subtest 'AddIssue & AllowReturnToBranch' => sub {
Link Here
|
| 1925 |
}; |
1925 |
}; |
| 1926 |
|
1926 |
|
| 1927 |
|
1927 |
|
| 1928 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
1928 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits + CirculationRules' => sub { |
| 1929 |
plan tests => 33; |
1929 |
plan tests => 22; |
| 1930 |
|
1930 |
|
| 1931 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
1931 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
| 1932 |
|
1932 |
|
|
Lines 1946-2078
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub {
Link Here
|
| 1946 |
set_userenv($holdingbranch); |
1946 |
set_userenv($holdingbranch); |
| 1947 |
my $issue = AddIssue( $patron, $item->barcode ); |
1947 |
my $issue = AddIssue( $patron, $item->barcode ); |
| 1948 |
|
1948 |
|
| 1949 |
# 'Anywhere' + BranchTransferLimits |
1949 |
# Attempt returns at returnbranch |
| 1950 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
|
|
| 1951 |
|
| 1952 |
# Attempt return at returnbranch (No limits defined) |
| 1953 |
my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 1954 |
is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed'); |
| 1955 |
is ( undef , $message , 'without limits provides no message'); |
| 1956 |
|
| 1957 |
# Set limit (Holding -> Return denied) |
| 1958 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
| 1959 |
my $limit = Koha::Item::Transfer::Limit->new({ |
| 1960 |
toBranch => $returnbranch->{branchcode}, |
| 1961 |
fromBranch => $holdingbranch->{branchcode}, |
| 1962 |
itemtype => $item->effective_itemtype, |
| 1963 |
})->store(); |
| 1964 |
|
| 1965 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Return limit)"); |
| 1966 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
1950 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 1967 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1951 |
my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}); |
| 1968 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
1952 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
| 1969 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1953 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 1970 |
|
1954 |
|
| 1971 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit)"); |
|
|
| 1972 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
1955 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 1973 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1956 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}); |
| 1974 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
1957 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
| 1975 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
1958 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
| 1976 |
|
1959 |
|
| 1977 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit)"); |
|
|
| 1978 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
1960 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 1979 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1961 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}); |
| 1980 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
1962 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
| 1981 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1963 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 1982 |
|
1964 |
|
| 1983 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Return limit)"); |
|
|
| 1984 |
# NOTE: This prevents receiving an item from a branch that is listed in |
| 1985 |
# the branchtransferlimits as not allowed to send to our returnbranch. |
| 1986 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1965 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 1987 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1966 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}); |
| 1988 |
is ( 0 , $allowed , 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch'); |
1967 |
is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed'); |
| 1989 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1968 |
is ( undef , $message , 'without limits provides no message'); |
| 1990 |
|
|
|
| 1991 |
# Set limit ( Return -> Home denied) |
| 1992 |
$limit->set( |
| 1993 |
{ |
| 1994 |
toBranch => $homebranch->{branchcode}, |
| 1995 |
fromBranch => $returnbranch->{branchcode} |
| 1996 |
} |
| 1997 |
)->store()->discard_changes; |
| 1998 |
|
| 1999 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Home limit)"); |
| 2000 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2001 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2002 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
| 2003 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2004 |
|
| 2005 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Home limit)"); |
| 2006 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2007 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2008 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
| 2009 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
| 2010 |
|
| 2011 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Home limit)"); |
| 2012 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2013 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2014 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
| 2015 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2016 |
|
| 2017 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Home limit)"); |
| 2018 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
| 2019 |
# to 'homebranch' (But we can transfer back to 'holdingbranch'). |
| 2020 |
# NOTE: This is the ONLY change that bug 7376 introduces currently. |
| 2021 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2022 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2023 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to holding (homebranch forbidden) from returnbranch'); |
| 2024 |
|
1969 |
|
| 2025 |
my $limit_2 = Koha::Item::Transfer::Limit->new({ |
1970 |
# Set limit (Holding -> Return denied) |
| 2026 |
toBranch => $holdingbranch->{branchcode}, |
1971 |
diag("Transfer limit: Holding -> Return"); |
| 2027 |
fromBranch => $returnbranch->{branchcode}, |
1972 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
|
|
1973 |
my $limit = Koha::Item::Transfer::Limit->new({ |
| 1974 |
toBranch => $returnbranch->{branchcode}, |
| 1975 |
fromBranch => $holdingbranch->{branchcode}, |
| 2028 |
itemtype => $item->effective_itemtype, |
1976 |
itemtype => $item->effective_itemtype, |
| 2029 |
})->store(); |
1977 |
})->store(); |
| 2030 |
|
1978 |
|
| 2031 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Home and Return -> Holding limit)"); |
|
|
| 2032 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
| 2033 |
# to 'homebranch' (But we can transfer back to 'holdingbranch'). |
| 2034 |
# NOTE: This is the ONLY change that bug 7376 introduces currently. |
| 2035 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1979 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2036 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1980 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}); |
| 2037 |
is ( 0 , $allowed , 'Prevent return where item can\'t be transferred to both homebranch and holding from returnbranch'); |
1981 |
is ( 1 , $allowed , 'Allow return where transferbranch is not passed'); |
| 2038 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1982 |
is ( undef , $message , 'without limits provides no message'); |
|
|
1983 |
|
| 1984 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 1985 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $homebranch->{branchcode}); |
| 1986 |
is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and homebranch'); |
| 1987 |
is ( undef , $message , 'without limits provides no message'); |
| 2039 |
|
1988 |
|
| 2040 |
$limit_2->delete()->store()->discard_changes; |
1989 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
|
|
1990 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $holdingbranch->{branchcode}); |
| 1991 |
is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and holdingbranch'); |
| 1992 |
is ( undef , $message , 'without limits provides no message'); |
| 2041 |
|
1993 |
|
| 2042 |
# Set limit ( Return -> Holding denied) |
1994 |
# Set limit ( Return -> Home denied) |
|
|
1995 |
diag("Transfer limit: Return -> Home"); |
| 2043 |
$limit->set( |
1996 |
$limit->set( |
| 2044 |
{ |
1997 |
{ |
| 2045 |
toBranch => $holdingbranch->{branchcode}, |
1998 |
toBranch => $homebranch->{branchcode}, |
| 2046 |
fromBranch => $returnbranch->{branchcode} |
1999 |
fromBranch => $returnbranch->{branchcode} |
| 2047 |
} |
2000 |
} |
| 2048 |
)->store()->discard_changes; |
2001 |
)->store()->discard_changes; |
| 2049 |
|
2002 |
|
| 2050 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Holding limit)"); |
2003 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2051 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
2004 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $homebranch->{branchcode}); |
| 2052 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2005 |
is ( 0 , $allowed , 'Prevent return where returnbranch cannot transfer to homebranch'); |
| 2053 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
|
|
| 2054 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2055 |
|
| 2056 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit)"); |
| 2057 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2058 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2059 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
| 2060 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
| 2061 |
|
| 2062 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit)"); |
| 2063 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2064 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2065 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
| 2066 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
2006 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2067 |
|
2007 |
|
| 2068 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Holding limit)"); |
|
|
| 2069 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
| 2070 |
# to 'holdingbranch' (But we can transfer back to 'homebranch'). |
| 2071 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2008 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2072 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2009 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $holdingbranch->{branchcode}); |
| 2073 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transferred to homebranch (holdingbranch forbidden) from returnbranch'); |
2010 |
is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and holdingbranch'); |
|
|
2011 |
is ( undef , $message , 'without limits provides no message'); |
| 2074 |
|
2012 |
|
| 2075 |
# Set limit ( Holding -> Home denied) |
2013 |
# Set limit ( Return -> Holding denied) |
|
|
2014 |
diag("Transfer limit: Return -> Holding"); |
| 2076 |
$limit->set( |
2015 |
$limit->set( |
| 2077 |
{ |
2016 |
{ |
| 2078 |
toBranch => $holdingbranch->{branchcode}, |
2017 |
toBranch => $holdingbranch->{branchcode}, |
|
Lines 2080-2109
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub {
Link Here
|
| 2080 |
} |
2019 |
} |
| 2081 |
)->store()->discard_changes; |
2020 |
)->store()->discard_changes; |
| 2082 |
|
2021 |
|
| 2083 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Home limit)"); |
2022 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2084 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
2023 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $homebranch->{branchcode}); |
| 2085 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2024 |
is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and homebranch'); |
| 2086 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
2025 |
is ( undef , $message , 'without limits provides no message'); |
| 2087 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
|
|
| 2088 |
|
| 2089 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit)"); |
| 2090 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2091 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2092 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
| 2093 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
| 2094 |
|
| 2095 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit)"); |
| 2096 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2097 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2098 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
| 2099 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2100 |
|
2026 |
|
| 2101 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Home limit)"); |
|
|
| 2102 |
# NOTE: A return here can subsequently be transferred to back to homebranch |
| 2103 |
# or holdingbranch. |
| 2104 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2027 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2105 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2028 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $holdingbranch->{branchcode}); |
| 2106 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transferred to from anywhere'); |
2029 |
is ( 0 , $allowed , 'Prevent return where returnbranch cannot transfer to holdingbranch'); |
|
|
2030 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
| 2107 |
}; |
2031 |
}; |
| 2108 |
|
2032 |
|
| 2109 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
2033 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
| 2110 |
- |
|
|