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; |