From 7c5eb8fe8ff6450f4886de4c4546fc96b49f1787 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/v3.0.2 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', EISSN: 'abc', a cardnumber '42' and a library. Click 'Make request' 6) Click 'Switch provider'. Pick 'Standard'. 7) Notice 'Eissn' shows. This is confusing as it means nothing in the 'Standard' context. 'Migrated from' is also shown and is equally as confusing for staff members (This is a remnant of previous behavior when migrating a request would create a new request). 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 | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100755 t/db_dependent/Koha/ILL/Backend/Standard.t diff --git a/t/db_dependent/Koha/ILL/Backend/Standard.t b/t/db_dependent/Koha/ILL/Backend/Standard.t new file mode 100755 index 00000000000..0406538abc0 --- /dev/null +++ b/t/db_dependent/Koha/ILL/Backend/Standard.t @@ -0,0 +1,146 @@ +#!/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 . + +use Modern::Perl; + +use Test::NoWarnings; +use Test::More tests => 3; +use Test::MockModule; + +use t::lib::Mocks; +use t::lib::TestBuilder; + +my $builder = t::lib::TestBuilder->new; +my $schema = Koha::Database->new->schema; + +subtest 'metadata() tests' => sub { + + plan tests => 5; + + $schema->storage->txn_begin; + + my $request = $builder->build_sample_ill_request( { backend => 'Standard' } ); + + is( + scalar %{ $request->metadata }, 0, + 'metadata() returns empty if no metadata is set' + ); + + $builder->build_object( + { + class => 'Koha::ILL::Request::Attributes', + value => { + illrequest_id => $request->illrequest_id, + type => 'title', + value => 'The Hobbit', + backend => 'Standard', + } + } + ); + + is( + scalar %{ $request->metadata }, 1, + 'metadata() returns non-empty if metadata is set' + ); + + $builder->build_object( + { + class => 'Koha::ILL::Request::Attributes', + value => { + illrequest_id => $request->illrequest_id, + type => 'author', + value => 'JRR Tolkien', + backend => 'Other_backend', + } + } + ); + + is( + scalar %{ $request->metadata }, 1, + 'metadata() only returns attributes from Standard' + ); + + is( + $request->metadata->{'Title'}, 'The Hobbit', + 'metadata() only returns attributes from Standard' + ); + + is( + $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, + 'Standard' + ); + + is( + $request->metadata->{'doi'}, undef, + '123/abc' + ); + + $schema->storage->txn_rollback; + +}; -- 2.39.5