From bda52c3c9d217f6f9c2b17a4c56344f327e7dfe7 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 19 May 2025 10:13:15 +0000 Subject: [PATCH] Bug 39934: Add tests prove t/db_dependent/Koha/ILL/Backend/Standard.t Test plan, k-t-d, don't apply patches yet: 1) Enable ILLModule sys pref 2) Install an additional backend, e.g. ReprintsDesk: https://github.com/openfifth/koha-ill-reprintsdesk/releases/tag/v4.0.3 3) Restart plack $ koha-plack --restart kohadev 4) Create a new ReprintsDesk request, visit: /cgi-bin/koha/ill/ill-requests.pl?method=create&backend=ReprintsDesk 5) Enter DOI: '123', 'First page of article in journal': 'abc', a cardnumber '42' and a library. Click 'Make request' 6) Click 'Switch provider'. Pick 'Standard'. 7) Notice 'First page of article in journal' shows. This is confusing as it means nothing in the 'Standard' context. 8) Apply patches. Repeat test plan. The attributes from the previous backend still exist in the database, but the UI now only shows attributes relevant to the current backend of the request. To confirm this, run: $ koha-mysql kohadev $ select * from illrequestattributes; --- t/db_dependent/Koha/ILL/Backend/Standard.t | 105 ++++++++++++++++++++- 1 file changed, 102 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Koha/ILL/Backend/Standard.t b/t/db_dependent/Koha/ILL/Backend/Standard.t index 94193aa9415..16a207abebd 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 => 3; +use Test::More tests => 4; use Test::MockModule; use Test::NoWarnings; @@ -116,12 +116,12 @@ subtest 'edititem() tests' => sub { subtest 'metadata() tests' => sub { - plan tests => 8; + plan tests => 13; $schema->storage->txn_begin; # Create a test ILL request - my $request = $builder->build_object( { class => 'Koha::ILL::Requests' } ); + my $request = $builder->build_sample_ill_request( { backend => 'Standard' } ); # Add various attributes including some that should be ignored $request->add_or_update_attributes( @@ -157,5 +157,104 @@ subtest 'metadata() tests' => sub { ok( !exists $metadata->{Requested_partners}, 'requested_partners excluded from metadata' ); ok( !exists $metadata->{Copyrightclearance_confirmed}, 'copyrightclearance_confirmed excluded from metadata' ); + my $new_request = $builder->build_sample_ill_request( { backend => 'Standard' } ); + + is( + scalar %{ $new_request->metadata }, 0, + 'metadata() returns empty if no metadata is set' + ); + + $builder->build_object( + { + class => 'Koha::ILL::Request::Attributes', + value => { + illrequest_id => $new_request->illrequest_id, + type => 'title', + value => 'The Hobbit', + backend => 'Standard', + } + } + ); + + is( + scalar %{ $new_request->metadata }, 1, + 'metadata() returns non-empty if metadata is set' + ); + + $builder->build_object( + { + class => 'Koha::ILL::Request::Attributes', + value => { + illrequest_id => $new_request->illrequest_id, + type => 'author', + value => 'JRR Tolkien', + backend => 'Other_backend', + } + } + ); + + is( + scalar %{ $new_request->metadata }, 1, + 'metadata() only returns attributes from Standard' + ); + + is( + $new_request->metadata->{'Title'}, 'The Hobbit', + 'metadata() only returns attributes from Standard' + ); + + is( + $new_request->metadata->{'Author'}, undef, + 'metadata() only returns attributes from Standard' + ); + + $schema->storage->txn_rollback; +}; + +subtest 'migrate() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $request = $builder->build_sample_ill_request( { backend => 'Other_backend' } ); + + # Add attribute that Standard does not consider metadata + $builder->build_object( + { + class => 'Koha::ILL::Request::Attributes', + value => { + illrequest_id => $request->illrequest_id, + type => 'Not_Standard_field', + value => 'test', + backend => 'Other_backend', + } + } + ); + + # Add attribute that Standard considers metadata + $builder->build_object( + { + class => 'Koha::ILL::Request::Attributes', + value => { + illrequest_id => $request->illrequest_id, + type => 'DOI', + value => '123/abc', + backend => 'Other_backend', + } + } + ); + + my $test = $request->backend_migrate( + { + backend => 'Standard', + illrequest_id => $request->illrequest_id + } + ); + + is( $request->metadata->{'Not_Standard_field'}, undef, 'Non standard field not migrated' ); + + is( $request->metadata->{'DOI'}, '123/abc', 'Standard field migrated' ); + $schema->storage->txn_rollback; }; -- 2.39.5