Lines 1742-1755
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
1742 |
$rule->store(); |
1742 |
$rule->store(); |
1743 |
|
1743 |
|
1744 |
# Patron cannot issue item_1, they have overdues |
1744 |
# Patron cannot issue item_1, they have overdues |
1745 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
1745 |
my $now = dt_from_string; |
1746 |
my $ten_days_ago = dt_from_string->subtract( days => 10 ); |
1746 |
my $five_days_ago = $now->clone->subtract( days => 5 ); |
|
|
1747 |
my $ten_days_ago = $now->clone->subtract( days => 10 ); |
1747 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
1748 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
1748 |
AddIssue( $patron, $item_2->{barcode}, $ten_days_ago ) |
1749 |
AddIssue( $patron, $item_2->{barcode}, $ten_days_ago ) |
1749 |
; # Add another overdue |
1750 |
; # Add another overdue |
1750 |
|
1751 |
|
1751 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' ); |
1752 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' ); |
1752 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, dt_from_string ); |
1753 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, $now ); |
1753 |
my $debarments = Koha::Patron::Debarments::GetDebarments( |
1754 |
my $debarments = Koha::Patron::Debarments::GetDebarments( |
1754 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1755 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1755 |
is( scalar(@$debarments), 1 ); |
1756 |
is( scalar(@$debarments), 1 ); |
Lines 1758-1777
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
1758 |
# Same for the others |
1759 |
# Same for the others |
1759 |
my $expected_expiration = output_pref( |
1760 |
my $expected_expiration = output_pref( |
1760 |
{ |
1761 |
{ |
1761 |
dt => dt_from_string->add( days => ( 5 - 1 ) * 2 ), |
1762 |
dt => $now->clone->add( days => ( 5 - 1 ) * 2 ), |
1762 |
dateformat => 'sql', |
1763 |
dateformat => 'sql', |
1763 |
dateonly => 1 |
1764 |
dateonly => 1 |
1764 |
} |
1765 |
} |
1765 |
); |
1766 |
); |
1766 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
1767 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
1767 |
|
1768 |
|
1768 |
AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, dt_from_string ); |
1769 |
AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, $now ); |
1769 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1770 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1770 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1771 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1771 |
is( scalar(@$debarments), 1 ); |
1772 |
is( scalar(@$debarments), 1 ); |
1772 |
$expected_expiration = output_pref( |
1773 |
$expected_expiration = output_pref( |
1773 |
{ |
1774 |
{ |
1774 |
dt => dt_from_string->add( days => ( 10 - 1 ) * 2 ), |
1775 |
dt => $now->clone->add( days => ( 10 - 1 ) * 2 ), |
1775 |
dateformat => 'sql', |
1776 |
dateformat => 'sql', |
1776 |
dateonly => 1 |
1777 |
dateonly => 1 |
1777 |
} |
1778 |
} |
Lines 1785-1810
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
1785 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
1786 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
1786 |
AddIssue( $patron, $item_2->{barcode}, $ten_days_ago ) |
1787 |
AddIssue( $patron, $item_2->{barcode}, $ten_days_ago ) |
1787 |
; # Add another overdue |
1788 |
; # Add another overdue |
1788 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, dt_from_string ); |
1789 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, $now ); |
1789 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1790 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1790 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1791 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1791 |
is( scalar(@$debarments), 1 ); |
1792 |
is( scalar(@$debarments), 1 ); |
1792 |
$expected_expiration = output_pref( |
1793 |
$expected_expiration = output_pref( |
1793 |
{ |
1794 |
{ |
1794 |
dt => dt_from_string->add( days => ( 5 - 1 ) * 2 ), |
1795 |
dt => $now->clone->add( days => ( 5 - 1 ) * 2 ), |
1795 |
dateformat => 'sql', |
1796 |
dateformat => 'sql', |
1796 |
dateonly => 1 |
1797 |
dateonly => 1 |
1797 |
} |
1798 |
} |
1798 |
); |
1799 |
); |
1799 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
1800 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
1800 |
|
1801 |
|
1801 |
AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, dt_from_string ); |
1802 |
AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, $now ); |
1802 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1803 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1803 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1804 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1804 |
is( scalar(@$debarments), 1 ); |
1805 |
is( scalar(@$debarments), 1 ); |
1805 |
$expected_expiration = output_pref( |
1806 |
$expected_expiration = output_pref( |
1806 |
{ |
1807 |
{ |
1807 |
dt => dt_from_string->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ), |
1808 |
dt => $now->clone->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ), |
1808 |
dateformat => 'sql', |
1809 |
dateformat => 'sql', |
1809 |
dateonly => 1 |
1810 |
dateonly => 1 |
1810 |
} |
1811 |
} |
Lines 1846-1855
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1846 |
); |
1847 |
); |
1847 |
$rule->store(); |
1848 |
$rule->store(); |
1848 |
|
1849 |
|
1849 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
1850 |
my $now = dt_from_string; |
|
|
1851 |
my $five_days_ago = $now->clone->subtract( days => 5 ); |
1850 |
# We want to charge 2 days every day, without grace |
1852 |
# We want to charge 2 days every day, without grace |
1851 |
# With 5 days of overdue: 5 * Z |
1853 |
# With 5 days of overdue: 5 * Z |
1852 |
my $expected_expiration = dt_from_string->add( days => ( 5 * 2 ) / 1 ); |
1854 |
my $expected_expiration = $now->clone->add( days => ( 5 * 2 ) / 1 ); |
1853 |
test_debarment_on_checkout( |
1855 |
test_debarment_on_checkout( |
1854 |
{ |
1856 |
{ |
1855 |
item => $item_1, |
1857 |
item => $item_1, |
Lines 1863-1869
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1863 |
# We want to charge 2 days every 2 days, without grace |
1865 |
# We want to charge 2 days every 2 days, without grace |
1864 |
# With 5 days of overdue: (5 * 2) / 2 |
1866 |
# With 5 days of overdue: (5 * 2) / 2 |
1865 |
$rule->suspension_chargeperiod(2)->store; |
1867 |
$rule->suspension_chargeperiod(2)->store; |
1866 |
$expected_expiration = dt_from_string->add( days => floor( 5 * 2 ) / 2 ); |
1868 |
$expected_expiration = $now->clone->add( days => floor( 5 * 2 ) / 2 ); |
1867 |
test_debarment_on_checkout( |
1869 |
test_debarment_on_checkout( |
1868 |
{ |
1870 |
{ |
1869 |
item => $item_1, |
1871 |
item => $item_1, |
Lines 1879-1884
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1879 |
$rule->suspension_chargeperiod(3)->store; |
1881 |
$rule->suspension_chargeperiod(3)->store; |
1880 |
$rule->firstremind(1)->store; |
1882 |
$rule->firstremind(1)->store; |
1881 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) ); |
1883 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) ); |
|
|
1884 |
$expected_expiration = $now->clone->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) ); |
1882 |
test_debarment_on_checkout( |
1885 |
test_debarment_on_checkout( |
1883 |
{ |
1886 |
{ |
1884 |
item => $item_1, |
1887 |
item => $item_1, |
Lines 1899-1905
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1899 |
|
1902 |
|
1900 |
# Adding a holiday 2 days ago |
1903 |
# Adding a holiday 2 days ago |
1901 |
my $calendar = C4::Calendar->new(branchcode => $library->{branchcode}); |
1904 |
my $calendar = C4::Calendar->new(branchcode => $library->{branchcode}); |
1902 |
my $two_days_ago = dt_from_string->subtract( days => 2 ); |
1905 |
my $two_days_ago = $now->clone->subtract( days => 2 ); |
1903 |
$calendar->insert_single_holiday( |
1906 |
$calendar->insert_single_holiday( |
1904 |
day => $two_days_ago->day, |
1907 |
day => $two_days_ago->day, |
1905 |
month => $two_days_ago->month, |
1908 |
month => $two_days_ago->month, |
Lines 1908-1914
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1908 |
description => 'holidayDesc 2 days ago' |
1911 |
description => 'holidayDesc 2 days ago' |
1909 |
); |
1912 |
); |
1910 |
# With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday) |
1913 |
# With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday) |
1911 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ); |
1914 |
$expected_expiration = $now->clone->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ); |
1912 |
test_debarment_on_checkout( |
1915 |
test_debarment_on_checkout( |
1913 |
{ |
1916 |
{ |
1914 |
item => $item_1, |
1917 |
item => $item_1, |
Lines 1920-1926
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1920 |
); |
1923 |
); |
1921 |
|
1924 |
|
1922 |
# Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped |
1925 |
# Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped |
1923 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
1926 |
my $two_days_ahead = $now->clone->add( days => 2 ); |
1924 |
$calendar->insert_single_holiday( |
1927 |
$calendar->insert_single_holiday( |
1925 |
day => $two_days_ahead->day, |
1928 |
day => $two_days_ahead->day, |
1926 |
month => $two_days_ahead->month, |
1929 |
month => $two_days_ahead->month, |
Lines 1930-1936
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1930 |
); |
1933 |
); |
1931 |
|
1934 |
|
1932 |
# Same as above, but we should skip D+2 |
1935 |
# Same as above, but we should skip D+2 |
1933 |
$expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ); |
1936 |
$expected_expiration = $now->clone->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ); |
1934 |
test_debarment_on_checkout( |
1937 |
test_debarment_on_checkout( |
1935 |
{ |
1938 |
{ |
1936 |
item => $item_1, |
1939 |
item => $item_1, |
Lines 1966-1973
subtest 'AddReturn + suspension_chargeperiod' => sub {
Link Here
|
1966 |
item => $item_1, |
1969 |
item => $item_1, |
1967 |
library => $library, |
1970 |
library => $library, |
1968 |
patron => $patron, |
1971 |
patron => $patron, |
1969 |
return_date => dt_from_string->add(days => 5), |
1972 |
return_date => $now->clone->add(days => 5), |
1970 |
expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) ), |
1973 |
expiration_date => $now->clone->add(days => 5 + (5 * 2 - 1) ), |
1971 |
} |
1974 |
} |
1972 |
); |
1975 |
); |
1973 |
|
1976 |
|
Lines 2064-2072
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
2064 |
$rule->store(); |
2067 |
$rule->store(); |
2065 |
|
2068 |
|
2066 |
my $now = dt_from_string; |
2069 |
my $now = dt_from_string; |
2067 |
my $one_day_ago = dt_from_string->subtract( days => 1 ); |
2070 |
my $one_day_ago = $now->clone->subtract( days => 1 ); |
2068 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
2071 |
my $five_days_ago = $now->clone->subtract( days => 5 ); |
2069 |
my $ten_days_ago = dt_from_string->subtract( days => 10 ); |
2072 |
my $ten_days_ago = $now->clone->subtract( days => 10 ); |
2070 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
2073 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
2071 |
|
2074 |
|
2072 |
# No return date specified, today will be used => 10 days overdue charged |
2075 |
# No return date specified, today will be used => 10 days overdue charged |
Lines 2805-2812
subtest 'CanBookBeIssued | is_overdue' => sub {
Link Here
|
2805 |
.10, 1 |
2808 |
.10, 1 |
2806 |
); |
2809 |
); |
2807 |
|
2810 |
|
2808 |
my $five_days_go = output_pref({ dt => dt_from_string->add( days => 5 ), dateonly => 1}); |
2811 |
my $now = dt_from_string; |
2809 |
my $ten_days_go = output_pref({ dt => dt_from_string->add( days => 10), dateonly => 1 }); |
2812 |
my $five_days_go = output_pref({ dt => $now->clone->add( days => 5 ), dateonly => 1}); |
|
|
2813 |
my $ten_days_go = output_pref({ dt => $now->clone->add( days => 10), dateonly => 1 }); |
2810 |
my $library = $builder->build( { source => 'Branch' } ); |
2814 |
my $library = $builder->build( { source => 'Branch' } ); |
2811 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } ); |
2815 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } ); |
2812 |
|
2816 |
|
Lines 3170-3176
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
Link Here
|
3170 |
$context = Test::MockModule->new('C4::Context'); |
3174 |
$context = Test::MockModule->new('C4::Context'); |
3171 |
$context->mock( userenv => { branch => undef, interface => 'CRON'} ); #Test statistical logging of renewal via cron (atuo_renew) |
3175 |
$context->mock( userenv => { branch => undef, interface => 'CRON'} ); #Test statistical logging of renewal via cron (atuo_renew) |
3172 |
|
3176 |
|
3173 |
$date = output_pref( { dt => dt_from_string(), dateonly => 1, dateformat => 'iso' } ); |
3177 |
my $now = dt_from_string; |
|
|
3178 |
$date = output_pref( { dt => $now, dateonly => 1, dateformat => 'iso' } ); |
3174 |
$old_log_size = Koha::ActionLogs->count( \%params_renewal ); |
3179 |
$old_log_size = Koha::ActionLogs->count( \%params_renewal ); |
3175 |
my $sth = $dbh->prepare("SELECT COUNT(*) FROM statistics WHERE itemnumber = ? AND branch = ?"); |
3180 |
my $sth = $dbh->prepare("SELECT COUNT(*) FROM statistics WHERE itemnumber = ? AND branch = ?"); |
3176 |
$sth->execute($item->id, $library->id); |
3181 |
$sth->execute($item->id, $library->id); |
Lines 3250-3258
subtest 'Incremented fee tests' => sub {
Link Here
|
3250 |
is( $item->effective_itemtype, $itemtype->id, |
3255 |
is( $item->effective_itemtype, $itemtype->id, |
3251 |
"Itemtype set correctly for item" ); |
3256 |
"Itemtype set correctly for item" ); |
3252 |
|
3257 |
|
3253 |
my $dt_from = dt_from_string(); |
3258 |
my $now = dt_from_string; |
3254 |
my $dt_to = dt_from_string()->add( days => 7 ); |
3259 |
my $dt_from = $now->clone; |
3255 |
my $dt_to_renew = dt_from_string()->add( days => 13 ); |
3260 |
my $dt_to = $now->clone->add( days => 7 ); |
|
|
3261 |
my $dt_to_renew = $now->clone->add( days => 13 ); |
3256 |
|
3262 |
|
3257 |
# Daily Tests |
3263 |
# Daily Tests |
3258 |
t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' ); |
3264 |
t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' ); |
Lines 3350-3357
subtest 'Incremented fee tests' => sub {
Link Here
|
3350 |
is( $itemtype->rentalcharge_hourly, |
3356 |
is( $itemtype->rentalcharge_hourly, |
3351 |
'0.25', 'Hourly rental charge stored and retreived correctly' ); |
3357 |
'0.25', 'Hourly rental charge stored and retreived correctly' ); |
3352 |
|
3358 |
|
3353 |
$dt_to = dt_from_string()->add( hours => 168 ); |
3359 |
$dt_to = $now->clone->add( hours => 168 ); |
3354 |
$dt_to_renew = dt_from_string()->add( hours => 312 ); |
3360 |
$dt_to_renew = $now->clone->add( hours => 312 ); |
3355 |
|
3361 |
|
3356 |
t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' ); |
3362 |
t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' ); |
3357 |
$issue = |
3363 |
$issue = |
Lines 3443-3449
subtest 'CanBookBeIssued & RentalFeesCheckoutConfirmation' => sub {
Link Here
|
3443 |
|
3449 |
|
3444 |
my ( $issuingimpossible, $needsconfirmation ); |
3450 |
my ( $issuingimpossible, $needsconfirmation ); |
3445 |
my $dt_from = dt_from_string(); |
3451 |
my $dt_from = dt_from_string(); |
3446 |
my $dt_due = dt_from_string()->add( days => 3 ); |
3452 |
my $dt_due = $dt_from->clone->add( days => 3 ); |
3447 |
|
3453 |
|
3448 |
$itemtype->rentalcharge(1)->store; |
3454 |
$itemtype->rentalcharge(1)->store; |
3449 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->barcode, $dt_due, undef, undef, undef ); |
3455 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->barcode, $dt_due, undef, undef, undef ); |
3450 |
- |
|
|