Lines 7-13
use C4::Circulation;
Link Here
|
7 |
use C4::Items; |
7 |
use C4::Items; |
8 |
use Koha::IssuingRule; |
8 |
use Koha::IssuingRule; |
9 |
use Koha::Items; |
9 |
use Koha::Items; |
10 |
use Test::More tests => 6; |
10 |
use Test::More tests => 10; |
11 |
|
11 |
|
12 |
use t::lib::TestBuilder; |
12 |
use t::lib::TestBuilder; |
13 |
use t::lib::Mocks; |
13 |
use t::lib::Mocks; |
Lines 93-108
my $rule = Koha::IssuingRule->new(
Link Here
|
93 |
); |
93 |
); |
94 |
$rule->store(); |
94 |
$rule->store(); |
95 |
|
95 |
|
96 |
my $is = IsAvailableForItemLevelRequest( $item1, $patron1); |
96 |
my $is; |
|
|
97 |
|
98 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); |
99 |
is( $is, 1, "Items availability: both of 2 items are available" ); |
100 |
|
101 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
97 |
is( $is, 0, "Item cannot be held, 2 items available" ); |
102 |
is( $is, 0, "Item cannot be held, 2 items available" ); |
98 |
|
103 |
|
99 |
my $issue1 = AddIssue( $patron2->unblessed, $item1->barcode ); |
104 |
my $issue1 = AddIssue( $patron2->unblessed, $item1->barcode ); |
100 |
|
105 |
|
|
|
106 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); |
107 |
is( $is, 1, "Items availability: one item is available" ); |
108 |
|
101 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
109 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
102 |
is( $is, 0, "Item cannot be held, 1 item available" ); |
110 |
is( $is, 0, "Item cannot be held, 1 item available" ); |
103 |
|
111 |
|
104 |
AddIssue( $patron2->unblessed, $item2->barcode ); |
112 |
AddIssue( $patron2->unblessed, $item2->barcode ); |
105 |
|
113 |
|
|
|
114 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); |
115 |
is( $is, 0, "Items availability: none of items are available" ); |
116 |
|
106 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
117 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
107 |
is( $is, 1, "Item can be held, no items available" ); |
118 |
is( $is, 1, "Item can be held, no items available" ); |
108 |
|
119 |
|
Lines 116-122
AddReturn( $item1->barcode );
Link Here
|
116 |
my $hold_allowed_from_any_libraries = 2; |
127 |
my $hold_allowed_from_any_libraries = 2; |
117 |
|
128 |
|
118 |
subtest 'Item is available at a different library' => sub { |
129 |
subtest 'Item is available at a different library' => sub { |
119 |
plan tests => 7; |
130 |
plan tests => 13; |
120 |
|
131 |
|
121 |
$item1->set({homebranch => $library_B, holdingbranch => $library_B })->store; |
132 |
$item1->set({homebranch => $library_B, holdingbranch => $library_B })->store; |
122 |
#Scenario is: |
133 |
#Scenario is: |
Lines 129-148
AddReturn( $item1->barcode );
Link Here
|
129 |
set_holdallowed_rule( $hold_allowed_from_home_library ); |
140 |
set_holdallowed_rule( $hold_allowed_from_home_library ); |
130 |
|
141 |
|
131 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
142 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
|
|
143 |
|
144 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item |
145 |
is( $is, 0, "Items availability: hold allowed from home + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" ); |
146 |
|
132 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
147 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
133 |
is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" ); |
148 |
is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" ); |
134 |
$is = IsAvailableForItemLevelRequest( $item1, $patron2); |
149 |
$is = IsAvailableForItemLevelRequest( $item1, $patron2); |
135 |
is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at home library, holdable = one available => the hold is not allowed at item level" ); |
150 |
is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at home library, holdable = one available => the hold is not allowed at item level" ); |
136 |
set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_B ); |
151 |
set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_B ); |
137 |
#Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary |
152 |
#Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary |
|
|
153 |
|
154 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item |
155 |
is( $is, 1, "Items availability: hold allowed from any library for library B + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" ); |
156 |
|
138 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
157 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
139 |
is( $is, 0, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, holdable = one available => the hold is not allowed at item level" ); |
158 |
is( $is, 0, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, holdable = one available => the hold is not allowed at item level" ); |
140 |
|
159 |
|
141 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
160 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
|
|
161 |
|
162 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item |
163 |
is( $is, 0, "Items availability: hold allowed from any library for library B + ReservesControlBranch=PatronLibrary + one item is available at different library" ); |
164 |
|
142 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
165 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
143 |
is( $is, 1, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" ); |
166 |
is( $is, 1, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" ); |
144 |
#Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary |
167 |
#Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary |
145 |
set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_A ); |
168 |
set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_A ); |
|
|
169 |
|
170 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item |
171 |
is( $is, 1, "Items availability: hold allowed from any library for library A + ReservesControlBranch=PatronLibrary + one item is available at different library" ); |
172 |
|
146 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
173 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
147 |
is( $is, 0, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, holdable = one available => the hold is not allowed at item level" ); |
174 |
is( $is, 0, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, holdable = one available => the hold is not allowed at item level" ); |
148 |
} |
175 |
} |
Lines 151-167
AddReturn( $item1->barcode );
Link Here
|
151 |
set_holdallowed_rule( $hold_allowed_from_any_libraries ); |
178 |
set_holdallowed_rule( $hold_allowed_from_any_libraries ); |
152 |
|
179 |
|
153 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
180 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
|
|
181 |
|
182 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item |
183 |
is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" ); |
184 |
|
154 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
185 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
155 |
is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" ); |
186 |
is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" ); |
156 |
|
187 |
|
157 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
188 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
|
|
189 |
|
190 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item |
191 |
is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at different library" ); |
192 |
|
158 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
193 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
159 |
is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" ); |
194 |
is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" ); |
160 |
} |
195 |
} |
161 |
}; |
196 |
}; |
162 |
|
197 |
|
163 |
subtest 'Item is available at the same library' => sub { |
198 |
subtest 'Item is available at the same library' => sub { |
164 |
plan tests => 4; |
199 |
plan tests => 8; |
165 |
|
200 |
|
166 |
$item1->set({homebranch => $library_A, holdingbranch => $library_A })->store; |
201 |
$item1->set({homebranch => $library_A, holdingbranch => $library_A })->store; |
167 |
#Scenario is: |
202 |
#Scenario is: |
Lines 176-185
AddReturn( $item1->barcode );
Link Here
|
176 |
set_holdallowed_rule( $hold_allowed_from_home_library ); |
211 |
set_holdallowed_rule( $hold_allowed_from_home_library ); |
177 |
|
212 |
|
178 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
213 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
|
|
214 |
|
215 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item |
216 |
is( $is, 1, "Items availability: hold allowed from home library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" ); |
217 |
|
179 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
218 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
180 |
is( $is, 0, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" ); |
219 |
is( $is, 0, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" ); |
181 |
|
220 |
|
182 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
221 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
|
|
222 |
|
223 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item |
224 |
is( $is, 1, "Items availability: hold allowed from home library + ReservesControlBranch=PatronLibrary + one item is available at home library" ); |
225 |
|
183 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
226 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
184 |
is( $is, 0, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" ); |
227 |
is( $is, 0, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" ); |
185 |
} |
228 |
} |
Lines 188-197
AddReturn( $item1->barcode );
Link Here
|
188 |
set_holdallowed_rule( $hold_allowed_from_any_libraries ); |
231 |
set_holdallowed_rule( $hold_allowed_from_any_libraries ); |
189 |
|
232 |
|
190 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
233 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
|
|
234 |
|
235 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item |
236 |
is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" ); |
237 |
|
191 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
238 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
192 |
is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" ); |
239 |
is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" ); |
193 |
|
240 |
|
194 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
241 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
|
|
242 |
|
243 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item |
244 |
is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at home library" ); |
245 |
|
195 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
246 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
196 |
is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" ); |
247 |
is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" ); |
197 |
} |
248 |
} |
Lines 226-231
$rule = Koha::IssuingRule->new(
Link Here
|
226 |
); |
277 |
); |
227 |
$rule->store(); |
278 |
$rule->store(); |
228 |
|
279 |
|
|
|
280 |
$is = ItemsAnyAvailableForHold( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item |
281 |
is( $is, 1, "Items availability: 1 item is available, 1 item held in T" ); |
282 |
|
229 |
$is = IsAvailableForItemLevelRequest( $item3, $patron1); |
283 |
$is = IsAvailableForItemLevelRequest( $item3, $patron1); |
230 |
is( $is, 1, "Item can be held, items in transit are not available" ); |
284 |
is( $is, 1, "Item can be held, items in transit are not available" ); |
231 |
|
285 |
|
232 |
- |
|
|