From 1e0f73e5bde39ec5e917ec71e7dda66e0de07023 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 25 Sep 2023 11:39:22 +0100 Subject: [PATCH] Bug 34737: (follow-up) Unit test for skipping bad lines We update the test rules set to include some malformed, empty and comment lines. No actual tests are added, but the skipping is checked by all other tests in this way. Signed-off-by: Toni Ford --- t/db_dependent/SIP/Transaction.t | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/SIP/Transaction.t b/t/db_dependent/SIP/Transaction.t index 54b77b2cdf5..6f170240f1f 100755 --- a/t/db_dependent/SIP/Transaction.t +++ b/t/db_dependent/SIP/Transaction.t @@ -5,6 +5,7 @@ use Modern::Perl; use Test::More tests => 17; +use Test::Warn; use Koha::Database; use t::lib::TestBuilder; @@ -974,13 +975,14 @@ subtest checkin_withdrawn => sub { }; subtest _get_sort_bin => sub { - plan tests => 5; + plan tests => 6; my $library = $builder->build_object( { class => 'Koha::Libraries' } ); my $branch = $library->branchcode; my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); my $branch2 = $library2->branchcode; + # Rules starts with malformed line, empty line and a comment to prove they are skipped my $rules = <<"RULES"; $branch:homebranch:ne:\$holdingbranch:X\r $branch:effective_itemtype:eq:CD:0\r @@ -991,7 +993,11 @@ $branch2:homebranch:ne:\$holdingbranch:X\r $branch2:effective_itemtype:eq:CD:4\r $branch2:itemcallnumber:>:600:5\r $branch2:effective_itemtype:eq:BOOK:ccode:eq:TEEN:6\r +# Comment line to skip\r +\r +$branch:homebranch:Z\r RULES + t::lib::Mocks::mock_preference( 'SIP2SortBinMapping', $rules ); my $item_cd = $builder->build_sample_item( @@ -1017,6 +1023,13 @@ RULES } ); + my $item_dvd = $builder->build_sample_item( + { + library => $library2->branchcode, + itype => 'DVD' + } + ); + my $bin; # Set holdingbranch as though item returned to library other than homebranch (As AddReturn would) @@ -1036,6 +1049,10 @@ RULES $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book2, $library2->branchcode ); is( $bin, '6', "Rules with multiple field matches" ); + + warnings_are { $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_dvd, $library2->branchcode ); } + ["Malformed preference line found: '$branch:homebranch:Z'"], + "Comments and blank lines are skipped, Malformed lines are warned and skipped"; }; subtest item_circulation_status => sub { -- 2.41.0