Lines 1836-1843
subtest 'AddIssue & AllowReturnToBranch' => sub {
Link Here
|
1836 |
}; |
1836 |
}; |
1837 |
|
1837 |
|
1838 |
|
1838 |
|
1839 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
1839 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits + CirculationRules' => sub { |
1840 |
plan tests => 33; |
1840 |
plan tests => 22; |
1841 |
|
1841 |
|
1842 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
1842 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
1843 |
|
1843 |
|
Lines 1857-1989
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub {
Link Here
|
1857 |
set_userenv($holdingbranch); |
1857 |
set_userenv($holdingbranch); |
1858 |
my $issue = AddIssue( $patron, $item->barcode ); |
1858 |
my $issue = AddIssue( $patron, $item->barcode ); |
1859 |
|
1859 |
|
1860 |
# 'Anywhere' + BranchTransferLimits |
1860 |
# Attempt returns at returnbranch |
1861 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
|
|
1862 |
|
1863 |
# Attempt return at returnbranch (No limits defined) |
1864 |
my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1865 |
is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed'); |
1866 |
is ( undef , $message , 'without limits provides no message'); |
1867 |
|
1868 |
# Set limit (Holding -> Return denied) |
1869 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
1870 |
my $limit = Koha::Item::Transfer::Limit->new({ |
1871 |
toBranch => $returnbranch->{branchcode}, |
1872 |
fromBranch => $holdingbranch->{branchcode}, |
1873 |
itemtype => $item->effective_itemtype, |
1874 |
})->store(); |
1875 |
|
1876 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Return limit)"); |
1877 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
1861 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
1878 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1862 |
my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}); |
1879 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
1863 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
1880 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1864 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1881 |
|
1865 |
|
1882 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit)"); |
|
|
1883 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
1866 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
1884 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1867 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}); |
1885 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
1868 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
1886 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
1869 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
1887 |
|
1870 |
|
1888 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit)"); |
|
|
1889 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
1871 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
1890 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1872 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}); |
1891 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
1873 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
1892 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1874 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1893 |
|
1875 |
|
1894 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Return limit)"); |
|
|
1895 |
# NOTE: This prevents receiving an item from a branch that is listed in |
1896 |
# the branchtransferlimits as not allowed to send to our returnbranch. |
1897 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1876 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1898 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1877 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}); |
1899 |
is ( 0 , $allowed , 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch'); |
1878 |
is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed'); |
1900 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1879 |
is ( undef , $message , 'without limits provides no message'); |
1901 |
|
|
|
1902 |
# Set limit ( Return -> Home denied) |
1903 |
$limit->set( |
1904 |
{ |
1905 |
toBranch => $homebranch->{branchcode}, |
1906 |
fromBranch => $returnbranch->{branchcode} |
1907 |
} |
1908 |
)->store()->discard_changes; |
1909 |
|
1910 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Home limit)"); |
1911 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
1912 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1913 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
1914 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1915 |
|
1916 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Home limit)"); |
1917 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
1918 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1919 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
1920 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
1921 |
|
1922 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Home limit)"); |
1923 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
1924 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1925 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
1926 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1927 |
|
1928 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Home limit)"); |
1929 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
1930 |
# to 'homebranch' (But we can transfer back to 'holdingbranch'). |
1931 |
# NOTE: This is the ONLY change that bug 7376 introduces currently. |
1932 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1933 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1934 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to holding (homebranch forbidden) from returnbranch'); |
1935 |
|
1880 |
|
1936 |
my $limit_2 = Koha::Item::Transfer::Limit->new({ |
1881 |
# Set limit (Holding -> Return denied) |
1937 |
toBranch => $holdingbranch->{branchcode}, |
1882 |
diag("Transfer limit: Holding -> Return"); |
1938 |
fromBranch => $returnbranch->{branchcode}, |
1883 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
|
|
1884 |
my $limit = Koha::Item::Transfer::Limit->new({ |
1885 |
toBranch => $returnbranch->{branchcode}, |
1886 |
fromBranch => $holdingbranch->{branchcode}, |
1939 |
itemtype => $item->effective_itemtype, |
1887 |
itemtype => $item->effective_itemtype, |
1940 |
})->store(); |
1888 |
})->store(); |
1941 |
|
1889 |
|
1942 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Home and Return -> Holding limit)"); |
|
|
1943 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
1944 |
# to 'homebranch' (But we can transfer back to 'holdingbranch'). |
1945 |
# NOTE: This is the ONLY change that bug 7376 introduces currently. |
1946 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1890 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1947 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1891 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}); |
1948 |
is ( 0 , $allowed , 'Prevent return where item can\'t be transferred to both homebranch and holding from returnbranch'); |
1892 |
is ( 1 , $allowed , 'Allow return where transferbranch is not passed'); |
1949 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1893 |
is ( undef , $message , 'without limits provides no message'); |
|
|
1894 |
|
1895 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1896 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $homebranch->{branchcode}); |
1897 |
is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and homebranch'); |
1898 |
is ( undef , $message , 'without limits provides no message'); |
1950 |
|
1899 |
|
1951 |
$limit_2->delete()->store()->discard_changes; |
1900 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
|
|
1901 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $holdingbranch->{branchcode}); |
1902 |
is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and holdingbranch'); |
1903 |
is ( undef , $message , 'without limits provides no message'); |
1952 |
|
1904 |
|
1953 |
# Set limit ( Return -> Holding denied) |
1905 |
# Set limit ( Return -> Home denied) |
|
|
1906 |
diag("Transfer limit: Return -> Home"); |
1954 |
$limit->set( |
1907 |
$limit->set( |
1955 |
{ |
1908 |
{ |
1956 |
toBranch => $holdingbranch->{branchcode}, |
1909 |
toBranch => $homebranch->{branchcode}, |
1957 |
fromBranch => $returnbranch->{branchcode} |
1910 |
fromBranch => $returnbranch->{branchcode} |
1958 |
} |
1911 |
} |
1959 |
)->store()->discard_changes; |
1912 |
)->store()->discard_changes; |
1960 |
|
1913 |
|
1961 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Holding limit)"); |
1914 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1962 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
1915 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $homebranch->{branchcode}); |
1963 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1916 |
is ( 0 , $allowed , 'Prevent return where returnbranch cannot transfer to homebranch'); |
1964 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
|
|
1965 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1966 |
|
1967 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit)"); |
1968 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
1969 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1970 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
1971 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
1972 |
|
1973 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit)"); |
1974 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
1975 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1976 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
1977 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1917 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1978 |
|
1918 |
|
1979 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Holding limit)"); |
|
|
1980 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
1981 |
# to 'holdingbranch' (But we can transfer back to 'homebranch'). |
1982 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1919 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1983 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1920 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $holdingbranch->{branchcode}); |
1984 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transferred to homebranch (holdingbranch forbidden) from returnbranch'); |
1921 |
is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and holdingbranch'); |
|
|
1922 |
is ( undef , $message , 'without limits provides no message'); |
1985 |
|
1923 |
|
1986 |
# Set limit ( Holding -> Home denied) |
1924 |
# Set limit ( Return -> Holding denied) |
|
|
1925 |
diag("Transfer limit: Return -> Holding"); |
1987 |
$limit->set( |
1926 |
$limit->set( |
1988 |
{ |
1927 |
{ |
1989 |
toBranch => $holdingbranch->{branchcode}, |
1928 |
toBranch => $holdingbranch->{branchcode}, |
Lines 1991-2020
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub {
Link Here
|
1991 |
} |
1930 |
} |
1992 |
)->store()->discard_changes; |
1931 |
)->store()->discard_changes; |
1993 |
|
1932 |
|
1994 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Home limit)"); |
1933 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1995 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
1934 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $homebranch->{branchcode}); |
1996 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1935 |
is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and homebranch'); |
1997 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
1936 |
is ( undef , $message , 'without limits provides no message'); |
1998 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
|
|
1999 |
|
2000 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit)"); |
2001 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
2002 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2003 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
2004 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
2005 |
|
2006 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit)"); |
2007 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
2008 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
2009 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
2010 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
2011 |
|
1937 |
|
2012 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Home limit)"); |
|
|
2013 |
# NOTE: A return here can subsequently be transferred to back to homebranch |
2014 |
# or holdingbranch. |
2015 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1938 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2016 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1939 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $holdingbranch->{branchcode}); |
2017 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transferred to from anywhere'); |
1940 |
is ( 0 , $allowed , 'Prevent return where returnbranch cannot transfer to holdingbranch'); |
|
|
1941 |
is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
2018 |
}; |
1942 |
}; |
2019 |
|
1943 |
|
2020 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1944 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
2021 |
- |
|
|