Lines 24-29
use POSIX qw( floor );
Link Here
|
24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
25 |
use t::lib::TestBuilder; |
25 |
use t::lib::TestBuilder; |
26 |
|
26 |
|
|
|
27 |
use C4::Calendar; |
27 |
use C4::Circulation; |
28 |
use C4::Circulation; |
28 |
use C4::Biblio; |
29 |
use C4::Biblio; |
29 |
use C4::Items; |
30 |
use C4::Items; |
Lines 48-53
my $dbh = C4::Context->dbh;
Link Here
|
48 |
# Start transaction |
49 |
# Start transaction |
49 |
$dbh->{RaiseError} = 1; |
50 |
$dbh->{RaiseError} = 1; |
50 |
|
51 |
|
|
|
52 |
my $cache = Koha::Caches->get_instance(); |
53 |
$dbh->do(q|DELETE FROM special_holidays|); |
54 |
$dbh->do(q|DELETE FROM repeatable_holidays|); |
55 |
$cache->clear_from_cache('single_holidays'); |
56 |
|
51 |
# Start with a clean slate |
57 |
# Start with a clean slate |
52 |
$dbh->do('DELETE FROM issues'); |
58 |
$dbh->do('DELETE FROM issues'); |
53 |
$dbh->do('DELETE FROM borrowers'); |
59 |
$dbh->do('DELETE FROM borrowers'); |
Lines 1758-1764
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
1758 |
}; |
1764 |
}; |
1759 |
|
1765 |
|
1760 |
subtest 'AddReturn + suspension_chargeperiod' => sub { |
1766 |
subtest 'AddReturn + suspension_chargeperiod' => sub { |
1761 |
plan tests => 6; |
1767 |
plan tests => 8; |
1762 |
|
1768 |
|
1763 |
my $library = $builder->build( { source => 'Branch' } ); |
1769 |
my $library = $builder->build( { source => 'Branch' } ); |
1764 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
1770 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
Lines 1863-1871
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1863 |
Koha::Patron::Debarments::DelUniqueDebarment( |
1869 |
Koha::Patron::Debarments::DelUniqueDebarment( |
1864 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1870 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1865 |
|
1871 |
|
1866 |
}; |
1872 |
|
|
|
1873 |
# We want to charge 2 days every days, with 0 day of grace (to not burn brains) |
1874 |
$rule->finedays(2)->store; |
1875 |
$rule->suspension_chargeperiod(1)->store; |
1876 |
$rule->firstremind(0)->store; |
1877 |
t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed'); |
1878 |
|
1879 |
# Adding a holiday 2 days ago |
1880 |
my $calendar = C4::Calendar->new(branchcode => $library->{branchcode}); |
1881 |
my $two_days_ago = dt_from_string->subtract( days => 2 ); |
1882 |
$calendar->insert_single_holiday( |
1883 |
day => $two_days_ago->day, |
1884 |
month => $two_days_ago->month, |
1885 |
year => $two_days_ago->year, |
1886 |
title => 'holidayTest-2d', |
1887 |
description => 'holidayDesc 2 days ago' |
1888 |
); |
1889 |
|
1890 |
# With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday) |
1891 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
1892 |
|
1893 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, |
1894 |
undef, undef, dt_from_string ); |
1895 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1896 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1897 |
$expected_expiration = output_pref( |
1898 |
{ |
1899 |
dt => dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ), |
1900 |
dateformat => 'sql', |
1901 |
dateonly => 1 |
1902 |
} |
1903 |
); |
1904 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
1905 |
Koha::Patron::Debarments::DelUniqueDebarment( |
1906 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1867 |
|
1907 |
|
1868 |
|
1908 |
|
|
|
1909 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
1910 |
$calendar->insert_single_holiday( |
1911 |
day => $two_days_ahead->day, |
1912 |
month => $two_days_ahead->month, |
1913 |
year => $two_days_ahead->year, |
1914 |
title => 'holidayTest+2d', |
1915 |
description => 'holidayDesc 2 days ahead' |
1916 |
); |
1917 |
|
1918 |
# Same as above, but we should skip D+2 |
1919 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
1920 |
|
1921 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, |
1922 |
undef, undef, dt_from_string ); |
1923 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1924 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1925 |
$expected_expiration = output_pref( |
1926 |
{ |
1927 |
dt => dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ), |
1928 |
dateformat => 'sql', |
1929 |
dateonly => 1 |
1930 |
} |
1931 |
); |
1932 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
1933 |
Koha::Patron::Debarments::DelUniqueDebarment( |
1934 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1935 |
|
1936 |
}; |
1937 |
|
1869 |
subtest 'AddReturn | is_overdue' => sub { |
1938 |
subtest 'AddReturn | is_overdue' => sub { |
1870 |
plan tests => 5; |
1939 |
plan tests => 5; |
1871 |
|
1940 |
|
Lines 2163-2168
subtest 'CanBookBeIssued | is_overdue' => sub {
Link Here
|
2163 |
|
2232 |
|
2164 |
}; |
2233 |
}; |
2165 |
|
2234 |
|
|
|
2235 |
|
2236 |
$schema->storage->txn_rollback; |
2237 |
$cache->clear_from_cache('single_holidays'); |
2238 |
|
2166 |
sub set_userenv { |
2239 |
sub set_userenv { |
2167 |
my ( $library ) = @_; |
2240 |
my ( $library ) = @_; |
2168 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
2241 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
2169 |
- |
|
|