View | Details | Raw Unified | Return to bug 22005
Collapse All | Expand All

(-)a/t/db_dependent/DecreaseLoanHighHolds.t (-13 / +76 lines)
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 => 42;
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 57-62 my $patron_category = $builder->build({ Link Here
57
    }
57
    }
58
});
58
});
59
59
60
# Create 20 patrons
60
my @patrons;
61
my @patrons;
61
for my $i ( 1 .. 20 ) {
62
for my $i ( 1 .. 20 ) {
62
    my $patron = Koha::Patron->new({
63
    my $patron = Koha::Patron->new({
Lines 69-87 for my $i ( 1 .. 20 ) { Link Here
69
    push( @patrons, $patron );
70
    push( @patrons, $patron );
70
}
71
}
71
72
73
# Create biblio
72
my $biblio = $builder->build_sample_biblio();
74
my $biblio = $builder->build_sample_biblio();
73
75
76
# Attach 10 items to the biblio
74
my @items;
77
my @items;
75
for my $i ( 1 .. 10 ) {
78
for my $i ( 1 .. 10 ) {
76
    my $item = $builder->build_sample_item(
79
    my $item = $builder->build_sample_item(
77
        {
80
        {
78
            biblionumber     => $biblio->id(),
81
            biblionumber     => $biblio->id(),
79
            itype            => $itemtype
82
            itype            => $itemtype,
83
            homebranch       => $library->{branchcode},
84
            holdingbranch    => $library->{branchcode},
80
        }
85
        }
81
    );
86
    );
82
    push( @items, $item );
87
    push( @items, $item );
83
}
88
}
84
89
90
# Add 6 holds to the biblio
85
for my $i ( 0 .. 5 ) {
91
for my $i ( 0 .. 5 ) {
86
    my $patron = $patrons[$i];
92
    my $patron = $patrons[$i];
87
    my $hold   = Koha::Hold->new(
93
    my $hold   = Koha::Hold->new(
Lines 93-111 for my $i ( 0 .. 5 ) { Link Here
93
    )->store();
99
    )->store();
94
}
100
}
95
101
102
# Get the first item and first patron from the lists (this removes them from the lists)
96
my $item   = pop(@items);
103
my $item   = pop(@items);
97
my $patron = pop(@patrons);
104
my $patron = pop(@patrons);
98
105
99
Koha::CirculationRules->set_rules(
106
Koha::CirculationRules->set_rules(
100
    {
107
    {
101
        branchcode   => undef,
108
        branchcode   => $library->{branchcode},
102
        categorycode => undef,
109
        categorycode => $category->{categorycode},
103
        itemtype     => $item->itype,
110
        itemtype     => $item->itype,
104
        rules        => {
111
        rules        => {
105
            issuelength     => '14',
112
            issuelength     => 14,
106
            lengthunit      => 'days',
113
            lengthunit      => 'days',
107
            reservesallowed => '99',
114
            reservesallowed => 99,
108
            holds_per_record => '99',
115
            holds_per_record => 99,
109
        }
116
        }
110
    }
117
    }
111
);
118
);
Lines 118-123 my $orig_due = C4::Circulation::CalcDateDue( Link Here
118
    $patron->unblessed
125
    $patron->unblessed
119
);
126
);
120
127
128
## decreaseLoanHighHoldsControl = static
129
121
t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds',               1 );
130
t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds',               1 );
122
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsDuration',       1 );
131
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsDuration',       1 );
123
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue',          1 );
132
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue',          1 );
Lines 128-135 my $item_hr = { itemnumber => $item->id, biblionumber => $biblio->id, homebranch Link Here
128
my $patron_hr = { borrowernumber => $patron->id, branchcode => $library->{branchcode} };
137
my $patron_hr = { borrowernumber => $patron->id, branchcode => $library->{branchcode} };
129
138
130
my $data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
139
my $data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
131
is( $data->{exceeded},        1,          "Static mode should exceed threshold" );
140
is( $data->{exceeded},        1,          "Static mode should exceed threshold when decreaseLoanHighHoldsValue = 1" );
132
is( $data->{outstanding},     6,          "Should have 5 outstanding holds" );
141
is( $data->{outstanding},     6,          "Should have 6 outstanding holds" );
133
is( $data->{duration},        1,          "Should have duration of 1" );
142
is( $data->{duration},        1,          "Should have duration of 1" );
134
is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" );
143
is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" );
135
144
Lines 138-147 is($duedate->hour, $orig_due->hour, 'New due hour is equal to original due hour. Link Here
138
is($duedate->min, $orig_due->min, 'New due minute is equal to original due minute.');
147
is($duedate->min, $orig_due->min, 'New due minute is equal to original due minute.');
139
is($duedate->sec, 0, 'New due date second is zero.');
148
is($duedate->sec, 0, 'New due date second is zero.');
140
149
150
# We have 6 holds so this SHOULD exceed the limit and trigger shortened loan time
151
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 5 );
152
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
153
is( $data->{exceeded},        1,          "Static mode should exceed threshold when decreaseLoanHighHoldsValue = 5" );
154
is( $data->{outstanding},     6,          "Should have 6 outstanding holds" );
155
is( $data->{duration},        1,          "Should have duration of 1" );
156
is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" );
157
158
# We have 6 holds so this should NOT exceed the limit and trigger shortened loan time
159
# The sysprefs say: "[Enable] the reduction of loan period to [x] days for high demand items with more than [y] holds [on the record]."
160
# This must mean that if the number of holds and the value of decreaseLoanHighHoldsValue are equal, checkHighHolds should NOT be triggered
161
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 6 );
162
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
163
is( $data->{exceeded},        0,          "Static mode should exceed threshold when decreaseLoanHighHoldsValue = 6" );
164
is( $data->{outstanding},     6,          "Should have 6 outstanding holds" );
165
is( $data->{duration},        0,          "Should have duration of 1" );
166
is( ref( $data->{due_date} ), '', "due_date should NOT be a DateTime object" );
167
168
# We have 6 holds so this should NOT exceed the limit and trigger shortened loan time
169
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 7 );
170
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
171
is( $data->{exceeded},        0,          "Static mode should not exceed threshold when decreaseLoanHighHoldsValue = 7" );
172
is( $data->{outstanding},     6,          "Should have 6 outstanding holds" );
173
is( $data->{duration},        0,          "Should have duration of 0" );
174
is( ref( $data->{due_date} ), '', "due_date should not be a DateTime object" );
175
176
## decreaseLoanHighHoldsControl = dynamic
177
141
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'dynamic' );
178
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'dynamic' );
179
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 1 );
180
181
# We have 10 items and 6 holds, so this should not exceed a threshold of 1
142
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
182
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
143
is( $data->{exceeded}, 0, "Should not exceed threshold" );
183
is( $data->{exceeded},        0,          "Dynamic mode should not exceed threshold of 1" );
184
is( $data->{outstanding},     6,          "Should have 6 outstanding holds" );
185
is( $data->{duration},        0,          "Should have duration of 0" );
186
is( ref( $data->{due_date} ), '', "due_date should not be a DateTime object" );
144
187
188
# Add 6 more holds, for a total of 12
145
for my $i ( 5 .. 10 ) {
189
for my $i ( 5 .. 10 ) {
146
    my $patron = $patrons[$i];
190
    my $patron = $patrons[$i];
147
    my $hold   = Koha::Hold->new(
191
    my $hold   = Koha::Hold->new(
Lines 153-165 for my $i ( 5 .. 10 ) { Link Here
153
    )->store();
197
    )->store();
154
}
198
}
155
199
200
# We have 10 holdable items + decreaseLoanHighHoldsValue=1 = threshold of 11, versus 12 holds, so this should trigger decreased loan time
156
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
201
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
157
is( $data->{exceeded}, 1, "Should exceed threshold of 1" );
202
is( $data->{exceeded},        1,          "Dynamic mode should not exceed threshold when decreaseLoanHighHoldsValue = 1" );
203
is( $data->{outstanding},    12,          "Should have 12 outstanding holds" );
204
is( $data->{duration},        1,          "Should have duration of 1" );
205
is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" );
158
206
207
# We have 10 holdable items + decreaseLoanHighHoldsValue=2 = threshold of 12, versus 12 holds, so this should NOT trigger decreased loan time
208
# The sysprefs say:
209
# [Enable] the reduction of loan period to [x] days for high demand items with more than [y] holds [over the number of holdable items on the record].
210
# This must mean that if the number of holdable items + decreaseLoanHighHoldsValue equals the number of holds, loan time should NOT be decreased
159
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 2 );
211
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 2 );
160
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
212
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
161
is( $data->{exceeded}, 0, "Should not exceed threshold of 2" );
213
is( $data->{exceeded},        0,          "Dynamic mode should not exceed threshold when decreaseLoanHighHoldsValue = 2" );
214
is( $data->{outstanding},    12,          "Should have 12 outstanding holds" );
215
is( $data->{duration},        0,          "Should have duration of 0" );
216
is( ref( $data->{due_date} ), '', "due_date should not be a DateTime object" );
217
218
# We have 10 holdable items + decreaseLoanHighHoldsValue=3 = threshold of 13, versus 12 holds, so this should trigger decreased loan time
219
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 3 );
220
$data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr );
221
is( $data->{exceeded},        0,          "Dynamic mode should not exceed threshold when decreaseLoanHighHoldsValue = 3" );
222
is( $data->{outstanding},    12,          "Should have 12 outstanding holds" );
223
is( $data->{duration},        0,          "Should have duration of 0" );
224
is( ref( $data->{due_date} ), '', "due_date should not be a DateTime object" );
162
225
226
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 2 );
163
my $unholdable = pop(@items);
227
my $unholdable = pop(@items);
164
$unholdable->damaged(-1);
228
$unholdable->damaged(-1);
165
$unholdable->store();
229
$unholdable->store();
166
- 

Return to bug 22005