Bugzilla – Attachment 40908 Details for
Bug 14494
Terribly slow checkout caused by DateTime->new in far future
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14494: Add some unit tests too for CalcDateDue
Bug-14494-Add-some-unit-tests-too-for-CalcDateDue.patch (text/plain), 3.69 KB, created by
Marcel de Rooy
on 2015-07-10 07:48:04 UTC
(
hide
)
Description:
Bug 14494: Add some unit tests too for CalcDateDue
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2015-07-10 07:48:04 UTC
Size:
3.69 KB
patch
obsolete
>From bdce4bc7b3ea19f9c90f6787af9aad3f3224b20d Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 9 Jul 2015 15:35:53 +0200 >Subject: [PATCH] Bug 14494: Add some unit tests too for CalcDateDue >Content-Type: text/plain; charset=utf-8 > >The second patch of this report made some changes to CalcDateDue. >We are adding some unit tests here. >See the commments on the third patch too. > >Test plan: >Run t/db_dependent/Circulation_dateexpiry.t >--- > t/db_dependent/Circulation_dateexpiry.t | 56 ++++++++++++++++++++++++++++--- > 1 file changed, 51 insertions(+), 5 deletions(-) > >diff --git a/t/db_dependent/Circulation_dateexpiry.t b/t/db_dependent/Circulation_dateexpiry.t >index 0c4d728..3e65f71 100644 >--- a/t/db_dependent/Circulation_dateexpiry.t >+++ b/t/db_dependent/Circulation_dateexpiry.t >@@ -18,19 +18,24 @@ > use Modern::Perl; > > use DateTime; >-use Time::HiRes qw/gettimeofday/; >+use Time::HiRes qw/gettimeofday time/; >+use Test::More tests => 2; > use C4::Members; > use Koha::DateUtils; > use t::lib::TestBuilder; >-use Test::More tests => 1; >+use t::lib::Mocks qw( mock_preference ); > >+my $builder = t::lib::TestBuilder->new(); > subtest 'Tests for CanBookBeIssued related to dateexpiry' => sub { > plan tests => 4; >- date_expiry(); >+ can_book_be_issued(); >+}; >+subtest 'Tests for CalcDateDue related to dateexpiry' => sub { >+ #plan tests => 4; >+ calc_date_due(); > }; > >-sub date_expiry { >- my $builder = t::lib::TestBuilder->new(); >+sub can_book_be_issued { > my $item = $builder->build( { source => 'Item' } ); > my $patron = $builder->build( > { source => 'Borrower', >@@ -66,3 +71,44 @@ sub date_expiry { > is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is tomorrow' ); > > } >+ >+sub calc_date_due { >+ t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1); >+ # this triggers the compare between expiry and due date >+ >+ my $patron = $builder->build( { source => 'Borrower' } ); >+ my $item = $builder->build( { source => 'Item' } ); >+ my $branch = $builder->build( { source => 'Branch' } ); >+ my $today = dt_from_string(); >+ >+ # first test with empty expiry date >+ # note that this expiry date will never lead to an issue btw !! >+ $patron->{dateexpiry}='0000-00-00'; >+ my $d= C4::Circulation::CalcDateDue( $today, $item->{itype}, >+ $branch->{branchcode}, $patron ); >+ is( ref $d eq "DateTime" && $d->mdy()=~/^\d+/, 1, "CalcDateDue with expiry 0000-00-00" ); >+ >+ # second test expiry date==today >+ my $d2 = output_pref( { dt => $today, dateonly =>1, dateformat => 'sql' } ); >+ $patron->{dateexpiry} = $d2; >+ $d= C4::Circulation::CalcDateDue( $today, $item->{itype}, >+ $branch->{branchcode}, $patron ); >+ is( ref $d eq "DateTime" && DateTime->compare( $d->truncate(to=>'day'), $today->truncate(to=>'day') )==0, 1, "CalcDateDue with expiry today" ); >+ >+ # third test expiry date tomorrow >+ my $dur = DateTime::Duration->new( days => 1 ); >+ my $tomorrow= $today->clone->add_duration( $dur ); >+ $d2 = output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' }); >+ $patron->{dateexpiry} = $d2; >+ $d= C4::Circulation::CalcDateDue( $today, $item->{itype}, >+ $branch->{branchcode}, $patron ); >+ is( ref $d eq "DateTime" && $d->mdy()=~/^\d+/, 1, "CalcDateDue with expiry tomorrow" ); >+ >+ # fourth test far future >+ $patron->{dateexpiry} = '9876-12-31'; >+ my $t1=time; >+ $d= C4::Circulation::CalcDateDue( $today, $item->{itype}, >+ $branch->{branchcode}, $patron ); >+ my $t2=time; >+ is( ref $d eq "DateTime" && $t2-$t1 < 1, 1, "CalcDateDue with expiry in year 9876 in ".sprintf("%6.4f", $t2-$t1)." seconds."); >+} >-- >1.7.10.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 14494
:
40860
|
40873
|
40874
|
40879
|
40880
|
40881
|
40882
|
40883
|
40908
|
40909
|
40910
|
40911
|
40912
|
40932
|
40933
|
40934
|
40935