| Lines 17-23
          
      
      
        Link Here | 
        
          | 17 |  | 17 |  | 
        
          | 18 | use Modern::Perl; | 18 | use Modern::Perl; | 
        
          | 19 |  | 19 |  | 
          
            
              | 20 | use Test::More tests => 112; | 20 | use Test::More tests => 113; | 
        
          | 21 |  | 21 |  | 
        
          | 22 | use DateTime; | 22 | use DateTime; | 
        
          | 23 |  | 23 |  | 
  
    | Lines 63-69
          my $itemtype = $builder->build(
      
      
        Link Here | 
        
          | 63 |         value  => { notforloan => undef, rentalcharge => 0, defaultreplacecost => undef, processfee => undef } | 63 |         value  => { notforloan => undef, rentalcharge => 0, defaultreplacecost => undef, processfee => undef } | 
        
          | 64 |     } | 64 |     } | 
        
          | 65 | )->{itemtype}; | 65 | )->{itemtype}; | 
          
            
              | 66 | my $patron_category = $builder->build({ source => 'Category', value => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } }); | 66 | my $patron_category = $builder->build( | 
            
              |  |  | 67 |     { | 
            
              | 68 |         source => 'Category', | 
            
              | 69 |         value  => { | 
            
              | 70 |             categorycode                  => 'NOT_X', | 
            
              | 71 |             category_type                 => 'P', | 
            
              | 72 |             enrolmentfee                  => 0, | 
            
              | 73 |             BlockExpiredPatronOpacActions => -1, # Pick the pref value | 
            
              | 74 |         } | 
            
              | 75 |     } | 
            
              | 76 | ); | 
        
          | 67 |  | 77 |  | 
        
          | 68 | my $CircControl = C4::Context->preference('CircControl'); | 78 | my $CircControl = C4::Context->preference('CircControl'); | 
        
          | 69 | my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch'); | 79 | my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch'); | 
  
    | Lines 290-302
          C4::Context->dbh->do("DELETE FROM accountlines");
      
      
        Link Here | 
        
          | 290 |         branchcode => $branch, | 300 |         branchcode => $branch, | 
        
          | 291 |     ); | 301 |     ); | 
        
          | 292 |  | 302 |  | 
            
              |  |  | 303 |     my %expired_borrower_data = ( | 
            
              | 304 |         firstname =>  'Ça', | 
            
              | 305 |         surname => 'Glisse', | 
            
              | 306 |         categorycode => $patron_category->{categorycode}, | 
            
              | 307 |         branchcode => $branch, | 
            
              | 308 |         dateexpiry => dt_from_string->subtract( months => 1 ), | 
            
              | 309 |     ); | 
            
              | 310 |  | 
        
          | 293 |     my $renewing_borrowernumber = AddMember(%renewing_borrower_data); | 311 |     my $renewing_borrowernumber = AddMember(%renewing_borrower_data); | 
        
          | 294 |     my $reserving_borrowernumber = AddMember(%reserving_borrower_data); | 312 |     my $reserving_borrowernumber = AddMember(%reserving_borrower_data); | 
        
          | 295 |     my $hold_waiting_borrowernumber = AddMember(%hold_waiting_borrower_data); | 313 |     my $hold_waiting_borrowernumber = AddMember(%hold_waiting_borrower_data); | 
        
          | 296 |     my $restricted_borrowernumber = AddMember(%restricted_borrower_data); | 314 |     my $restricted_borrowernumber = AddMember(%restricted_borrower_data); | 
            
              |  |  | 315 |     my $expired_borrowernumber = AddMember(%expired_borrower_data); | 
        
          | 297 |  | 316 |  | 
        
          | 298 |     my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed; | 317 |     my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed; | 
        
          | 299 |     my $restricted_borrower = Koha::Patrons->find( $restricted_borrowernumber )->unblessed; | 318 |     my $restricted_borrower = Koha::Patrons->find( $restricted_borrowernumber )->unblessed; | 
            
              |  |  | 319 |     my $expired_borrower = Koha::Patrons->find( $expired_borrowernumber )->unblessed; | 
        
          | 300 |  | 320 |  | 
        
          | 301 |     my $bibitems       = ''; | 321 |     my $bibitems       = ''; | 
        
          | 302 |     my $priority       = '1'; | 322 |     my $priority       = '1'; | 
  
    | Lines 695-700
          C4::Context->dbh->do("DELETE FROM accountlines");
      
      
        Link Here | 
        
          | 695 |         $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber); | 715 |         $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber); | 
        
          | 696 |     }; | 716 |     }; | 
        
          | 697 |  | 717 |  | 
            
              |  |  | 718 |     subtest "auto_account_expired | BlockExpiredPatronOpacActions" => sub { | 
            
              | 719 |         plan tests => 6; | 
            
              | 720 |         my $item_to_auto_renew = $builder->build({ | 
            
              | 721 |             source => 'Item', | 
            
              | 722 |             value => { | 
            
              | 723 |                 biblionumber => $biblionumber, | 
            
              | 724 |                 homebranch       => $branch, | 
            
              | 725 |                 holdingbranch    => $branch, | 
            
              | 726 |             } | 
            
              | 727 |         }); | 
            
              | 728 |  | 
            
              | 729 |         $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11'); | 
            
              | 730 |  | 
            
              | 731 |         my $ten_days_before = dt_from_string->add( days => -10 ); | 
            
              | 732 |         my $ten_days_ahead = dt_from_string->add( days => 10 ); | 
            
              | 733 |  | 
            
              | 734 |         # Patron is expired and BlockExpiredPatronOpacActions=0 | 
            
              | 735 |         # => auto renew is allowed | 
            
              | 736 |         t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0); | 
            
              | 737 |         my $patron = $expired_borrower; | 
            
              | 738 |         my $checkout = AddIssue( $patron, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); | 
            
              | 739 |         ( $renewokay, $error ) = | 
            
              | 740 |           CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} ); | 
            
              | 741 |         is( $renewokay, 0, 'Do not renew, renewal is automatic' ); | 
            
              | 742 |         is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' ); | 
            
              | 743 |         Koha::Checkouts->find( $checkout->issue_id )->delete; | 
            
              | 744 |  | 
            
              | 745 |  | 
            
              | 746 |         # Patron is expired and BlockExpiredPatronOpacActions=1 | 
            
              | 747 |         # => auto renew is not allowed | 
            
              | 748 |         t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1); | 
            
              | 749 |         $patron = $expired_borrower; | 
            
              | 750 |         $checkout = AddIssue( $patron, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); | 
            
              | 751 |         ( $renewokay, $error ) = | 
            
              | 752 |           CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} ); | 
            
              | 753 |         is( $renewokay, 0, 'Do not renew, renewal is automatic' ); | 
            
              | 754 |         is( $error, 'auto_account_expired', 'Can not auto renew, lockExpiredPatronOpacActions=1 and patron is expired' ); | 
            
              | 755 |         Koha::Checkouts->find( $checkout->issue_id )->delete; | 
            
              | 756 |  | 
            
              | 757 |  | 
            
              | 758 |         # Patron is not expired and BlockExpiredPatronOpacActions=1 | 
            
              | 759 |         # => auto renew is allowed | 
            
              | 760 |         t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1); | 
            
              | 761 |         $patron = $renewing_borrower; | 
            
              | 762 |         $checkout = AddIssue( $patron, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); | 
            
              | 763 |         ( $renewokay, $error ) = | 
            
              | 764 |           CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} ); | 
            
              | 765 |         is( $renewokay, 0, 'Do not renew, renewal is automatic' ); | 
            
              | 766 |         is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' ); | 
            
              | 767 |         Koha::Checkouts->find( $checkout->issue_id )->delete; | 
            
              | 768 |     }; | 
            
              | 769 |  | 
        
          | 698 |     subtest "GetLatestAutoRenewDate" => sub { | 770 |     subtest "GetLatestAutoRenewDate" => sub { | 
        
          | 699 |         plan tests => 5; | 771 |         plan tests => 5; | 
        
          | 700 |         my $item_to_auto_renew = $builder->build( | 772 |         my $item_to_auto_renew = $builder->build( | 
            
              | 701 | -  |  |  |