Bugzilla – Attachment 187195 Details for
Bug 40910
Log pollution for undefined/empty barcodes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40910: Regression tests
Bug-40910-Regression-tests.patch (text/plain), 5.97 KB, created by
Kyle M Hall (khall)
on 2025-10-01 14:28:04 UTC
(
hide
)
Description:
Bug 40910: Regression tests
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2025-10-01 14:28:04 UTC
Size:
5.97 KB
patch
obsolete
>From 56cef4358706eaa5a7b61860c15975dc8728996b Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= <tomascohen@theke.io> >Date: Tue, 30 Sep 2025 11:10:43 -0300 >Subject: [PATCH] Bug 40910: Regression tests >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > t/db_dependent/SIP/Item.t | 153 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 153 insertions(+) > create mode 100755 t/db_dependent/SIP/Item.t > >diff --git a/t/db_dependent/SIP/Item.t b/t/db_dependent/SIP/Item.t >new file mode 100755 >index 00000000000..c2fda1b8747 >--- /dev/null >+++ b/t/db_dependent/SIP/Item.t >@@ -0,0 +1,153 @@ >+#!/usr/bin/perl >+ >+# Copyright 2025 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <https://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+use Test::NoWarnings; >+use Test::Warn; >+ >+use C4::SIP::ILS::Item; >+use C4::Context; >+use Koha::Database; >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+my $schema = Koha::Database->new->schema(); >+my $builder = t::lib::TestBuilder->new(); >+ >+subtest 'C4::SIP::ILS::Item->new() tests' => sub { >+ >+ plan tests => 7; >+ >+ $schema->storage->txn_begin; >+ >+ # Create test data >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $biblio = $builder->build_sample_biblio(); >+ my $item = $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ homebranch => $library->branchcode, >+ holdingbranch => $library->branchcode, >+ barcode => 'TEST_BARCODE_123' >+ } >+ ); >+ >+ subtest 'Valid barcode' => sub { >+ >+ plan tests => 3; >+ >+ my $sip_item = C4::SIP::ILS::Item->new('TEST_BARCODE_123'); >+ ok( defined $sip_item, 'Item created successfully with valid barcode' ); >+ is( $sip_item->{id}, 'TEST_BARCODE_123', 'Item ID matches barcode' ); >+ isa_ok( $sip_item->{_object}, 'Koha::Item', 'Item object is correct type' ); >+ }; >+ >+ subtest 'Nonexistent barcode' => sub { >+ >+ plan tests => 2; >+ >+ warnings_like { >+ my $sip_item = C4::SIP::ILS::Item->new('NONEXISTENT_BARCODE'); >+ ok( !defined $sip_item, 'Item not created for nonexistent barcode' ); >+ } >+ [qr/No item 'NONEXISTENT_BARCODE'/], 'Expected warning for nonexistent barcode'; >+ }; >+ >+ subtest 'Undefined item_id (barcodedecode returns undef)' => sub { >+ >+ plan tests => 2; >+ >+ # barcodedecode(undef) returns undef - should generate no warnings >+ warnings_are { >+ my $sip_item = C4::SIP::ILS::Item->new(undef); >+ ok( !defined $sip_item, 'Item not created for undefined item_id' ); >+ } >+ [], 'No warnings when barcodedecode returns undef'; >+ }; >+ >+ subtest 'Empty item_id (barcodedecode returns empty)' => sub { >+ >+ plan tests => 2; >+ >+ # barcodedecode('') returns '' after trimming - should generate no warnings >+ warnings_are { >+ my $sip_item = C4::SIP::ILS::Item->new(''); >+ ok( !defined $sip_item, 'Item not created for empty item_id' ); >+ } >+ [], 'No warnings when barcodedecode returns empty string'; >+ }; >+ >+ subtest 'Whitespace-only item_id (barcodedecode trims to empty)' => sub { >+ >+ plan tests => 6; >+ >+ # barcodedecode trims whitespace, may result in empty string >+ warnings_are { >+ my $sip_item = C4::SIP::ILS::Item->new(' '); >+ ok( !defined $sip_item, 'Item not created for whitespace-only item_id' ); >+ } >+ [], 'No warnings for spaces-only item_id'; >+ >+ warnings_are { >+ my $sip_item = C4::SIP::ILS::Item->new("\t"); >+ ok( !defined $sip_item, 'Item not created for tab-only item_id' ); >+ } >+ [], 'No warnings for tab-only item_id'; >+ >+ warnings_are { >+ my $sip_item = C4::SIP::ILS::Item->new("\n"); >+ ok( !defined $sip_item, 'Item not created for newline-only item_id' ); >+ } >+ [], 'No warnings for newline-only item_id'; >+ }; >+ >+ subtest 'barcodedecode edge cases' => sub { >+ >+ plan tests => 4; >+ >+ # Test cases where barcodedecode might return unexpected values >+ warnings_are { >+ my $sip_item = C4::SIP::ILS::Item->new(" \t \n "); >+ ok( !defined $sip_item, 'Item not created for mixed whitespace' ); >+ } >+ [], 'No warnings for mixed whitespace that trims to empty'; >+ >+ # Zero is a valid barcode that should generate expected warning >+ warnings_like { >+ my $sip_item = C4::SIP::ILS::Item->new(0); >+ ok( !defined $sip_item, 'Item not created for zero item_id' ); >+ } >+ [qr/No item '0'/], 'Expected warning for zero item_id (valid barcode)'; >+ }; >+ >+ subtest 'Barcode decoding functionality' => sub { >+ >+ plan tests => 2; >+ >+ # Test that barcodedecode is working properly with valid input >+ my $sip_item = C4::SIP::ILS::Item->new('TEST_BARCODE_123'); >+ ok( defined $sip_item, 'Item found with barcode that needs decoding' ); >+ is( $sip_item->{id}, 'TEST_BARCODE_123', 'Barcode properly decoded and stored' ); >+ }; >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.39.5 (Apple Git-154)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40910
:
187106
|
187107
|
187195
|
187196
|
187197