|
Lines 4-10
Link Here
|
| 4 |
# Current state is very rudimentary. Please help to extend it! |
4 |
# Current state is very rudimentary. Please help to extend it! |
| 5 |
|
5 |
|
| 6 |
use Modern::Perl; |
6 |
use Modern::Perl; |
| 7 |
use Test::More tests => 17; |
7 |
use Test::More tests => 18; |
| 8 |
|
8 |
|
| 9 |
use Koha::Database; |
9 |
use Koha::Database; |
| 10 |
use t::lib::TestBuilder; |
10 |
use t::lib::TestBuilder; |
|
Lines 22-27
use C4::Reserves qw( AddReserve ModReserve ModReserveAffect RevertWaitingStatus
Link Here
|
| 22 |
use Koha::CirculationRules; |
22 |
use Koha::CirculationRules; |
| 23 |
use Koha::Item::Transfer; |
23 |
use Koha::Item::Transfer; |
| 24 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
24 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
|
|
25 |
use Koha::Recalls; |
| 25 |
|
26 |
|
| 26 |
my $schema = Koha::Database->new->schema; |
27 |
my $schema = Koha::Database->new->schema; |
| 27 |
$schema->storage->txn_begin; |
28 |
$schema->storage->txn_begin; |
|
Lines 1043-1046
subtest item_circulation_status => sub {
Link Here
|
| 1043 |
is( $status, '01', "Item circulation status is damaged" ); |
1044 |
is( $status, '01', "Item circulation status is damaged" ); |
| 1044 |
$item->damaged(0)->store(); |
1045 |
$item->damaged(0)->store(); |
| 1045 |
}; |
1046 |
}; |
|
|
1047 |
|
| 1048 |
subtest do_checkout_with_recalls => sub { |
| 1049 |
plan tests => 7; |
| 1050 |
|
| 1051 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 1052 |
my $patron = $builder->build_object( |
| 1053 |
{ |
| 1054 |
class => 'Koha::Patrons', |
| 1055 |
value => { |
| 1056 |
branchcode => $library->branchcode, |
| 1057 |
} |
| 1058 |
} |
| 1059 |
); |
| 1060 |
my $patron2 = $builder->build_object( |
| 1061 |
{ |
| 1062 |
class => 'Koha::Patrons', |
| 1063 |
value => { |
| 1064 |
branchcode => $library->branchcode, |
| 1065 |
} |
| 1066 |
} |
| 1067 |
); |
| 1068 |
|
| 1069 |
t::lib::Mocks::mock_userenv( |
| 1070 |
{ branchcode => $library->branchcode, flags => 1 } ); |
| 1071 |
|
| 1072 |
my $item = $builder->build_sample_item( |
| 1073 |
{ |
| 1074 |
library => $library->branchcode, |
| 1075 |
} |
| 1076 |
); |
| 1077 |
|
| 1078 |
t::lib::Mocks::mock_preference('UseRecalls',1); |
| 1079 |
Koha::CirculationRules->set_rule({ |
| 1080 |
branchcode => undef, |
| 1081 |
categorycode => undef, |
| 1082 |
itemtype => undef, |
| 1083 |
rule_name => 'recalls_allowed', |
| 1084 |
rule_value => '10', |
| 1085 |
}); |
| 1086 |
|
| 1087 |
my $recall1 = Koha::Recall->new( |
| 1088 |
{ |
| 1089 |
patron_id => $patron2->borrowernumber, |
| 1090 |
created_date => \'NOW()', |
| 1091 |
biblio_id => $item->biblio->biblionumber, |
| 1092 |
pickup_library_id => $library->branchcode, |
| 1093 |
item_id => $item->itemnumber, |
| 1094 |
expiration_date => undef, |
| 1095 |
item_level => 1 |
| 1096 |
} |
| 1097 |
)->store; |
| 1098 |
|
| 1099 |
my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); |
| 1100 |
my $sip_item = C4::SIP::ILS::Item->new( $item->barcode ); |
| 1101 |
my $co_transaction = C4::SIP::ILS::Transaction::Checkout->new(); |
| 1102 |
is( $co_transaction->patron($sip_patron), |
| 1103 |
$sip_patron, "Patron assigned to transaction" ); |
| 1104 |
is( $co_transaction->item($sip_item), |
| 1105 |
$sip_item, "Item assigned to transaction" ); |
| 1106 |
|
| 1107 |
# Test recalls made by another patron |
| 1108 |
|
| 1109 |
$recall1->set_waiting({ item => $item }); |
| 1110 |
$co_transaction->do_checkout(); |
| 1111 |
is( $patron->checkouts->count, 0, 'Checkout was not done due to waiting recall'); |
| 1112 |
|
| 1113 |
$recall1->revert_waiting; |
| 1114 |
$recall1->start_transfer({ item => $item }); |
| 1115 |
$co_transaction->do_checkout(); |
| 1116 |
is( $patron->checkouts->count, 0, 'Checkout was not done due to recall in transit'); |
| 1117 |
|
| 1118 |
$recall1->revert_transfer; |
| 1119 |
$recall1->update({ item_id => undef, item_level => 0 }); |
| 1120 |
$co_transaction->do_checkout(); |
| 1121 |
is( $patron->checkouts->count, 0, 'Checkout was not done due to a biblio-level recall that this item could fill'); |
| 1122 |
|
| 1123 |
$recall1->set_cancelled; |
| 1124 |
|
| 1125 |
my $recall2 = Koha::Recall->new( |
| 1126 |
{ |
| 1127 |
patron_id => $patron->borrowernumber, |
| 1128 |
created_date => \'NOW()', |
| 1129 |
biblio_id => $item->biblio->biblionumber, |
| 1130 |
pickup_library_id => $library->branchcode, |
| 1131 |
item_id => $item->itemnumber, |
| 1132 |
expiration_date => undef, |
| 1133 |
item_level => 1 |
| 1134 |
} |
| 1135 |
)->store; |
| 1136 |
|
| 1137 |
# Test recalls made by SIP patron |
| 1138 |
|
| 1139 |
$recall2->set_waiting({ item => $item }); |
| 1140 |
$co_transaction->do_checkout(); |
| 1141 |
is( $patron->checkouts->count, 1, 'Checkout was done because recalled item was allocated to them' ); |
| 1142 |
$recall2 = Koha::Recalls->find( $recall2->id ); |
| 1143 |
is( $recall2->status, 'fulfilled', 'Recall is fulfilled by checked out item' ); |
| 1144 |
}; |
| 1145 |
|
| 1046 |
$schema->storage->txn_rollback; |
1146 |
$schema->storage->txn_rollback; |
| 1047 |
- |
|
|