Lines 25-31
use POSIX qw( floor );
Link Here
|
25 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
26 |
use t::lib::TestBuilder; |
26 |
use t::lib::TestBuilder; |
27 |
|
27 |
|
28 |
use C4::Calendar; |
|
|
29 |
use C4::Circulation; |
28 |
use C4::Circulation; |
30 |
use C4::Biblio; |
29 |
use C4::Biblio; |
31 |
use C4::Items; |
30 |
use C4::Items; |
Lines 34-39
use C4::Reserves;
Link Here
|
34 |
use C4::Overdues qw(UpdateFine CalcFine); |
33 |
use C4::Overdues qw(UpdateFine CalcFine); |
35 |
use Koha::DateUtils; |
34 |
use Koha::DateUtils; |
36 |
use Koha::Database; |
35 |
use Koha::Database; |
|
|
36 |
use Koha::DiscreteCalendar; |
37 |
use Koha::IssuingRules; |
37 |
use Koha::IssuingRules; |
38 |
use Koha::Checkouts; |
38 |
use Koha::Checkouts; |
39 |
use Koha::Patrons; |
39 |
use Koha::Patrons; |
Lines 50-57
my $dbh = C4::Context->dbh;
Link Here
|
50 |
$dbh->{RaiseError} = 1; |
50 |
$dbh->{RaiseError} = 1; |
51 |
|
51 |
|
52 |
my $cache = Koha::Caches->get_instance(); |
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'); |
53 |
$cache->clear_from_cache('single_holidays'); |
56 |
|
54 |
|
57 |
# Start with a clean slate |
55 |
# Start with a clean slate |
Lines 1780-1795
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1780 |
); |
1778 |
); |
1781 |
$rule->store(); |
1779 |
$rule->store(); |
1782 |
|
1780 |
|
1783 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
1781 |
my $in_five_days = dt_from_string->add( days => 5 ); |
1784 |
# We want to charge 2 days every day, without grace |
1782 |
# We want to charge 2 days every day, without grace |
1785 |
# With 5 days of overdue: 5 * Z |
1783 |
# With 5 days of overdue: 5 * Z |
1786 |
my $expected_expiration = dt_from_string->add( days => ( 5 * 2 ) / 1 ); |
1784 |
my $expected_expiration = dt_from_string->add( days => 5 + ( 5 * 2 ) / 1 ); |
1787 |
test_debarment_on_checkout( |
1785 |
test_debarment_on_checkout( |
1788 |
{ |
1786 |
{ |
1789 |
item => $item_1, |
1787 |
item => $item_1, |
1790 |
library => $library, |
1788 |
library => $library, |
1791 |
patron => $patron, |
1789 |
patron => $patron, |
1792 |
due_date => $five_days_ago, |
1790 |
return_date => $in_five_days, |
1793 |
expiration_date => $expected_expiration, |
1791 |
expiration_date => $expected_expiration, |
1794 |
} |
1792 |
} |
1795 |
); |
1793 |
); |
Lines 1797-1809
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1797 |
# We want to charge 2 days every 2 days, without grace |
1795 |
# We want to charge 2 days every 2 days, without grace |
1798 |
# With 5 days of overdue: (5 * 2) / 2 |
1796 |
# With 5 days of overdue: (5 * 2) / 2 |
1799 |
$rule->suspension_chargeperiod(2)->store; |
1797 |
$rule->suspension_chargeperiod(2)->store; |
1800 |
$expected_expiration = dt_from_string->add( days => floor( 5 * 2 ) / 2 ); |
1798 |
$expected_expiration = dt_from_string->add( days => 5 + floor( 5 * 2 ) / 2 ); |
1801 |
test_debarment_on_checkout( |
1799 |
test_debarment_on_checkout( |
1802 |
{ |
1800 |
{ |
1803 |
item => $item_1, |
1801 |
item => $item_1, |
1804 |
library => $library, |
1802 |
library => $library, |
1805 |
patron => $patron, |
1803 |
patron => $patron, |
1806 |
due_date => $five_days_ago, |
1804 |
return_date => $in_five_days, |
1807 |
expiration_date => $expected_expiration, |
1805 |
expiration_date => $expected_expiration, |
1808 |
} |
1806 |
} |
1809 |
); |
1807 |
); |
Lines 1812-1824
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1812 |
# With 5 days of overdue: ((5-1) / 3 ) * 2 |
1810 |
# With 5 days of overdue: ((5-1) / 3 ) * 2 |
1813 |
$rule->suspension_chargeperiod(3)->store; |
1811 |
$rule->suspension_chargeperiod(3)->store; |
1814 |
$rule->firstremind(1)->store; |
1812 |
$rule->firstremind(1)->store; |
1815 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) ); |
1813 |
$expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 1 ) / 3 ) * 2 ) ); |
1816 |
test_debarment_on_checkout( |
1814 |
test_debarment_on_checkout( |
1817 |
{ |
1815 |
{ |
1818 |
item => $item_1, |
1816 |
item => $item_1, |
1819 |
library => $library, |
1817 |
library => $library, |
1820 |
patron => $patron, |
1818 |
patron => $patron, |
1821 |
due_date => $five_days_ago, |
1819 |
return_date => $in_five_days, |
1822 |
expiration_date => $expected_expiration, |
1820 |
expiration_date => $expected_expiration, |
1823 |
} |
1821 |
} |
1824 |
); |
1822 |
); |
Lines 1831-1895
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1831 |
t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed'); |
1829 |
t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed'); |
1832 |
|
1830 |
|
1833 |
# Adding a holiday 2 days ago |
1831 |
# Adding a holiday 2 days ago |
1834 |
my $calendar = C4::Calendar->new(branchcode => $library->{branchcode}); |
1832 |
my $calendar = Koha::DiscreteCalendar->new( { branchcode => $library->{branchcode} } ); |
1835 |
my $two_days_ago = dt_from_string->subtract( days => 2 ); |
1833 |
my $in_two_days = dt_from_string->add( days => 2 ); |
1836 |
$calendar->insert_single_holiday( |
1834 |
$calendar->edit_holiday( { |
1837 |
day => $two_days_ago->day, |
1835 |
title => 'holidayTest+2d', |
1838 |
month => $two_days_ago->month, |
1836 |
holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},, |
1839 |
year => $two_days_ago->year, |
1837 |
start_date => $in_two_days, |
1840 |
title => 'holidayTest-2d', |
1838 |
end_date => $in_two_days, |
1841 |
description => 'holidayDesc 2 days ago' |
1839 |
} ); |
1842 |
); |
|
|
1843 |
# With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday) |
1840 |
# With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday) |
1844 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ); |
1841 |
$expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ); |
1845 |
test_debarment_on_checkout( |
1842 |
test_debarment_on_checkout( |
1846 |
{ |
1843 |
{ |
1847 |
item => $item_1, |
1844 |
item => $item_1, |
1848 |
library => $library, |
1845 |
library => $library, |
1849 |
patron => $patron, |
1846 |
patron => $patron, |
1850 |
due_date => $five_days_ago, |
1847 |
return_date => $in_five_days, |
1851 |
expiration_date => $expected_expiration, |
1848 |
expiration_date => $expected_expiration, |
1852 |
} |
1849 |
} |
1853 |
); |
1850 |
); |
1854 |
|
1851 |
|
1855 |
# Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped |
1852 |
# Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped |
1856 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
1853 |
my $in_seven_days = dt_from_string->add( days => 7 ); |
1857 |
$calendar->insert_single_holiday( |
1854 |
$calendar->edit_holiday( { |
1858 |
day => $two_days_ahead->day, |
1855 |
title => 'holidayTest+7d', |
1859 |
month => $two_days_ahead->month, |
1856 |
holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, |
1860 |
year => $two_days_ahead->year, |
1857 |
start_date => $in_seven_days, |
1861 |
title => 'holidayTest+2d', |
1858 |
end_date => $in_seven_days, |
1862 |
description => 'holidayDesc 2 days ahead' |
1859 |
} ); |
1863 |
); |
|
|
1864 |
|
1860 |
|
1865 |
# Same as above, but we should skip D+2 |
1861 |
# Same as above, but we should skip D+2 |
1866 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ); |
1862 |
$expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ); |
1867 |
test_debarment_on_checkout( |
1863 |
test_debarment_on_checkout( |
1868 |
{ |
1864 |
{ |
1869 |
item => $item_1, |
1865 |
item => $item_1, |
1870 |
library => $library, |
1866 |
library => $library, |
1871 |
patron => $patron, |
1867 |
patron => $patron, |
1872 |
due_date => $five_days_ago, |
1868 |
return_date => $in_five_days, |
1873 |
expiration_date => $expected_expiration, |
1869 |
expiration_date => $expected_expiration, |
1874 |
} |
1870 |
} |
1875 |
); |
1871 |
); |
1876 |
|
1872 |
|
1877 |
# Adding another holiday, day of expiration date |
1873 |
# Adding another holiday, day of expiration date |
1878 |
my $expected_expiration_dt = dt_from_string($expected_expiration); |
1874 |
my $expected_expiration_dt = dt_from_string($expected_expiration); |
1879 |
$calendar->insert_single_holiday( |
1875 |
$calendar->edit_holiday( { |
1880 |
day => $expected_expiration_dt->day, |
1876 |
title => 'holidayTest+expected_expiration', |
1881 |
month => $expected_expiration_dt->month, |
1877 |
holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, |
1882 |
year => $expected_expiration_dt->year, |
1878 |
start_date => $expected_expiration_dt, |
1883 |
title => 'holidayTest_exp', |
1879 |
end_date => $expected_expiration_dt, |
1884 |
description => 'holidayDesc on expiration date' |
1880 |
} ); |
1885 |
); |
1881 |
|
1886 |
# Expiration date will be the day after |
1882 |
# Expiration date will be the day after |
1887 |
test_debarment_on_checkout( |
1883 |
test_debarment_on_checkout( |
1888 |
{ |
1884 |
{ |
1889 |
item => $item_1, |
1885 |
item => $item_1, |
1890 |
library => $library, |
1886 |
library => $library, |
1891 |
patron => $patron, |
1887 |
patron => $patron, |
1892 |
due_date => $five_days_ago, |
1888 |
return_date => $in_five_days, |
1893 |
expiration_date => $expected_expiration_dt->clone->add( days => 1 ), |
1889 |
expiration_date => $expected_expiration_dt->clone->add( days => 1 ), |
1894 |
} |
1890 |
} |
1895 |
); |
1891 |
); |
Lines 1900-1906
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1900 |
library => $library, |
1896 |
library => $library, |
1901 |
patron => $patron, |
1897 |
patron => $patron, |
1902 |
return_date => dt_from_string->add(days => 5), |
1898 |
return_date => dt_from_string->add(days => 5), |
1903 |
expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) ), |
1899 |
expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) + 1 ), # We add an extra +1 because of the holiday |
1904 |
} |
1900 |
} |
1905 |
); |
1901 |
); |
1906 |
}; |
1902 |
}; |
1907 |
- |
|
|