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

(-)a/t/db_dependent/Koha/CirculationRules.t (-2 / +126 lines)
Lines 19-30 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 4;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use Koha::CirculationRules;
25
use Koha::CirculationRules;
26
use Koha::Database;
26
use Koha::Database;
27
27
28
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
use t::lib::TestBuilder;
29
use t::lib::Mocks;
30
use t::lib::Mocks;
30
31
Lines 376-378 subtest 'get_effective_daysmode' => sub { Link Here
376
377
377
    $schema->storage->txn_rollback;
378
    $schema->storage->txn_rollback;
378
};
379
};
379
- 
380
381
subtest 'get_lostreturn_policy() tests' => sub {
382
    plan tests => 6;
383
384
    $schema->storage->txn_begin;
385
386
    $schema->resultset('CirculationRule')->search()->delete;
387
388
    my $default_rule = $builder->build(
389
        {
390
            source => 'CirculationRule',
391
            value  => {
392
                branchcode   => undef,
393
                categorycode => undef,
394
                itemtype     => undef,
395
                rule_name    => 'refund',
396
                rule_value   => 1
397
            }
398
        }
399
    );
400
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
401
    my $specific_rule_false = $builder->build(
402
        {
403
            source => 'CirculationRule',
404
            value  => {
405
                branchcode   => $branchcode,
406
                categorycode => undef,
407
                itemtype     => undef,
408
                rule_name    => 'refund',
409
                rule_value   => 0
410
            }
411
        }
412
    );
413
    my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
414
    my $specific_rule_true = $builder->build(
415
        {
416
            source => 'CirculationRule',
417
            value  => {
418
                branchcode   => $branchcode2,
419
                categorycode => undef,
420
                itemtype     => undef,
421
                rule_name    => 'refund',
422
                rule_value   => 1
423
            }
424
        }
425
    );
426
    # Make sure we have an unused branchcode
427
    my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode};
428
    my $specific_rule_dummy = $builder->build(
429
        {
430
            source => 'CirculationRule',
431
            value  => {
432
                branchcode   => $branchcode3,
433
                categorycode => undef,
434
                itemtype     => undef,
435
                rule_name    => 'refund',
436
            }
437
        }
438
    );
439
    my $branch_without_rule = $specific_rule_dummy->{ branchcode };
440
    Koha::CirculationRules
441
        ->search(
442
            {
443
                branchcode   => $branch_without_rule,
444
                categorycode => undef,
445
                itemtype     => undef,
446
                rule_name    => 'refund'
447
            }
448
          )
449
        ->next
450
        ->delete;
451
452
    my $item = $builder->build_sample_item(
453
        {
454
            homebranch    => $specific_rule_true->{branchcode},
455
            holdingbranch => $specific_rule_false->{branchcode}
456
        }
457
    );
458
    my $params = {
459
        return_branch => $specific_rule_true->{ branchcode },
460
        item          => $item
461
    };
462
463
    # Specific rules
464
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
465
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
466
          1,'Specific rule for checkin branch is applied (true)');
467
468
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
469
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
470
         1,'Specific rule for home branch is applied (true)');
471
472
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' );
473
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
474
         0,'Specific rule for holoding branch is applied (false)');
475
476
    # Default rule check
477
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
478
    $params->{return_branch} = $branch_without_rule;
479
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
480
         1,'No rule for branch, global rule applied (true)');
481
482
    # Change the default value just to try
483
    Koha::CirculationRules->search({ branchcode => undef, rule_name => 'refund' })->next->rule_value(0)->store;
484
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
485
         0,'No rule for branch, global rule applied (false)');
486
487
    # No default rule defined check
488
    Koha::CirculationRules
489
        ->search(
490
            {
491
                branchcode   => undef,
492
                categorycode => undef,
493
                itemtype     => undef,
494
                rule_name    => 'refund'
495
            }
496
          )
497
        ->next
498
        ->delete;
499
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
500
         1,'No rule for branch, no default rule, fallback default (true)');
501
502
    $schema->storage->txn_rollback;
503
};

Return to bug 25663