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