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

(-)a/t/db_dependent/Circulation.t (-4 / +4 lines)
Lines 3720-3727 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
3720
                branchcode   => undef,
3720
                branchcode   => undef,
3721
                categorycode => undef,
3721
                categorycode => undef,
3722
                itemtype     => undef,
3722
                itemtype     => undef,
3723
                rule_name    => 'refund',
3723
                rule_name    => 'lostreturn',
3724
                rule_value   => 1
3724
                rule_value   => 'refund'
3725
            }
3725
            }
3726
        }
3726
        }
3727
    );
3727
    );
Lines 3913-3920 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
3913
                branchcode   => undef,
3913
                branchcode   => undef,
3914
                categorycode => undef,
3914
                categorycode => undef,
3915
                itemtype     => undef,
3915
                itemtype     => undef,
3916
                rule_name    => 'refund',
3916
                rule_name    => 'lostreturn',
3917
                rule_value   => 1
3917
                rule_value   => 'refund'
3918
            }
3918
            }
3919
        }
3919
        }
3920
    );
3920
    );
(-)a/t/db_dependent/Koha/CirculationRules.t (-22 / +38 lines)
Lines 304-318 subtest 'get_lostreturn_policy() tests' => sub { Link Here
304
304
305
    $schema->resultset('CirculationRule')->search()->delete;
305
    $schema->resultset('CirculationRule')->search()->delete;
306
306
307
    my $default_rule = $builder->build(
307
    my $default_rule_charge = $builder->build(
308
        {
308
        {
309
            source => 'CirculationRule',
309
            source => 'CirculationRule',
310
            value  => {
310
            value  => {
311
                branchcode   => undef,
311
                branchcode   => undef,
312
                categorycode => undef,
312
                categorycode => undef,
313
                itemtype     => undef,
313
                itemtype     => undef,
314
                rule_name    => 'refund',
314
                rule_name    => 'lostreturn',
315
                rule_value   => 1
315
                rule_value   => 'charge'
316
            }
316
            }
317
        }
317
        }
318
    );
318
    );
Lines 324-357 subtest 'get_lostreturn_policy() tests' => sub { Link Here
324
                branchcode   => $branchcode,
324
                branchcode   => $branchcode,
325
                categorycode => undef,
325
                categorycode => undef,
326
                itemtype     => undef,
326
                itemtype     => undef,
327
                rule_name    => 'refund',
327
                rule_name    => 'lostreturn',
328
                rule_value   => 0
328
                rule_value   => 0
329
            }
329
            }
330
        }
330
        }
331
    );
331
    );
332
    my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
332
    my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
333
    my $specific_rule_true = $builder->build(
333
    my $specific_rule_refund = $builder->build(
334
        {
334
        {
335
            source => 'CirculationRule',
335
            source => 'CirculationRule',
336
            value  => {
336
            value  => {
337
                branchcode   => $branchcode2,
337
                branchcode   => $branchcode2,
338
                categorycode => undef,
338
                categorycode => undef,
339
                itemtype     => undef,
339
                itemtype     => undef,
340
                rule_name    => 'refund',
340
                rule_name    => 'lostreturn',
341
                rule_value   => 1
341
                rule_value   => 'refund'
342
            }
342
            }
343
        }
343
        }
344
    );
344
    );
345
    # Make sure we have an unused branchcode
346
    my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode};
345
    my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode};
347
    my $specific_rule_dummy = $builder->build(
346
    my $specific_rule_restore = $builder->build(
348
        {
347
        {
349
            source => 'CirculationRule',
348
            source => 'CirculationRule',
350
            value  => {
349
            value  => {
351
                branchcode   => $branchcode3,
350
                branchcode   => $branchcode3,
352
                categorycode => undef,
351
                categorycode => undef,
353
                itemtype     => undef,
352
                itemtype     => undef,
354
                rule_name    => 'refund',
353
                rule_name    => 'lostreturn',
354
                rule_value   => 'restore'
355
            }
356
        }
357
    );
358
359
    # Make sure we have an unused branchcode
360
    my $branchcode4 = $builder->build( { source => 'Branch' } )->{branchcode};
361
    my $specific_rule_dummy = $builder->build(
362
        {
363
            source => 'CirculationRule',
364
            value  => {
365
                branchcode   => $branchcode4,
366
                categorycode => undef,
367
                itemtype     => undef,
368
                rule_name    => 'lostreturn',
369
                rule_value   => 'refund'
355
            }
370
            }
356
        }
371
        }
357
    );
372
    );
Lines 362-368 subtest 'get_lostreturn_policy() tests' => sub { Link Here
362
                branchcode   => $branch_without_rule,
377
                branchcode   => $branch_without_rule,
363
                categorycode => undef,
378
                categorycode => undef,
364
                itemtype     => undef,
379
                itemtype     => undef,
365
                rule_name    => 'refund'
380
                rule_name    => 'lostreturn',
381
                rule_value   => 'refund'
366
            }
382
            }
367
          )
383
          )
368
        ->next
384
        ->next
Lines 370-405 subtest 'get_lostreturn_policy() tests' => sub { Link Here
370
386
371
    my $item = $builder->build_sample_item(
387
    my $item = $builder->build_sample_item(
372
        {
388
        {
373
            homebranch    => $specific_rule_false->{branchcode},
389
            homebranch    => $specific_rule_restore->{branchcode},
374
            holdingbranch => $specific_rule_true->{branchcode}
390
            holdingbranch => $specific_rule_false->{branchcode}
375
        }
391
        }
376
    );
392
    );
377
    my $params = {
393
    my $params = {
378
        return_branch => $specific_rule_true->{ branchcode },
394
        return_branch => $specific_rule_refund->{ branchcode },
379
        item          => $item
395
        item          => $item
380
    };
396
    };
381
397
382
    # Specific rules
398
    # Specific rules
383
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
399
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
384
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
400
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
385
          1,'Specific rule for checkin branch is applied (true)');
401
        'refund','Specific rule for checkin branch is applied (refund)');
386
402
387
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
403
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
388
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
404
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
389
         0,'Specific rule for home branch is applied (false)');
405
         'restore','Specific rule for home branch is applied (restore)');
390
406
391
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' );
407
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' );
392
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
408
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
393
         1,'Specific rule for holding branch is applied (true)');
409
         0,'Specific rule for holding branch is applied (false)');
394
410
395
    # Default rule check
411
    # Default rule check
396
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
412
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
397
    $params->{return_branch} = $branch_without_rule;
413
    $params->{return_branch} = $branch_without_rule;
398
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
414
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
399
         1,'No rule for branch, global rule applied (true)');
415
         'charge','No rule for branch, global rule applied (charge)');
400
416
401
    # Change the default value just to try
417
    # Change the default value just to try
402
    Koha::CirculationRules->search({ branchcode => undef, rule_name => 'refund' })->next->rule_value(0)->store;
418
    Koha::CirculationRules->search({ branchcode => undef, rule_name => 'lostreturn' })->next->rule_value(0)->store;
403
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
419
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
404
         0,'No rule for branch, global rule applied (false)');
420
         0,'No rule for branch, global rule applied (false)');
405
421
Lines 410-427 subtest 'get_lostreturn_policy() tests' => sub { Link Here
410
                branchcode   => undef,
426
                branchcode   => undef,
411
                categorycode => undef,
427
                categorycode => undef,
412
                itemtype     => undef,
428
                itemtype     => undef,
413
                rule_name    => 'refund'
429
                rule_name    => 'lostreturn'
414
            }
430
            }
415
          )
431
          )
416
        ->next
432
        ->next
417
        ->delete;
433
        ->delete;
418
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
434
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
419
         1,'No rule for branch, no default rule, fallback default (true)');
435
         'refund','No rule for branch, no default rule, fallback default (refund)');
420
436
421
    # Fallback to ItemHoldBranch if CheckinLibrary is undefined
437
    # Fallback to ItemHoldBranch if CheckinLibrary is undefined
422
    $params->{return_branch} = undef;
438
    $params->{return_branch} = undef;
423
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
439
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
424
         0,'return_branch undefined, fallback to ItemHomeBranch rule (false)');
440
         'restore','return_branch undefined, fallback to ItemHomeBranch rule (restore)');
425
441
426
    $schema->storage->txn_rollback;
442
    $schema->storage->txn_rollback;
427
};
443
};
(-)a/t/db_dependent/Koha/IssuingRules.t (-7 / +6 lines)
Lines 163-172 subtest 'set_rule' => sub { Link Here
163
        lives_ok( sub {
163
        lives_ok( sub {
164
            Koha::CirculationRules->set_rule( {
164
            Koha::CirculationRules->set_rule( {
165
                branchcode => $branchcode,
165
                branchcode => $branchcode,
166
                rule_name => 'refund',
166
                rule_name => 'lostreturn',
167
                rule_value => '',
167
                rule_value => '',
168
            } );
168
            } );
169
        }, 'setting refund with branch' );
169
        }, 'setting lostreturn with branch' );
170
170
171
        lives_ok( sub {
171
        lives_ok( sub {
172
            Koha::CirculationRules->set_rule( {
172
            Koha::CirculationRules->set_rule( {
Lines 204-213 subtest 'set_rule' => sub { Link Here
204
204
205
        throws_ok( sub {
205
        throws_ok( sub {
206
            Koha::CirculationRules->set_rule( {
206
            Koha::CirculationRules->set_rule( {
207
                rule_name => 'refund',
207
                rule_name => 'lostreturn',
208
                rule_value => '',
208
                rule_value => '',
209
            } );
209
            } );
210
        }, qr/branchcode/, 'setting refund without branch fails' );
210
        }, qr/branchcode/, 'setting lostreturn without branch fails' );
211
211
212
        throws_ok( sub {
212
        throws_ok( sub {
213
            Koha::CirculationRules->set_rule( {
213
            Koha::CirculationRules->set_rule( {
Lines 244-253 subtest 'set_rule' => sub { Link Here
244
            Koha::CirculationRules->set_rule( {
244
            Koha::CirculationRules->set_rule( {
245
                branchcode => $branchcode,
245
                branchcode => $branchcode,
246
                categorycode => $categorycode,
246
                categorycode => $categorycode,
247
                rule_name => 'refund',
247
                rule_name => 'lostreturn',
248
                rule_value => '',
248
                rule_value => '',
249
            } );
249
            } );
250
        }, qr/categorycode/, 'setting refund with categorycode fails' );
250
        }, qr/categorycode/, 'setting lostreturn with categorycode fails' );
251
251
252
        throws_ok( sub {
252
        throws_ok( sub {
253
            Koha::CirculationRules->set_rule( {
253
            Koha::CirculationRules->set_rule( {
254
- 

Return to bug 23091