Lines 1764-1770
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
1764 |
}; |
1764 |
}; |
1765 |
|
1765 |
|
1766 |
subtest 'AddReturn + suspension_chargeperiod' => sub { |
1766 |
subtest 'AddReturn + suspension_chargeperiod' => sub { |
1767 |
plan tests => 8; |
1767 |
plan tests => 10; |
1768 |
|
1768 |
|
1769 |
my $library = $builder->build( { source => 'Branch' } ); |
1769 |
my $library = $builder->build( { source => 'Branch' } ); |
1770 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
1770 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
Lines 1803-1875
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1803 |
$rule->store(); |
1803 |
$rule->store(); |
1804 |
|
1804 |
|
1805 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
1805 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
1806 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
|
|
1807 |
|
1808 |
# We want to charge 2 days every day, without grace |
1806 |
# We want to charge 2 days every day, without grace |
1809 |
# With 5 days of overdue: 5 * Z |
1807 |
# With 5 days of overdue: 5 * Z |
1810 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, |
1808 |
my $expected_expiration = dt_from_string->add( days => ( 5 * 2 ) / 1 ); |
1811 |
undef, undef, dt_from_string ); |
1809 |
test_debarment_on_checkout( |
1812 |
my $debarments = Koha::Patron::Debarments::GetDebarments( |
|
|
1813 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1814 |
is( scalar(@$debarments), 1 ); |
1815 |
|
1816 |
my $expected_expiration = output_pref( |
1817 |
{ |
1810 |
{ |
1818 |
dt => dt_from_string->add( days => ( 5 * 2 ) / 1 ), |
1811 |
item => $item_1, |
1819 |
dateformat => 'sql', |
1812 |
library => $library, |
1820 |
dateonly => 1 |
1813 |
patron => $patron, |
|
|
1814 |
due_date => $five_days_ago, |
1815 |
expiration_date => $expected_expiration, |
1821 |
} |
1816 |
} |
1822 |
); |
1817 |
); |
1823 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
|
|
1824 |
Koha::Patron::Debarments::DelUniqueDebarment( |
1825 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1826 |
|
1818 |
|
1827 |
# We want to charge 2 days every 2 days, without grace |
1819 |
# We want to charge 2 days every 2 days, without grace |
1828 |
# With 5 days of overdue: (5 * 2) / 2 |
1820 |
# With 5 days of overdue: (5 * 2) / 2 |
1829 |
$rule->suspension_chargeperiod(2)->store; |
1821 |
$rule->suspension_chargeperiod(2)->store; |
1830 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
1822 |
$expected_expiration = dt_from_string->add( days => floor( 5 * 2 ) / 2 ); |
1831 |
|
1823 |
test_debarment_on_checkout( |
1832 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, |
|
|
1833 |
undef, undef, dt_from_string ); |
1834 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1835 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1836 |
is( scalar(@$debarments), 1 ); |
1837 |
|
1838 |
$expected_expiration = output_pref( |
1839 |
{ |
1824 |
{ |
1840 |
dt => dt_from_string->add( days => floor( 5 * 2 ) / 2 ), |
1825 |
item => $item_1, |
1841 |
dateformat => 'sql', |
1826 |
library => $library, |
1842 |
dateonly => 1 |
1827 |
patron => $patron, |
|
|
1828 |
due_date => $five_days_ago, |
1829 |
expiration_date => $expected_expiration, |
1843 |
} |
1830 |
} |
1844 |
); |
1831 |
); |
1845 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
|
|
1846 |
Koha::Patron::Debarments::DelUniqueDebarment( |
1847 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1848 |
|
1832 |
|
1849 |
# We want to charge 2 days every 3 days, with 1 day of grace |
1833 |
# We want to charge 2 days every 3 days, with 1 day of grace |
1850 |
# With 5 days of overdue: ((5-1) / 3 ) * 2 |
1834 |
# With 5 days of overdue: ((5-1) / 3 ) * 2 |
1851 |
$rule->suspension_chargeperiod(3)->store; |
1835 |
$rule->suspension_chargeperiod(3)->store; |
1852 |
$rule->firstremind(1)->store; |
1836 |
$rule->firstremind(1)->store; |
1853 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
1837 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) ); |
1854 |
|
1838 |
test_debarment_on_checkout( |
1855 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, |
|
|
1856 |
undef, undef, dt_from_string ); |
1857 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1858 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1859 |
is( scalar(@$debarments), 1 ); |
1860 |
|
1861 |
$expected_expiration = output_pref( |
1862 |
{ |
1839 |
{ |
1863 |
dt => dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) ), |
1840 |
item => $item_1, |
1864 |
dateformat => 'sql', |
1841 |
library => $library, |
1865 |
dateonly => 1 |
1842 |
patron => $patron, |
|
|
1843 |
due_date => $five_days_ago, |
1844 |
expiration_date => $expected_expiration, |
1866 |
} |
1845 |
} |
1867 |
); |
1846 |
); |
1868 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
|
|
1869 |
Koha::Patron::Debarments::DelUniqueDebarment( |
1870 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1871 |
|
1872 |
|
1847 |
|
|
|
1848 |
# Use finesCalendar to know if holiday must be skipped to calculate the due date |
1873 |
# We want to charge 2 days every days, with 0 day of grace (to not burn brains) |
1849 |
# We want to charge 2 days every days, with 0 day of grace (to not burn brains) |
1874 |
$rule->finedays(2)->store; |
1850 |
$rule->finedays(2)->store; |
1875 |
$rule->suspension_chargeperiod(1)->store; |
1851 |
$rule->suspension_chargeperiod(1)->store; |
Lines 1886-1911
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1886 |
title => 'holidayTest-2d', |
1862 |
title => 'holidayTest-2d', |
1887 |
description => 'holidayDesc 2 days ago' |
1863 |
description => 'holidayDesc 2 days ago' |
1888 |
); |
1864 |
); |
1889 |
|
|
|
1890 |
# With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday) |
1865 |
# 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 |
1866 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ); |
1892 |
|
1867 |
test_debarment_on_checkout( |
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 |
{ |
1868 |
{ |
1899 |
dt => dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ), |
1869 |
item => $item_1, |
1900 |
dateformat => 'sql', |
1870 |
library => $library, |
1901 |
dateonly => 1 |
1871 |
patron => $patron, |
|
|
1872 |
due_date => $five_days_ago, |
1873 |
expiration_date => $expected_expiration, |
1902 |
} |
1874 |
} |
1903 |
); |
1875 |
); |
1904 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
|
|
1905 |
Koha::Patron::Debarments::DelUniqueDebarment( |
1906 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1907 |
|
1908 |
|
1876 |
|
|
|
1877 |
# Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped |
1909 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
1878 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
1910 |
$calendar->insert_single_holiday( |
1879 |
$calendar->insert_single_holiday( |
1911 |
day => $two_days_ahead->day, |
1880 |
day => $two_days_ahead->day, |
Lines 1916-1938
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1916 |
); |
1885 |
); |
1917 |
|
1886 |
|
1918 |
# Same as above, but we should skip D+2 |
1887 |
# Same as above, but we should skip D+2 |
1919 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
1888 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ); |
1920 |
|
1889 |
test_debarment_on_checkout( |
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 |
{ |
1890 |
{ |
1927 |
dt => dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ), |
1891 |
item => $item_1, |
1928 |
dateformat => 'sql', |
1892 |
library => $library, |
1929 |
dateonly => 1 |
1893 |
patron => $patron, |
|
|
1894 |
due_date => $five_days_ago, |
1895 |
expiration_date => $expected_expiration, |
1930 |
} |
1896 |
} |
1931 |
); |
1897 |
); |
1932 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
|
|
1933 |
Koha::Patron::Debarments::DelUniqueDebarment( |
1934 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1935 |
|
1936 |
}; |
1898 |
}; |
1937 |
|
1899 |
|
1938 |
subtest 'AddReturn | is_overdue' => sub { |
1900 |
subtest 'AddReturn | is_overdue' => sub { |
Lines 2272-2274
sub add_biblio {
Link Here
|
2272 |
|
2234 |
|
2273 |
return AddBiblio($biblio, ''); |
2235 |
return AddBiblio($biblio, ''); |
2274 |
} |
2236 |
} |
2275 |
- |
2237 |
|
|
|
2238 |
sub test_debarment_on_checkout { |
2239 |
my ($params) = @_; |
2240 |
my $item = $params->{item}; |
2241 |
my $library = $params->{library}; |
2242 |
my $patron = $params->{patron}; |
2243 |
my $due_date = $params->{due_date} || dt_from_string; |
2244 |
my $expected_expiration_date = $params->{expiration_date}; |
2245 |
|
2246 |
$expected_expiration_date = output_pref( |
2247 |
{ |
2248 |
dt => $expected_expiration_date, |
2249 |
dateformat => 'sql', |
2250 |
dateonly => 1, |
2251 |
} |
2252 |
); |
2253 |
my @caller = caller; |
2254 |
my $line_number = $caller[2]; |
2255 |
AddIssue( $patron, $item->{barcode}, $due_date ); |
2256 |
|
2257 |
AddReturn( $item->{barcode}, $library->{branchcode}, |
2258 |
undef, undef, dt_from_string ); |
2259 |
my $debarments = Koha::Patron::Debarments::GetDebarments( |
2260 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
2261 |
is( scalar(@$debarments), 1, 'Test at line ' . $line_number ); |
2262 |
|
2263 |
is( $debarments->[0]->{expiration}, |
2264 |
$expected_expiration_date, 'Test at line ' . $line_number ); |
2265 |
Koha::Patron::Debarments::DelUniqueDebarment( |
2266 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
2267 |
} |