|
Lines 1926-1968
subtest 'AddIssue & AllowReturnToBranch' => sub {
Link Here
|
| 1926 |
|
1926 |
|
| 1927 |
|
1927 |
|
| 1928 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
1928 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
| 1929 |
plan tests => 6; |
1929 |
plan tests => 31; |
|
|
1930 |
|
| 1931 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
| 1930 |
|
1932 |
|
| 1931 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
1933 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
| 1932 |
my $otherbranch = $builder->build( { source => 'Branch' } ); |
1934 |
my $holdingbranch = $builder->build( { source => 'Branch' } ); |
|
|
1935 |
my $returnbranch = $builder->build( { source => 'Branch' } ); |
| 1933 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
1936 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
| 1934 |
|
1937 |
|
| 1935 |
my $item = $builder->build_sample_item( |
1938 |
my $item = $builder->build_sample_item( |
| 1936 |
{ |
1939 |
{ |
| 1937 |
homebranch => $homebranch->{branchcode}, |
1940 |
homebranch => $homebranch->{branchcode}, |
| 1938 |
holdingbranch => $homebranch->{branchcode}, |
1941 |
holdingbranch => $holdingbranch->{branchcode}, |
| 1939 |
} |
1942 |
} |
| 1940 |
); |
1943 |
); |
| 1941 |
|
1944 |
|
| 1942 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1945 |
# Issue from holdingbranch |
| 1943 |
set_userenv($homebranch); |
1946 |
set_userenv($holdingbranch); |
| 1944 |
my $issue = AddIssue( $patron, $item->barcode ); |
1947 |
my $issue = AddIssue( $patron, $item->barcode ); |
| 1945 |
my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $otherbranch); |
1948 |
|
| 1946 |
is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to other is allowed'); |
1949 |
# 'Anywhere' + BranchTransferLimits |
|
|
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'); |
| 1947 |
is ( undef , $message , 'without limits provides no message'); |
1955 |
is ( undef , $message , 'without limits provides no message'); |
| 1948 |
|
1956 |
|
| 1949 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
1957 |
# Set limit (Holding -> Return denied) |
| 1950 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
1958 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
| 1951 |
|
|
|
| 1952 |
# set limit |
| 1953 |
my $limit = Koha::Item::Transfer::Limit->new({ |
1959 |
my $limit = Koha::Item::Transfer::Limit->new({ |
| 1954 |
toBranch => $otherbranch->{branchcode}, |
1960 |
toBranch => $returnbranch->{branchcode}, |
| 1955 |
fromBranch => $item->homebranch, |
1961 |
fromBranch => $holdingbranch->{branchcode}, |
| 1956 |
itemtype => $item->effective_itemtype, |
1962 |
itemtype => $item->effective_itemtype, |
| 1957 |
})->store(); |
1963 |
})->store(); |
| 1958 |
|
1964 |
|
| 1959 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $otherbranch); |
1965 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Return limit)"); |
| 1960 |
is ( 0 , $allowed , 'With transfer limits cannot return to otherbranch'); |
1966 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 1961 |
is ( $homebranch->{branchcode} , $message , 'With transfer limits asks return to homebranch'); |
1967 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
|
|
1968 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
| 1969 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 1970 |
|
| 1971 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit)"); |
| 1972 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 1973 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 1974 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
| 1975 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
| 1976 |
|
| 1977 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit)"); |
| 1978 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 1979 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 1980 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
| 1981 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 1982 |
|
| 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' ); |
| 1987 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 1988 |
is ( 0 , $allowed , 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch'); |
| 1989 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 1990 |
|
| 1991 |
# Set limit ( Return -> Home denied) |
| 1992 |
$limit->set( |
| 1993 |
{ |
| 1994 |
toBranch => $homebranch->{branchcode}, |
| 1995 |
fromBranch => $returnbranch->{branchcode} |
| 1996 |
} |
| 1997 |
)->store()->discard_changes; |
| 1962 |
|
1998 |
|
| 1963 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $homebranch); |
1999 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Home limit)"); |
| 1964 |
is ( 1 , $allowed , 'With transfer limits can return to homebranch'); |
2000 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 1965 |
is ( undef , $message , 'With transfer limits and homebranch provides no message'); |
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 from anywhere'); |
| 2024 |
|
| 2025 |
# Set limit ( Return -> Holding denied) |
| 2026 |
$limit->set( |
| 2027 |
{ |
| 2028 |
toBranch => $holdingbranch->{branchcode}, |
| 2029 |
fromBranch => $returnbranch->{branchcode} |
| 2030 |
} |
| 2031 |
)->store()->discard_changes; |
| 2032 |
|
| 2033 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Holding limit)"); |
| 2034 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2035 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2036 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
| 2037 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2038 |
|
| 2039 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit)"); |
| 2040 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2041 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2042 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
| 2043 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
| 2044 |
|
| 2045 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit)"); |
| 2046 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2047 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2048 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
| 2049 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2050 |
|
| 2051 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Holding limit)"); |
| 2052 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
| 2053 |
# to 'holdingbranch' (But we can transfer back to 'homebranch'). |
| 2054 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2055 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2056 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to from anywhere'); |
| 2057 |
|
| 2058 |
# Set limit ( Holding -> Home denied) |
| 2059 |
$limit->set( |
| 2060 |
{ |
| 2061 |
toBranch => $holdingbranch->{branchcode}, |
| 2062 |
fromBranch => $returnbranch->{branchcode} |
| 2063 |
} |
| 2064 |
)->store()->discard_changes; |
| 2065 |
|
| 2066 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Home limit)"); |
| 2067 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2068 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2069 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
| 2070 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2071 |
|
| 2072 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit)"); |
| 2073 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2074 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2075 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
| 2076 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
| 2077 |
|
| 2078 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit)"); |
| 2079 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2080 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2081 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
| 2082 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
| 2083 |
|
| 2084 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Home limit)"); |
| 2085 |
# NOTE: A return here can subsequently be transfered to back to homebranch |
| 2086 |
# or holdingbranch. |
| 2087 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2088 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
| 2089 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to from anywhere'); |
| 1966 |
}; |
2090 |
}; |
| 1967 |
|
2091 |
|
| 1968 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
2092 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
| 1969 |
- |
|
|