Bugzilla – Attachment 57524 Details for
Bug 17583
Use Koha::Patron->is_expired from circulation.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 17583: Add the Koha::Patron->is_going_to_expired method
SIGNED-OFF-Bug-17583-Add-the-KohaPatron-isgoingtoe.patch (text/plain), 4.81 KB, created by
Josef Moravec
on 2016-11-16 08:05:55 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 17583: Add the Koha::Patron->is_going_to_expired method
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2016-11-16 08:05:55 UTC
Size:
4.81 KB
patch
obsolete
>From 5c516b9e1377fa033586d7198b7851a9dd083657 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 8 Nov 2016 15:01:55 +0000 >Subject: [PATCH] [SIGNED-OFF] Bug 17583: Add the > Koha::Patron->is_going_to_expired method > >In order to be consistent, we need to create this method as well. > >Test plan: >Make sure the pref NotifyBorrowerDeparture works as expected > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > Koha/Patron.pm | 19 +++++++++++++++++++ > circ/circulation.pl | 5 +---- > t/db_dependent/Koha/Patrons.t | 39 ++++++++++++++++++++++++++++++++++++++- > 3 files changed, 58 insertions(+), 5 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index e1af2eb..057db0a 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -282,6 +282,25 @@ sub is_expired { > return 0; > } > >+=head2 is_going_to_expired >+ >+my $is_going_to_expired = $patron->is_going_to_expired; >+ >+Returns 1 if the patron is going to expired, depending on the NotifyBorrowerDeparture pref or 0 >+ >+=cut >+ >+sub is_going_to_expired { >+ my ($self) = @_; >+ >+ my $delay = C4::Context->preference('NotifyBorrowerDeparture') || 0; >+ >+ return 0 unless $self->dateexpiry; >+ return 0 if $self->dateexpiry eq '0000-00-00'; >+ return 1 if dt_from_string( $self->dateexpiry )->add( days => $delay ) < dt_from_string; >+ return 0; >+} >+ > =head2 update_password > > my $updated = $patron->update_password( $userid, $password ); >diff --git a/circ/circulation.pl b/circ/circulation.pl >index 5dc0f6a..e2f7097 100755 >--- a/circ/circulation.pl >+++ b/circ/circulation.pl >@@ -278,10 +278,7 @@ if ($borrowernumber) { > ); > } > # check for NotifyBorrowerDeparture >- elsif ( C4::Context->preference('NotifyBorrowerDeparture') && >- Date_to_Days(Add_Delta_Days($warning_year,$warning_month,$warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) < >- Date_to_Days( $today_year, $today_month, $today_day ) ) >- { >+ elsif ( $patron->is_going_to_expired ) { > # borrower card soon to expire warn librarian > $template->param( "warndeparture" => $borrower->{dateexpiry} , > ); >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index a527591..e8a8172 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 12; >+use Test::More tests => 13; > use Test::Warn; > > use C4::Members; >@@ -183,6 +183,43 @@ subtest 'is_expired' => sub { > $patron->delete; > }; > >+subtest 'is_going_to_expired' => sub { >+ plan tests => 8; >+ my $patron = $builder->build({ source => 'Borrower' }); >+ $patron = Koha::Patrons->find( $patron->{borrowernumber} ); >+ $patron->dateexpiry( undef )->store; >+ is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not set'); >+ $patron->dateexpiry( '0000-00-00' )->store; >+ is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00'); >+ $patron->dateexpiry( dt_from_string )->store; >+ is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today'); >+ >+ t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); >+ my $dt_from_string = dt_from_string; >+ $patron->dateexpiry( $dt_from_string )->store; >+ is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0'); >+ >+ t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); >+ $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store; >+ is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 11 days before and pref is 10'); >+ >+ t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); >+ $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store; >+ is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days before and pref is 0'); >+ >+ t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); >+ $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store; >+ is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days before and pref is 10'); >+ $patron->delete; >+ >+ t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); >+ $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store; >+ is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 20 days before and pref is 10'); >+ >+ $patron->delete; >+}; >+ >+ > subtest 'renew_account' => sub { > plan tests => 10; > my $a_month_ago = dt_from_string->add( months => -1 )->truncate( to => 'day' ); >-- >2.1.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 17583
:
57329
|
57330
|
57334
|
57364
|
57380
|
57384
|
57387
|
57488
|
57523
|
57524
|
57525
|
57526
|
57527
|
57528
|
57888
|
57889
|
57890
|
57891
|
57892
|
57893
|
57914
|
57915
|
57916
|
57917
|
57918
|
57919
|
57920