Lines 1820-1862
subtest 'AddIssue & AllowReturnToBranch' => sub {
Link Here
|
1820 |
|
1820 |
|
1821 |
|
1821 |
|
1822 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
1822 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
1823 |
plan tests => 6; |
1823 |
plan tests => 31; |
|
|
1824 |
|
1825 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
1824 |
|
1826 |
|
1825 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
1827 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
1826 |
my $otherbranch = $builder->build( { source => 'Branch' } ); |
1828 |
my $holdingbranch = $builder->build( { source => 'Branch' } ); |
|
|
1829 |
my $returnbranch = $builder->build( { source => 'Branch' } ); |
1827 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
1830 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
1828 |
|
1831 |
|
1829 |
my $item = $builder->build_sample_item( |
1832 |
my $item = $builder->build_sample_item( |
1830 |
{ |
1833 |
{ |
1831 |
homebranch => $homebranch->{branchcode}, |
1834 |
homebranch => $homebranch->{branchcode}, |
1832 |
holdingbranch => $homebranch->{branchcode}, |
1835 |
holdingbranch => $holdingbranch->{branchcode}, |
1833 |
} |
1836 |
} |
1834 |
); |
1837 |
); |
1835 |
|
1838 |
|
1836 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1839 |
# Issue from holdingbranch |
1837 |
set_userenv($homebranch); |
1840 |
set_userenv($holdingbranch); |
1838 |
my $issue = AddIssue( $patron, $item->barcode ); |
1841 |
my $issue = AddIssue( $patron, $item->barcode ); |
1839 |
my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $otherbranch); |
1842 |
|
1840 |
is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to other is allowed'); |
1843 |
# 'Anywhere' + BranchTransferLimits |
|
|
1844 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1845 |
|
1846 |
# Attempt return at returnbranch (No limits defined) |
1847 |
my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1848 |
is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed'); |
1841 |
is ( undef , $message , 'without limits provides no message'); |
1849 |
is ( undef , $message , 'without limits provides no message'); |
1842 |
|
1850 |
|
1843 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
1851 |
# Set limit (Holding -> Return denied) |
1844 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
1852 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
1845 |
|
|
|
1846 |
# set limit |
1847 |
my $limit = Koha::Item::Transfer::Limit->new({ |
1853 |
my $limit = Koha::Item::Transfer::Limit->new({ |
1848 |
toBranch => $otherbranch->{branchcode}, |
1854 |
toBranch => $returnbranch->{branchcode}, |
1849 |
fromBranch => $item->homebranch, |
1855 |
fromBranch => $holdingbranch->{branchcode}, |
1850 |
itemtype => $item->effective_itemtype, |
1856 |
itemtype => $item->effective_itemtype, |
1851 |
})->store(); |
1857 |
})->store(); |
1852 |
|
1858 |
|
1853 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $otherbranch); |
1859 |
# Attempt return at returnbranch ('Homebranch' + Holding -> Return limit) |
1854 |
is ( 0 , $allowed , 'With transfer limits cannot return to otherbranch'); |
1860 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
1855 |
is ( $homebranch->{branchcode} , $message , 'With transfer limits asks return to homebranch'); |
1861 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
|
|
1862 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
1863 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1864 |
|
1865 |
# Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit) |
1866 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
1867 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1868 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
1869 |
is ( $homebranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
1870 |
|
1871 |
# Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit) |
1872 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
1873 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1874 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
1875 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1876 |
|
1877 |
# Attempt return at returnbranch ('Anywhere' + Holding -> Return limit) |
1878 |
# NOTE: This prevents receiving an item from a branch that is listed in |
1879 |
# the branchtransferlimits as not allowed to send to our returnbranch. |
1880 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1881 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1882 |
is ( 0 , $allowed , 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch'); |
1883 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1884 |
|
1885 |
# Set limit ( Return -> Home denied) |
1886 |
$limit->set( |
1887 |
{ |
1888 |
toBranch => $homebranch->{branchcode}, |
1889 |
fromBranch => $returnbranch->{branchcode} |
1890 |
} |
1891 |
)->store()->discard_changes; |
1856 |
|
1892 |
|
1857 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $homebranch); |
1893 |
# Attempt return at returnbranch ('Homebranch' + Return -> Home limit) |
1858 |
is ( 1 , $allowed , 'With transfer limits can return to homebranch'); |
1894 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
1859 |
is ( undef , $message , 'With transfer limits and homebranch provides no message'); |
1895 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
|
|
1896 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
1897 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1898 |
|
1899 |
# Attempt return at returnbranch ('Holdingbranch' + Return -> Home limit) |
1900 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
1901 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1902 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
1903 |
is ( $homebranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
1904 |
|
1905 |
# Attempt return at returnbranch ('Home Or Holding' + Return -> Home limit) |
1906 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
1907 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1908 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
1909 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1910 |
|
1911 |
# Attempt return at returnbranch ('Anywhere' + Return -> Home limit) |
1912 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
1913 |
# to 'homebranch' (But we can transfer back to 'holdingbranch'). |
1914 |
# NOTE: This is the ONLY change that bug 7376 introduces currently. |
1915 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1916 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1917 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to from anywhere'); |
1918 |
|
1919 |
# Set limit ( Return -> Holding denied) |
1920 |
$limit->set( |
1921 |
{ |
1922 |
toBranch => $holdingbranch->{branchcode}, |
1923 |
fromBranch => $returnbranch->{branchcode} |
1924 |
} |
1925 |
)->store()->discard_changes; |
1926 |
|
1927 |
# Attempt return at returnbranch ('Homebranch' + Return -> Holding limit) |
1928 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
1929 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1930 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
1931 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1932 |
|
1933 |
# Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit) |
1934 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
1935 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1936 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
1937 |
is ( $homebranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
1938 |
|
1939 |
# Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit) |
1940 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
1941 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1942 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
1943 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1944 |
|
1945 |
# Attempt return at returnbranch ('Anywhere' + Return -> Holding limit) |
1946 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
1947 |
# to 'holdingbranch' (But we can transfer back to 'homebranch'). |
1948 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1949 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1950 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to from anywhere'); |
1951 |
|
1952 |
# Set limit ( Holding -> Home denied) |
1953 |
$limit->set( |
1954 |
{ |
1955 |
toBranch => $holdingbranch->{branchcode}, |
1956 |
fromBranch => $returnbranch->{branchcode} |
1957 |
} |
1958 |
)->store()->discard_changes; |
1959 |
|
1960 |
# Attempt return at returnbranch ('Homebranch' + Holding -> Home limit) |
1961 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
1962 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1963 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch'); |
1964 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1965 |
|
1966 |
# Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit) |
1967 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
1968 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1969 |
is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch'); |
1970 |
is ( $homebranch->{branchcode} , $message , 'Redirect to holdingbranch'); |
1971 |
|
1972 |
# Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit) |
1973 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
1974 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1975 |
is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch'); |
1976 |
is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch'); |
1977 |
|
1978 |
# Attempt return at returnbranch ('Anywhere' + Holding -> Home limit) |
1979 |
# NOTE: A return here can subsequently be transfered to back to homebranch |
1980 |
# or holdingbranch. |
1981 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
1982 |
($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch); |
1983 |
is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to from anywhere'); |
1860 |
}; |
1984 |
}; |
1861 |
|
1985 |
|
1862 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1986 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1863 |
- |
|
|