Lines 672-725
subtest '_koha_notify_reserve() tests' => sub {
Link Here
|
672 |
}; |
672 |
}; |
673 |
|
673 |
|
674 |
subtest 'ReservesNeedReturns' => sub { |
674 |
subtest 'ReservesNeedReturns' => sub { |
675 |
plan tests => 4; |
675 |
plan tests => 10; |
676 |
|
676 |
|
677 |
my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } ); |
|
|
678 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
677 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
679 |
my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes', value => { rentalcharge => 0 } } ); |
|
|
680 |
my $item_info = { |
678 |
my $item_info = { |
681 |
biblionumber => $biblioitem->biblionumber, |
|
|
682 |
biblioitemnumber => $biblioitem->biblioitemnumber, |
683 |
homebranch => $library->branchcode, |
679 |
homebranch => $library->branchcode, |
684 |
holdingbranch => $library->branchcode, |
680 |
holdingbranch => $library->branchcode, |
685 |
itype => $itemtype->itemtype, |
|
|
686 |
}; |
681 |
}; |
687 |
my $item = $builder->build_object( { class => 'Koha::Items', value => $item_info } ); |
682 |
my $item = $builder->build_sample_item($item_info); |
688 |
my $patron = $builder->build_object( |
683 |
my $patron = $builder->build_object( |
689 |
{ |
684 |
{ |
690 |
class => 'Koha::Patrons', |
685 |
class => 'Koha::Patrons', |
691 |
value => { branchcode => $library->branchcode, } |
686 |
value => { branchcode => $library->branchcode, } |
692 |
} |
687 |
} |
693 |
); |
688 |
); |
694 |
|
689 |
my $patron_2 = $builder->build_object( |
695 |
my $priority = 1; |
690 |
{ |
696 |
my ( $hold_id, $hold ); |
691 |
class => 'Koha::Patrons', |
697 |
|
692 |
value => { branchcode => $library->branchcode, } |
698 |
t::lib::Mocks::mock_preference('ReservesNeedReturns', 0); # '0' means 'Automatically mark a hold as found and waiting' |
693 |
} |
699 |
$hold_id = C4::Reserves::AddReserve( |
|
|
700 |
$library->branchcode, $patron->borrowernumber, |
701 |
$item->biblionumber, '', |
702 |
$priority, undef, |
703 |
undef, '', |
704 |
"title for fee", $item->itemnumber, |
705 |
); |
694 |
); |
706 |
$hold = Koha::Holds->find($hold_id); |
|
|
707 |
is( $hold->priority, 0, 'If ReservesNeedReturns is 0, priority must have been set to 0' ); |
708 |
is( $hold->found, 'W', 'If ReservesNeedReturns is 0, found must have been set waiting' ); |
709 |
|
695 |
|
710 |
$hold->delete; # cleanup |
696 |
my $priority = 1; |
711 |
|
697 |
|
712 |
t::lib::Mocks::mock_preference('ReservesNeedReturns', 1); # '0' means "Don't automatically mark a hold as found and waiting" |
698 |
t::lib::Mocks::mock_preference('ReservesNeedReturns', 1); # Test with feature disabled |
713 |
$hold_id = C4::Reserves::AddReserve( |
699 |
my $hold = place_item_hold( $patron, $item, $library, $priority ); |
714 |
$library->branchcode, $patron->borrowernumber, |
|
|
715 |
$item->biblionumber, '', |
716 |
$priority, undef, |
717 |
undef, '', |
718 |
"title for fee", $item->itemnumber, |
719 |
); |
720 |
$hold = Koha::Holds->find($hold_id); |
721 |
is( $hold->priority, $priority, 'If ReservesNeedReturns is 1, priority must not have been set to changed' ); |
700 |
is( $hold->priority, $priority, 'If ReservesNeedReturns is 1, priority must not have been set to changed' ); |
722 |
is( $hold->found, undef, 'If ReservesNeedReturns is 1, found must not have been set waiting' ); |
701 |
is( $hold->found, undef, 'If ReservesNeedReturns is 1, found must not have been set waiting' ); |
|
|
702 |
$hold->delete; |
703 |
|
704 |
t::lib::Mocks::mock_preference('ReservesNeedReturns', 0); # '0' means 'Automatically mark a hold as found and waiting' |
705 |
$hold = place_item_hold( $patron, $item, $library, $priority ); |
706 |
is( $hold->priority, 0, 'If ReservesNeedReturns is 0 and no other status, priority must have been set to 0' ); |
707 |
is( $hold->found, 'W', 'If ReservesNeedReturns is 0 and no other status, found must have been set waiting' ); |
708 |
$hold->delete; |
709 |
|
710 |
$item->onloan('2010-01-01')->store; |
711 |
$hold = place_item_hold( $patron, $item, $library, $priority ); |
712 |
isnt( $hold->priority, 0, 'If ReservesNeedReturns is 0 but item onloan priority must not be set to 0' ); |
713 |
$hold->delete; |
714 |
|
715 |
t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 0); # '0' means damaged holds not allowed |
716 |
$item->onloan(undef)->damaged(1)->store; |
717 |
$hold = place_item_hold( $patron, $item, $library, $priority ); |
718 |
isnt( $hold->priority, 0, 'If ReservesNeedReturns is 0 but item damaged and not allowed holds on damaged items priority must not be set to 0' ); |
719 |
$hold->delete; |
720 |
t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1); # '0' means damaged holds not allowed |
721 |
$hold = place_item_hold( $patron, $item, $library, $priority ); |
722 |
is( $hold->priority, 0, 'If ReservesNeedReturns is 0 and damaged holds allowed, priority must have been set to 0' ); |
723 |
is( $hold->found, 'W', 'If ReservesNeedReturns is 0 and damaged holds allowed, found must have been set waiting' ); |
724 |
|
725 |
my $hold_1 = place_item_hold( $patron, $item, $library, $priority ); |
726 |
$hold = place_item_hold( $patron_2, $item, $library, $priority ); |
727 |
isnt( $hold->priority, 0, 'If ReservesNeedReturns is 0 but item already on hold priority must not be set to 0' ); |
728 |
$hold->delete; |
729 |
$hold_1->delete; |
730 |
|
731 |
$hold->delete; |
732 |
$builder->build({ source => "Branchtransfer", value => { |
733 |
itemnumber => $item->itemnumber, |
734 |
datearrived => undef, |
735 |
} }); |
736 |
$item->damaged(0)->store; |
737 |
$hold = place_item_hold( $patron, $item, $library, $priority ); |
738 |
isnt( $hold->priority, 0, 'If ReservesNeedReturns is 0 but item in transit the hold must not be set to waiting' ); |
739 |
|
740 |
t::lib::Mocks::mock_preference('ReservesNeedReturns', 1); # Don't affect other tests |
723 |
}; |
741 |
}; |
724 |
|
742 |
|
725 |
subtest 'ChargeReserveFee tests' => sub { |
743 |
subtest 'ChargeReserveFee tests' => sub { |
Lines 845-849
sub count_hold_print_messages {
Link Here
|
845 |
return $message_count->[0]->[0]; |
863 |
return $message_count->[0]->[0]; |
846 |
} |
864 |
} |
847 |
|
865 |
|
|
|
866 |
sub place_item_hold { |
867 |
my ($patron,$item,$library,$priority) = @_; |
868 |
|
869 |
my $hold_id = C4::Reserves::AddReserve( |
870 |
$library->branchcode, $patron->borrowernumber, |
871 |
$item->biblionumber, '', |
872 |
$priority, undef, |
873 |
undef, '', |
874 |
"title for fee", $item->itemnumber, |
875 |
); |
876 |
my $hold = Koha::Holds->find($hold_id); |
877 |
return $hold; |
878 |
} |
879 |
|
848 |
# we reached the finish |
880 |
# we reached the finish |
849 |
$schema->storage->txn_rollback(); |
881 |
$schema->storage->txn_rollback(); |
850 |
- |
|
|