| Lines 17-23
          
      
      
        Link Here | 
        
          | 17 |  | 17 |  | 
        
          | 18 | use Modern::Perl; | 18 | use Modern::Perl; | 
        
          | 19 |  | 19 |  | 
          
            
              | 20 | use Test::More tests => 95; | 20 | use Test::More tests => 96; | 
        
          | 21 |  | 21 |  | 
        
          | 22 | use DateTime; | 22 | use DateTime; | 
        
          | 23 |  | 23 |  | 
  
    | Lines 1632-1637
          subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
      
      
        Link Here | 
        
          | 1632 |     is( $debarments->[0]->{expiration}, $expected_expiration ); | 1632 |     is( $debarments->[0]->{expiration}, $expected_expiration ); | 
        
          | 1633 | }; | 1633 | }; | 
        
          | 1634 |  | 1634 |  | 
            
              |  |  | 1635 | subtest 'AddReturn | is_overdue' => sub { | 
            
              | 1636 |     plan tests => 5; | 
            
              | 1637 |  | 
            
              | 1638 |     t::lib::Mocks::mock_preference('CalculateFinesOnReturn', 1); | 
            
              | 1639 |     t::lib::Mocks::mock_preference('finesMode', 'production'); | 
            
              | 1640 |     t::lib::Mocks::mock_preference('MaxFine', '100'); | 
            
              | 1641 |  | 
            
              | 1642 |     my $library = $builder->build( { source => 'Branch' } ); | 
            
              | 1643 |     my $patron  = $builder->build( { source => 'Borrower' } ); | 
            
              | 1644 |  | 
            
              | 1645 |     my $biblioitem = $builder->build( { source => 'Biblioitem' } ); | 
            
              | 1646 |     my $item = $builder->build( | 
            
              | 1647 |         { | 
            
              | 1648 |             source => 'Item', | 
            
              | 1649 |             value  => { | 
            
              | 1650 |                 homebranch    => $library->{branchcode}, | 
            
              | 1651 |                 holdingbranch => $library->{branchcode}, | 
            
              | 1652 |                 notforloan    => 0, | 
            
              | 1653 |                 itemlost      => 0, | 
            
              | 1654 |                 withdrawn     => 0, | 
            
              | 1655 |                 biblionumber  => $biblioitem->{biblionumber}, | 
            
              | 1656 |             } | 
            
              | 1657 |         } | 
            
              | 1658 |     ); | 
            
              | 1659 |  | 
            
              | 1660 |     Koha::IssuingRules->search->delete; | 
            
              | 1661 |     my $rule = Koha::IssuingRule->new( | 
            
              | 1662 |         { | 
            
              | 1663 |             categorycode => '*', | 
            
              | 1664 |             itemtype     => '*', | 
            
              | 1665 |             branchcode   => '*', | 
            
              | 1666 |             maxissueqty  => 99, | 
            
              | 1667 |             issuelength  => 6, | 
            
              | 1668 |             lengthunit   => 'days', | 
            
              | 1669 |             fine         => 1, # Charge 1 every day of overdue | 
            
              | 1670 |             chargeperiod => 1, | 
            
              | 1671 |         } | 
            
              | 1672 |     ); | 
            
              | 1673 |     $rule->store(); | 
            
              | 1674 |  | 
            
              | 1675 |     my $one_day_ago   = dt_from_string->subtract( days => 1 ); | 
            
              | 1676 |     my $five_days_ago = dt_from_string->subtract( days => 5 ); | 
            
              | 1677 |     my $ten_days_ago  = dt_from_string->subtract( days => 10 ); | 
            
              | 1678 |     $patron = Koha::Patrons->find( $patron->{borrowernumber} ); | 
            
              | 1679 |  | 
            
              | 1680 |     # No date specify, today will be used | 
            
              | 1681 |     AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago | 
            
              | 1682 |     AddReturn( $item->{barcode}, $library->{branchcode} ); | 
            
              | 1683 |     is( int($patron->account->balance()), 10, 'Patron should have a charge of 10 (10 days x 1)' ); | 
            
              | 1684 |     Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; | 
            
              | 1685 |  | 
            
              | 1686 |     # specify return date 5 days before => no overdue | 
            
              | 1687 |     AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago | 
            
              | 1688 |     AddReturn( $item->{barcode}, $library->{branchcode}, undef, undef, $ten_days_ago ); | 
            
              | 1689 |     is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' ); | 
            
              | 1690 |     Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; | 
            
              | 1691 |  | 
            
              | 1692 |     # specify return date 5 days later => overdue | 
            
              | 1693 |     AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago | 
            
              | 1694 |     AddReturn( $item->{barcode}, $library->{branchcode}, undef, undef, $five_days_ago ); | 
            
              | 1695 |     is( int($patron->account->balance()), 5, 'AddReturn: pass return_date => overdue' ); | 
            
              | 1696 |     Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; | 
            
              | 1697 |  | 
            
              | 1698 |     # specify dropbox date 5 days before => no overdue | 
            
              | 1699 |     AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago | 
            
              | 1700 |     AddReturn( $item->{barcode}, $library->{branchcode}, undef, 1, undef, $ten_days_ago ); | 
            
              | 1701 |     is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' ); | 
            
              | 1702 |     Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; | 
            
              | 1703 |  | 
            
              | 1704 |     # specify dropbox date 5 days later => overdue, or... not | 
            
              | 1705 |     AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago | 
            
              | 1706 |     AddReturn( $item->{barcode}, $library->{branchcode}, undef, 1, undef, $five_days_ago ); | 
            
              | 1707 |     is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue in dropbox mode' ); # FIXME? This is weird, the FU fine is created ( _CalculateAndUpdateFine > C4::Overdues::UpdateFine ) then remove later (in _FixOverduesOnReturn). Looks like it is a feature | 
            
              | 1708 |     Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; | 
            
              | 1709 |  | 
            
              | 1710 | }; | 
            
              | 1711 |  | 
        
          | 1635 | sub set_userenv { | 1712 | sub set_userenv { | 
        
          | 1636 |     my ( $library ) = @_; | 1713 |     my ( $library ) = @_; | 
        
          | 1637 |     C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); | 1714 |     C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); | 
            
              | 1638 | -  |  |  |