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