|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 3; |
22 |
use Test::More tests => 4; |
| 23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
| 24 |
use Test::NoWarnings; |
24 |
use Test::NoWarnings; |
| 25 |
|
25 |
|
|
Lines 116-127
subtest 'edititem() tests' => sub {
Link Here
|
| 116 |
|
116 |
|
| 117 |
subtest 'metadata() tests' => sub { |
117 |
subtest 'metadata() tests' => sub { |
| 118 |
|
118 |
|
| 119 |
plan tests => 8; |
119 |
plan tests => 13; |
| 120 |
|
120 |
|
| 121 |
$schema->storage->txn_begin; |
121 |
$schema->storage->txn_begin; |
| 122 |
|
122 |
|
| 123 |
# Create a test ILL request |
123 |
# Create a test ILL request |
| 124 |
my $request = $builder->build_object( { class => 'Koha::ILL::Requests' } ); |
124 |
my $request = $builder->build_sample_ill_request( { backend => 'Standard' } ); |
| 125 |
|
125 |
|
| 126 |
# Add various attributes including some that should be ignored |
126 |
# Add various attributes including some that should be ignored |
| 127 |
$request->add_or_update_attributes( |
127 |
$request->add_or_update_attributes( |
|
Lines 157-161
subtest 'metadata() tests' => sub {
Link Here
|
| 157 |
ok( !exists $metadata->{Requested_partners}, 'requested_partners excluded from metadata' ); |
157 |
ok( !exists $metadata->{Requested_partners}, 'requested_partners excluded from metadata' ); |
| 158 |
ok( !exists $metadata->{Copyrightclearance_confirmed}, 'copyrightclearance_confirmed excluded from metadata' ); |
158 |
ok( !exists $metadata->{Copyrightclearance_confirmed}, 'copyrightclearance_confirmed excluded from metadata' ); |
| 159 |
|
159 |
|
|
|
160 |
my $new_request = $builder->build_sample_ill_request( { backend => 'Standard' } ); |
| 161 |
|
| 162 |
is( |
| 163 |
scalar %{ $new_request->metadata }, 0, |
| 164 |
'metadata() returns empty if no metadata is set' |
| 165 |
); |
| 166 |
|
| 167 |
$builder->build_object( |
| 168 |
{ |
| 169 |
class => 'Koha::ILL::Request::Attributes', |
| 170 |
value => { |
| 171 |
illrequest_id => $new_request->illrequest_id, |
| 172 |
type => 'title', |
| 173 |
value => 'The Hobbit', |
| 174 |
backend => 'Standard', |
| 175 |
} |
| 176 |
} |
| 177 |
); |
| 178 |
|
| 179 |
is( |
| 180 |
scalar %{ $new_request->metadata }, 1, |
| 181 |
'metadata() returns non-empty if metadata is set' |
| 182 |
); |
| 183 |
|
| 184 |
$builder->build_object( |
| 185 |
{ |
| 186 |
class => 'Koha::ILL::Request::Attributes', |
| 187 |
value => { |
| 188 |
illrequest_id => $new_request->illrequest_id, |
| 189 |
type => 'author', |
| 190 |
value => 'JRR Tolkien', |
| 191 |
backend => 'Other_backend', |
| 192 |
} |
| 193 |
} |
| 194 |
); |
| 195 |
|
| 196 |
is( |
| 197 |
scalar %{ $new_request->metadata }, 1, |
| 198 |
'metadata() only returns attributes from Standard' |
| 199 |
); |
| 200 |
|
| 201 |
is( |
| 202 |
$new_request->metadata->{'Title'}, 'The Hobbit', |
| 203 |
'metadata() only returns attributes from Standard' |
| 204 |
); |
| 205 |
|
| 206 |
is( |
| 207 |
$new_request->metadata->{'Author'}, undef, |
| 208 |
'metadata() only returns attributes from Standard' |
| 209 |
); |
| 210 |
|
| 211 |
$schema->storage->txn_rollback; |
| 212 |
}; |
| 213 |
|
| 214 |
subtest 'migrate() tests' => sub { |
| 215 |
|
| 216 |
plan tests => 2; |
| 217 |
|
| 218 |
$schema->storage->txn_begin; |
| 219 |
|
| 220 |
my $request = $builder->build_sample_ill_request( { backend => 'Other_backend' } ); |
| 221 |
|
| 222 |
# Add attribute that Standard does not consider metadata |
| 223 |
$builder->build_object( |
| 224 |
{ |
| 225 |
class => 'Koha::ILL::Request::Attributes', |
| 226 |
value => { |
| 227 |
illrequest_id => $request->illrequest_id, |
| 228 |
type => 'Not_Standard_field', |
| 229 |
value => 'test', |
| 230 |
backend => 'Other_backend', |
| 231 |
} |
| 232 |
} |
| 233 |
); |
| 234 |
|
| 235 |
# Add attribute that Standard considers metadata |
| 236 |
$builder->build_object( |
| 237 |
{ |
| 238 |
class => 'Koha::ILL::Request::Attributes', |
| 239 |
value => { |
| 240 |
illrequest_id => $request->illrequest_id, |
| 241 |
type => 'DOI', |
| 242 |
value => '123/abc', |
| 243 |
backend => 'Other_backend', |
| 244 |
} |
| 245 |
} |
| 246 |
); |
| 247 |
|
| 248 |
my $test = $request->backend_migrate( |
| 249 |
{ |
| 250 |
backend => 'Standard', |
| 251 |
illrequest_id => $request->illrequest_id |
| 252 |
} |
| 253 |
); |
| 254 |
|
| 255 |
is( $request->metadata->{'Not_Standard_field'}, undef, 'Non standard field not migrated' ); |
| 256 |
|
| 257 |
is( $request->metadata->{'DOI'}, '123/abc', 'Standard field migrated' ); |
| 258 |
|
| 160 |
$schema->storage->txn_rollback; |
259 |
$schema->storage->txn_rollback; |
| 161 |
}; |
260 |
}; |
| 162 |
- |
|
|