|
Lines 12-20
use MARC::Record;
Link Here
|
| 12 |
use C4::Context; |
12 |
use C4::Context; |
| 13 |
use C4::Biblio; |
13 |
use C4::Biblio; |
| 14 |
use C4::Items; |
14 |
use C4::Items; |
| 15 |
use C4::Reserves qw(CancelExpiredReserves); |
|
|
| 16 |
use Koha::Database; |
15 |
use Koha::Database; |
| 17 |
use Koha::Holds; |
16 |
use Koha::Holds; |
|
|
17 |
use Koha::Notice::Messages; |
| 18 |
|
18 |
|
| 19 |
BEGIN { |
19 |
BEGIN { |
| 20 |
use FindBin; |
20 |
use FindBin; |
|
Lines 46-66
my $branch_2 = $builder->build_object({
Link Here
|
| 46 |
}); |
46 |
}); |
| 47 |
my $library_2 = $branch_2->branchcode; |
47 |
my $library_2 = $branch_2->branchcode; |
| 48 |
|
48 |
|
| 49 |
my $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); |
|
|
| 50 |
my $biblionumber = $biblio->id; |
| 51 |
|
| 52 |
# Create item instance for testing. |
| 53 |
my $itemnumber = $builder->build_sample_item({ library => $library_1, biblionumber => $biblio->biblionumber })->itemnumber; |
| 54 |
|
| 55 |
my $patron_1 = $builder->build( { source => 'Borrower' } ); |
| 56 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
| 57 |
my $patron_3 = $builder->build( { source => 'Borrower' } ); |
| 58 |
|
49 |
|
| 59 |
subtest 'Test automatically canceled expired waiting holds to fill the next hold, without a transfer' => sub { |
50 |
subtest 'Test automatically canceled expired waiting holds to fill the next hold, without a transfer' => sub { |
| 60 |
plan tests => 10; |
51 |
plan tests => 12; |
|
|
52 |
|
| 53 |
my $item = $builder->build_sample_item({ library => $library_1 }); |
| 54 |
my $biblionumber = $item->biblionumber; |
| 55 |
my $itemnumber = $item->itemnumber; |
| 61 |
|
56 |
|
| 62 |
$dbh->do('DELETE FROM reserves'); |
57 |
my $patron_1 = $builder->build( { source => 'Borrower' } ); |
| 63 |
$dbh->do('DELETE FROM message_queue'); |
58 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
|
|
59 |
my $patron_3 = $builder->build( { source => 'Borrower' } ); |
| 64 |
|
60 |
|
| 65 |
# Add a hold on the item for each of our patrons |
61 |
# Add a hold on the item for each of our patrons |
| 66 |
my $hold_1 = Koha::Hold->new( |
62 |
my $hold_1 = Koha::Hold->new( |
|
Lines 94-100
subtest 'Test automatically canceled expired waiting holds to fill the next hold
Link Here
|
| 94 |
my $hold_3 = Koha::Hold->new( |
90 |
my $hold_3 = Koha::Hold->new( |
| 95 |
{ |
91 |
{ |
| 96 |
priority => 2, |
92 |
priority => 2, |
| 97 |
borrowernumber => $patron_2->{borrowernumber}, |
93 |
borrowernumber => $patron_3->{borrowernumber}, |
| 98 |
branchcode => $library_1, |
94 |
branchcode => $library_1, |
| 99 |
biblionumber => $biblionumber, |
95 |
biblionumber => $biblionumber, |
| 100 |
itemnumber => $itemnumber, |
96 |
itemnumber => $itemnumber, |
|
Lines 113-121
subtest 'Test automatically canceled expired waiting holds to fill the next hold
Link Here
|
| 113 |
t::lib::Mocks::mock_preference( 'ExpireReservesAutoFillEmail', |
109 |
t::lib::Mocks::mock_preference( 'ExpireReservesAutoFillEmail', |
| 114 |
'kyle@example.com' ); |
110 |
'kyle@example.com' ); |
| 115 |
|
111 |
|
| 116 |
CancelExpiredReserves(); |
112 |
$hold_1->cancel({ autofill => 1 }); |
| 117 |
|
113 |
|
| 118 |
my $holds = Koha::Holds->search( {}, { order_by => 'priority' } ); |
114 |
my $holds = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } ); |
| 119 |
$hold_2 = $holds->next; |
115 |
$hold_2 = $holds->next; |
| 120 |
$hold_3 = $holds->next; |
116 |
$hold_3 = $holds->next; |
| 121 |
|
117 |
|
|
Lines 123-155
subtest 'Test automatically canceled expired waiting holds to fill the next hold
Link Here
|
| 123 |
is( $hold_2->priority, 0, 'Next hold in line now has priority of 0' ); |
119 |
is( $hold_2->priority, 0, 'Next hold in line now has priority of 0' ); |
| 124 |
is( $hold_2->found, 'W', 'Next hold in line is now set to waiting' ); |
120 |
is( $hold_2->found, 'W', 'Next hold in line is now set to waiting' ); |
| 125 |
|
121 |
|
| 126 |
my @messages = $schema->resultset('MessageQueue') |
122 |
my $messages = Koha::Notice::Messages->search({ |
| 127 |
->search( { letter_code => 'HOLD_CHANGED' } ); |
123 |
letter_code => 'HOLD_CHANGED', |
| 128 |
is( @messages, 1, 'Found 1 message in the message queue' ); |
124 |
borrowernumber => $patron_2->{borrowernumber} |
| 129 |
is( $messages[0]->to_address, 'kyle@example.com', 'Message sent to correct email address' ); |
125 |
} ); |
| 130 |
|
126 |
is( $messages->count, 1, 'Found message in the message queue with borrower 2 as the object' ); |
| 131 |
$hold_2->expirationdate('1900-01-01')->store(); |
127 |
my $message = $messages->next; |
|
|
128 |
is( $message->to_address, 'kyle@example.com', 'Message sent to correct email address' ); |
| 129 |
is( $message->from_address, $branch_1->branchemail, "Message is sent from library's email"); |
| 132 |
|
130 |
|
| 133 |
CancelExpiredReserves(); |
131 |
$hold_2->cancel({ autofill => 1 }); |
| 134 |
|
132 |
|
| 135 |
$holds = Koha::Holds->search( {}, { order_by => 'priority' } ); |
133 |
$holds = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } ); |
| 136 |
$hold_3 = $holds->next; |
134 |
$hold_3 = $holds->next; |
| 137 |
|
135 |
|
| 138 |
is( $holds->count, 1, 'Found 1 hold' ); |
136 |
is( $holds->count, 1, 'Found 1 hold' ); |
| 139 |
is( $hold_3->priority, 0, 'Next hold in line now has priority of 0' ); |
137 |
is( $hold_3->priority, 0, 'Next hold in line now has priority of 0' ); |
| 140 |
is( $hold_3->found, 'W', 'Next hold in line is now set to waiting' ); |
138 |
is( $hold_3->found, 'W', 'Next hold in line is now set to waiting' ); |
| 141 |
|
139 |
|
| 142 |
@messages = $schema->resultset('MessageQueue') |
140 |
$messages = Koha::Notice::Messages->search({ |
| 143 |
->search( { letter_code => 'HOLD_CHANGED' } ); |
141 |
letter_code => 'HOLD_CHANGED', |
| 144 |
is( @messages, 2, 'Found 2 messages in the message queue' ); |
142 |
borrowernumber => $patron_3->{borrowernumber} |
| 145 |
is( $messages[0]->to_address, 'kyle@example.com', 'Message sent to correct email address' ); |
143 |
}); |
|
|
144 |
is( $messages->count, 1, 'Found message with borrower 3 as the object' ); |
| 145 |
$message = $messages->next; |
| 146 |
is( $message->to_address, 'kyle@example.com', 'Message sent to correct email address' ); |
| 147 |
is( $message->from_address, $branch_1->branchemail, "Message is sent from library's email"); |
| 146 |
}; |
148 |
}; |
| 147 |
|
149 |
|
| 148 |
subtest 'Test automatically canceled expired waiting holds to fill the next hold, with a transfer' => sub { |
150 |
subtest 'Test automatically canceled expired waiting holds to fill the next hold, with a transfer' => sub { |
| 149 |
plan tests => 6; |
151 |
plan tests => 7; |
| 150 |
|
152 |
|
| 151 |
$dbh->do('DELETE FROM reserves'); |
153 |
my $item = $builder->build_sample_item({ library => $library_1 }); |
| 152 |
$dbh->do('DELETE FROM message_queue'); |
154 |
my $biblionumber = $item->biblionumber; |
|
|
155 |
my $itemnumber = $item->itemnumber; |
| 156 |
|
| 157 |
my $patron_1 = $builder->build( { source => 'Borrower' } ); |
| 158 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
| 159 |
my $patron_3 = $builder->build( { source => 'Borrower' } ); |
| 153 |
|
160 |
|
| 154 |
# Add a hold on the item for each of our patrons |
161 |
# Add a hold on the item for each of our patrons |
| 155 |
my $hold_1 = Koha::Hold->new( |
162 |
my $hold_1 = Koha::Hold->new( |
|
Lines 186-197
subtest 'Test automatically canceled expired waiting holds to fill the next hold
Link Here
|
| 186 |
t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', 1 ); |
193 |
t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', 1 ); |
| 187 |
t::lib::Mocks::mock_preference( 'ExpireReservesOnHolidays', 1 ); |
194 |
t::lib::Mocks::mock_preference( 'ExpireReservesOnHolidays', 1 ); |
| 188 |
t::lib::Mocks::mock_preference( 'ExpireReservesAutoFill', 1 ); |
195 |
t::lib::Mocks::mock_preference( 'ExpireReservesAutoFill', 1 ); |
| 189 |
t::lib::Mocks::mock_preference( 'ExpireReservesAutoFillEmail', |
196 |
t::lib::Mocks::mock_preference( 'ExpireReservesAutoFillEmail', '' ); |
| 190 |
'kyle@example.com' ); |
|
|
| 191 |
|
197 |
|
| 192 |
CancelExpiredReserves(); |
198 |
$hold_1->cancel({ autofill => 1 }); |
| 193 |
|
199 |
|
| 194 |
my @holds = Koha::Holds->search( {}, { order_by => 'priority' } )->as_list; |
200 |
my @holds = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } )->as_list; |
| 195 |
$hold_2 = $holds[0]; |
201 |
$hold_2 = $holds[0]; |
| 196 |
|
202 |
|
| 197 |
is( @holds, 1, 'Found 1 hold' ); |
203 |
is( @holds, 1, 'Found 1 hold' ); |
|
Lines 199-210
subtest 'Test automatically canceled expired waiting holds to fill the next hold
Link Here
|
| 199 |
is( $hold_2->found, 'T', 'Next hold in line is now set to in transit' ); |
205 |
is( $hold_2->found, 'T', 'Next hold in line is now set to in transit' ); |
| 200 |
is( $hold_2->branchcode, $library_2, "Next hold in line has correct branchcode" ); |
206 |
is( $hold_2->branchcode, $library_2, "Next hold in line has correct branchcode" ); |
| 201 |
|
207 |
|
| 202 |
my @messages = $schema->resultset('MessageQueue') |
208 |
my $messages = Koha::Notice::Messages->search({ |
| 203 |
->search( { letter_code => 'HOLD_CHANGED' } ); |
209 |
letter_code => 'HOLD_CHANGED', |
| 204 |
is( @messages, 1, 'Message is generated in the message queue when generating transfer' ); |
210 |
borrowernumber => $patron_2->{borrowernumber} |
| 205 |
|
211 |
}); |
| 206 |
my $email = $messages[0]; |
212 |
is( $messages->count, 1, 'Message is generated in the message queue when generating transfer' ); |
| 207 |
is( $email->from_address, $branch_2->branchemail, "Message is sent from library's email"); |
213 |
my $message = $messages->next; |
|
|
214 |
# Is the below correct? Email of changed hold is sent to the receiving library |
| 215 |
# how does the sending library know to remove book from the holds shelf? |
| 216 |
is( $message->to_address, $branch_2->branchreplyto, "Message is sent to the incoming email of the library with the next hold"); |
| 217 |
is( $message->from_address, $branch_2->branchemail, "Message is sent from library's email"); |
| 208 |
}; |
218 |
}; |
| 209 |
|
219 |
|
| 210 |
$schema->storage->txn_rollback; |
220 |
$schema->storage->txn_rollback; |
| 211 |
- |
|
|