From 9a525191f057210832daf168dda401f1298e3ac5 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 20 Aug 2020 07:56:12 -0400 Subject: [PATCH] Bug 25903: Add unit tests --- t/db_dependent/SIP/Message.t | 56 +++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/SIP/Message.t b/t/db_dependent/SIP/Message.t index 3b6eed812d..f875fd7738 100755 --- a/t/db_dependent/SIP/Message.t +++ b/t/db_dependent/SIP/Message.t @@ -21,7 +21,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 7; +use Test::More tests => 8; use Test::MockObject; use Test::MockModule; use Test::Warn; @@ -196,6 +196,60 @@ subtest "Test build_additional_item_fields_string" => sub { $schema->storage->txn_rollback; }; +subtest 'Patron info summary > 5 should not crash server' => sub { + + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + + plan tests => 22; + my $builder = t::lib::TestBuilder->new(); + my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; + my ( $response, $findpatron ); + my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); + my $seen_patron = $builder->build({ + source => 'Borrower', + value => { + lastseen => '2001-01-01', + password => hash_password( PATRON_PW ), + branchcode => $branchcode, + }, + }); + my $cardnum = $seen_patron->{cardnumber}; + my $sip_patron = C4::SIP::ILS::Patron->new( $cardnum ); + $findpatron = $sip_patron; + + my @summaries = ( + ' ', + 'Y ', + ' Y ', + ' Y ', + ' Y ', + ' Y ', + ' Y ', + ' Y ', + ' Y ', + ' Y ', + ' Y', + ); + for my $summary ( @summaries ) { + my $siprequest = PATRON_INFO . 'engYYYYMMDDZZZZHHMMSS' . $summary . + FID_INST_ID . $branchcode . '|' . + FID_PATRON_ID . $cardnum . '|' . + FID_PATRON_PWD . PATRON_PW . '|'; + my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); + + my $server = { ils => $mocks->{ils} }; + undef $response; + $msg->handle_patron_info( $server ); + + isnt( $response, undef, 'At least we got a response.' ); + my $respcode = substr( $response, 0, 2 ); + is( $respcode, PATRON_INFO_RESP, 'Response code fine' ); + } + + $schema->storage->txn_rollback; +}; + # Here is room for some more subtests # END of main code -- 2.24.1 (Apple Git-126)