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

(-)a/t/db_dependent/Circulation/Returns.t (-1 / +88 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 7;
20
use Test::More tests => 8;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 419-422 subtest 'Backdated returns should reduce fine if needed' => sub { Link Here
419
    is( $fine, undef, "Fine was removed correctly with a backdated return" );
419
    is( $fine, undef, "Fine was removed correctly with a backdated return" );
420
};
420
};
421
421
422
subtest 'Test library float limits' => sub {
423
    plan tests => 2;
424
425
    my $library1 = $builder->build( { source => 'Branch' } );
426
    my $library2 = $builder->build( { source => 'Branch' } );
427
    my $library3 = $builder->build( { source => 'Branch' } );
428
    my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } );
429
430
    my $biblio = $builder->build_sample_biblio();
431
432
    for ( 1 .. 5 ) {
433
        $builder->build_sample_item(
434
            {
435
                biblionumber  => $biblio->biblionumber,
436
                homebranch    => $library1->{branchcode},
437
                holdingbranch => $library1->{branchcode},
438
                itype         => $itemtype->itemtype,
439
            }
440
        );
441
    }
442
443
    for ( 1 .. 10 ) {
444
        $builder->build_sample_item(
445
            {
446
                biblionumber  => $biblio->biblionumber,
447
                homebranch    => $library2->{branchcode},
448
                holdingbranch => $library2->{branchcode},
449
                itype         => $itemtype->itemtype,
450
            }
451
        );
452
    }
453
454
    for ( 1 .. 15 ) {
455
        $builder->build_sample_item(
456
            {
457
                biblionumber  => $biblio->biblionumber,
458
                homebranch    => $library3->{branchcode},
459
                holdingbranch => $library3->{branchcode},
460
                itype         => $itemtype->itemtype,
461
            }
462
        );
463
    }
464
465
    my $item = $builder->build_sample_item(
466
        {
467
            biblionumber  => $biblio->biblionumber,
468
            homebranch    => $library1->{branchcode},
469
            holdingbranch => $library1->{branchcode},
470
            itype         => $itemtype->itemtype,
471
        }
472
    );
473
474
    my $limit1 = Koha::Library::FloatLimit->new(
475
        {
476
            branchcode  => $library1->{branchcode},
477
            itemtype    => $itemtype->itemtype,
478
            float_limit => 1,
479
        }
480
    )->store();
481
482
    my $limit2 = Koha::Library::FloatLimit->new(
483
        {
484
            branchcode  => $library2->{branchcode},
485
            itemtype    => $itemtype->itemtype,
486
            float_limit => 100,
487
        }
488
    )->store();
489
490
    my $limit3 = Koha::Library::FloatLimit->new(
491
        {
492
            branchcode  => $library3->{branchcode},
493
            itemtype    => $itemtype->itemtype,
494
            float_limit => 1000,
495
        }
496
    )->store();
497
498
    t::lib::Mocks::mock_preference( 'UseLibraryFloatLimits', '0' );
499
500
    my ( $doreturn, $messages, $iteminformation, $borrower ) = AddReturn( $item->barcode, $item->holdingbranch );
501
    is( $messages->{TransferTrigger}, undef, "Library float limit not triggered if syspref is not enabled" );
502
503
    t::lib::Mocks::mock_preference( 'UseLibraryFloatLimits', '1' );
504
505
    ( $doreturn, $messages, $iteminformation, $borrower ) = AddReturn( $item->barcode, $item->holdingbranch );
506
    is( $messages->{TransferTrigger}, 'LibraryFloatLimit', "Library float limit is triggered if syspref is enabled" );
507
};
508
422
$schema->storage->txn_rollback;
509
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Library/FloatLimits.t (-1 / +133 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2023 ByWater Solutions
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 5;
23
24
use Koha::Database;
25
use C4::Circulation qw(CreateBranchTransferLimit);
26
27
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
30
BEGIN {
31
    use_ok('Koha::Library::FloatLimit');
32
    use_ok('Koha::Library::FloatLimits');
33
}
34
35
my $schema = Koha::Database->new->schema;
36
$schema->storage->txn_begin;
37
38
my $builder  = t::lib::TestBuilder->new;
39
my $library1 = $builder->build( { source => 'Branch' } );
40
my $library2 = $builder->build( { source => 'Branch' } );
41
my $library3 = $builder->build( { source => 'Branch' } );
42
my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } );
43
44
my $biblio = $builder->build_sample_biblio();
45
46
for ( 1 .. 5 ) {
47
    $builder->build_sample_item(
48
        {
49
            biblionumber  => $biblio->biblionumber,
50
            homebranch    => $library1->{branchcode},
51
            holdingbranch => $library1->{branchcode},
52
            itype         => $itemtype->itemtype,
53
        }
54
    );
55
}
56
57
for ( 1 .. 10 ) {
58
    $builder->build_sample_item(
59
        {
60
            biblionumber  => $biblio->biblionumber,
61
            homebranch    => $library2->{branchcode},
62
            holdingbranch => $library2->{branchcode},
63
            itype         => $itemtype->itemtype,
64
        }
65
    );
66
}
67
68
for ( 1 .. 15 ) {
69
    $builder->build_sample_item(
70
        {
71
            biblionumber  => $biblio->biblionumber,
72
            homebranch    => $library3->{branchcode},
73
            holdingbranch => $library3->{branchcode},
74
            itype         => $itemtype->itemtype,
75
        }
76
    );
77
}
78
79
my $item = $builder->build_sample_item(
80
    {
81
        biblionumber  => $biblio->biblionumber,
82
        homebranch    => $library1->{branchcode},
83
        holdingbranch => $library1->{branchcode},
84
        itype         => $itemtype->itemtype,
85
    }
86
);
87
88
my $limit1 = Koha::Library::FloatLimit->new(
89
    {
90
        branchcode  => $library1->{branchcode},
91
        itemtype    => $itemtype->itemtype,
92
        float_limit => 1,
93
    }
94
)->store();
95
96
my $float_limit2 = Koha::Library::FloatLimit->new(
97
    {
98
        branchcode  => $library2->{branchcode},
99
        itemtype    => $itemtype->itemtype,
100
        float_limit => 100,
101
    }
102
)->store();
103
104
my $float_limit3 = Koha::Library::FloatLimit->new(
105
    {
106
        branchcode  => $library3->{branchcode},
107
        itemtype    => $itemtype->itemtype,
108
        float_limit => 1000,
109
    }
110
)->store();
111
112
is(
113
    Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} ), $library3->{branchcode},
114
    "Correct library selected for float limit transfer"
115
);
116
117
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '1' );
118
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
119
120
my $to   = $library3->{branchcode};
121
my $from = $item->holdingbranch;
122
my $code = $itemtype->itemtype;
123
CreateBranchTransferLimit( $to, $from, $code );
124
125
is( C4::Circulation::IsBranchTransferAllowed( $to, $from, $code ), 0, "Transfer to best library is no longer allowed" );
126
say "C4::Circulation::IsBranchTransferAllowed( $to, $from, $code )";
127
128
is(
129
    Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} ), $library2->{branchcode},
130
    "Correct library selected for float limit transfer when best cannot be used"
131
);
132
133
$schema->storage->txn_rollback;

Return to bug 28530