Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 6; |
22 |
use Test::More tests => 7; |
23 |
|
23 |
|
24 |
use C4::Biblio; |
24 |
use C4::Biblio; |
25 |
use C4::Circulation; |
25 |
use C4::Circulation; |
Lines 493-495
subtest 'renewal_branchcode' => sub {
Link Here
|
493 |
is( $item->renewal_branchcode({branch=>'MANATEE'}), $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item even if branch passed"); |
493 |
is( $item->renewal_branchcode({branch=>'MANATEE'}), $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item even if branch passed"); |
494 |
|
494 |
|
495 |
}; |
495 |
}; |
496 |
- |
496 |
|
|
|
497 |
subtest 'Recalls tests' => sub { |
498 |
|
499 |
plan tests => 17; |
500 |
|
501 |
$schema->storage->txn_begin; |
502 |
|
503 |
my $item1 = $builder->build_sample_item; |
504 |
my $biblio = $item1->biblio; |
505 |
my $branchcode = $item1->holdingbranch; |
506 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $branchcode } }); |
507 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $branchcode } }); |
508 |
my $patron3 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $branchcode } }); |
509 |
my $item2 = $builder->build_object({ class => 'Koha::Items', value => { holdingbranch => $branchcode, homebranch => $branchcode, biblionumber => $biblio->biblionumber, itype => $item1->effective_itemtype } }); |
510 |
t::lib::Mocks::mock_userenv({ patron => $patron1 }); |
511 |
|
512 |
my $recall1 = Koha::Recall->new({ |
513 |
borrowernumber => $patron1->borrowernumber, |
514 |
recalldate => Koha::DateUtils::dt_from_string, |
515 |
biblionumber => $biblio->biblionumber, |
516 |
branchcode => $branchcode, |
517 |
status => 'R', |
518 |
itemnumber => $item1->itemnumber, |
519 |
expirationdate => undef, |
520 |
item_level_recall => 1 |
521 |
})->store; |
522 |
my $recall2 = Koha::Recall->new({ |
523 |
borrowernumber => $patron2->borrowernumber, |
524 |
recalldate => Koha::DateUtils::dt_from_string, |
525 |
biblionumber => $biblio->biblionumber, |
526 |
branchcode => $branchcode, |
527 |
status => 'R', |
528 |
itemnumber => $item1->itemnumber, |
529 |
expirationdate => undef, |
530 |
item_level_recall =>1 |
531 |
})->store; |
532 |
|
533 |
is( $item1->recall->borrowernumber, $patron1->borrowernumber, 'Correctly returns most relevant recall' ); |
534 |
|
535 |
$recall2->set_cancelled; |
536 |
|
537 |
t::lib::Mocks::mock_preference('UseRecalls', 0); |
538 |
is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall with UseRecalls disabled" ); |
539 |
|
540 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
541 |
|
542 |
$item1->update({ notforloan => 1 }); |
543 |
is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall that is not for loan" ); |
544 |
$item1->update({ notforloan => 0, itemlost => 1 }); |
545 |
is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall that is marked lost" ); |
546 |
$item1->update({ itemlost => 0, withdrawn => 1 }); |
547 |
is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall that is withdrawn" ); |
548 |
is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall item if not checked out" ); |
549 |
|
550 |
$item1->update({ withdrawn => 0 }); |
551 |
C4::Circulation::AddIssue( $patron2->unblessed, $item1->barcode ); |
552 |
|
553 |
Koha::CirculationRules->set_rules({ |
554 |
branchcode => $branchcode, |
555 |
categorycode => $patron1->categorycode, |
556 |
itemtype => $item1->effective_itemtype, |
557 |
rules => { |
558 |
recalls_allowed => 0, |
559 |
recalls_per_record => 1, |
560 |
on_shelf_recalls => 'all', |
561 |
}, |
562 |
}); |
563 |
is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if recalls_allowed = 0" ); |
564 |
|
565 |
Koha::CirculationRules->set_rules({ |
566 |
branchcode => $branchcode, |
567 |
categorycode => $patron1->categorycode, |
568 |
itemtype => $item1->effective_itemtype, |
569 |
rules => { |
570 |
recalls_allowed => 1, |
571 |
recalls_per_record => 1, |
572 |
on_shelf_recalls => 'all', |
573 |
}, |
574 |
}); |
575 |
is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has more existing recall(s) than recalls_allowed" ); |
576 |
is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has more existing recall(s) than recalls_per_record" ); |
577 |
is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has already recalled this item" ); |
578 |
|
579 |
my $reserve_id = C4::Reserves::AddReserve({ branchcode => $branchcode, borrowernumber => $patron1->borrowernumber, biblionumber => $item1->biblionumber, itemnumber => $item1->itemnumber }); |
580 |
is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall item if patron has already reserved it" ); |
581 |
C4::Reserves::ModReserve({ rank => 'del', reserve_id => $reserve_id, branchcode => $branchcode, itemnumber => $item1->itemnumber, borrowernumber => $patron1->borrowernumber, biblionumber => $item1->biblionumber }); |
582 |
|
583 |
$recall1->set_cancelled; |
584 |
is( $item1->can_be_recalled({ patron => $patron2 }), 0, "Can't recall if patron has already checked out an item attached to this biblio" ); |
585 |
|
586 |
is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if on_shelf_recalls = all and items are still available" ); |
587 |
|
588 |
Koha::CirculationRules->set_rules({ |
589 |
branchcode => $branchcode, |
590 |
categorycode => $patron1->categorycode, |
591 |
itemtype => $item1->effective_itemtype, |
592 |
rules => { |
593 |
recalls_allowed => 1, |
594 |
recalls_per_record => 1, |
595 |
on_shelf_recalls => 'any', |
596 |
}, |
597 |
}); |
598 |
C4::Circulation::AddReturn( $item1->barcode, $branchcode ); |
599 |
is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if no items are checked out" ); |
600 |
|
601 |
C4::Circulation::AddIssue( $patron2->unblessed, $item1->barcode ); |
602 |
is( $item1->can_be_recalled({ patron => $patron1 }), 1, "Can recall item" ); |
603 |
|
604 |
$recall1 = Koha::Recall->new({ |
605 |
borrowernumber => $patron1->borrowernumber, |
606 |
recalldate => Koha::DateUtils::dt_from_string, |
607 |
biblionumber => $biblio->biblionumber, |
608 |
branchcode => $branchcode, |
609 |
status => 'R', |
610 |
itemnumber => undef, |
611 |
expirationdate => undef, |
612 |
item_level_recall => 0 |
613 |
})->store; |
614 |
|
615 |
# Patron2 has Item1 checked out. Patron1 has placed a biblio-level recall on Biblio1, so check if Item1 can fulfill Patron1's recall. |
616 |
|
617 |
Koha::CirculationRules->set_rules({ |
618 |
branchcode => undef, |
619 |
categorycode => undef, |
620 |
itemtype => $item1->effective_itemtype, |
621 |
rules => { |
622 |
recalls_allowed => 0, |
623 |
recalls_per_record => 1, |
624 |
on_shelf_recalls => 'any', |
625 |
}, |
626 |
}); |
627 |
is( $item1->can_be_waiting_recall, 0, "Recalls not allowed for this itemtype" ); |
628 |
|
629 |
Koha::CirculationRules->set_rules({ |
630 |
branchcode => undef, |
631 |
categorycode => undef, |
632 |
itemtype => $item1->effective_itemtype, |
633 |
rules => { |
634 |
recalls_allowed => 1, |
635 |
recalls_per_record => 1, |
636 |
on_shelf_recalls => 'any', |
637 |
}, |
638 |
}); |
639 |
is( $item1->can_be_waiting_recall, 1, "Recalls are allowed for this itemtype" ); |
640 |
}; |