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 376-379 subtest 'Backdated returns should reduce fine if needed' => sub { Link Here
376
    is( $fine, undef, "Fine was removed correctly with a backdated return" );
376
    is( $fine, undef, "Fine was removed correctly with a backdated return" );
377
};
377
};
378
378
379
subtest 'Test library float limits' => sub {
380
    plan tests => 2;
381
382
    my $library1 = $builder->build( { source => 'Branch' } );
383
    my $library2 = $builder->build( { source => 'Branch' } );
384
    my $library3 = $builder->build( { source => 'Branch' } );
385
    my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } );
386
387
    my $biblio = $builder->build_sample_biblio();
388
389
    for ( 1 .. 5 ) {
390
        $builder->build_sample_item(
391
            {
392
                biblionumber  => $biblio->biblionumber,
393
                homebranch    => $library1->{branchcode},
394
                holdingbranch => $library1->{branchcode},
395
                itype         => $itemtype->itemtype,
396
            }
397
        );
398
    }
399
400
    for ( 1 .. 10 ) {
401
        $builder->build_sample_item(
402
            {
403
                biblionumber  => $biblio->biblionumber,
404
                homebranch    => $library2->{branchcode},
405
                holdingbranch => $library2->{branchcode},
406
                itype         => $itemtype->itemtype,
407
            }
408
        );
409
    }
410
411
    for ( 1 .. 15 ) {
412
        $builder->build_sample_item(
413
            {
414
                biblionumber  => $biblio->biblionumber,
415
                homebranch    => $library3->{branchcode},
416
                holdingbranch => $library3->{branchcode},
417
                itype         => $itemtype->itemtype,
418
            }
419
        );
420
    }
421
422
    my $item = $builder->build_sample_item(
423
        {
424
            biblionumber  => $biblio->biblionumber,
425
            homebranch    => $library1->{branchcode},
426
            holdingbranch => $library1->{branchcode},
427
            itype         => $itemtype->itemtype,
428
        }
429
    );
430
431
    my $limit1 = Koha::Library::FloatLimit->new(
432
        {
433
            branchcode  => $library1->{branchcode},
434
            itemtype    => $itemtype->itemtype,
435
            float_limit => 1,
436
        }
437
    )->store();
438
439
    my $limit2 = Koha::Library::FloatLimit->new(
440
        {
441
            branchcode  => $library2->{branchcode},
442
            itemtype    => $itemtype->itemtype,
443
            float_limit => 100,
444
        }
445
    )->store();
446
447
    my $limit3 = Koha::Library::FloatLimit->new(
448
        {
449
            branchcode  => $library3->{branchcode},
450
            itemtype    => $itemtype->itemtype,
451
            float_limit => 1000,
452
        }
453
    )->store();
454
455
    t::lib::Mocks::mock_preference( 'UseLibraryFloatLimits', '0' );
456
457
    my ( $doreturn, $messages, $iteminformation, $borrower ) = AddReturn( $item->barcode, $item->holdingbranch );
458
    is( $messages->{TransferTrigger}, undef, "Library float limit not triggered if syspref is not enabled" );
459
460
    t::lib::Mocks::mock_preference( 'UseLibraryFloatLimits', '1' );
461
462
    ( $doreturn, $messages, $iteminformation, $borrower ) = AddReturn( $item->barcode, $item->holdingbranch );
463
    is( $messages->{TransferTrigger}, 'LibraryFloatLimit', "Library float limit is triggered if syspref is enabled" );
464
};
465
379
$schema->storage->txn_rollback;
466
$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