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 => 10; |
24 |
use Test::More tests => 12; |
25 |
use Test::MockObject; |
25 |
use Test::MockObject; |
26 |
use Test::MockModule; |
26 |
use Test::MockModule; |
27 |
use Test::Warn; |
27 |
use Test::Warn; |
Lines 76-81
subtest 'Checkout V2' => sub {
Link Here
|
76 |
$schema->storage->txn_rollback; |
76 |
$schema->storage->txn_rollback; |
77 |
}; |
77 |
}; |
78 |
|
78 |
|
|
|
79 |
subtest 'Test checkout desensitize' => sub { |
80 |
my $schema = Koha::Database->new->schema; |
81 |
$schema->storage->txn_begin; |
82 |
plan tests => 3; |
83 |
$C4::SIP::Sip::protocol_version = 2; |
84 |
test_checkout_desensitize(); |
85 |
$schema->storage->txn_rollback; |
86 |
}; |
87 |
|
88 |
subtest 'Test renew desensitize' => sub { |
89 |
my $schema = Koha::Database->new->schema; |
90 |
$schema->storage->txn_begin; |
91 |
plan tests => 3; |
92 |
$C4::SIP::Sip::protocol_version = 2; |
93 |
test_renew_desensitize(); |
94 |
$schema->storage->txn_rollback; |
95 |
}; |
96 |
|
79 |
subtest 'Checkin V2' => sub { |
97 |
subtest 'Checkin V2' => sub { |
80 |
my $schema = Koha::Database->new->schema; |
98 |
my $schema = Koha::Database->new->schema; |
81 |
$schema->storage->txn_begin; |
99 |
$schema->storage->txn_begin; |
Lines 793-798
sub test_hold_patron_bcode {
Link Here
|
793 |
is( $resp, q{}, "maybe_add returns empty string for SIP item with no hold returns empty string" ); |
811 |
is( $resp, q{}, "maybe_add returns empty string for SIP item with no hold returns empty string" ); |
794 |
} |
812 |
} |
795 |
|
813 |
|
|
|
814 |
sub test_checkout_desensitize { |
815 |
my $builder = t::lib::TestBuilder->new(); |
816 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
817 |
my ( $response, $findpatron ); |
818 |
my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); |
819 |
|
820 |
# create some data |
821 |
my $patron1 = $builder->build({ |
822 |
source => 'Borrower', |
823 |
value => { |
824 |
password => hash_password( PATRON_PW ), |
825 |
}, |
826 |
}); |
827 |
my $card1 = $patron1->{cardnumber}; |
828 |
my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 ); |
829 |
my $patron_category = $sip_patron1->ptype(); |
830 |
$findpatron = $sip_patron1; |
831 |
my $item_object = $builder->build_sample_item({ |
832 |
damaged => 0, |
833 |
withdrawn => 0, |
834 |
itemlost => 0, |
835 |
restricted => 0, |
836 |
homebranch => $branchcode, |
837 |
holdingbranch => $branchcode, |
838 |
}); |
839 |
|
840 |
my $mockILS = $mocks->{ils}; |
841 |
my $server = { ils => $mockILS, account => {} }; |
842 |
$mockILS->mock( 'institution', sub { $branchcode; } ); |
843 |
$mockILS->mock( 'supports', sub { return; } ); |
844 |
$mockILS->mock( 'checkout', sub { |
845 |
shift; |
846 |
return C4::SIP::ILS->checkout(@_); |
847 |
}); |
848 |
my $today = dt_from_string; |
849 |
t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 }); |
850 |
t::lib::Mocks::mock_preference( 'CheckPrevCheckout', 'hardyes' ); |
851 |
|
852 |
my $siprequest = CHECKOUT . 'YN' . siprequestdate($today) . |
853 |
siprequestdate( $today->clone->add( days => 1) ) . |
854 |
FID_INST_ID . $branchcode . '|'. |
855 |
FID_PATRON_ID . $sip_patron1->id . '|' . |
856 |
FID_ITEM_ID . $item_object->barcode . '|' . |
857 |
FID_TERMINAL_PWD . 'ignored' . '|'; |
858 |
|
859 |
undef $response; |
860 |
my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
861 |
$server->{account}->{never_demagnitize} = "A,$patron_category,Z"; |
862 |
$msg->handle_checkout( $server ); |
863 |
my $respcode = substr( $response, 5, 1 ); |
864 |
is( $respcode, 'N', "Desensitize flag was not set for patron category in never_demagnitize" ); |
865 |
|
866 |
undef $response; |
867 |
$server->{account}->{never_demagnitize} = "A,B,C"; |
868 |
$msg->handle_checkout( $server ); |
869 |
$respcode = substr( $response, 5, 1 ); |
870 |
is( $respcode, 'Y', "Desensitize flag was set for patron category not in never_demagnitize" ); |
871 |
|
872 |
undef $response; |
873 |
$server->{account}->{never_demagnitize} = ""; |
874 |
$msg->handle_checkout( $server ); |
875 |
$respcode = substr( $response, 5, 1 ); |
876 |
is( $respcode, 'Y', "Desensitize flag was set for empty never_demagnitize" ); |
877 |
} |
878 |
|
879 |
sub test_renew_desensitize { |
880 |
my $builder = t::lib::TestBuilder->new(); |
881 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
882 |
my ( $response, $findpatron ); |
883 |
my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); |
884 |
|
885 |
# create some data |
886 |
my $patron1 = $builder->build({ |
887 |
source => 'Borrower', |
888 |
value => { |
889 |
password => hash_password( PATRON_PW ), |
890 |
}, |
891 |
}); |
892 |
my $card1 = $patron1->{cardnumber}; |
893 |
my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 ); |
894 |
my $patron_category = $sip_patron1->ptype(); |
895 |
$findpatron = $sip_patron1; |
896 |
my $item_object = $builder->build_sample_item({ |
897 |
damaged => 0, |
898 |
withdrawn => 0, |
899 |
itemlost => 0, |
900 |
restricted => 0, |
901 |
homebranch => $branchcode, |
902 |
holdingbranch => $branchcode, |
903 |
}); |
904 |
|
905 |
my $mockILS = $mocks->{ils}; |
906 |
my $server = { ils => $mockILS, account => {} }; |
907 |
$mockILS->mock( 'institution', sub { $branchcode; } ); |
908 |
$mockILS->mock( 'supports', sub { return; } ); |
909 |
$mockILS->mock( 'checkout', sub { |
910 |
shift; |
911 |
return C4::SIP::ILS->checkout(@_); |
912 |
}); |
913 |
my $today = dt_from_string; |
914 |
t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 }); |
915 |
|
916 |
my $issue = Koha::Checkout->new({ branchcode => $branchcode, borrowernumber => $patron1->{borrowernumber}, itemnumber => $item_object->itemnumber })->store; |
917 |
|
918 |
my $siprequest = RENEW . 'YN' . siprequestdate($today) . |
919 |
siprequestdate( $today->clone->add( days => 1) ) . |
920 |
FID_INST_ID . $branchcode . '|'. |
921 |
FID_PATRON_ID . $sip_patron1->id . '|' . |
922 |
FID_ITEM_ID . $item_object->barcode . '|' . |
923 |
FID_TERMINAL_PWD . 'ignored' . '|'; |
924 |
|
925 |
undef $response; |
926 |
my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
927 |
$server->{account}->{never_demagnitize} = "A,$patron_category,Z"; |
928 |
$msg->handle_checkout( $server ); |
929 |
my $respcode = substr( $response, 5, 1 ); |
930 |
is( $respcode, 'N', "Desensitize flag was not set for patron category in never_demagnitize" ); |
931 |
|
932 |
undef $response; |
933 |
$server->{account}->{never_demagnitize} = "A,B,C"; |
934 |
$msg->handle_checkout( $server ); |
935 |
$respcode = substr( $response, 5, 1 ); |
936 |
is( $respcode, 'Y', "Desensitize flag was set for patron category not in never_demagnitize" ); |
937 |
|
938 |
undef $response; |
939 |
$server->{account}->{never_demagnitize} = ""; |
940 |
$msg->handle_checkout( $server ); |
941 |
$respcode = substr( $response, 5, 1 ); |
942 |
is( $respcode, 'Y', "Desensitize flag was set for empty never_demagnitize" ); |
943 |
} |
944 |
|
796 |
# Helper routines |
945 |
# Helper routines |
797 |
|
946 |
|
798 |
sub create_mocks { |
947 |
sub create_mocks { |
799 |
- |
|
|