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