|
Lines 30-36
use Koha::CirculationRules;
Link Here
|
| 30 |
use t::lib::TestBuilder; |
30 |
use t::lib::TestBuilder; |
| 31 |
use t::lib::Mocks; |
31 |
use t::lib::Mocks; |
| 32 |
|
32 |
|
| 33 |
use Test::More tests => 17; |
33 |
use Test::More tests => 19; |
| 34 |
|
34 |
|
| 35 |
my $dbh = C4::Context->dbh; |
35 |
my $dbh = C4::Context->dbh; |
| 36 |
my $schema = Koha::Database->new()->schema(); |
36 |
my $schema = Koha::Database->new()->schema(); |
|
Lines 71-76
for my $i ( 1 .. 20 ) {
Link Here
|
| 71 |
|
71 |
|
| 72 |
my $biblio = $builder->build_sample_biblio(); |
72 |
my $biblio = $builder->build_sample_biblio(); |
| 73 |
|
73 |
|
|
|
74 |
# The biblio gets 10 items |
| 74 |
my @items; |
75 |
my @items; |
| 75 |
for my $i ( 1 .. 10 ) { |
76 |
for my $i ( 1 .. 10 ) { |
| 76 |
my $item = $builder->build_sample_item( |
77 |
my $item = $builder->build_sample_item( |
|
Lines 82-87
for my $i ( 1 .. 10 ) {
Link Here
|
| 82 |
push( @items, $item ); |
83 |
push( @items, $item ); |
| 83 |
} |
84 |
} |
| 84 |
|
85 |
|
|
|
86 |
# Place 6 holds, patrons 0,1,2,3,4,5 |
| 85 |
for my $i ( 0 .. 5 ) { |
87 |
for my $i ( 0 .. 5 ) { |
| 86 |
my $patron = $patrons[$i]; |
88 |
my $patron = $patrons[$i]; |
| 87 |
my $hold = Koha::Hold->new( |
89 |
my $hold = Koha::Hold->new( |
|
Lines 93-100
for my $i ( 0 .. 5 ) {
Link Here
|
| 93 |
)->store(); |
95 |
)->store(); |
| 94 |
} |
96 |
} |
| 95 |
|
97 |
|
| 96 |
my $item = pop(@items); |
98 |
my $item = shift(@items); |
| 97 |
my $patron = pop(@patrons); |
99 |
my $patron = shift(@patrons); |
|
|
100 |
my $patron_hold = Koha::Holds->find({ borrowernumber => $patron->borrowernumber, biblionumber => $item->biblionumber }); |
| 98 |
|
101 |
|
| 99 |
Koha::CirculationRules->set_rules( |
102 |
Koha::CirculationRules->set_rules( |
| 100 |
{ |
103 |
{ |
|
Lines 129-135
my $patron_hr = { borrowernumber => $patron->id, branchcode => $library->{branch
Link Here
|
| 129 |
|
132 |
|
| 130 |
my $data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
133 |
my $data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
| 131 |
is( $data->{exceeded}, 1, "Static mode should exceed threshold" ); |
134 |
is( $data->{exceeded}, 1, "Static mode should exceed threshold" ); |
| 132 |
is( $data->{outstanding}, 6, "Should have 5 outstanding holds" ); |
135 |
is( $data->{outstanding}, 6, "Should have 6 outstanding holds" ); |
| 133 |
is( $data->{duration}, 1, "Should have duration of 1" ); |
136 |
is( $data->{duration}, 1, "Should have duration of 1" ); |
| 134 |
is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" ); |
137 |
is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" ); |
| 135 |
|
138 |
|
|
Lines 142-147
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'dynamic' );
Link Here
|
| 142 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
145 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
| 143 |
is( $data->{exceeded}, 0, "Should not exceed threshold" ); |
146 |
is( $data->{exceeded}, 0, "Should not exceed threshold" ); |
| 144 |
|
147 |
|
|
|
148 |
|
| 149 |
# Place 6 more holds - patrons 5,6,7,8,9,10 |
| 145 |
for my $i ( 5 .. 10 ) { |
150 |
for my $i ( 5 .. 10 ) { |
| 146 |
my $patron = $patrons[$i]; |
151 |
my $patron = $patrons[$i]; |
| 147 |
my $hold = Koha::Hold->new( |
152 |
my $hold = Koha::Hold->new( |
|
Lines 153-161
for my $i ( 5 .. 10 ) {
Link Here
|
| 153 |
)->store(); |
158 |
)->store(); |
| 154 |
} |
159 |
} |
| 155 |
|
160 |
|
|
|
161 |
# 12 holds, threshold is 1 over 10 holdable items = 11 |
| 156 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
162 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
| 157 |
is( $data->{exceeded}, 1, "Should exceed threshold of 1" ); |
163 |
is( $data->{exceeded}, 1, "Should exceed threshold of 1" ); |
|
|
164 |
is( $data->{outstanding}, 12, "Should exceed threshold of 1" ); |
| 158 |
|
165 |
|
|
|
166 |
# 12 holds, threshold is 2 over 10 holdable items = 12 (equal is okay) |
| 159 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 2 ); |
167 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 2 ); |
| 160 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
168 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
| 161 |
is( $data->{exceeded}, 0, "Should not exceed threshold of 2" ); |
169 |
is( $data->{exceeded}, 0, "Should not exceed threshold of 2" ); |
|
Lines 164-169
my $unholdable = pop(@items);
Link Here
|
| 164 |
$unholdable->damaged(-1); |
172 |
$unholdable->damaged(-1); |
| 165 |
$unholdable->store(); |
173 |
$unholdable->store(); |
| 166 |
|
174 |
|
|
|
175 |
# 12 holds, threshold is 2 over 9 holdable items = 11 |
| 167 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
176 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
| 168 |
is( $data->{exceeded}, 1, "Should exceed threshold with one damaged item" ); |
177 |
is( $data->{exceeded}, 1, "Should exceed threshold with one damaged item" ); |
| 169 |
|
178 |
|
|
Lines 171-176
$unholdable->damaged(0);
Link Here
|
| 171 |
$unholdable->itemlost(-1); |
180 |
$unholdable->itemlost(-1); |
| 172 |
$unholdable->store(); |
181 |
$unholdable->store(); |
| 173 |
|
182 |
|
|
|
183 |
# 12 holds, threshold is 2 over 9 holdable items = 11 |
| 174 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
184 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
| 175 |
is( $data->{exceeded}, 1, "Should exceed threshold with one lost item" ); |
185 |
is( $data->{exceeded}, 1, "Should exceed threshold with one lost item" ); |
| 176 |
|
186 |
|
|
Lines 178-183
$unholdable->itemlost(0);
Link Here
|
| 178 |
$unholdable->notforloan(-1); |
188 |
$unholdable->notforloan(-1); |
| 179 |
$unholdable->store(); |
189 |
$unholdable->store(); |
| 180 |
|
190 |
|
|
|
191 |
# 12 holds, threshold is 2 over 9 holdable items = 11 |
| 181 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
192 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
| 182 |
is( $data->{exceeded}, 1, "Should exceed threshold with one notforloan item" ); |
193 |
is( $data->{exceeded}, 1, "Should exceed threshold with one notforloan item" ); |
| 183 |
|
194 |
|
|
Lines 185-192
$unholdable->notforloan(0);
Link Here
|
| 185 |
$unholdable->withdrawn(-1); |
196 |
$unholdable->withdrawn(-1); |
| 186 |
$unholdable->store(); |
197 |
$unholdable->store(); |
| 187 |
|
198 |
|
|
|
199 |
# 12 holds, threshold is 2 over 9 holdable items = 11 |
| 200 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
| 201 |
is( $data->{exceeded}, 1, "Should exceed threshold with one withdrawn item" ); |
| 202 |
|
| 203 |
$patron_hold->found('F')->store; |
| 204 |
# 11 holds, threshold is 2 over 9 holdable items = 11 |
| 188 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
205 |
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); |
| 189 |
is( $data->{exceeded}, 1, "Should exceed threshold with one withdrawn item" ); |
206 |
is( $data->{exceeded}, 1, "Should exceed threshold with one withdrawn item" ); |
|
|
207 |
$patron_hold->found(undef)->store; |
| 190 |
|
208 |
|
| 191 |
t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary'); |
209 |
t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary'); |
| 192 |
|
210 |
|