Bug 20145: Do not insert 0000-00-00 in patron tests (and more)
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 14 Feb 2018 18:15:39 +0000 (15:15 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sun, 18 Feb 2018 17:48:05 +0000 (14:48 -0300)
We should call Koha::Patron->is_expired in CanBookBeIssued instead of
doing the same calculation.

Tests have been adapted to pass with new SQL modes.

We should not need to update the values in DB, we already have
  Bug 14717: Prevent 0000-00-00 dates in patron data (3.21.00.023)

Test plan:
  prove t/db_dependent/Circulation/dateexpiry.t
  prove t/db_dependent/Koha/Patrons.t
must return green

Signed-off-by: Roch D'Amour <roch.damour@inlibro.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Circulation.pm
C4/Utils/DataTables/Members.pm
Koha/Patron.pm
t/db_dependent/Circulation/dateexpiry.t
t/db_dependent/Koha/Patrons.t

index 2f75d8c..4b39a2d 100644 (file)
@@ -736,16 +736,9 @@ sub CanBookBeIssued {
             $issuingimpossible{DEBARRED} = 1;
         }
     }
-    if ( !defined $patron->dateexpiry || $patron->dateexpiry eq '0000-00-00') {
+
+    if ( $patron->is_expired ) {
         $issuingimpossible{EXPIRED} = 1;
-    } else {
-        my $expiry_dt = dt_from_string( $patron->dateexpiry, 'sql', 'floating' );
-        $expiry_dt->truncate( to => 'day');
-        my $today = $now->clone()->truncate(to => 'day');
-        $today->set_time_zone( 'floating' );
-        if ( DateTime->compare($today, $expiry_dt) == 1 ) {
-            $issuingimpossible{EXPIRED} = 1;
-        }
     }
 
     #
index 0005b01..8912146 100644 (file)
@@ -184,7 +184,8 @@ sub search {
         # FIXME Should be formatted from the template
         $patron->{fines} = sprintf("%.2f", $balance);
 
-        if($patron->{dateexpiry} and $patron->{dateexpiry} ne '0000-00-00') {
+        if( $patron->{dateexpiry} ) {
+            # FIXME We should not format the date here, do it in template-side instead
             $patron->{dateexpiry} = output_pref( { dt => dt_from_string( $patron->{dateexpiry}, 'iso'), dateonly => 1} );
         } else {
             $patron->{dateexpiry} = '';
index ed4a1b3..d0be998 100644 (file)
@@ -297,7 +297,7 @@ Returns 1 if the patron is expired or 0;
 sub is_expired {
     my ($self) = @_;
     return 0 unless $self->dateexpiry;
-    return 0 if $self->dateexpiry eq '0000-00-00';
+    return 0 if $self->dateexpiry =~ '^9999';
     return 1 if dt_from_string( $self->dateexpiry ) < dt_from_string->truncate( to => 'day' );
     return 0;
 }
@@ -317,7 +317,7 @@ sub is_going_to_expire {
 
     return 0 unless $delay;
     return 0 unless $self->dateexpiry;
-    return 0 if $self->dateexpiry eq '0000-00-00';
+    return 0 if $self->dateexpiry =~ '^9999';
     return 1 if dt_from_string( $self->dateexpiry )->subtract( days => $delay ) < dt_from_string->truncate( to => 'day' );
     return 0;
 }
index d81b273..e8ea535 100644 (file)
@@ -65,13 +65,13 @@ sub can_book_be_issued {
     $patron = $builder->build_object(
         {   class  => 'Koha::Patrons',
             value  => {
-                dateexpiry => '0000-00-00',
+                dateexpiry => undef,
                 categorycode => $patron_category->{categorycode},
             }
         }
     );
     ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
-    is( $issuingimpossible->{EXPIRED}, 1, 'The patron should be considered as expired if dateexpiry is 0000-00-00' );
+    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is not set' );
 
     my $tomorrow = dt_from_string->add_duration( DateTime::Duration->new( days => 1 ) );
     $item = $builder->build( { source => 'Item' } );
index 46012d8..b5a36a3 100644 (file)
@@ -186,13 +186,11 @@ subtest 'update_password' => sub {
 };
 
 subtest 'is_expired' => sub {
-    plan tests => 5;
+    plan tests => 4;
     my $patron = $builder->build({ source => 'Borrower' });
     $patron = Koha::Patrons->find( $patron->{borrowernumber} );
     $patron->dateexpiry( undef )->store->discard_changes;
     is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is not set');
-    $patron->dateexpiry( '0000-00-00' );
-    is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is 0000-00-00');
     $patron->dateexpiry( dt_from_string )->store->discard_changes;
     is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is today');
     $patron->dateexpiry( dt_from_string->add( days => 1 ) )->store->discard_changes;
@@ -204,13 +202,11 @@ subtest 'is_expired' => sub {
 };
 
 subtest 'is_going_to_expire' => sub {
-    plan tests => 9;
+    plan tests => 8;
     my $patron = $builder->build({ source => 'Borrower' });
     $patron = Koha::Patrons->find( $patron->{borrowernumber} );
     $patron->dateexpiry( undef )->store->discard_changes;
     is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is not set');
-    $patron->dateexpiry( '0000-00-00' );
-    is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 0000-00-00');
 
     t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
     $patron->dateexpiry( dt_from_string )->store->discard_changes;