Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
use Modern::Perl; |
4 |
|
5 |
use Test::More; |
6 |
|
7 |
use t::lib::TestBuilder; |
8 |
use Koha::Database; |
9 |
use Koha::Cache::Memory::Lite; |
10 |
use Koha::DateUtils qw( dt_from_string ); |
11 |
use C4::Reserves; |
12 |
|
13 |
plan tests => 1; |
14 |
|
15 |
my $schema = Koha::Database->schema; |
16 |
my $circulationrule_rs = $schema->resultset('CirculationRule'); |
17 |
my $builder = t::lib::TestBuilder->new; |
18 |
|
19 |
subtest '2 items, 1 itemtype, 1 library' => sub { |
20 |
plan tests => 3; |
21 |
$schema->txn_begin; |
22 |
|
23 |
my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } )->itemtype; |
24 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
25 |
my $branchcode = $library->branchcode; |
26 |
my $biblio = $builder->build_sample_biblio( { itemtype => $itemtype } ); |
27 |
my $item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, library => $branchcode } ); |
28 |
my $item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, library => $branchcode } ); |
29 |
my $patron = |
30 |
$builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $branchcode } } ); |
31 |
my $categorycode = $patron->categorycode; |
32 |
|
33 |
$circulationrule_rs->populate( |
34 |
[ |
35 |
[ 'branchcode', 'categorycode', 'itemtype', 'rule_name', 'rule_value' ], |
36 |
[ $branchcode, undef, $itemtype, 'holdallowed', 'from_any_library' ], |
37 |
[ $branchcode, undef, $itemtype, 'hold_fulfillment_policy', 'any' ], |
38 |
[ $branchcode, $categorycode, undef, 'max_holds', '99' ], |
39 |
[ $branchcode, $categorycode, $itemtype, 'holds_per_day', '99' ], |
40 |
[ $branchcode, $categorycode, $itemtype, 'holds_per_record', '99' ], |
41 |
[ $branchcode, $categorycode, $itemtype, 'reservesallowed', '99' ], |
42 |
] |
43 |
); |
44 |
my $onshelfholds_rule = $circulationrule_rs->create( |
45 |
{ |
46 |
branchcode => $branchcode, |
47 |
categorycode => $categorycode, |
48 |
itemtype => $itemtype, |
49 |
rule_name => 'onshelfholds', |
50 |
rule_value => '0', |
51 |
} |
52 |
); |
53 |
|
54 |
subtest 'when all items are available' => sub { |
55 |
plan tests => 3; |
56 |
|
57 |
$onshelfholds_rule->update( { rule_value => '0' } ); |
58 |
Koha::Cache::Memory::Lite->flush(); |
59 |
ok( |
60 |
!C4::Reserves::IsOnShelfHoldsPolicySatisfied( { item => $item1, patron => $patron } ), |
61 |
'on shelf hold is not allowed if onshelfholds == 0' |
62 |
); |
63 |
|
64 |
$onshelfholds_rule->update( { rule_value => '1' } ); |
65 |
Koha::Cache::Memory::Lite->flush(); |
66 |
ok( |
67 |
C4::Reserves::IsOnShelfHoldsPolicySatisfied( { item => $item1, patron => $patron } ), |
68 |
'on shelf hold is always allowed if onshelfholds == 1' |
69 |
); |
70 |
|
71 |
$onshelfholds_rule->update( { rule_value => '2' } ); |
72 |
Koha::Cache::Memory::Lite->flush(); |
73 |
ok( |
74 |
!C4::Reserves::IsOnShelfHoldsPolicySatisfied( { item => $item1, patron => $patron } ), |
75 |
'on shelf hold is not allowed if onshelfholds == 2' |
76 |
); |
77 |
}; |
78 |
|
79 |
subtest 'when checked item is not available but others are available' => sub { |
80 |
plan tests => 3; |
81 |
|
82 |
$item1->onloan( dt_from_string() )->store; |
83 |
|
84 |
$onshelfholds_rule->update( { rule_value => '0' } ); |
85 |
Koha::Cache::Memory::Lite->flush(); |
86 |
ok( |
87 |
C4::Reserves::IsOnShelfHoldsPolicySatisfied( { item => $item1, patron => $patron } ), |
88 |
'on shelf hold is allowed if onshelfholds == 0' |
89 |
); |
90 |
|
91 |
$onshelfholds_rule->update( { rule_value => '1' } ); |
92 |
Koha::Cache::Memory::Lite->flush(); |
93 |
ok( |
94 |
C4::Reserves::IsOnShelfHoldsPolicySatisfied( { item => $item1, patron => $patron } ), |
95 |
'on shelf hold is always allowed if onshelfholds == 1' |
96 |
); |
97 |
|
98 |
$onshelfholds_rule->update( { rule_value => '2' } ); |
99 |
Koha::Cache::Memory::Lite->flush(); |
100 |
ok( |
101 |
!C4::Reserves::IsOnShelfHoldsPolicySatisfied( { item => $item1, patron => $patron } ), |
102 |
'on shelf hold is not allowed if onshelfholds == 2' |
103 |
); |
104 |
}; |
105 |
|
106 |
subtest 'when all items are unavailable' => sub { |
107 |
plan tests => 3; |
108 |
|
109 |
$item1->onloan( dt_from_string() )->store; |
110 |
$item2->onloan( dt_from_string() )->store; |
111 |
|
112 |
$onshelfholds_rule->update( { rule_value => '0' } ); |
113 |
Koha::Cache::Memory::Lite->flush(); |
114 |
ok( |
115 |
C4::Reserves::IsOnShelfHoldsPolicySatisfied( { item => $item1, patron => $patron } ), |
116 |
'on shelf hold is allowed if onshelfholds == 0' |
117 |
); |
118 |
|
119 |
$onshelfholds_rule->update( { rule_value => '1' } ); |
120 |
Koha::Cache::Memory::Lite->flush(); |
121 |
ok( |
122 |
C4::Reserves::IsOnShelfHoldsPolicySatisfied( { item => $item1, patron => $patron } ), |
123 |
'on shelf hold is always allowed if onshelfholds == 1' |
124 |
); |
125 |
|
126 |
$onshelfholds_rule->update( { rule_value => '2' } ); |
127 |
Koha::Cache::Memory::Lite->flush(); |
128 |
ok( |
129 |
C4::Reserves::IsOnShelfHoldsPolicySatisfied( { item => $item1, patron => $patron } ), |
130 |
'on shelf hold is allowed if onshelfholds == 2' |
131 |
); |
132 |
}; |
133 |
|
134 |
$schema->txn_rollback; |
135 |
}; |