|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 103; |
20 |
use Test::More tests => 104; |
| 21 |
|
21 |
|
| 22 |
use DateTime; |
22 |
use DateTime; |
| 23 |
|
23 |
|
|
Lines 208-214
C4::Context->dbh->do("DELETE FROM borrowers WHERE cardnumber = '99999999999'");
Link Here
|
| 208 |
C4::Context->dbh->do("DELETE FROM accountlines"); |
208 |
C4::Context->dbh->do("DELETE FROM accountlines"); |
| 209 |
{ |
209 |
{ |
| 210 |
# CanBookBeRenewed tests |
210 |
# CanBookBeRenewed tests |
| 211 |
|
211 |
t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', '' ); #Ensure pref doesn't affect current tests |
| 212 |
# Generate test biblio |
212 |
# Generate test biblio |
| 213 |
my $biblio = MARC::Record->new(); |
213 |
my $biblio = MARC::Record->new(); |
| 214 |
my $title = 'Silence in the library'; |
214 |
my $title = 'Silence in the library'; |
|
Lines 1873-1878
subtest 'CanBookBeIssued | is_overdue' => sub {
Link Here
|
| 1873 |
my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron,$item->{barcode},$ten_days_go, undef, undef, undef); |
1873 |
my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron,$item->{barcode},$ten_days_go, undef, undef, undef); |
| 1874 |
is( $needsconfirmation->{RENEW_ISSUE}, 1, "This is a renewal"); |
1874 |
is( $needsconfirmation->{RENEW_ISSUE}, 1, "This is a renewal"); |
| 1875 |
is( $needsconfirmation->{TOO_MANY}, undef, "Not too many, is a renewal"); |
1875 |
is( $needsconfirmation->{TOO_MANY}, undef, "Not too many, is a renewal"); |
|
|
1876 |
}; |
| 1877 |
|
| 1878 |
subtest 'ItemsDeniedRenewal preference' => sub { |
| 1879 |
plan tests => 14; |
| 1880 |
|
| 1881 |
t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', '' ); |
| 1882 |
|
| 1883 |
$dbh->do('DELETE FROM issues'); |
| 1884 |
$dbh->do('DELETE FROM items'); |
| 1885 |
$dbh->do('DELETE FROM issuingrules'); |
| 1886 |
$dbh->do( |
| 1887 |
q{ |
| 1888 |
INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod, |
| 1889 |
norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) |
| 1890 |
}, |
| 1891 |
{}, |
| 1892 |
'*', '*', '*', 25, |
| 1893 |
20, 14, 'days', |
| 1894 |
10, 7, |
| 1895 |
undef, 0, |
| 1896 |
.10, 1 |
| 1897 |
); |
| 1898 |
|
| 1899 |
my $deny_book = $builder->build_object({ class => 'Koha::Items', value => { |
| 1900 |
withdrawn => 1, |
| 1901 |
itype => 'HIDE', |
| 1902 |
location => 'PROC' |
| 1903 |
} |
| 1904 |
}); |
| 1905 |
my $allow_book = $builder->build_object({ class => 'Koha::Items', value => { |
| 1906 |
withdrawn => 0, |
| 1907 |
itype => 'NOHIDE', |
| 1908 |
location => 'NOPROC' |
| 1909 |
} |
| 1910 |
}); |
| 1911 |
|
| 1912 |
my $idr_borrower = $builder->build_object({ class => 'Koha::Patrons'}); |
| 1913 |
|
| 1914 |
my $deny_issue = $builder->build_object({ class => 'Koha::Checkouts', value => { |
| 1915 |
returndate => undef, |
| 1916 |
renewals => 0, |
| 1917 |
auto_renew => 0, |
| 1918 |
borrowernumber => $idr_borrower->borrowernumber, |
| 1919 |
itemnumber => $deny_book->itemnumber, |
| 1920 |
onsite_checkout => 0, |
| 1921 |
} |
| 1922 |
}); |
| 1923 |
my $allow_issue = $builder->build_object({ class => 'Koha::Checkouts', value => { |
| 1924 |
returndate => undef, |
| 1925 |
renewals => 0, |
| 1926 |
auto_renew => 0, |
| 1927 |
borrowernumber => $idr_borrower->borrowernumber, |
| 1928 |
itemnumber => $allow_book->itemnumber, |
| 1929 |
onsite_checkout => 0, |
| 1930 |
} |
| 1931 |
}); |
| 1932 |
|
| 1933 |
my $idr_rules; |
| 1934 |
|
| 1935 |
my ( $idr_mayrenew, $idr_error ) = |
| 1936 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
| 1937 |
is( $idr_mayrenew, 1, 'Renewal allowed when no rules' ); |
| 1938 |
is( $idr_error, undef, 'Renewal allowed when no rules' ); |
| 1939 |
|
| 1940 |
$idr_rules=" |
| 1941 |
withdrawn: [1]"; |
| 1942 |
|
| 1943 |
t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules ); |
| 1944 |
( $idr_mayrenew, $idr_error ) = |
| 1945 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
| 1946 |
is( $idr_mayrenew, 0, 'Renewal blocked when 1 rules (withdrawn)' ); |
| 1947 |
is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 1 rule (withdrawn)' ); |
| 1948 |
( $idr_mayrenew, $idr_error ) = |
| 1949 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber ); |
| 1950 |
is( $idr_mayrenew, 1, 'Renewal allowed when 1 rules not matched (withdrawn)' ); |
| 1951 |
is( $idr_error, undef, 'Renewal allowed when 1 rules not matched (withdrawn)' ); |
| 1952 |
|
| 1953 |
$idr_rules=" |
| 1954 |
withdrawn: [1] |
| 1955 |
itype: [HIDE,INVISILE]"; |
| 1956 |
|
| 1957 |
t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules ); |
| 1958 |
( $idr_mayrenew, $idr_error ) = |
| 1959 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
| 1960 |
is( $idr_mayrenew, 0, 'Renewal blocked when 2 rules matched (withdrawn, itype)' ); |
| 1961 |
is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 2 rules matched (withdrawn,itype)' ); |
| 1962 |
( $idr_mayrenew, $idr_error ) = |
| 1963 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber ); |
| 1964 |
is( $idr_mayrenew, 1, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' ); |
| 1965 |
is( $idr_error, undef, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' ); |
| 1966 |
|
| 1967 |
$idr_rules=" |
| 1968 |
withdrawn: [1] |
| 1969 |
itype: [HIDE,INVISIBLE] |
| 1970 |
location: [PROC]"; |
| 1971 |
|
| 1972 |
t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules ); |
| 1973 |
( $idr_mayrenew, $idr_error ) = |
| 1974 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
| 1975 |
is( $idr_mayrenew, 0, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' ); |
| 1976 |
is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 3 rules matched (withdrawn,itype, location)' ); |
| 1977 |
( $idr_mayrenew, $idr_error ) = |
| 1978 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber ); |
| 1979 |
is( $idr_mayrenew, 1, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' ); |
| 1980 |
is( $idr_error, undef, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' ); |
| 1876 |
|
1981 |
|
| 1877 |
}; |
1982 |
}; |
| 1878 |
|
1983 |
|
| 1879 |
- |
|
|