Lines 7-13
use Koha::Database;
Link Here
|
7 |
use Koha::DateUtils qw( dt_from_string ); |
7 |
use Koha::DateUtils qw( dt_from_string ); |
8 |
use Koha::Patrons; |
8 |
use Koha::Patrons; |
9 |
|
9 |
|
10 |
use Test::More tests => 61; |
10 |
use Test::More tests => 169; |
11 |
|
11 |
|
12 |
use_ok('Koha::Patron'); |
12 |
use_ok('Koha::Patron'); |
13 |
|
13 |
|
Lines 42-47
my $inheritCatCode = $builder->build({
Link Here
|
42 |
}, |
42 |
}, |
43 |
}); |
43 |
}); |
44 |
|
44 |
|
|
|
45 |
my $yesItypeCode = $builder->build_object({ |
46 |
class => 'Koha::ItemTypes', |
47 |
value => { |
48 |
checkprevcheckout => 'yes', |
49 |
} |
50 |
}); |
51 |
|
52 |
my $noItypeCode = $builder->build_object({ |
53 |
class => 'Koha::ItemTypes', |
54 |
value => { |
55 |
checkprevcheckout => 'no', |
56 |
} |
57 |
}); |
58 |
|
59 |
my $inheritItypeCode = $builder->build_object({ |
60 |
class => 'Koha::ItemTypes', |
61 |
value => { |
62 |
checkprevcheckout => 'inherit', |
63 |
} |
64 |
}); |
65 |
|
45 |
# Create context for some tests late on in the file. |
66 |
# Create context for some tests late on in the file. |
46 |
my $library = $builder->build({ source => 'Branch' }); |
67 |
my $library = $builder->build({ source => 'Branch' }); |
47 |
my $staff = $builder->build({source => 'Borrower'}); |
68 |
my $staff = $builder->build({source => 'Borrower'}); |
Lines 50-55
t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
Link Here
|
50 |
|
71 |
|
51 |
# wants_check_for_previous_checkout |
72 |
# wants_check_for_previous_checkout |
52 |
|
73 |
|
|
|
74 |
# We want to test the subroutine without passing the $item parameter |
53 |
# We expect the following result matrix: |
75 |
# We expect the following result matrix: |
54 |
# |
76 |
# |
55 |
# (1/0 indicates the return value of WantsCheckPrevCheckout; i.e. 1 says we |
77 |
# (1/0 indicates the return value of WantsCheckPrevCheckout; i.e. 1 says we |
Lines 205-210
map {
Link Here
|
205 |
} @{$_->{categories}}; |
227 |
} @{$_->{categories}}; |
206 |
} @{$mappings}; |
228 |
} @{$mappings}; |
207 |
|
229 |
|
|
|
230 |
|
231 |
# wants_check_for_previous_checkout |
232 |
|
233 |
# We want to test the subroutine by passing the $item parameter |
234 |
# We expect the following result matrix: |
235 |
# |
236 |
# (1/0 indicates the return value of WantsCheckPrevCheckout; i.e. 1 says we |
237 |
# should check whether the item was previously issued) |
238 |
# |
239 |
# | System Preference | hardyes | |
240 |
# |-------------------+-----------------------------------------------------------------------------------------------------------| |
241 |
# | Item Type Setting | yes | no | inherit | |
242 |
# |-------------------+-----------------------------------+-----------------------------------+-----------------------------------| |
243 |
# | Category Setting | yes | no | inherit | yes | no | inherit | yes | no | inherit | |
244 |
# |-------------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------| |
245 |
# | Patron Setting | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | |
246 |
# |-------------------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---| |
247 |
# | Expected Result | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
248 |
# |
249 |
# |
250 |
# | System Preference | softyes | |
251 |
# |-------------------+-----------------------------------------------------------------------------------------------------------| |
252 |
# | Item Type Setting | yes | no | inherit | |
253 |
# |-------------------+-----------------------------------+-----------------------------------+-----------------------------------| |
254 |
# | Category Setting | yes | no | inherit | yes | no | inherit | yes | no | inherit | |
255 |
# |-------------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------| |
256 |
# | Patron Setting | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | |
257 |
# |-------------------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---| |
258 |
# | Expected Result | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | |
259 |
# |
260 |
# |
261 |
# | System Preference | softno | |
262 |
# |-------------------+-----------------------------------------------------------------------------------------------------------| |
263 |
# | Item Type Setting | yes | no | inherit | |
264 |
# |-------------------+-----------------------------------+-----------------------------------+-----------------------------------| |
265 |
# | Category Setting | yes | no | inherit | yes | no | inherit | yes | no | inherit | |
266 |
# |-------------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------| |
267 |
# | Patron Setting | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | |
268 |
# |-------------------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---| |
269 |
# | Expected Result | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | |
270 |
# |
271 |
# |
272 |
# | System Preference | hardno | |
273 |
# |-------------------+-----------------------------------------------------------------------------------------------------------| |
274 |
# | Item Type Setting | yes | no | inherit | |
275 |
# |-------------------+-----------------------------------+-----------------------------------+-----------------------------------| |
276 |
# | Category Setting | yes | no | inherit | yes | no | inherit | yes | no | inherit | |
277 |
# |-------------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------| |
278 |
# | Patron Setting | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | y | n | i | |
279 |
# |-------------------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---| |
280 |
# | Expected Result | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
281 |
|
282 |
my $itypeCode = { |
283 |
'yes' => $yesItypeCode->itemtype, |
284 |
'no' => $noItypeCode->itemtype, |
285 |
'inherit' => $inheritItypeCode->itemtype, |
286 |
}; |
287 |
|
288 |
foreach my $syspref ('hardyes','softyes','softno','hardno'){ |
289 |
t::lib::Mocks::mock_preference( 'checkprevcheckout', $syspref ); |
290 |
foreach my $itemtype_setting ('yes','no','inherit'){ #itemtype Setting |
291 |
my $item = $builder->build_sample_item( { itype => $itypeCode->{$itemtype_setting} } ); |
292 |
foreach my $categorie_settings('yes','no','inherit'){ |
293 |
my $catCode = $categorie_settings . 'Cat'; |
294 |
foreach my $patron_setting('yes','no','inherit'){ |
295 |
my $result = undef; |
296 |
$result = 1 if($syspref eq 'hardyes'); |
297 |
$result = 0 if($syspref eq 'hardno'); |
298 |
$result = 1 if(!defined $result && $itemtype_setting eq 'yes'); |
299 |
$result = 0 if(!defined $result && $itemtype_setting eq 'no'); |
300 |
$result = 1 if(!defined $result && $patron_setting eq 'yes'); |
301 |
$result = 0 if(!defined $result && $patron_setting eq 'no'); |
302 |
$result = 1 if(!defined $result && $categorie_settings eq 'yes'); |
303 |
$result = 0 if(!defined $result && $categorie_settings eq 'no'); |
304 |
$result = 1 if(!defined $result && $syspref eq 'softyes'); |
305 |
$result = 0 if(!defined $result && $syspref eq 'softno'); |
306 |
my $kpatron = $builder->build( |
307 |
{ |
308 |
source => 'Borrower', |
309 |
value => { |
310 |
checkprevcheckout => $patron_setting, |
311 |
categorycode => $catCode, |
312 |
}, |
313 |
} |
314 |
); |
315 |
my $patron = Koha::Patrons->find( $kpatron->{borrowernumber} ); |
316 |
is( |
317 |
$patron->wants_check_for_previous_checkout($item), $result, |
318 |
"Predicate with syspref " |
319 |
. $syspref |
320 |
. ", cat " |
321 |
. $catCode |
322 |
. ", patron " |
323 |
. $patron_setting |
324 |
. ", item type " |
325 |
. $itypeCode->{$itemtype_setting} |
326 |
); |
327 |
} |
328 |
} |
329 |
} |
330 |
} |
331 |
|
208 |
# do_check_for_previous_checkout |
332 |
# do_check_for_previous_checkout |
209 |
|
333 |
|
210 |
# We want to test: |
334 |
# We want to test: |
211 |
- |
|
|