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

(-)a/t/db_dependent/Koha/Hold.t (-2 / +134 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 5;
23
23
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
Lines 27-38 use Test::MockModule; Link Here
27
use t::lib::Mocks;
27
use t::lib::Mocks;
28
use t::lib::TestBuilder;
28
use t::lib::TestBuilder;
29
29
30
use Koha::ActionLogs;
31
use Koha::Holds;
30
use Koha::Libraries;
32
use Koha::Libraries;
31
use Koha::Old::Holds;
33
use Koha::Old::Holds;
32
34
33
my $schema  = Koha::Database->new->schema;
35
my $schema  = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new;
36
my $builder = t::lib::TestBuilder->new;
35
37
38
subtest 'fill() tests' => sub {
39
40
    plan tests => 11;
41
42
    $schema->storage->txn_begin;
43
44
    my $fee = 15;
45
46
    my $category = $builder->build_object(
47
        {
48
            class => 'Koha::Patron::Categories',
49
            value => { reservefee => $fee }
50
        }
51
    );
52
    my $patron = $builder->build_object(
53
        {
54
            class => 'Koha::Patrons',
55
            value => { categorycode => $category->id }
56
        }
57
    );
58
    my $manager = $builder->build_object( { class => 'Koha::Patrons' } );
59
60
    my $title  = 'Do what you want';
61
    my $biblio = $builder->build_sample_biblio( { title => $title } );
62
    my $item   = $builder->build_sample_item( { biblionumber => $biblio->id } );
63
    my $hold   = $builder->build_object(
64
        {
65
            class => 'Koha::Holds',
66
            value => {
67
                biblionumber   => $biblio->id,
68
                borrowernumber => $patron->id,
69
                itemnumber     => $item->id,
70
                priority       => 10,
71
            }
72
        }
73
    );
74
75
    t::lib::Mocks::mock_preference( 'HoldFeeMode', 'any_time_is_collected' );
76
    t::lib::Mocks::mock_preference( 'HoldsLog',    1 );
77
    t::lib::Mocks::mock_userenv(
78
        { patron => $manager, branchcode => $manager->branchcode } );
79
80
    my $interface = 'api';
81
    C4::Context->interface($interface);
82
83
    my $ret = $hold->fill;
84
85
    is( ref($ret), 'Koha::Hold', '->fill returns the object type' );
86
    is( $ret->id, $hold->id, '->fill returns the object' );
87
88
    is( Koha::Holds->find($hold->id), undef, 'Hold no longer current' );
89
    my $old_hold = Koha::Old::Holds->find( $hold->id );
90
91
    is( $old_hold->id, $hold->id, 'reserve_id retained' );
92
    is( $old_hold->priority, 0, 'priority set to 0' );
93
    is( $old_hold->found, 'F', 'found set to F' );
94
95
    subtest 'fee applied tests' => sub {
96
97
        plan tests => 9;
98
99
        my $account = $patron->account;
100
        is( $account->balance, $fee, 'Charge applied correctly' );
101
102
        my $debits = $account->outstanding_debits;
103
        is( $debits->count, 1, 'Only one fee charged' );
104
105
        my $fee_debit = $debits->next;
106
        is( $fee_debit->amount * 1, $fee, 'Fee amount stored correctly' );
107
        is( $fee_debit->description, $title,
108
            'Fee description stored correctly' );
109
        is( $fee_debit->manager_id, $manager->id,
110
            'Fee manager_id stored correctly' );
111
        is( $fee_debit->branchcode, $manager->branchcode,
112
            'Fee branchcode stored correctly' );
113
        is( $fee_debit->interface, $interface,
114
            'Fee interface stored correctly' );
115
        is( $fee_debit->debit_type_code,
116
            'RESERVE', 'Fee debit_type_code stored correctly' );
117
        is( $fee_debit->itemnumber, $item->id,
118
            'Fee itemnumber stored correctly' );
119
    };
120
121
    my $logs = Koha::ActionLogs->search(
122
        {
123
            action => 'FILL',
124
            module => 'HOLDS',
125
            object => $hold->id
126
        }
127
    );
128
129
    is( $logs->count, 1, '1 log line added' );
130
131
    # Set HoldFeeMode to something other than any_time_is_collected
132
    t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' );
133
    # Disable logging
134
    t::lib::Mocks::mock_preference( 'HoldsLog',    0 );
135
136
    $hold = $builder->build_object(
137
        {
138
            class => 'Koha::Holds',
139
            value => {
140
                biblionumber   => $biblio->id,
141
                borrowernumber => $patron->id,
142
                itemnumber     => $item->id,
143
                priority       => 10,
144
            }
145
        }
146
    );
147
148
    $hold->fill;
149
150
    my $account = $patron->account;
151
    is( $account->balance, $fee, 'No new charge applied' );
152
153
    my $debits = $account->outstanding_debits;
154
    is( $debits->count, 1, 'Only one fee charged, because of HoldFeeMode' );
155
156
    $logs = Koha::ActionLogs->search(
157
        {
158
            action => 'FILL',
159
            module => 'HOLDS',
160
            object => $hold->id
161
        }
162
    );
163
164
    is( $logs->count, 0, 'HoldsLog disabled, no logs added' );
165
166
    $schema->storage->txn_rollback;
167
};
168
36
subtest 'patron() tests' => sub {
169
subtest 'patron() tests' => sub {
37
170
38
    plan tests => 2;
171
    plan tests => 2;
39
- 

Return to bug 29869