|
Lines 19-24
use Modern::Perl;
Link Here
|
| 19 |
use utf8; |
19 |
use utf8; |
| 20 |
|
20 |
|
| 21 |
use Test::More tests => 123; |
21 |
use Test::More tests => 123; |
|
|
22 |
use Test::MockModule; |
| 22 |
|
23 |
|
| 23 |
use Data::Dumper; |
24 |
use Data::Dumper; |
| 24 |
use DateTime; |
25 |
use DateTime; |
|
Lines 2823-2828
$schema->storage->txn_rollback;
Link Here
|
| 2823 |
C4::Context->clear_syspref_cache(); |
2824 |
C4::Context->clear_syspref_cache(); |
| 2824 |
$cache->clear_from_cache('single_holidays'); |
2825 |
$cache->clear_from_cache('single_holidays'); |
| 2825 |
|
2826 |
|
|
|
2827 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
| 2828 |
|
| 2829 |
plan tests => 12; |
| 2830 |
|
| 2831 |
$schema->storage->txn_begin; |
| 2832 |
|
| 2833 |
my $issuing_charges = 15; |
| 2834 |
my $title = 'A title'; |
| 2835 |
my $author = 'Author, An'; |
| 2836 |
my $barcode = 'WHATARETHEODDS'; |
| 2837 |
|
| 2838 |
my $circ = Test::MockModule->new('C4::Circulation'); |
| 2839 |
$circ->mock( |
| 2840 |
'GetIssuingCharges', |
| 2841 |
sub { |
| 2842 |
return $issuing_charges; |
| 2843 |
} |
| 2844 |
); |
| 2845 |
|
| 2846 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
| 2847 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
| 2848 |
my $patron = $builder->build_object({ |
| 2849 |
class => 'Koha::Patrons', |
| 2850 |
value => { branchcode => $library->id } |
| 2851 |
}); |
| 2852 |
|
| 2853 |
my ( $biblionumber, $biblioitemnumber ) = add_biblio( $title, $author ); |
| 2854 |
my ( undef, undef, $item_id ) = AddItem( |
| 2855 |
{ |
| 2856 |
homebranch => $library->id, |
| 2857 |
holdingbranch => $library->id, |
| 2858 |
barcode => $barcode, |
| 2859 |
replacementprice => 23.00, |
| 2860 |
itype => $itemtype->id |
| 2861 |
}, |
| 2862 |
$biblionumber |
| 2863 |
); |
| 2864 |
my $item = Koha::Items->find( $item_id ); |
| 2865 |
|
| 2866 |
my $items = Test::MockModule->new('C4::Items'); |
| 2867 |
$items->mock( GetItem => $item->unblessed ); |
| 2868 |
my $context = Test::MockModule->new('C4::Context'); |
| 2869 |
$context->mock( userenv => { branch => $library->id } ); |
| 2870 |
|
| 2871 |
# Check the item out |
| 2872 |
AddIssue( $patron->unblessed, $item->barcode ); |
| 2873 |
|
| 2874 |
t::lib::Mocks::mock_preference( 'RenewalLog', 0 ); |
| 2875 |
my $date = output_pref( { dt => dt_from_string(), datenonly => 1, dateformat => 'iso' } ); |
| 2876 |
my $old_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); |
| 2877 |
AddRenewal( $patron->id, $item->id, $library->id ); |
| 2878 |
my $new_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); |
| 2879 |
is( $new_log_size, $old_log_size, 'renew log not added because of the syspref RenewalLog' ); |
| 2880 |
|
| 2881 |
t::lib::Mocks::mock_preference( 'RenewalLog', 1 ); |
| 2882 |
$date = output_pref( { dt => dt_from_string(), datenonly => 1, dateformat => 'iso' } ); |
| 2883 |
$old_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); |
| 2884 |
AddRenewal( $patron->id, $item->id, $library->id ); |
| 2885 |
$new_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); |
| 2886 |
is( $new_log_size, $old_log_size + 1, 'renew log successfully added' ); |
| 2887 |
|
| 2888 |
my $lines = Koha::Account::Lines->search({ |
| 2889 |
borrowernumber => $patron->id, |
| 2890 |
itemnumber => $item->id |
| 2891 |
}); |
| 2892 |
|
| 2893 |
is( $lines->count, 3 ); |
| 2894 |
|
| 2895 |
my $line = $lines->next; |
| 2896 |
is( $line->accounttype, 'Rent', 'The issuing charge generates an accountline' ); |
| 2897 |
is( $line->branchcode, $library->id, 'AddIssuingCharge correctly sets branchcode' ); |
| 2898 |
is( $line->description, 'Rental', 'AddIssuingCharge set a hardcoded description for the accountline' ); |
| 2899 |
|
| 2900 |
$line = $lines->next; |
| 2901 |
is( $line->accounttype, 'Rent', 'Fine on renewed item is closed out properly' ); |
| 2902 |
is( $line->branchcode, $library->id, 'AddRenewal correctly sets branchcode' ); |
| 2903 |
is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' ); |
| 2904 |
|
| 2905 |
$line = $lines->next; |
| 2906 |
is( $line->accounttype, 'Rent', 'Fine on renewed item is closed out properly' ); |
| 2907 |
is( $line->branchcode, $library->id, 'AddRenewal correctly sets branchcode' ); |
| 2908 |
is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' ); |
| 2909 |
|
| 2910 |
$schema->storage->txn_rollback; |
| 2911 |
}; |
| 2912 |
|
| 2913 |
|
| 2826 |
sub set_userenv { |
2914 |
sub set_userenv { |
| 2827 |
my ( $library ) = @_; |
2915 |
my ( $library ) = @_; |
| 2828 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
2916 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |