View | Details | Raw Unified | Return to bug 19066
Collapse All | Expand All

(-)a/t/db_dependent/Circulation.t (+88 lines)
Lines 18-23 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 120;
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 2748-2753 $schema->storage->txn_rollback; Link Here
2748
C4::Context->clear_syspref_cache();
2749
C4::Context->clear_syspref_cache();
2749
$cache->clear_from_cache('single_holidays');
2750
$cache->clear_from_cache('single_holidays');
2750
2751
2752
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
2753
2754
    plan tests => 12;
2755
2756
    $schema->storage->txn_begin;
2757
2758
    my $issuing_charges = 15;
2759
    my $title   = 'A title';
2760
    my $author  = 'Author, An';
2761
    my $barcode = 'WHATARETHEODDS';
2762
2763
    my $circ = Test::MockModule->new('C4::Circulation');
2764
    $circ->mock(
2765
        'GetIssuingCharges',
2766
        sub {
2767
            return $issuing_charges;
2768
        }
2769
    );
2770
2771
    my $library  = $builder->build_object({ class => 'Koha::Libraries' });
2772
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
2773
    my $patron   = $builder->build_object({
2774
        class => 'Koha::Patrons',
2775
        value => { branchcode => $library->id }
2776
    });
2777
2778
    my ( $biblionumber, $biblioitemnumber ) = add_biblio( $title, $author );
2779
    my ( undef, undef, $item_id ) = AddItem(
2780
        {
2781
            homebranch       => $library->id,
2782
            holdingbranch    => $library->id,
2783
            barcode          => $barcode,
2784
            replacementprice => 23.00,
2785
            itype            => $itemtype->id
2786
        },
2787
        $biblionumber
2788
    );
2789
    my $item = Koha::Items->find( $item_id );
2790
2791
    my $items = Test::MockModule->new('C4::Items');
2792
    $items->mock( GetItem => $item->unblessed );
2793
    my $context = Test::MockModule->new('C4::Context');
2794
    $context->mock( userenv => { branch => $library->id } );
2795
2796
    # Check the item out
2797
    AddIssue( $patron->unblessed, $item->barcode );
2798
2799
    t::lib::Mocks::mock_preference( 'RenewalLog', 0 );
2800
    my $date = output_pref( { dt => dt_from_string(), datenonly => 1, dateformat => 'iso' } );
2801
    my $old_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } );
2802
    AddRenewal( $patron->id, $item->id, $library->id );
2803
    my $new_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } );
2804
    is( $new_log_size, $old_log_size, 'renew log not added because of the syspref RenewalLog' );
2805
2806
    t::lib::Mocks::mock_preference( 'RenewalLog', 1 );
2807
    $date = output_pref( { dt => dt_from_string(), datenonly => 1, dateformat => 'iso' } );
2808
    $old_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } );
2809
    AddRenewal( $patron->id, $item->id, $library->id );
2810
    $new_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } );
2811
    is( $new_log_size, $old_log_size + 1, 'renew log successfully added' );
2812
2813
    my $lines = Koha::Account::Lines->search({
2814
        borrowernumber => $patron->id,
2815
        itemnumber     => $item->id
2816
    });
2817
2818
    is( $lines->count, 3 );
2819
2820
    my $line = $lines->next;
2821
    is( $line->accounttype, 'Rent',       'The issuing charge generates an accountline' );
2822
    is( $line->branchcode,  $library->id, 'AddIssuingCharge correctly sets branchcode' );
2823
    is( $line->description, 'Rental',     'AddIssuingCharge set a hardcoded description for the accountline' );
2824
2825
    $line = $lines->next;
2826
    is( $line->accounttype, 'Rent', 'Fine on renewed item is closed out properly' );
2827
    is( $line->branchcode,  $library->id, 'AddRenewal correctly sets branchcode' );
2828
    is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' );
2829
2830
    $line = $lines->next;
2831
    is( $line->accounttype, 'Rent', 'Fine on renewed item is closed out properly' );
2832
    is( $line->branchcode,  $library->id, 'AddRenewal correctly sets branchcode' );
2833
    is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' );
2834
2835
    $schema->storage->txn_rollback;
2836
};
2837
2838
2751
sub set_userenv {
2839
sub set_userenv {
2752
    my ( $library ) = @_;
2840
    my ( $library ) = @_;
2753
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', '');
2841
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', '');
(-)a/t/db_dependent/Reserves.t (-2 / +26 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 57;
20
use Test::More tests => 58;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 719-724 subtest 'ReservesNeedReturns' => sub { Link Here
719
    is( $hold->found, undef, 'If ReservesNeedReturns is 1, found must not have been set waiting' );
719
    is( $hold->found, undef, 'If ReservesNeedReturns is 1, found must not have been set waiting' );
720
};
720
};
721
721
722
subtest 'ChargeReserveFee tests' => sub {
723
724
    plan tests => 8;
725
726
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
727
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
728
729
    my $fee   = 20;
730
    my $title = 'A title';
731
732
    my $context = Test::MockModule->new('C4::Context');
733
    $context->mock( userenv => { branch => $library->id } );
734
735
    my $line = C4::Reserves::ChargeReserveFee( $patron->id, $fee, $title );
736
737
    is( ref($line), 'Koha::Account::Line' , 'Returns a Koha::Account::Line object');
738
    ok( $line->is_debit, 'Generates a debit line' );
739
    is( $line->accounttype, 'Res' , 'generates Res accounttype');
740
    is( $line->borrowernumber, $patron->id , 'generated line belongs to the passed patron');
741
    is( $line->amount, $fee , 'amount set correctly');
742
    is( $line->amountoutstanding, $fee , 'amountoutstanding set correctly');
743
    is( $line->description, "Reserve Charge - $title" , 'Hardcoded description is generated');
744
    is( $line->branchcode, $library->id , "Library id is picked from userenv and stored correctly" );
745
};
746
722
sub count_hold_print_messages {
747
sub count_hold_print_messages {
723
    my $message_count = $dbh->selectall_arrayref(q{
748
    my $message_count = $dbh->selectall_arrayref(q{
724
        SELECT COUNT(*)
749
        SELECT COUNT(*)
725
- 

Return to bug 19066