Lines 21-27
Link Here
|
21 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
21 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
22 |
|
22 |
|
23 |
use Modern::Perl; |
23 |
use Modern::Perl; |
24 |
use Test::More tests => 11; |
24 |
use Test::More tests => 13; |
25 |
use Test::Exception; |
25 |
use Test::Exception; |
26 |
use Test::MockObject; |
26 |
use Test::MockObject; |
27 |
use Test::MockModule; |
27 |
use Test::MockModule; |
Lines 77-82
subtest 'Checkout V2' => sub {
Link Here
|
77 |
$schema->storage->txn_rollback; |
77 |
$schema->storage->txn_rollback; |
78 |
}; |
78 |
}; |
79 |
|
79 |
|
|
|
80 |
subtest 'Test checkout desensitize' => sub { |
81 |
my $schema = Koha::Database->new->schema; |
82 |
$schema->storage->txn_begin; |
83 |
plan tests => 3; |
84 |
$C4::SIP::Sip::protocol_version = 2; |
85 |
test_checkout_desensitize(); |
86 |
$schema->storage->txn_rollback; |
87 |
}; |
88 |
|
89 |
subtest 'Test renew desensitize' => sub { |
90 |
my $schema = Koha::Database->new->schema; |
91 |
$schema->storage->txn_begin; |
92 |
plan tests => 3; |
93 |
$C4::SIP::Sip::protocol_version = 2; |
94 |
test_renew_desensitize(); |
95 |
$schema->storage->txn_rollback; |
96 |
}; |
97 |
|
80 |
subtest 'Checkin V2' => sub { |
98 |
subtest 'Checkin V2' => sub { |
81 |
my $schema = Koha::Database->new->schema; |
99 |
my $schema = Koha::Database->new->schema; |
82 |
$schema->storage->txn_begin; |
100 |
$schema->storage->txn_begin; |
Lines 841-846
sub test_hold_patron_bcode {
Link Here
|
841 |
is( $resp, q{}, "maybe_add returns empty string for SIP item with no hold returns empty string" ); |
859 |
is( $resp, q{}, "maybe_add returns empty string for SIP item with no hold returns empty string" ); |
842 |
} |
860 |
} |
843 |
|
861 |
|
|
|
862 |
sub test_checkout_desensitize { |
863 |
my $builder = t::lib::TestBuilder->new(); |
864 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
865 |
my ( $response, $findpatron ); |
866 |
my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); |
867 |
|
868 |
# create some data |
869 |
my $patron1 = $builder->build({ |
870 |
source => 'Borrower', |
871 |
value => { |
872 |
password => hash_password( PATRON_PW ), |
873 |
}, |
874 |
}); |
875 |
my $card1 = $patron1->{cardnumber}; |
876 |
my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 ); |
877 |
my $patron_category = $sip_patron1->ptype(); |
878 |
$findpatron = $sip_patron1; |
879 |
my $item_object = $builder->build_sample_item({ |
880 |
damaged => 0, |
881 |
withdrawn => 0, |
882 |
itemlost => 0, |
883 |
restricted => 0, |
884 |
homebranch => $branchcode, |
885 |
holdingbranch => $branchcode, |
886 |
}); |
887 |
|
888 |
my $mockILS = $mocks->{ils}; |
889 |
my $server = { ils => $mockILS, account => {} }; |
890 |
$mockILS->mock( 'institution', sub { $branchcode; } ); |
891 |
$mockILS->mock( 'supports', sub { return; } ); |
892 |
$mockILS->mock( 'checkout', sub { |
893 |
shift; |
894 |
return C4::SIP::ILS->checkout(@_); |
895 |
}); |
896 |
my $today = dt_from_string; |
897 |
t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 }); |
898 |
t::lib::Mocks::mock_preference( 'CheckPrevCheckout', 'hardyes' ); |
899 |
|
900 |
my $siprequest = CHECKOUT . 'YN' . siprequestdate($today) . |
901 |
siprequestdate( $today->clone->add( days => 1) ) . |
902 |
FID_INST_ID . $branchcode . '|'. |
903 |
FID_PATRON_ID . $sip_patron1->id . '|' . |
904 |
FID_ITEM_ID . $item_object->barcode . '|' . |
905 |
FID_TERMINAL_PWD . 'ignored' . '|'; |
906 |
|
907 |
undef $response; |
908 |
my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
909 |
$server->{account}->{never_demagnitize} = "A,$patron_category,Z"; |
910 |
$msg->handle_checkout( $server ); |
911 |
my $respcode = substr( $response, 5, 1 ); |
912 |
is( $respcode, 'N', "Desensitize flag was not set for patron category in never_demagnitize" ); |
913 |
|
914 |
undef $response; |
915 |
$server->{account}->{never_demagnitize} = "A,B,C"; |
916 |
$msg->handle_checkout( $server ); |
917 |
$respcode = substr( $response, 5, 1 ); |
918 |
is( $respcode, 'Y', "Desensitize flag was set for patron category not in never_demagnitize" ); |
919 |
|
920 |
undef $response; |
921 |
$server->{account}->{never_demagnitize} = ""; |
922 |
$msg->handle_checkout( $server ); |
923 |
$respcode = substr( $response, 5, 1 ); |
924 |
is( $respcode, 'Y', "Desensitize flag was set for empty never_demagnitize" ); |
925 |
} |
926 |
|
927 |
sub test_renew_desensitize { |
928 |
my $builder = t::lib::TestBuilder->new(); |
929 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
930 |
my ( $response, $findpatron ); |
931 |
my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); |
932 |
|
933 |
# create some data |
934 |
my $patron1 = $builder->build({ |
935 |
source => 'Borrower', |
936 |
value => { |
937 |
password => hash_password( PATRON_PW ), |
938 |
}, |
939 |
}); |
940 |
my $card1 = $patron1->{cardnumber}; |
941 |
my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 ); |
942 |
my $patron_category = $sip_patron1->ptype(); |
943 |
$findpatron = $sip_patron1; |
944 |
my $item_object = $builder->build_sample_item({ |
945 |
damaged => 0, |
946 |
withdrawn => 0, |
947 |
itemlost => 0, |
948 |
restricted => 0, |
949 |
homebranch => $branchcode, |
950 |
holdingbranch => $branchcode, |
951 |
}); |
952 |
|
953 |
my $mockILS = $mocks->{ils}; |
954 |
my $server = { ils => $mockILS, account => {} }; |
955 |
$mockILS->mock( 'institution', sub { $branchcode; } ); |
956 |
$mockILS->mock( 'supports', sub { return; } ); |
957 |
$mockILS->mock( 'checkout', sub { |
958 |
shift; |
959 |
return C4::SIP::ILS->checkout(@_); |
960 |
}); |
961 |
my $today = dt_from_string; |
962 |
t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 }); |
963 |
|
964 |
my $issue = Koha::Checkout->new({ branchcode => $branchcode, borrowernumber => $patron1->{borrowernumber}, itemnumber => $item_object->itemnumber })->store; |
965 |
|
966 |
my $siprequest = RENEW . 'YN' . siprequestdate($today) . |
967 |
siprequestdate( $today->clone->add( days => 1) ) . |
968 |
FID_INST_ID . $branchcode . '|'. |
969 |
FID_PATRON_ID . $sip_patron1->id . '|' . |
970 |
FID_ITEM_ID . $item_object->barcode . '|' . |
971 |
FID_TERMINAL_PWD . 'ignored' . '|'; |
972 |
|
973 |
undef $response; |
974 |
my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
975 |
$server->{account}->{never_demagnitize} = "A,$patron_category,Z"; |
976 |
$msg->handle_checkout( $server ); |
977 |
my $respcode = substr( $response, 5, 1 ); |
978 |
is( $respcode, 'N', "Desensitize flag was not set for patron category in never_demagnitize" ); |
979 |
|
980 |
undef $response; |
981 |
$server->{account}->{never_demagnitize} = "A,B,C"; |
982 |
$msg->handle_checkout( $server ); |
983 |
$respcode = substr( $response, 5, 1 ); |
984 |
is( $respcode, 'Y', "Desensitize flag was set for patron category not in never_demagnitize" ); |
985 |
|
986 |
undef $response; |
987 |
$server->{account}->{never_demagnitize} = ""; |
988 |
$msg->handle_checkout( $server ); |
989 |
$respcode = substr( $response, 5, 1 ); |
990 |
is( $respcode, 'Y', "Desensitize flag was set for empty never_demagnitize" ); |
991 |
} |
992 |
|
844 |
# Helper routines |
993 |
# Helper routines |
845 |
|
994 |
|
846 |
sub create_mocks { |
995 |
sub create_mocks { |
847 |
- |
|
|