|
Lines 36-67
my $itemtype = $builder->build({
Link Here
|
| 36 |
t::lib::Mocks::mock_userenv({ branchcode => $library1->{branchcode} }); |
36 |
t::lib::Mocks::mock_userenv({ branchcode => $library1->{branchcode} }); |
| 37 |
|
37 |
|
| 38 |
|
38 |
|
| 39 |
my $borrower1 = $builder->build({ |
39 |
my $patron1 = $builder->build_object({ |
| 40 |
source => 'Borrower', |
40 |
class => 'Koha::Patrons', |
| 41 |
value => { |
41 |
value => { |
| 42 |
branchcode => $library1->{branchcode}, |
42 |
branchcode => $library1->{branchcode}, |
| 43 |
dateexpiry => '3000-01-01', |
43 |
dateexpiry => '3000-01-01', |
| 44 |
} |
44 |
} |
| 45 |
}); |
45 |
}); |
|
|
46 |
my $borrower1 = $patron1->unblessed; |
| 46 |
|
47 |
|
| 47 |
my $borrower2 = $builder->build({ |
48 |
my $patron2 = $builder->build_object({ |
| 48 |
source => 'Borrower', |
49 |
class => 'Koha::Patrons', |
| 49 |
value => { |
50 |
value => { |
| 50 |
branchcode => $library1->{branchcode}, |
51 |
branchcode => $library1->{branchcode}, |
| 51 |
dateexpiry => '3000-01-01', |
52 |
dateexpiry => '3000-01-01', |
| 52 |
} |
53 |
} |
| 53 |
}); |
54 |
}); |
| 54 |
|
55 |
|
| 55 |
my $borrower3 = $builder->build({ |
56 |
my $patron3 = $builder->build_object({ |
| 56 |
source => 'Borrower', |
57 |
class => 'Koha::Patrons', |
| 57 |
value => { |
58 |
value => { |
| 58 |
branchcode => $library2->{branchcode}, |
59 |
branchcode => $library2->{branchcode}, |
| 59 |
dateexpiry => '3000-01-01', |
60 |
dateexpiry => '3000-01-01', |
| 60 |
} |
61 |
} |
| 61 |
}); |
62 |
}); |
| 62 |
|
63 |
|
| 63 |
my $borrowernumber1 = $borrower1->{borrowernumber}; |
|
|
| 64 |
my $borrowernumber2 = $borrower2->{borrowernumber}; |
| 65 |
my $library_A = $library1->{branchcode}; |
64 |
my $library_A = $library1->{branchcode}; |
| 66 |
my $library_B = $library2->{branchcode}; |
65 |
my $library_B = $library2->{branchcode}; |
| 67 |
|
66 |
|
|
Lines 72-89
my $item1 = $builder->build_sample_item({
Link Here
|
| 72 |
itype=>$itemtype, |
71 |
itype=>$itemtype, |
| 73 |
homebranch => $library_A, |
72 |
homebranch => $library_A, |
| 74 |
holdingbranch => $library_A |
73 |
holdingbranch => $library_A |
| 75 |
})->unblessed; |
74 |
}); |
| 76 |
my $item2 = $builder->build_sample_item({ |
75 |
my $item2 = $builder->build_sample_item({ |
| 77 |
biblionumber=>$biblionumber, |
76 |
biblionumber=>$biblionumber, |
| 78 |
itype=>$itemtype, |
77 |
itype=>$itemtype, |
| 79 |
homebranch => $library_A, |
78 |
homebranch => $library_A, |
| 80 |
holdingbranch => $library_A |
79 |
holdingbranch => $library_A |
| 81 |
})->unblessed; |
80 |
}); |
| 82 |
|
81 |
|
| 83 |
# Test hold_fulfillment_policy |
82 |
# Test hold_fulfillment_policy |
| 84 |
|
|
|
| 85 |
|
| 86 |
|
| 87 |
my $rule = Koha::IssuingRule->new( |
83 |
my $rule = Koha::IssuingRule->new( |
| 88 |
{ |
84 |
{ |
| 89 |
categorycode => '*', |
85 |
categorycode => '*', |
|
Lines 97-116
my $rule = Koha::IssuingRule->new(
Link Here
|
| 97 |
); |
93 |
); |
| 98 |
$rule->store(); |
94 |
$rule->store(); |
| 99 |
|
95 |
|
| 100 |
my $is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
96 |
my $is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 101 |
is( $is, 0, "Item cannot be held, 2 items available" ); |
97 |
is( $is, 0, "Item cannot be held, 2 items available" ); |
| 102 |
|
98 |
|
| 103 |
my $issue1 = AddIssue( $borrower2, $item1->{barcode} ); |
99 |
my $issue1 = AddIssue( $patron2->unblessed, $item1->barcode ); |
| 104 |
|
100 |
|
| 105 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
101 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 106 |
is( $is, 0, "Item cannot be held, 1 item available" ); |
102 |
is( $is, 0, "Item cannot be held, 1 item available" ); |
| 107 |
|
103 |
|
| 108 |
AddIssue( $borrower2, $item2->{barcode} ); |
104 |
AddIssue( $patron2->unblessed, $item2->barcode ); |
| 109 |
|
105 |
|
| 110 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
106 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 111 |
is( $is, 1, "Item can be held, no items available" ); |
107 |
is( $is, 1, "Item can be held, no items available" ); |
| 112 |
|
108 |
|
| 113 |
AddReturn( $item1->{barcode} ); |
109 |
AddReturn( $item1->barcode ); |
| 114 |
|
110 |
|
| 115 |
{ # Remove the issue for the first patron, and modify the branch for item1 |
111 |
{ # Remove the issue for the first patron, and modify the branch for item1 |
| 116 |
subtest 'IsAvailableForItemLevelRequest behaviours depending on ReservesControlBranch + holdallowed' => sub { |
112 |
subtest 'IsAvailableForItemLevelRequest behaviours depending on ReservesControlBranch + holdallowed' => sub { |
|
Lines 125-133
AddReturn( $item1->{barcode} );
Link Here
|
| 125 |
subtest 'Item is available at a different library' => sub { |
121 |
subtest 'Item is available at a different library' => sub { |
| 126 |
plan tests => 7; |
122 |
plan tests => 7; |
| 127 |
|
123 |
|
| 128 |
$item1 = Koha::Items->find( $item1->{itemnumber} ); |
|
|
| 129 |
$item1->set({homebranch => $library_B, holdingbranch => $library_B })->store; |
124 |
$item1->set({homebranch => $library_B, holdingbranch => $library_B })->store; |
| 130 |
$item1 = $item1->unblessed; |
|
|
| 131 |
#Scenario is: |
125 |
#Scenario is: |
| 132 |
#One shelf holds is 'If all unavailable'/2 |
126 |
#One shelf holds is 'If all unavailable'/2 |
| 133 |
#Item 1 homebranch library B is available |
127 |
#Item 1 homebranch library B is available |
|
Lines 139-159
AddReturn( $item1->{barcode} );
Link Here
|
| 139 |
$sth_insert_rule->execute( $hold_allowed_from_home_library ); |
133 |
$sth_insert_rule->execute( $hold_allowed_from_home_library ); |
| 140 |
|
134 |
|
| 141 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
135 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
| 142 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
136 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 143 |
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" ); |
137 |
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" ); |
| 144 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower2); |
138 |
$is = IsAvailableForItemLevelRequest( $item1, $patron2); |
| 145 |
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" ); |
139 |
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" ); |
| 146 |
$sth_insert_branch_rule->execute( $library_B, $hold_allowed_from_any_libraries ); |
140 |
$sth_insert_branch_rule->execute( $library_B, $hold_allowed_from_any_libraries ); |
| 147 |
#Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary |
141 |
#Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary |
| 148 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
142 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 149 |
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" ); |
143 |
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" ); |
| 150 |
|
144 |
|
| 151 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
145 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
| 152 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
146 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 153 |
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" ); |
147 |
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" ); |
| 154 |
#Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary |
148 |
#Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary |
| 155 |
$sth_insert_branch_rule->execute( $library_A, $hold_allowed_from_any_libraries ); |
149 |
$sth_insert_branch_rule->execute( $library_A, $hold_allowed_from_any_libraries ); |
| 156 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
150 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 157 |
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" ); |
151 |
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" ); |
| 158 |
} |
152 |
} |
| 159 |
|
153 |
|
|
Lines 162-172
AddReturn( $item1->{barcode} );
Link Here
|
| 162 |
$sth_insert_rule->execute( $hold_allowed_from_any_libraries ); |
156 |
$sth_insert_rule->execute( $hold_allowed_from_any_libraries ); |
| 163 |
|
157 |
|
| 164 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
158 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
| 165 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
159 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 166 |
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" ); |
160 |
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" ); |
| 167 |
|
161 |
|
| 168 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
162 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
| 169 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
163 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 170 |
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" ); |
164 |
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" ); |
| 171 |
} |
165 |
} |
| 172 |
}; |
166 |
}; |
|
Lines 174-182
AddReturn( $item1->{barcode} );
Link Here
|
| 174 |
subtest 'Item is available at the same library' => sub { |
168 |
subtest 'Item is available at the same library' => sub { |
| 175 |
plan tests => 4; |
169 |
plan tests => 4; |
| 176 |
|
170 |
|
| 177 |
$item1 = Koha::Items->find( $item1->{itemnumber} ); |
|
|
| 178 |
$item1->set({homebranch => $library_A, holdingbranch => $library_A })->store; |
171 |
$item1->set({homebranch => $library_A, holdingbranch => $library_A })->store; |
| 179 |
$item1 = $item1->unblessed; |
|
|
| 180 |
#Scenario is: |
172 |
#Scenario is: |
| 181 |
#One shelf holds is 'If all unavailable'/2 |
173 |
#One shelf holds is 'If all unavailable'/2 |
| 182 |
#Item 1 homebranch library A is available |
174 |
#Item 1 homebranch library A is available |
|
Lines 190-200
AddReturn( $item1->{barcode} );
Link Here
|
| 190 |
$sth_insert_rule->execute( $hold_allowed_from_home_library ); |
182 |
$sth_insert_rule->execute( $hold_allowed_from_home_library ); |
| 191 |
|
183 |
|
| 192 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
184 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
| 193 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
185 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 194 |
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" ); |
186 |
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" ); |
| 195 |
|
187 |
|
| 196 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
188 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
| 197 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
189 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 198 |
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" ); |
190 |
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" ); |
| 199 |
} |
191 |
} |
| 200 |
|
192 |
|
|
Lines 203-213
AddReturn( $item1->{barcode} );
Link Here
|
| 203 |
$sth_insert_rule->execute( $hold_allowed_from_any_libraries ); |
195 |
$sth_insert_rule->execute( $hold_allowed_from_any_libraries ); |
| 204 |
|
196 |
|
| 205 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
197 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
| 206 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
198 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 207 |
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" ); |
199 |
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" ); |
| 208 |
|
200 |
|
| 209 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
201 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
| 210 |
$is = IsAvailableForItemLevelRequest( $item1, $borrower1); |
202 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1); |
| 211 |
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" ); |
203 |
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" ); |
| 212 |
} |
204 |
} |
| 213 |
}; |
205 |
}; |
|
Lines 241-247
$rule = Koha::IssuingRule->new(
Link Here
|
| 241 |
); |
233 |
); |
| 242 |
$rule->store(); |
234 |
$rule->store(); |
| 243 |
|
235 |
|
| 244 |
$is = IsAvailableForItemLevelRequest( $item3->unblessed, $borrower1); |
236 |
$is = IsAvailableForItemLevelRequest( $item3, $patron1); |
| 245 |
is( $is, 1, "Item can be held, items in transit are not available" ); |
237 |
is( $is, 1, "Item can be held, items in transit are not available" ); |
| 246 |
|
238 |
|
| 247 |
# Cleanup |
239 |
# Cleanup |