Bugzilla – Attachment 67882 Details for
Bug 17983
Add minutes loan to DiscreteCalendar
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17983 - Tests for minutes loan
Bug-17983---Tests-for-minutes-loan.patch (text/plain), 7.12 KB, created by
David Bourgault
on 2017-10-10 15:20:55 UTC
(
hide
)
Description:
Bug 17983 - Tests for minutes loan
Filename:
MIME Type:
Creator:
David Bourgault
Created:
2017-10-10 15:20:55 UTC
Size:
7.12 KB
patch
obsolete
>From 43e3f76db691b621744c4de899e701c4346b9645 Mon Sep 17 00:00:00 2001 >From: mehdi <mehdi@inlibro.com> >Date: Mon, 23 Jan 2017 16:58:04 -0500 >Subject: [PATCH] Bug 17983 - Tests for minutes loan > >--- > t/db_dependent/minutes_loan.t | 201 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 201 insertions(+) > create mode 100644 t/db_dependent/minutes_loan.t > >diff --git a/t/db_dependent/minutes_loan.t b/t/db_dependent/minutes_loan.t >new file mode 100644 >index 0000000..1e39882 >--- /dev/null >+++ b/t/db_dependent/minutes_loan.t >@@ -0,0 +1,201 @@ >+#!/usr/bin/env perl >+ >+use strict; >+use warnings; >+ >+use DateTime; >+use DateTime::Duration; >+use Test::More tests => 10; >+use Test::MockModule; >+ >+use C4::Circulation; >+use C4::Overdues; >+use Koha::DateUtils; >+use Koha::DiscreteCalendar; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+my $dbh = C4::Context->dbh(); >+my $today = DateTime->today; >+my $branch1 = "DFLT"; >+my $schema = Koha::Database->new->schema; >+my $calendar = Koha::DiscreteCalendar->new(branchcode => $branch1); >+ >+$schema->storage->txn_begin; >+$schema->resultset('DiscreteCalendar')->search({ >+ branchcode =>'DFLT' >+})->update_all({ >+ isopened => 1, >+ holidaytype => '', >+ note => '', >+ openhour => '08:00:00', >+ closehour => '16:00:00' >+}); >+ >+ >+####################################### >+# Add minutes and open minutes between >+####################################### >+ >+my $start_date = dt_from_string('2017-01-19 14:15:00', 'iso'); >+my $end_date = dt_from_string('2017-01-19 14:20:00', 'iso'); >+ >+is($calendar->open_minutes_between($start_date, $end_date)->in_units('minutes'), 5, "Item returned 5 minutes late"); >+ >+#Adding 10 minutes >+my $ten_mins_duration = DateTime::Duration->new( minutes => 10); >+is($calendar->addDate($start_date, $ten_mins_duration, 'minutes' ), >+ dt_from_string('2017-01-19 14:25:00', 'iso'), >+ 'Added 10 minutes to loan' ); >+ >+#Adding 10 minutes, passed closing hour >+$start_date = dt_from_string('2017-01-19 15:51:00', 'iso'); >+is($calendar->addDate($start_date, $ten_mins_duration, 'minutes' ), >+ dt_from_string('2017-01-19 16:00:00', 'iso'), >+ 'Added 10 minutes, due date passed closing hours, set due date to same day at close hour' ); >+ >+#Item returened next open day after a holiday. >+my $open_minutes_today = DateTime->today->add(hours =>10, minutes => 10); >+my $open_minutes_tomorrow = DateTime->today->add(days =>1); >+my $open_minutes_day_after_tomorrow = DateTime->today->add(days => 2, hours =>11); >+ >+$calendar->edit_holiday("Single holiday Today", '', "E", '', '', $open_minutes_tomorrow, $open_minutes_tomorrow); >+ >+is($calendar->open_minutes_between($open_minutes_today, $open_minutes_day_after_tomorrow)->in_units('minutes'), >+ 530, >+ "Correct open minutes, with a holiday in between"); >+ >+###################### >+# DueDate calculation >+###################### >+ >+#Set syspref ReturnBeforeExpiry = 1 and useDaysMode = 'Days' >+t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1); >+t::lib::Mocks::mock_preference('useDaysMode', 'Days'); >+ >+my $issuelength = 25; >+my $renewalperiod = 5; >+my $lengthunit = 'minutes'; >+my $dateexpiry = '2018-01-01'; >+ >+my $mock_loan_length = [ >+ ['issuelength', 'renewalperiod', 'lengthunit'], >+ [$issuelength, $renewalperiod, $lengthunit] >+]; >+ >+my $categorycode = 'X'; >+my $itemtype = 'MINUTES'; >+my $borrower = {categorycode => 'X', dateexpiry => $dateexpiry}; >+$dbh->do("INSERT INTO issuingrules (categorycode, branchcode, itemtype, issuelength, lengthunit) VALUES('$categorycode', '$branch1', '$itemtype', '$issuelength', '$lengthunit')"); >+ >+my $date = C4::Circulation::CalcDateDue( $today, $itemtype, $branch1, $borrower ); >+is($date, DateTime->today->add(minutes => $issuelength), "Due date calculated correctly"); >+ >+#passed closing hour >+$issuelength = 1300; >+$dbh->do("UPDATE issuingrules SET issuelength=$issuelength where branchcode='$branch1' and itemtype='$itemtype'"); >+ >+$date = C4::Circulation::CalcDateDue( $today, $itemtype, $branch1, $borrower ); >+is($date, DateTime->today->add(hours =>16), "Due date passed close hour, item due at close hour"); >+ >+############################# >+# Chargeable minutes between >+############################ >+ >+$issuelength = 25; >+$dbh->do("UPDATE issuingrules SET issuelength=$issuelength where branchcode='$branch1' and itemtype='$itemtype'"); >+ >+my $date_due = DateTime->today; >+my $date_returned = DateTime->today->add(minutes => 40); >+ >+my $chargeable_units = C4::Overdues::get_chargeable_units('minutes', $date_due, $date_returned, $branch1); >+is($chargeable_units, 40, "40 minutes of use"); >+ >+###################### >+# Fines calculation >+##################### >+ >+my $builder = t::lib::TestBuilder->new(); >+ >+my $category = $builder->build( >+ { >+ source => 'Category', >+ } >+); >+ >+my $patron = $builder->build( >+ { >+ source => 'Borrower', >+ value => { >+ categorycode => $category->{categorycode}, >+ branchcode => $branch1 >+ }, >+ } >+); >+ >+my $biblio = $builder->build( >+ { >+ source => 'Biblio', >+ value => { >+ branchcode => $branch1, >+ }, >+ } >+); >+ >+my $item = $builder->build( >+ { >+ source => 'Item', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ homebranch => $branch1, >+ holdingbranch => $branch1, >+ replacementprice => '5.00', >+ }, >+ } >+); >+ >+my $rule = $builder->schema->resultset('Issuingrule')->find({ >+ branchcode => '*', >+ categorycode => '*', >+ itemtype => '*', >+}); >+$rule->delete if $rule; >+# FinesIncludeGracePeriod included >+t::lib::Mocks::mock_preference('FinesIncludeGracePeriod', 1); >+my $issuingrule = $builder->build( >+ { >+ source => 'Issuingrule', >+ value => { >+ branchcode => '*', >+ categorycode => '*', >+ itemtype => '*', >+ fine => '1', >+ lengthunit => 'minutes', >+ finedays => 0, >+ firstremind => 5, >+ chargeperiod => 1, >+ overduefinescap => undef, >+ cap_fine_to_replacement_price => 0, >+ }, >+ } >+); >+my $start_dt = dt_from_string('2017-01-02 15:00:00', 'iso'); >+my $end_dt = dt_from_string('2017-01-02 15:04:00', 'iso'); >+ >+my ($amount) = C4::Overdues::CalcFine( $item, $patron->{categorycode}, $branch1, $start_dt, $end_dt ); >+is($amount, 0, "No fine when under the fine grace periode"); >+ >+$end_dt = dt_from_string('2017-01-02 15:06:00', 'iso'); >+($amount) = C4::Overdues::CalcFine( $item, $patron->{categorycode}, $branch1, $start_dt, $end_dt ); >+is($amount, 6, "6\$ fine for 6 minutes delay, fine grace periode included"); >+ >+# FinesIncludeGracePeriod not included >+t::lib::Mocks::mock_preference('FinesIncludeGracePeriod', 0); >+ >+($amount) = C4::Overdues::CalcFine( $item, $patron->{categorycode}, $branch1, $start_dt, $end_dt ); >+is($amount, 1, "1\$ fine for 6 minutes delay, fine grace periode not included"); >+ >+$schema->storage->txn_rollback; >+ >+1; >-- >2.7.4
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 17983
:
59521
|
59522
|
59523
|
67880
|
67881
|
67882
|
67969
|
68016
|
68017
|
73353
|
73354
|
73355
|
75480
|
131929
|
131930
|
131931
|
131932
|
136414
|
136415
|
139519
|
144267
|
151452
|
167846