|
Lines 20-26
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::NoWarnings; |
22 |
use Test::NoWarnings; |
| 23 |
use Test::More tests => 7; |
23 |
use Test::More tests => 8; |
| 24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
| 25 |
|
25 |
|
| 26 |
use Koha::ILL::Requests; |
26 |
use Koha::ILL::Requests; |
|
Lines 233-235
subtest 'copyright clearance methods tests' => sub {
Link Here
|
| 233 |
|
233 |
|
| 234 |
$schema->storage->txn_rollback; |
234 |
$schema->storage->txn_rollback; |
| 235 |
}; |
235 |
}; |
| 236 |
- |
236 |
|
|
|
237 |
subtest 'add_or_update_attributes() tests' => sub { |
| 238 |
|
| 239 |
plan tests => 13; |
| 240 |
|
| 241 |
$schema->storage->txn_begin; |
| 242 |
|
| 243 |
my $request = $builder->build_object( { class => 'Koha::ILL::Requests' } ); |
| 244 |
|
| 245 |
# Test adding new attributes |
| 246 |
$request->add_or_update_attributes( |
| 247 |
{ |
| 248 |
title => 'Test Title', |
| 249 |
author => 'Test Author', |
| 250 |
isbn => '1234567890' |
| 251 |
} |
| 252 |
); |
| 253 |
|
| 254 |
my $title_attr = $request->extended_attributes->find( { type => 'title' } ); |
| 255 |
my $author_attr = $request->extended_attributes->find( { type => 'author' } ); |
| 256 |
my $isbn_attr = $request->extended_attributes->find( { type => 'isbn' } ); |
| 257 |
|
| 258 |
ok( $title_attr, 'Title attribute created' ); |
| 259 |
is( $title_attr->value, 'Test Title', 'Title value set correctly' ); |
| 260 |
ok( $author_attr, 'Author attribute created' ); |
| 261 |
is( $author_attr->value, 'Test Author', 'Author value set correctly' ); |
| 262 |
ok( $isbn_attr, 'ISBN attribute created' ); |
| 263 |
is( $isbn_attr->value, '1234567890', 'ISBN value set correctly' ); |
| 264 |
|
| 265 |
# Test updating existing attributes |
| 266 |
$request->add_or_update_attributes( |
| 267 |
{ |
| 268 |
title => 'Updated Title', |
| 269 |
author => 'Test Author', # Same value, should not update |
| 270 |
year => '2023' # New attribute |
| 271 |
} |
| 272 |
); |
| 273 |
|
| 274 |
$title_attr->discard_changes; |
| 275 |
$author_attr->discard_changes; |
| 276 |
my $year_attr = $request->extended_attributes->find( { type => 'year' } ); |
| 277 |
|
| 278 |
is( $title_attr->value, 'Updated Title', 'Title attribute updated' ); |
| 279 |
is( $author_attr->value, 'Test Author', 'Author attribute unchanged when same value' ); |
| 280 |
ok( $year_attr, 'Year attribute created' ); |
| 281 |
is( $year_attr->value, '2023', 'Year value set correctly' ); |
| 282 |
|
| 283 |
# Test with empty/undefined values (should be skipped) |
| 284 |
$request->add_or_update_attributes( |
| 285 |
{ |
| 286 |
empty_field => '', |
| 287 |
undef_field => undef, |
| 288 |
valid_field => 'valid' |
| 289 |
} |
| 290 |
); |
| 291 |
|
| 292 |
my $empty_attr = $request->extended_attributes->find( { type => 'empty_field' } ); |
| 293 |
my $undef_attr = $request->extended_attributes->find( { type => 'undef_field' } ); |
| 294 |
my $valid_attr = $request->extended_attributes->find( { type => 'valid_field' } ); |
| 295 |
|
| 296 |
is( $empty_attr, undef, 'Empty value skipped' ); |
| 297 |
is( $undef_attr, undef, 'Undefined value skipped' ); |
| 298 |
ok( $valid_attr, 'Valid value processed' ); |
| 299 |
|
| 300 |
$schema->storage->txn_rollback; |
| 301 |
}; |