Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 122; |
20 |
use Test::More tests => 123; |
|
|
21 |
use Test::MockModule; |
21 |
|
22 |
|
22 |
use Data::Dumper; |
23 |
use Data::Dumper; |
23 |
use DateTime; |
24 |
use DateTime; |
Lines 2757-2762
$schema->storage->txn_rollback;
Link Here
|
2757 |
C4::Context->clear_syspref_cache(); |
2758 |
C4::Context->clear_syspref_cache(); |
2758 |
$cache->clear_from_cache('single_holidays'); |
2759 |
$cache->clear_from_cache('single_holidays'); |
2759 |
|
2760 |
|
|
|
2761 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
2762 |
|
2763 |
plan tests => 12; |
2764 |
|
2765 |
$schema->storage->txn_begin; |
2766 |
|
2767 |
my $issuing_charges = 15; |
2768 |
my $title = 'A title'; |
2769 |
my $author = 'Author, An'; |
2770 |
my $barcode = 'WHATARETHEODDS'; |
2771 |
|
2772 |
my $circ = Test::MockModule->new('C4::Circulation'); |
2773 |
$circ->mock( |
2774 |
'GetIssuingCharges', |
2775 |
sub { |
2776 |
return $issuing_charges; |
2777 |
} |
2778 |
); |
2779 |
|
2780 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
2781 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
2782 |
my $patron = $builder->build_object({ |
2783 |
class => 'Koha::Patrons', |
2784 |
value => { branchcode => $library->id } |
2785 |
}); |
2786 |
|
2787 |
my ( $biblionumber, $biblioitemnumber ) = add_biblio( $title, $author ); |
2788 |
my ( undef, undef, $item_id ) = AddItem( |
2789 |
{ |
2790 |
homebranch => $library->id, |
2791 |
holdingbranch => $library->id, |
2792 |
barcode => $barcode, |
2793 |
replacementprice => 23.00, |
2794 |
itype => $itemtype->id |
2795 |
}, |
2796 |
$biblionumber |
2797 |
); |
2798 |
my $item = Koha::Items->find( $item_id ); |
2799 |
|
2800 |
my $items = Test::MockModule->new('C4::Items'); |
2801 |
$items->mock( GetItem => $item->unblessed ); |
2802 |
my $context = Test::MockModule->new('C4::Context'); |
2803 |
$context->mock( userenv => { branch => $library->id } ); |
2804 |
|
2805 |
# Check the item out |
2806 |
AddIssue( $patron->unblessed, $item->barcode ); |
2807 |
|
2808 |
t::lib::Mocks::mock_preference( 'RenewalLog', 0 ); |
2809 |
my $date = output_pref( { dt => dt_from_string(), datenonly => 1, dateformat => 'iso' } ); |
2810 |
my $old_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); |
2811 |
AddRenewal( $patron->id, $item->id, $library->id ); |
2812 |
my $new_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); |
2813 |
is( $new_log_size, $old_log_size, 'renew log not added because of the syspref RenewalLog' ); |
2814 |
|
2815 |
t::lib::Mocks::mock_preference( 'RenewalLog', 1 ); |
2816 |
$date = output_pref( { dt => dt_from_string(), datenonly => 1, dateformat => 'iso' } ); |
2817 |
$old_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); |
2818 |
AddRenewal( $patron->id, $item->id, $library->id ); |
2819 |
$new_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); |
2820 |
is( $new_log_size, $old_log_size + 1, 'renew log successfully added' ); |
2821 |
|
2822 |
my $lines = Koha::Account::Lines->search({ |
2823 |
borrowernumber => $patron->id, |
2824 |
itemnumber => $item->id |
2825 |
}); |
2826 |
|
2827 |
is( $lines->count, 3 ); |
2828 |
|
2829 |
my $line = $lines->next; |
2830 |
is( $line->accounttype, 'Rent', 'The issuing charge generates an accountline' ); |
2831 |
is( $line->branchcode, $library->id, 'AddIssuingCharge correctly sets branchcode' ); |
2832 |
is( $line->description, 'Rental', 'AddIssuingCharge set a hardcoded description for the accountline' ); |
2833 |
|
2834 |
$line = $lines->next; |
2835 |
is( $line->accounttype, 'Rent', 'Fine on renewed item is closed out properly' ); |
2836 |
is( $line->branchcode, $library->id, 'AddRenewal correctly sets branchcode' ); |
2837 |
is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' ); |
2838 |
|
2839 |
$line = $lines->next; |
2840 |
is( $line->accounttype, 'Rent', 'Fine on renewed item is closed out properly' ); |
2841 |
is( $line->branchcode, $library->id, 'AddRenewal correctly sets branchcode' ); |
2842 |
is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' ); |
2843 |
|
2844 |
$schema->storage->txn_rollback; |
2845 |
}; |
2846 |
|
2847 |
|
2760 |
sub set_userenv { |
2848 |
sub set_userenv { |
2761 |
my ( $library ) = @_; |
2849 |
my ( $library ) = @_; |
2762 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
2850 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |