From 2a24453c158822dd20496c232437ed5bd82a23cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Mon, 22 Sep 2025 16:24:27 -0300 Subject: [PATCH] Bug 40856: Add unit tests for Standard backend metadata method This patch adds comprehensive unit tests for the metadata() method in the Standard ILL backend to establish baseline behavior before optimization. The tests cover: - Metadata structure (returns hashref) - Included attributes (title, author, isbn, year, custom fields) - Excluded attributes (ignored fields like requested_partners, type, etc.) - Display name transformation (attribute types become display names) Current behavior tested: - metadata() filters out predefined ignore list attributes - Uses linear search with grep for each attribute - Transforms attribute types to display names (title -> Title) - Custom fields get ucfirst transformation (custom_field -> Custom_field) - Returns hashref with display names as keys These tests document the current inefficient implementation and will ensure the upcoming optimization maintains compatibility. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/ILL/Backend/Standard.t => SUCCESS: Tests pass! Current metadata behavior documented 3. Tests establish baseline for upcoming optimization 4. Sign off :-D --- t/db_dependent/Koha/ILL/Backend/Standard.t | 48 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/ILL/Backend/Standard.t b/t/db_dependent/Koha/ILL/Backend/Standard.t index 652a3d21b9..318008c13c 100755 --- a/t/db_dependent/Koha/ILL/Backend/Standard.t +++ b/t/db_dependent/Koha/ILL/Backend/Standard.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Test::MockModule; use Test::NoWarnings; @@ -113,3 +113,49 @@ subtest 'edititem() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'metadata() tests' => sub { + + plan tests => 8; + + $schema->storage->txn_begin; + + # Create a test ILL request + my $request = $builder->build_object( { class => 'Koha::ILL::Requests' } ); + + # Add various attributes including some that should be ignored + $request->add_or_update_attributes( + { + title => 'Test Title', + author => 'Test Author', + isbn => '1234567890', + year => '2023', + custom_field => 'custom_value', + + # These should be ignored by metadata() + requested_partners => 'partner@example.com', + type => 'book', + copyrightclearance_confirmed => '1', + unauthenticated_email => 'user@example.com' + } + ); + + my $backend = Koha::ILL::Backend::Standard->new; + my $metadata = $backend->metadata($request); + + # Check that metadata is a hashref + is( ref($metadata), 'HASH', 'metadata returns a hashref' ); + + # Check that included attributes are present (metadata uses display names) + is( $metadata->{Title}, 'Test Title', 'Title included in metadata' ); + is( $metadata->{Author}, 'Test Author', 'Author included in metadata' ); + is( $metadata->{ISBN}, '1234567890', 'ISBN included in metadata' ); + is( $metadata->{Year}, '2023', 'Year included in metadata' ); + is( $metadata->{Custom_field}, 'custom_value', 'Custom field included in metadata' ); + + # Check that ignored attributes are excluded + ok( !exists $metadata->{Requested_partners}, 'requested_partners excluded from metadata' ); + ok( !exists $metadata->{Copyrightclearance_confirmed}, 'copyrightclearance_confirmed excluded from metadata' ); + + $schema->storage->txn_rollback; +}; -- 2.51.0