| 
      
            Lines 18-36
          
      
      
        Link Here
      
     | 
  
        
          | 18 | 
          use Modern::Perl;  | 
          18 | 
          use Modern::Perl;  | 
        
        
          | 19 | 
           | 
          19 | 
           | 
        
        
          | 20 | 
          use DateTime;  | 
          20 | 
          use DateTime;  | 
        
          
            
              | 21 | 
              use Time::HiRes qw/gettimeofday/;  | 
              21 | 
              use Time::HiRes qw/gettimeofday time/;  | 
            
            
               | 
               | 
              22 | 
              use Test::More tests => 2;  | 
            
        
          | 22 | 
          use C4::Members;  | 
          23 | 
          use C4::Members;  | 
        
        
          | 23 | 
          use Koha::DateUtils;  | 
          24 | 
          use Koha::DateUtils;  | 
        
        
          | 24 | 
          use t::lib::TestBuilder;  | 
          25 | 
          use t::lib::TestBuilder;  | 
        
          
            
              | 25 | 
              use Test::More tests => 1;  | 
              26 | 
              use t::lib::Mocks qw( mock_preference );  | 
            
        
          | 26 | 
           | 
          27 | 
           | 
        
            
               | 
               | 
              28 | 
              my $builder = t::lib::TestBuilder->new();  | 
            
        
          | 27 | 
          subtest 'Tests for CanBookBeIssued related to dateexpiry' => sub { | 
          29 | 
          subtest 'Tests for CanBookBeIssued related to dateexpiry' => sub { | 
        
        
          | 28 | 
              plan tests => 4;  | 
          30 | 
              plan tests => 4;  | 
        
          
            
              | 29 | 
                  date_expiry();  | 
              31 | 
                  can_book_be_issued();  | 
            
            
               | 
               | 
              32 | 
              };  | 
            
            
              | 33 | 
              subtest 'Tests for CalcDateDue related to dateexpiry' => sub { | 
            
            
              | 34 | 
                  #plan tests => 4;  | 
            
            
              | 35 | 
                  calc_date_due();  | 
            
        
          | 30 | 
          };  | 
          36 | 
          };  | 
        
        
          | 31 | 
           | 
          37 | 
           | 
        
          
            
              | 32 | 
              sub date_expiry { | 
              38 | 
              sub can_book_be_issued { | 
            
            
              | 33 | 
                  my $builder = t::lib::TestBuilder->new();  | 
               | 
               | 
            
        
          | 34 | 
              my $item    = $builder->build( { source => 'Item' } ); | 
          39 | 
              my $item    = $builder->build( { source => 'Item' } ); | 
        
        
          | 35 | 
              my $patron  = $builder->build(  | 
          40 | 
              my $patron  = $builder->build(  | 
        
        
          | 36 | 
                  {   source => 'Borrower', | 
          41 | 
                  {   source => 'Borrower', | 
        
  
    | 
      
            Lines 66-68
          sub date_expiry {
      
      
        Link Here
      
     | 
  
        
          | 66 | 
              is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is tomorrow' ); | 
          71 | 
              is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is tomorrow' ); | 
        
        
          | 67 | 
           | 
          72 | 
           | 
        
        
          | 68 | 
          }  | 
          73 | 
          }  | 
        
          
            
              | 69 | 
              -   | 
              74 | 
               | 
            
            
               | 
               | 
              75 | 
              sub calc_date_due { | 
            
            
              | 76 | 
                  t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1); | 
            
            
              | 77 | 
                      # this triggers the compare between expiry and due date  | 
            
            
              | 78 | 
               | 
            
            
              | 79 | 
                  my $patron  = $builder->build( {   source => 'Borrower' } ); | 
            
            
              | 80 | 
                  my $item = $builder->build( { source => 'Item' } ); | 
            
            
              | 81 | 
                  my $branch = $builder->build( { source => 'Branch' } ); | 
            
            
              | 82 | 
                  my $today = dt_from_string();  | 
            
            
              | 83 | 
               | 
            
            
              | 84 | 
                  # first test with empty expiry date  | 
            
            
              | 85 | 
                  # note that this expiry date will never lead to an issue btw !!  | 
            
            
              | 86 | 
                  $patron->{dateexpiry}='0000-00-00'; | 
            
            
              | 87 | 
                  my $d= C4::Circulation::CalcDateDue( $today, $item->{itype}, | 
            
            
              | 88 | 
                      $branch->{branchcode}, $patron ); | 
            
            
              | 89 | 
                  is( ref $d eq "DateTime" && $d->mdy()=~/^\d+/, 1, "CalcDateDue with expiry 0000-00-00" );  | 
            
            
              | 90 | 
               | 
            
            
              | 91 | 
                  # second test expiry date==today  | 
            
            
              | 92 | 
                  my $d2 = output_pref( { dt => $today, dateonly =>1, dateformat => 'sql' } ); | 
            
            
              | 93 | 
                  $patron->{dateexpiry} = $d2; | 
            
            
              | 94 | 
                  $d= C4::Circulation::CalcDateDue( $today, $item->{itype}, | 
            
            
              | 95 | 
                      $branch->{branchcode}, $patron ); | 
            
            
              | 96 | 
                  is( ref $d eq "DateTime" && DateTime->compare( $d->truncate(to=>'day'), $today->truncate(to=>'day') )==0, 1, "CalcDateDue with expiry today" );  | 
            
            
              | 97 | 
               | 
            
            
              | 98 | 
                  # third test expiry date tomorrow  | 
            
            
              | 99 | 
                  my $dur =  DateTime::Duration->new( days => 1 );  | 
            
            
              | 100 | 
                  my $tomorrow= $today->clone->add_duration( $dur );  | 
            
            
              | 101 | 
                  $d2 = output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' }); | 
            
            
              | 102 | 
                  $patron->{dateexpiry} = $d2; | 
            
            
              | 103 | 
                  $d= C4::Circulation::CalcDateDue( $today, $item->{itype}, | 
            
            
              | 104 | 
                      $branch->{branchcode}, $patron ); | 
            
            
              | 105 | 
                  is( ref $d eq "DateTime" && $d->mdy()=~/^\d+/, 1, "CalcDateDue with expiry tomorrow" );  | 
            
            
              | 106 | 
               | 
            
            
              | 107 | 
                  # fourth test far future  | 
            
            
              | 108 | 
                  $patron->{dateexpiry} = '9876-12-31'; | 
            
            
              | 109 | 
                  my $t1=time;  | 
            
            
              | 110 | 
                  $d= C4::Circulation::CalcDateDue( $today, $item->{itype}, | 
            
            
              | 111 | 
                      $branch->{branchcode}, $patron ); | 
            
            
              | 112 | 
                  my $t2=time;  | 
            
            
              | 113 | 
                  is( ref $d eq "DateTime" && $t2-$t1 < 1, 1, "CalcDateDue with expiry in year 9876 in ".sprintf("%6.4f", $t2-$t1)." seconds."); | 
            
            
              | 114 | 
              }  |