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

(-)a/t/db_dependent/Koha/CirculationRules.t (-17 / +19 lines)
Lines 392-399 subtest 'get_lostreturn_policy() tests' => sub { Link Here
392
                branchcode   => undef,
392
                branchcode   => undef,
393
                categorycode => undef,
393
                categorycode => undef,
394
                itemtype     => undef,
394
                itemtype     => undef,
395
                rule_name    => 'refund',
395
                rule_name    => 'lostreturn',
396
                rule_value   => 1
396
                rule_value   => 'charge'
397
            }
397
            }
398
        }
398
        }
399
    );
399
    );
Lines 405-425 subtest 'get_lostreturn_policy() tests' => sub { Link Here
405
                branchcode   => $branchcode,
405
                branchcode   => $branchcode,
406
                categorycode => undef,
406
                categorycode => undef,
407
                itemtype     => undef,
407
                itemtype     => undef,
408
                rule_name    => 'refund',
408
                rule_name    => 'lostreturn',
409
                rule_value   => 0
409
                rule_value   => 0
410
            }
410
            }
411
        }
411
        }
412
    );
412
    );
413
    my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
413
    my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
414
    my $specific_rule_true = $builder->build(
414
    my $specific_rule_lostreturn = $builder->build(
415
        {
415
        {
416
            source => 'CirculationRule',
416
            source => 'CirculationRule',
417
            value  => {
417
            value  => {
418
                branchcode   => $branchcode2,
418
                branchcode   => $branchcode2,
419
                categorycode => undef,
419
                categorycode => undef,
420
                itemtype     => undef,
420
                itemtype     => undef,
421
                rule_name    => 'refund',
421
                rule_name    => 'lostreturn',
422
                rule_value   => 1
422
                rule_value   => 'refund'
423
            }
423
            }
424
        }
424
        }
425
    );
425
    );
Lines 432-438 subtest 'get_lostreturn_policy() tests' => sub { Link Here
432
                branchcode   => $branchcode3,
432
                branchcode   => $branchcode3,
433
                categorycode => undef,
433
                categorycode => undef,
434
                itemtype     => undef,
434
                itemtype     => undef,
435
                rule_name    => 'refund',
435
                rule_name    => 'lostreturn',
436
                rule_value   => 'restore'
436
            }
437
            }
437
        }
438
        }
438
    );
439
    );
Lines 443-449 subtest 'get_lostreturn_policy() tests' => sub { Link Here
443
                branchcode   => $branch_without_rule,
444
                branchcode   => $branch_without_rule,
444
                categorycode => undef,
445
                categorycode => undef,
445
                itemtype     => undef,
446
                itemtype     => undef,
446
                rule_name    => 'refund'
447
                rule_name    => 'lostreturn',
448
                rule_value   => 'restore'
447
            }
449
            }
448
          )
450
          )
449
        ->next
451
        ->next
Lines 451-486 subtest 'get_lostreturn_policy() tests' => sub { Link Here
451
453
452
    my $item = $builder->build_sample_item(
454
    my $item = $builder->build_sample_item(
453
        {
455
        {
454
            homebranch    => $specific_rule_true->{branchcode},
456
            homebranch    => $specific_rule_lostreturn->{branchcode},
455
            holdingbranch => $specific_rule_false->{branchcode}
457
            holdingbranch => $specific_rule_false->{branchcode}
456
        }
458
        }
457
    );
459
    );
458
    my $params = {
460
    my $params = {
459
        return_branch => $specific_rule_true->{ branchcode },
461
        return_branch => $specific_rule_lostreturn->{ branchcode },
460
        item          => $item
462
        item          => $item
461
    };
463
    };
462
464
463
    # Specific rules
465
    # Specific rules
464
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
466
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
465
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
467
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
466
          1,'Specific rule for checkin branch is applied (true)');
468
        'refund','Specific rule for checkin branch is applied (refund)');
467
469
468
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
470
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
469
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
471
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
470
         1,'Specific rule for home branch is applied (true)');
472
         'refund','Specific rule for home branch is applied (refund)');
471
473
472
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' );
474
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' );
473
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
475
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
474
         0,'Specific rule for holoding branch is applied (false)');
476
         0,'Specific rule for holding branch is applied (false)');
475
477
476
    # Default rule check
478
    # Default rule check
477
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
479
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
478
    $params->{return_branch} = $branch_without_rule;
480
    $params->{return_branch} = $branch_without_rule;
479
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
481
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
480
         1,'No rule for branch, global rule applied (true)');
482
         'charge','No rule for branch, global rule applied (charge)');
481
483
482
    # Change the default value just to try
484
    # Change the default value just to try
483
    Koha::CirculationRules->search({ branchcode => undef, rule_name => 'refund' })->next->rule_value(0)->store;
485
    Koha::CirculationRules->search({ branchcode => undef, rule_name => 'lostreturn' })->next->rule_value(0)->store;
484
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
486
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
485
         0,'No rule for branch, global rule applied (false)');
487
         0,'No rule for branch, global rule applied (false)');
486
488
Lines 491-503 subtest 'get_lostreturn_policy() tests' => sub { Link Here
491
                branchcode   => undef,
493
                branchcode   => undef,
492
                categorycode => undef,
494
                categorycode => undef,
493
                itemtype     => undef,
495
                itemtype     => undef,
494
                rule_name    => 'refund'
496
                rule_name    => 'lostreturn'
495
            }
497
            }
496
          )
498
          )
497
        ->next
499
        ->next
498
        ->delete;
500
        ->delete;
499
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
501
    is( Koha::CirculationRules->get_lostreturn_policy( $params ),
500
         1,'No rule for branch, no default rule, fallback default (true)');
502
         'refund','No rule for branch, no default rule, fallback default (refund)');
501
503
502
    $schema->storage->txn_rollback;
504
    $schema->storage->txn_rollback;
503
};
505
};
(-)a/t/db_dependent/Koha/IssuingRules.t (-7 / +6 lines)
Lines 458-467 subtest 'set_rule' => sub { Link Here
458
        lives_ok( sub {
458
        lives_ok( sub {
459
            Koha::CirculationRules->set_rule( {
459
            Koha::CirculationRules->set_rule( {
460
                branchcode => $branchcode,
460
                branchcode => $branchcode,
461
                rule_name => 'refund',
461
                rule_name => 'lostreturn',
462
                rule_value => '',
462
                rule_value => '',
463
            } );
463
            } );
464
        }, 'setting refund with branch' );
464
        }, 'setting lostreturn with branch' );
465
465
466
        lives_ok( sub {
466
        lives_ok( sub {
467
            Koha::CirculationRules->set_rule( {
467
            Koha::CirculationRules->set_rule( {
Lines 499-508 subtest 'set_rule' => sub { Link Here
499
499
500
        throws_ok( sub {
500
        throws_ok( sub {
501
            Koha::CirculationRules->set_rule( {
501
            Koha::CirculationRules->set_rule( {
502
                rule_name => 'refund',
502
                rule_name => 'lostreturn',
503
                rule_value => '',
503
                rule_value => '',
504
            } );
504
            } );
505
        }, qr/branchcode/, 'setting refund without branch fails' );
505
        }, qr/branchcode/, 'setting lostreturn without branch fails' );
506
506
507
        throws_ok( sub {
507
        throws_ok( sub {
508
            Koha::CirculationRules->set_rule( {
508
            Koha::CirculationRules->set_rule( {
Lines 539-548 subtest 'set_rule' => sub { Link Here
539
            Koha::CirculationRules->set_rule( {
539
            Koha::CirculationRules->set_rule( {
540
                branchcode => $branchcode,
540
                branchcode => $branchcode,
541
                categorycode => $categorycode,
541
                categorycode => $categorycode,
542
                rule_name => 'refund',
542
                rule_name => 'lostreturn',
543
                rule_value => '',
543
                rule_value => '',
544
            } );
544
            } );
545
        }, qr/categorycode/, 'setting refund with categorycode fails' );
545
        }, qr/categorycode/, 'setting lostreturn with categorycode fails' );
546
546
547
        throws_ok( sub {
547
        throws_ok( sub {
548
            Koha::CirculationRules->set_rule( {
548
            Koha::CirculationRules->set_rule( {
549
- 

Return to bug 23091