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

(-)a/t/db_dependent/Overdues.t (-2 / +74 lines)
Lines 165-176 $schema->storage->txn_rollback; Link Here
165
165
166
subtest 'UpdateFine tests' => sub {
166
subtest 'UpdateFine tests' => sub {
167
167
168
    plan tests => 75;
168
    plan tests => 83;
169
169
170
    $schema->storage->txn_begin;
170
    $schema->storage->txn_begin;
171
171
172
    t::lib::Mocks::mock_preference( 'MaxFine', '100' );
172
    t::lib::Mocks::mock_preference( 'MaxFine', '100' );
173
173
174
    # Branch context tests for OVERDUE fines (Bug 35612)
175
    my $lib_home   = $builder->build_object( { class => 'Koha::Libraries' } );
176
    my $lib_hold   = $builder->build_object( { class => 'Koha::Libraries' } );
177
    my $lib_issue  = $builder->build_object( { class => 'Koha::Libraries' } );
178
    my $lib_patron = $builder->build_object( { class => 'Koha::Libraries' } );
179
180
    my $context_patron = $builder->build_object(
181
        {
182
            class => 'Koha::Patrons',
183
            value => { branchcode => $lib_patron->branchcode }
184
        }
185
    );
186
187
    # Helper to create a scenario checkout/item and assert the resulting fine's branchcode
188
    my $assert_overdue_branchcode = sub {
189
        my ( $circ_control, $hoh, $expected_branchcode, $label ) = @_;
190
191
        t::lib::Mocks::mock_preference( 'CircControl',         $circ_control );
192
        t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', $hoh ) if defined $hoh;
193
194
        my $item = $builder->build_sample_item();
195
        $item->homebranch( $lib_home->branchcode )->holdingbranch( $lib_hold->branchcode )->store;
196
197
        my $checkout = $builder->build_object(
198
            {
199
                class => 'Koha::Checkouts',
200
                value => {
201
                    itemnumber     => $item->itemnumber,
202
                    borrowernumber => $context_patron->borrowernumber,
203
                    branchcode     => $lib_issue->branchcode,
204
                }
205
            }
206
        );
207
208
        UpdateFine(
209
            {
210
                issue_id       => $checkout->issue_id,
211
                itemnumber     => $item->itemnumber,
212
                borrowernumber => $context_patron->borrowernumber,
213
                amount         => '1',
214
                due            => $checkout->date_due,
215
            }
216
        );
217
218
        my $fine = Koha::Account::Lines->search(
219
            { issue_id => $checkout->issue_id, debit_type_code => 'OVERDUE' },
220
            { order_by => { -desc => 'accountlines_id' } }
221
        )->next;
222
223
        ok( $fine, "$label: fine created" );
224
        is( $fine->branchcode, $expected_branchcode, "$label: branchcode recorded correctly" );
225
    };
226
227
    $assert_overdue_branchcode->(
228
        'PatronLibrary', undef, $lib_patron->branchcode,
229
        'CircControl=PatronLibrary'
230
    );
231
232
    $assert_overdue_branchcode->(
233
        'PickupLibrary', undef, $lib_issue->branchcode,
234
        'CircControl=PickupLibrary'
235
    );
236
237
    $assert_overdue_branchcode->(
238
        'ItemHomeLibrary', 'homebranch', $lib_home->branchcode,
239
        'CircControl=ItemHomeLibrary + HomeOrHoldingBranch=homebranch'
240
    );
241
242
    $assert_overdue_branchcode->(
243
        'ItemHomeLibrary', 'holdingbranch', $lib_hold->branchcode,
244
        'CircControl=ItemHomeLibrary + HomeOrHoldingBranch=holdingbranch'
245
    );
246
174
    my $patron    = $builder->build_object( { class => 'Koha::Patrons' } );
247
    my $patron    = $builder->build_object( { class => 'Koha::Patrons' } );
175
    my $item1     = $builder->build_sample_item();
248
    my $item1     = $builder->build_sample_item();
176
    my $item2     = $builder->build_sample_item();
249
    my $item2     = $builder->build_sample_item();
177
- 

Return to bug 35612