Lines 17-26
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 1; |
20 |
use Test::More tests => 2; |
21 |
use Test::Exception; |
21 |
use Test::Exception; |
22 |
|
22 |
|
23 |
use Koha::Database; |
23 |
use Koha::Database; |
|
|
24 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
24 |
use Koha::Checkouts::ReturnClaims; |
25 |
use Koha::Checkouts::ReturnClaims; |
25 |
|
26 |
|
26 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
Lines 148-150
subtest "store() tests" => sub {
Link Here
|
148 |
|
149 |
|
149 |
$schema->storage->txn_rollback; |
150 |
$schema->storage->txn_rollback; |
150 |
}; |
151 |
}; |
151 |
- |
152 |
|
|
|
153 |
subtest "resolve() tests" => sub { |
154 |
|
155 |
plan tests => 9; |
156 |
|
157 |
$schema->storage->txn_begin; |
158 |
|
159 |
my $itemlost = 1; |
160 |
my $librarian = $builder->build_object({ class => 'Koha::Patrons' }); |
161 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
162 |
my $item = $builder->build_sample_item({ itemlost => $itemlost }); |
163 |
|
164 |
my $checkout = $builder->build_object( |
165 |
{ |
166 |
class => 'Koha::Checkouts', |
167 |
value => { |
168 |
borrowernumber => $patron->borrowernumber, |
169 |
itemnumber => $item->itemnumber, |
170 |
branchcode => $patron->branchcode |
171 |
} |
172 |
} |
173 |
); |
174 |
|
175 |
my $claim = Koha::Checkouts::ReturnClaim->new( |
176 |
{ |
177 |
issue_id => $checkout->id, |
178 |
itemnumber => $checkout->itemnumber, |
179 |
borrowernumber => $checkout->borrowernumber, |
180 |
notes => 'Some notes', |
181 |
created_by => $librarian->borrowernumber |
182 |
} |
183 |
)->store; |
184 |
|
185 |
throws_ok |
186 |
{ $claim->resolve({ resolution => 1 }); } |
187 |
'Koha::Exceptions::MissingParameter', |
188 |
"Not passing 'resolved_by' makes it throw an exception"; |
189 |
|
190 |
throws_ok |
191 |
{ $claim->resolve({ resolved_by => 1 }); } |
192 |
'Koha::Exceptions::MissingParameter', |
193 |
"Not passing 'resolution' makes it throw an exception"; |
194 |
|
195 |
my $deleted_patron = $builder->build_object({ class => 'Koha::Patrons' }); |
196 |
my $deleted_patron_id = $deleted_patron->id; |
197 |
$deleted_patron->delete; |
198 |
|
199 |
{ # hide useless warnings |
200 |
local *STDERR; |
201 |
open STDERR, '>', '/dev/null'; |
202 |
|
203 |
throws_ok |
204 |
{ $claim->resolve({ resolution => "X", resolved_by => $deleted_patron_id }) } |
205 |
'Koha::Exceptions::Object::FKConstraint', |
206 |
"Exception thrown on invalid resolver"; |
207 |
|
208 |
close STDERR; |
209 |
} |
210 |
|
211 |
my $today = dt_from_string; |
212 |
my $tomorrow = dt_from_string->add( days => 1 ); |
213 |
|
214 |
$claim->resolve( |
215 |
{ |
216 |
resolution => "X", |
217 |
resolved_by => $librarian->id, |
218 |
resolved_on => $tomorrow, |
219 |
} |
220 |
)->discard_changes; |
221 |
|
222 |
is( output_pref( { str => $claim->resolved_on } ), output_pref( { dt => $tomorrow } ), 'resolved_on set to the passed param' ); |
223 |
is( $claim->updated_by, $librarian->id, 'updated_by set to the passed resolved_by' ); |
224 |
|
225 |
# Make sure $item is refreshed |
226 |
$item->discard_changes; |
227 |
is( $item->itemlost, $itemlost, 'Item lost status remains unchanged' ); |
228 |
|
229 |
# New checkout and claim |
230 |
$checkout->delete; |
231 |
$checkout = $builder->build_object( |
232 |
{ |
233 |
class => 'Koha::Checkouts', |
234 |
value => { |
235 |
borrowernumber => $patron->borrowernumber, |
236 |
itemnumber => $item->itemnumber, |
237 |
branchcode => $patron->branchcode |
238 |
} |
239 |
} |
240 |
); |
241 |
|
242 |
$claim = Koha::Checkouts::ReturnClaim->new( |
243 |
{ |
244 |
issue_id => $checkout->id, |
245 |
itemnumber => $checkout->itemnumber, |
246 |
borrowernumber => $checkout->borrowernumber, |
247 |
notes => 'Some notes', |
248 |
created_by => $librarian->borrowernumber |
249 |
} |
250 |
)->store; |
251 |
|
252 |
my $new_lost_status = 2; |
253 |
|
254 |
$claim->resolve( |
255 |
{ |
256 |
resolution => "X", |
257 |
resolved_by => $librarian->id, |
258 |
resolved_on => $tomorrow, |
259 |
new_lost_status => $new_lost_status, |
260 |
} |
261 |
)->discard_changes; |
262 |
|
263 |
is( output_pref( { str => $claim->resolved_on } ), output_pref( { dt => $tomorrow } ), 'resolved_on set to the passed param' ); |
264 |
is( $claim->updated_by, $librarian->id, 'updated_by set to the passed resolved_by' ); |
265 |
|
266 |
# Make sure $item is refreshed |
267 |
$item->discard_changes; |
268 |
is( $item->itemlost, $new_lost_status, 'Item lost status is updated' ); |
269 |
|
270 |
$schema->storage->txn_rollback; |
271 |
}; |