|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 2; |
20 |
use Test::More tests => 6; |
| 21 |
use Test::Exception; |
21 |
use Test::Exception; |
| 22 |
|
22 |
|
| 23 |
use Koha::Database; |
23 |
use Koha::Database; |
|
Lines 284-286
subtest "resolve() tests" => sub {
Link Here
|
| 284 |
|
284 |
|
| 285 |
$schema->storage->txn_rollback; |
285 |
$schema->storage->txn_rollback; |
| 286 |
}; |
286 |
}; |
| 287 |
- |
287 |
|
|
|
288 |
subtest 'item() tests' => sub { |
| 289 |
|
| 290 |
plan tests => 3; |
| 291 |
|
| 292 |
$schema->storage->txn_begin; |
| 293 |
|
| 294 |
my $librarian = $builder->build_object({ class => 'Koha::Patrons' }); |
| 295 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 296 |
my $item = $builder->build_sample_item; |
| 297 |
my $checkout = $builder->build_object( |
| 298 |
{ |
| 299 |
class => 'Koha::Checkouts', |
| 300 |
value => { |
| 301 |
borrowernumber => $patron->borrowernumber, |
| 302 |
itemnumber => $item->itemnumber, |
| 303 |
branchcode => $patron->branchcode |
| 304 |
} |
| 305 |
} |
| 306 |
); |
| 307 |
|
| 308 |
my $claim = Koha::Checkouts::ReturnClaim->new( |
| 309 |
{ |
| 310 |
issue_id => $checkout->id, |
| 311 |
itemnumber => $checkout->itemnumber, |
| 312 |
borrowernumber => $checkout->borrowernumber, |
| 313 |
notes => 'Some notes', |
| 314 |
created_by => $librarian->borrowernumber |
| 315 |
} |
| 316 |
)->store; |
| 317 |
|
| 318 |
my $return_claim_item = $claim->item; |
| 319 |
is( ref( $return_claim_item ), 'Koha::Item', 'Koha::Checkouts::ReturnClaim->item should return a Koha::Item' ); |
| 320 |
is( $claim->itemnumber, $return_claim_item->itemnumber, 'Koha::Checkouts::ReturnClaim->item should return the correct item' ); |
| 321 |
|
| 322 |
my $itemnumber = $item->itemnumber; |
| 323 |
$checkout->delete; # Required to allow deletion of item |
| 324 |
$item->delete; |
| 325 |
|
| 326 |
my $claims = Koha::Checkouts::ReturnClaims->search({ itemnumber => $itemnumber }); |
| 327 |
is( $claims->count, 0, 'Koha::Checkouts::ReturnClaim is deleted on item deletion' ); |
| 328 |
|
| 329 |
$schema->storage->txn_rollback; |
| 330 |
}; |
| 331 |
|
| 332 |
subtest 'patron() tests' => sub { |
| 333 |
|
| 334 |
plan tests => 3; |
| 335 |
|
| 336 |
$schema->storage->txn_begin; |
| 337 |
|
| 338 |
my $librarian = $builder->build_object({ class => 'Koha::Patrons' }); |
| 339 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 340 |
my $item = $builder->build_sample_item; |
| 341 |
my $checkout = $builder->build_object( |
| 342 |
{ |
| 343 |
class => 'Koha::Checkouts', |
| 344 |
value => { |
| 345 |
borrowernumber => $patron->borrowernumber, |
| 346 |
itemnumber => $item->itemnumber, |
| 347 |
branchcode => $patron->branchcode |
| 348 |
} |
| 349 |
} |
| 350 |
); |
| 351 |
|
| 352 |
my $claim = Koha::Checkouts::ReturnClaim->new( |
| 353 |
{ |
| 354 |
issue_id => $checkout->id, |
| 355 |
itemnumber => $checkout->itemnumber, |
| 356 |
borrowernumber => $checkout->borrowernumber, |
| 357 |
notes => 'Some notes', |
| 358 |
created_by => $librarian->borrowernumber |
| 359 |
} |
| 360 |
)->store; |
| 361 |
|
| 362 |
my $return_claim_patron = $claim->patron; |
| 363 |
is( ref( $return_claim_patron ), 'Koha::Patron', 'Koha::Checkouts::ReturnClaim->patron should return a Koha::Patron' ); |
| 364 |
is( $claim->borrowernumber, $return_claim_patron->borrowernumber, 'Koha::Checkouts::ReturnClaim->patron should return the correct borrower' ); |
| 365 |
|
| 366 |
my $borrowernumber = $patron->borrowernumber; |
| 367 |
$checkout->delete; # Required to allow deletion of patron |
| 368 |
$patron->delete; |
| 369 |
|
| 370 |
my $claims = Koha::Checkouts::ReturnClaims->search({ borrowernumber => $borrowernumber }); |
| 371 |
is( $claims->count, 0, 'Koha::Checkouts::ReturnClaim is deleted on borrower deletion' ); |
| 372 |
|
| 373 |
$schema->storage->txn_rollback; |
| 374 |
}; |
| 375 |
|
| 376 |
subtest 'old_checkout() tests' => sub { |
| 377 |
|
| 378 |
plan tests => 4; |
| 379 |
|
| 380 |
$schema->storage->txn_begin; |
| 381 |
|
| 382 |
my $librarian = $builder->build_object({ class => 'Koha::Patrons' }); |
| 383 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 384 |
my $item = $builder->build_sample_item; |
| 385 |
my $old_checkout = $builder->build_object( |
| 386 |
{ |
| 387 |
class => 'Koha::Old::Checkouts', |
| 388 |
value => { |
| 389 |
borrowernumber => $patron->borrowernumber, |
| 390 |
itemnumber => $item->itemnumber, |
| 391 |
branchcode => $patron->branchcode |
| 392 |
} |
| 393 |
} |
| 394 |
); |
| 395 |
|
| 396 |
my $claim = Koha::Checkouts::ReturnClaim->new( |
| 397 |
{ |
| 398 |
issue_id => $old_checkout->id, |
| 399 |
itemnumber => $old_checkout->itemnumber, |
| 400 |
borrowernumber => $old_checkout->borrowernumber, |
| 401 |
notes => 'Some notes', |
| 402 |
created_by => $librarian->borrowernumber |
| 403 |
} |
| 404 |
)->store; |
| 405 |
|
| 406 |
my $return_claim_old_checkout = $claim->old_checkout; |
| 407 |
is( ref( $return_claim_old_checkout ), 'Koha::Old::Checkout', 'Koha::Checkouts::ReturnClaim->old_checkout should return a Koha::Old::Checkout' ); |
| 408 |
is( $claim->issue_id, $return_claim_old_checkout->issue_id, 'Koha::Checkouts::ReturnClaim->old_checkout should return the correct borrower' ); |
| 409 |
|
| 410 |
my $issue_id = $old_checkout->issue_id; |
| 411 |
$old_checkout->delete; |
| 412 |
|
| 413 |
my $claims = Koha::Checkouts::ReturnClaims->search({ issue_id => $issue_id }); |
| 414 |
is( $claims->count, 1, 'Koha::Checkouts::ReturnClaim remains on old_checkout deletion' ); |
| 415 |
# FIXME: Should we actually set null on OldCheckout deletion? |
| 416 |
|
| 417 |
$claim->issue_id(undef)->store; |
| 418 |
is( $claim->old_checkout, undef, 'Koha::Checkouts::ReturnClaim->old_checkout should return undef if no old_checkout linked' ); |
| 419 |
|
| 420 |
$schema->storage->txn_rollback; |
| 421 |
}; |
| 422 |
|
| 423 |
subtest 'checkout() tests' => sub { |
| 424 |
|
| 425 |
plan tests => 4; |
| 426 |
|
| 427 |
$schema->storage->txn_begin; |
| 428 |
|
| 429 |
my $librarian = $builder->build_object({ class => 'Koha::Patrons' }); |
| 430 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 431 |
my $item = $builder->build_sample_item; |
| 432 |
my $checkout = $builder->build_object( |
| 433 |
{ |
| 434 |
class => 'Koha::Checkouts', |
| 435 |
value => { |
| 436 |
borrowernumber => $patron->borrowernumber, |
| 437 |
itemnumber => $item->itemnumber, |
| 438 |
branchcode => $patron->branchcode |
| 439 |
} |
| 440 |
} |
| 441 |
); |
| 442 |
|
| 443 |
my $claim = Koha::Checkouts::ReturnClaim->new( |
| 444 |
{ |
| 445 |
issue_id => $checkout->id, |
| 446 |
itemnumber => $checkout->itemnumber, |
| 447 |
borrowernumber => $checkout->borrowernumber, |
| 448 |
notes => 'Some notes', |
| 449 |
created_by => $librarian->borrowernumber |
| 450 |
} |
| 451 |
)->store; |
| 452 |
|
| 453 |
my $return_claim_checkout = $claim->checkout; |
| 454 |
is( ref( $return_claim_checkout ), 'Koha::Checkout', 'Koha::Checkouts::ReturnClaim->checkout should return a Koha::Checkout' ); |
| 455 |
is( $claim->issue_id, $return_claim_checkout->issue_id, 'Koha::Checkouts::ReturnClaim->checkout should return the correct borrower' ); |
| 456 |
|
| 457 |
my $issue_id = $checkout->issue_id; |
| 458 |
$checkout->delete; |
| 459 |
|
| 460 |
my $claims = Koha::Checkouts::ReturnClaims->search({ issue_id => $issue_id }); |
| 461 |
is( $claims->count, 1, 'Koha::Checkouts::ReturnClaim remains on checkout deletion' ); |
| 462 |
|
| 463 |
$claim->issue_id(undef)->store; |
| 464 |
is( $claim->checkout, undef, 'Koha::Checkouts::ReturnClaim->checkout should return undef if no checkout linked' ); |
| 465 |
|
| 466 |
$schema->storage->txn_rollback; |
| 467 |
}; |