Bugzilla – Attachment 85788 Details for
Bug 14293
Error in the calculation of the suspension of users per day
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14293: Add more tests and fix floor/ceil
Bug-14293-Add-more-tests-and-fix-floorceil.patch (text/plain), 4.40 KB, created by
Jonathan Druart
on 2019-02-27 17:00:06 UTC
(
hide
)
Description:
Bug 14293: Add more tests and fix floor/ceil
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2019-02-27 17:00:06 UTC
Size:
4.40 KB
patch
obsolete
>From eb2de46dc000c7de47c2a3c693849af3b168166d Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 27 Feb 2019 13:59:37 -0300 >Subject: [PATCH] Bug 14293: Add more tests and fix floor/ceil > >--- > C4/Circulation.pm | 4 +- > .../Circulation/IssuingRules/maxsuspensiondays.t | 77 +++++++++++++++++++++- > 2 files changed, 78 insertions(+), 3 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index f9b0ae0271..54b5182082 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -22,7 +22,7 @@ package C4::Circulation; > use strict; > #use warnings; FIXME - Bug 2505 > use DateTime; >-use POSIX qw( floor ); >+use POSIX qw( floor ceil ); > use Koha::DateUtils; > use C4::Context; > use C4::Stats; >@@ -2242,7 +2242,7 @@ sub _debar_user_on_return { > if ( $issuing_rule->suspension_chargeperiod > 1 ) { > # No need to / 1 and do not consider / 0 > $suspension_days = DateTime::Duration->new( >- days => floor( $suspension_days->in_units('days') / $issuing_rule->suspension_chargeperiod ) >+ days => ceil( $suspension_days->in_units('days') / $issuing_rule->suspension_chargeperiod ) > ); > } > >diff --git a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t b/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t >index 683a314eba..35de10228b 100644 >--- a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t >+++ b/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t >@@ -1,5 +1,5 @@ > use Modern::Perl; >-use Test::More tests => 5; >+use Test::More tests => 10; > > use MARC::Record; > use MARC::Field; >@@ -152,4 +152,79 @@ is( > ); > DelDebarment( $debarments->[0]->{borrower_debarment_id} ); > >+# 2 hours before => 0 day of suspension >+my $hoursafter2= dt_from_string->add_duration(DateTime::Duration->new(hours => 2)); >+AddIssue( $borrower, $barcode, $hoursafter2); >+AddReturn( $barcode, $branchcode ); >+$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}}); >+is_deeply( >+ $debarments, >+ [], >+ 'No debarment if in time' >+); >+DelDebarment( $debarments->[0]->{borrower_debarment_id} ); >+ >+Koha::IssuingRules->search->delete; >+# Add 1 day every 2 days >+$builder->build( >+ { >+ source => 'Issuingrule', >+ value => { >+ categorycode => '*', >+ itemtype => '*', >+ branchcode => '*', >+ firstremind => 0, >+ finedays => 1, >+ lengthunit => 'hours', >+ suspension_chargeperiod => 2, >+ maxsuspensiondays => 100, >+ } >+ } >+); >+ >+# 20 days late => 20/2 * 1 => 10 days of suspension >+AddIssue( $borrower, $barcode, $daysago20 ); >+AddReturn( $barcode, $branchcode ); >+$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}}); >+is( >+ $debarments->[0]->{expiration}, >+ output_pref({ dt => $daysafter10, dateformat => 'iso', dateonly => 1 }), >+ 'calculate suspension with lengthunit hours.' >+); >+DelDebarment( $debarments->[0]->{borrower_debarment_id} ); >+ >+# 1 day late => ceil(1/2) * 1 => 1 day of suspension >+my $tomorrow = dt_from_string->add_duration(DateTime::Duration->new( days => 1 )); >+AddIssue( $borrower, $barcode, $yesterday); >+AddReturn( $barcode, $branchcode ); >+$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}}); >+is( >+ $debarments->[0]->{expiration}, >+ output_pref({ dt => $tomorrow, dateformat => 'iso', dateonly => 1 }), >+ 'calculate suspension with lengthunit hours.' >+); >+DelDebarment( $debarments->[0]->{borrower_debarment_id} ); >+ >+# 2 hours late => ceil(.x/2) * 1 => 1 day of suspension >+AddIssue( $borrower, $barcode, $hoursago2); >+AddReturn( $barcode, $branchcode ); >+$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}}); >+is( >+ $debarments->[0]->{expiration}, >+ output_pref({ dt => $tomorrow, dateformat => 'iso', dateonly => 1 }), >+ 'calculate suspension with lengthunit hours.' >+); >+DelDebarment( $debarments->[0]->{borrower_debarment_id} ); >+ >+# 2 hours before => 0 day of suspension >+AddIssue( $borrower, $barcode, $hoursafter2); >+AddReturn( $barcode, $branchcode ); >+$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}}); >+is_deeply( >+ $debarments, >+ [], >+ 'No debarment if in time' >+); >+DelDebarment( $debarments->[0]->{borrower_debarment_id} ); >+ > $schema->storage->txn_rollback; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14293
:
42387
|
42492
|
85210
|
85211
|
85251
|
85252
|
85255
|
85407
|
85408
|
85788
|
90955
|
90956
|
90957
|
159075
|
159076
|
159128
|
159129
|
159277
|
159504
|
160924
|
160925