|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2025 Koha Development team |
| 4 |
# |
| 5 |
# This file is part of Koha |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use Test::NoWarnings; |
| 23 |
use Test::More tests => 3; |
| 24 |
use Test::MockModule; |
| 25 |
|
| 26 |
use t::lib::Mocks; |
| 27 |
use t::lib::TestBuilder; |
| 28 |
|
| 29 |
my $builder = t::lib::TestBuilder->new; |
| 30 |
my $schema = Koha::Database->new->schema; |
| 31 |
|
| 32 |
subtest 'metadata() tests' => sub { |
| 33 |
|
| 34 |
plan tests => 5; |
| 35 |
|
| 36 |
$schema->storage->txn_begin; |
| 37 |
|
| 38 |
my $request = $builder->build_sample_ill_request( { backend => 'Standard' } ); |
| 39 |
|
| 40 |
is( |
| 41 |
scalar %{ $request->metadata }, 0, |
| 42 |
'metadata() returns empty if no metadata is set' |
| 43 |
); |
| 44 |
|
| 45 |
$builder->build_object( |
| 46 |
{ |
| 47 |
class => 'Koha::ILL::Request::Attributes', |
| 48 |
value => { |
| 49 |
illrequest_id => $request->illrequest_id, |
| 50 |
type => 'title', |
| 51 |
value => 'The Hobbit', |
| 52 |
backend => 'Standard', |
| 53 |
} |
| 54 |
} |
| 55 |
); |
| 56 |
|
| 57 |
is( |
| 58 |
scalar %{ $request->metadata }, 1, |
| 59 |
'metadata() returns non-empty if metadata is set' |
| 60 |
); |
| 61 |
|
| 62 |
$builder->build_object( |
| 63 |
{ |
| 64 |
class => 'Koha::ILL::Request::Attributes', |
| 65 |
value => { |
| 66 |
illrequest_id => $request->illrequest_id, |
| 67 |
type => 'author', |
| 68 |
value => 'JRR Tolkien', |
| 69 |
backend => 'Other_backend', |
| 70 |
} |
| 71 |
} |
| 72 |
); |
| 73 |
|
| 74 |
is( |
| 75 |
scalar %{ $request->metadata }, 1, |
| 76 |
'metadata() only returns attributes from Standard' |
| 77 |
); |
| 78 |
|
| 79 |
is( |
| 80 |
$request->metadata->{'Title'}, 'The Hobbit', |
| 81 |
'metadata() only returns attributes from Standard' |
| 82 |
); |
| 83 |
|
| 84 |
is( |
| 85 |
$request->metadata->{'Author'}, undef, |
| 86 |
'metadata() only returns attributes from Standard' |
| 87 |
); |
| 88 |
|
| 89 |
$schema->storage->txn_rollback; |
| 90 |
|
| 91 |
}; |
| 92 |
|
| 93 |
subtest 'migrate() tests' => sub { |
| 94 |
|
| 95 |
plan tests => 2; |
| 96 |
|
| 97 |
$schema->storage->txn_begin; |
| 98 |
|
| 99 |
my $request = $builder->build_sample_ill_request( { backend => 'Other_backend' } ); |
| 100 |
|
| 101 |
# Add attribute that Standard does not consider metadata |
| 102 |
$builder->build_object( |
| 103 |
{ |
| 104 |
class => 'Koha::ILL::Request::Attributes', |
| 105 |
value => { |
| 106 |
illrequest_id => $request->illrequest_id, |
| 107 |
type => 'not_Standard_field', |
| 108 |
value => 'test', |
| 109 |
backend => 'Other_backend', |
| 110 |
} |
| 111 |
} |
| 112 |
); |
| 113 |
|
| 114 |
# Add attribute that Standard considers metadata |
| 115 |
$builder->build_object( |
| 116 |
{ |
| 117 |
class => 'Koha::ILL::Request::Attributes', |
| 118 |
value => { |
| 119 |
illrequest_id => $request->illrequest_id, |
| 120 |
type => 'doi', |
| 121 |
value => '123/abc', |
| 122 |
backend => 'Other_backend', |
| 123 |
} |
| 124 |
} |
| 125 |
); |
| 126 |
|
| 127 |
my $test = $request->backend_migrate( |
| 128 |
{ |
| 129 |
backend => 'Standard', |
| 130 |
illrequest_id => $request->illrequest_id |
| 131 |
} |
| 132 |
); |
| 133 |
|
| 134 |
is( |
| 135 |
$request->metadata->{'not_Standard_field'}, undef, |
| 136 |
'Standard' |
| 137 |
); |
| 138 |
|
| 139 |
is( |
| 140 |
$request->metadata->{'doi'}, undef, |
| 141 |
'123/abc' |
| 142 |
); |
| 143 |
|
| 144 |
$schema->storage->txn_rollback; |
| 145 |
|
| 146 |
}; |