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

(-)a/t/db_dependent/Koha/Patron.t (-2 / +126 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 45;
22
use Test::More tests => 46;
23
use Test::NoWarnings;
23
use Test::NoWarnings;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::Warn;
25
use Test::Warn;
Lines 2952-2957 subtest 'is_patron_inside_charge_limits() tests' => sub { Link Here
2952
    $schema->storage->txn_rollback;
2952
    $schema->storage->txn_rollback;
2953
};
2953
};
2954
2954
2955
subtest 'is_patron_inside_charge_limits - edge cases for empty string and zero' => sub {
2956
    plan tests => 14;
2957
2958
    $schema->storage->txn_begin;
2959
2960
    my $patron_category = $builder->build(
2961
        {
2962
            source => 'Category',
2963
            value  => {
2964
                categorycode                           => 'TEST_CAT',
2965
                category_type                          => 'P',
2966
                enrolmentfee                           => 0,
2967
                noissuescharge                         => undef,
2968
                noissueschargeguarantees               => undef,
2969
                noissueschargeguarantorswithguarantees => undef
2970
            }
2971
        }
2972
    );
2973
2974
    my $patron = $builder->build_object(
2975
        {
2976
            class => 'Koha::Patrons',
2977
            value => { categorycode => $patron_category->{categorycode} }
2978
        }
2979
    );
2980
2981
    my $child = $builder->build_object( { class => 'Koha::Patrons' } );
2982
    $child->add_guarantor( { guarantor_id => $patron->borrowernumber, relationship => 'parent' } );
2983
2984
    # Add some charges to the child
2985
    my $fee = $builder->build_object(
2986
        {
2987
            class => 'Koha::Account::Lines',
2988
            value => {
2989
                borrowernumber    => $child->borrowernumber,
2990
                amountoutstanding => 5.50,
2991
                debit_type_code   => 'OVERDUE',
2992
            }
2993
        }
2994
    )->store;
2995
2996
    # Test 1: Empty string values should be treated as "not set"
2997
    # Empty string is the default value in sysprefs for these preferences
2998
    t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantees',               '' );
2999
    t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantorsWithGuarantees', '' );
3000
3001
    my $patron_borrowing_status = $patron->is_patron_inside_charge_limits();
3002
3003
    is(
3004
        $patron_borrowing_status->{NoIssuesChargeGuarantees}->{limit}, '',
3005
        "Empty string limit is preserved in return value"
3006
    );
3007
    is(
3008
        $patron_borrowing_status->{NoIssuesChargeGuarantees}->{charge}, 0,
3009
        "Charges should be 0 when limit is empty string (calculation skipped)"
3010
    );
3011
    is(
3012
        $patron_borrowing_status->{NoIssuesChargeGuarantees}->{overlimit}, 0,
3013
        "Patron should not be overlimit when preference is empty string"
3014
    );
3015
3016
    is(
3017
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{limit}, '',
3018
        "Empty string limit is preserved for guarantors preference"
3019
    );
3020
    is(
3021
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{charge}, 0,
3022
        "Guarantors charges should be 0 when limit is empty string (calculation skipped)"
3023
    );
3024
    is(
3025
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit}, 0,
3026
        "Patron should not be overlimit when guarantors preference is empty string"
3027
    );
3028
3029
    # Test 2: Zero values should trigger calculation but not block
3030
    t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantees',               0 );
3031
    t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantorsWithGuarantees', 0 );
3032
3033
    $patron_borrowing_status = $patron->is_patron_inside_charge_limits();
3034
3035
    is(
3036
        $patron_borrowing_status->{NoIssuesChargeGuarantees}->{limit}, 0,
3037
        "Zero limit is preserved in return value"
3038
    );
3039
    is(
3040
        $patron_borrowing_status->{NoIssuesChargeGuarantees}->{charge}, 5.50,
3041
        "Charges should be calculated when limit is 0 (valid number)"
3042
    );
3043
    is(
3044
        $patron_borrowing_status->{NoIssuesChargeGuarantees}->{overlimit}, 0,
3045
        "Patron should not be overlimit when limit is 0 (0 means no blocking)"
3046
    );
3047
3048
    is(
3049
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{limit}, 0,
3050
        "Zero limit is preserved for guarantors preference"
3051
    );
3052
3053
    # Note: This will be 5.50 because the child is included in guarantor debt calculation
3054
    ok(
3055
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{charge} > 0,
3056
        "Guarantors charges should be calculated when limit is 0 (valid number)"
3057
    );
3058
    is(
3059
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit}, 0,
3060
        "Patron should not be overlimit when guarantors limit is 0 (0 means no blocking)"
3061
    );
3062
3063
    # Test 3: Verify that a small positive number triggers calculation and can block
3064
    t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantees', 5.00 );
3065
3066
    $patron_borrowing_status = $patron->is_patron_inside_charge_limits();
3067
3068
    is(
3069
        $patron_borrowing_status->{NoIssuesChargeGuarantees}->{charge}, 5.50,
3070
        "Charges are calculated with positive limit"
3071
    );
3072
    is(
3073
        $patron_borrowing_status->{NoIssuesChargeGuarantees}->{overlimit}, 1,
3074
        "Patron is correctly marked overlimit when charges exceed limit"
3075
    );
3076
3077
    $schema->storage->txn_rollback;
3078
};
3079
2955
subtest 'Scrub the note fields' => sub {
3080
subtest 'Scrub the note fields' => sub {
2956
    plan tests => 4;
3081
    plan tests => 4;
2957
3082
2958
- 

Return to bug 41404