Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 119; |
20 |
use Test::More tests => 120; |
|
|
21 |
use Test::MockModule; |
21 |
|
22 |
|
22 |
use Data::Dumper; |
23 |
use Data::Dumper; |
23 |
use DateTime; |
24 |
use DateTime; |
Lines 2620-2625
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
Link Here
|
2620 |
$schema->storage->txn_rollback; |
2621 |
$schema->storage->txn_rollback; |
2621 |
$cache->clear_from_cache('single_holidays'); |
2622 |
$cache->clear_from_cache('single_holidays'); |
2622 |
|
2623 |
|
|
|
2624 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
2625 |
|
2626 |
plan tests => 12; |
2627 |
|
2628 |
$schema->storage->txn_begin; |
2629 |
|
2630 |
my $issuing_charges = 15; |
2631 |
my $title = 'A title'; |
2632 |
my $author = 'Author, An'; |
2633 |
my $barcode = 'WHATARETHEODDS'; |
2634 |
|
2635 |
my $circ = Test::MockModule->new('C4::Circulation'); |
2636 |
$circ->mock( |
2637 |
'GetIssuingCharges', |
2638 |
sub { |
2639 |
return $issuing_charges; |
2640 |
} |
2641 |
); |
2642 |
|
2643 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
2644 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
2645 |
my $patron = $builder->build_object({ |
2646 |
class => 'Koha::Patrons', |
2647 |
value => { branchcode => $library->id } |
2648 |
}); |
2649 |
|
2650 |
my ( $biblionumber, $biblioitemnumber ) = add_biblio( $title, $author ); |
2651 |
my ( undef, undef, $item_id ) = AddItem( |
2652 |
{ |
2653 |
homebranch => $library->id, |
2654 |
holdingbranch => $library->id, |
2655 |
barcode => $barcode, |
2656 |
replacementprice => 23.00, |
2657 |
itype => $itemtype->id |
2658 |
}, |
2659 |
$biblionumber |
2660 |
); |
2661 |
my $item = Koha::Items->find( $item_id ); |
2662 |
|
2663 |
my $items = Test::MockModule->new('C4::Items'); |
2664 |
$items->mock( GetItem => $item->unblessed ); |
2665 |
my $context = Test::MockModule->new('C4::Context'); |
2666 |
$context->mock( userenv => { branch => $library->id } ); |
2667 |
|
2668 |
# Check the item out |
2669 |
AddIssue( $patron->unblessed, $item->barcode ); |
2670 |
|
2671 |
t::lib::Mocks::mock_preference( 'RenewalLog', 0 ); |
2672 |
my $date = output_pref( { dt => dt_from_string(), datenonly => 1, dateformat => 'iso' } ); |
2673 |
my $old_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); |
2674 |
AddRenewal( $patron->id, $item->id, $library->id ); |
2675 |
my $new_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); |
2676 |
is( $new_log_size, $old_log_size, 'renew log not added because of the syspref RenewalLog' ); |
2677 |
|
2678 |
t::lib::Mocks::mock_preference( 'RenewalLog', 1 ); |
2679 |
$date = output_pref( { dt => dt_from_string(), datenonly => 1, dateformat => 'iso' } ); |
2680 |
$old_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); |
2681 |
AddRenewal( $patron->id, $item->id, $library->id ); |
2682 |
$new_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); |
2683 |
is( $new_log_size, $old_log_size + 1, 'renew log successfully added' ); |
2684 |
|
2685 |
my $lines = Koha::Account::Lines->search({ |
2686 |
borrowernumber => $patron->id, |
2687 |
itemnumber => $item->id |
2688 |
}); |
2689 |
|
2690 |
is( $lines->count, 3 ); |
2691 |
|
2692 |
my $line = $lines->next; |
2693 |
is( $line->accounttype, 'Rent', 'The issuing charge generates an accountline' ); |
2694 |
is( $line->branchcode, $library->id, 'AddIssuingCharge correctly sets branchcode' ); |
2695 |
is( $line->description, 'Rental', 'AddIssuingCharge set a hardcoded description for the accountline' ); |
2696 |
|
2697 |
$line = $lines->next; |
2698 |
is( $line->accounttype, 'Rent', 'Fine on renewed item is closed out properly' ); |
2699 |
is( $line->branchcode, $library->id, 'AddRenewal correctly sets branchcode' ); |
2700 |
is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' ); |
2701 |
|
2702 |
$line = $lines->next; |
2703 |
is( $line->accounttype, 'Rent', 'Fine on renewed item is closed out properly' ); |
2704 |
is( $line->branchcode, $library->id, 'AddRenewal correctly sets branchcode' ); |
2705 |
is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' ); |
2706 |
|
2707 |
$schema->storage->txn_rollback; |
2708 |
}; |
2709 |
|
2710 |
|
2623 |
sub set_userenv { |
2711 |
sub set_userenv { |
2624 |
my ( $library ) = @_; |
2712 |
my ( $library ) = @_; |
2625 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
2713 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |