Lines 32-38
use Koha::Biblios;
Link Here
|
32 |
use Koha::Patron::Category; |
32 |
use Koha::Patron::Category; |
33 |
use Koha::Patron::Categories; |
33 |
use Koha::Patron::Categories; |
34 |
use Koha::Patrons; |
34 |
use Koha::Patrons; |
35 |
use Koha::Library::Allowlist; |
|
|
36 |
use Koha::Database; |
35 |
use Koha::Database; |
37 |
use Koha::DateUtils qw( dt_from_string ); |
36 |
use Koha::DateUtils qw( dt_from_string ); |
38 |
|
37 |
|
Lines 400-466
subtest "to_api() tests" => sub {
Link Here
|
400 |
} |
399 |
} |
401 |
|
400 |
|
402 |
subtest 'unprivileged request tests' => sub { |
401 |
subtest 'unprivileged request tests' => sub { |
403 |
|
402 |
plan tests => 4; |
404 |
my @all_attrs = Koha::Libraries->columns(); |
|
|
405 |
my $allowlist = Koha::Library::Allowlist->new({ interface => 'opac' })->load(); |
406 |
my $public_attrs = $allowlist->{_entries}; |
407 |
my $mapping = Koha::Library->to_api_mapping; |
408 |
|
403 |
|
409 |
# Create sample libraries |
404 |
# Create sample libraries |
410 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
405 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
411 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
406 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
412 |
my $libraries = Koha::Libraries->search( |
407 |
my $libraries = Koha::Libraries->search({ |
413 |
{ |
408 |
branchcode => [ $library_1->branchcode, $library_2->branchcode ], |
414 |
branchcode => { |
409 |
}); |
415 |
'-in' => [ |
|
|
416 |
$library_1->branchcode, $library_2->branchcode |
417 |
] |
418 |
} |
419 |
} |
420 |
); |
421 |
|
422 |
plan tests => scalar @all_attrs * 2 * $libraries->count; |
423 |
|
410 |
|
424 |
my $libraries_unprivileged_representation = $libraries->to_api({ public => 1 }); |
411 |
my $libraries_unprivileged_representation = $libraries->to_api({ public => 1 }); |
425 |
my $libraries_privileged_representation = $libraries->to_api(); |
412 |
my $libraries_privileged_representation = $libraries->to_api(); |
|
|
413 |
my $mapping = Koha::Library->to_api_mapping; |
426 |
|
414 |
|
427 |
for (my $i = 0; $i < $libraries->count; $i++) { |
415 |
my $public_attrs = [ sort map { $mapping->{$_} //$_ } @{$library_1->_result->get_column_set('public_read')} ]; |
428 |
my $privileged_representation = $libraries_privileged_representation->[$i]; |
416 |
is_deeply( [ sort keys %{$libraries_unprivileged_representation->[0]} ], $public_attrs, 'Check first, public' ); |
429 |
my $unprivileged_representation = $libraries_unprivileged_representation->[$i]; |
417 |
is_deeply( [ sort keys %{$libraries_unprivileged_representation->[1]} ], $public_attrs, 'Check second, public' ); |
430 |
foreach my $attr (@all_attrs) { |
|
|
431 |
my $mapped = exists $mapping->{$attr} ? $mapping->{$attr} : $attr; |
432 |
if ( defined($mapped) ) { |
433 |
ok( |
434 |
exists $privileged_representation->{$mapped}, |
435 |
"Attribute '$attr' is present when privileged" |
436 |
); |
437 |
if ( exists $public_attrs->{$attr} ) { |
438 |
ok( |
439 |
exists $unprivileged_representation->{$mapped}, |
440 |
"Attribute '$attr' is present when public" |
441 |
); |
442 |
} |
443 |
else { |
444 |
ok( |
445 |
!exists $unprivileged_representation->{$mapped}, |
446 |
"Attribute '$attr' is not present when public" |
447 |
); |
448 |
} |
449 |
} |
450 |
else { |
451 |
ok( |
452 |
!exists $privileged_representation->{$attr}, |
453 |
"Unmapped attribute '$attr' is not present when privileged" |
454 |
); |
455 |
ok( |
456 |
!exists $unprivileged_representation->{$attr}, |
457 |
"Unmapped attribute '$attr' is not present when public" |
458 |
); |
459 |
} |
460 |
} |
461 |
} |
462 |
}; |
463 |
|
418 |
|
|
|
419 |
my $staff_attrs = [ sort map { $mapping->{$_} //$_ } @{$library_1->_result->get_column_set('staff_read')} ]; |
420 |
is_deeply( [ sort keys %{$libraries_privileged_representation->[0]} ], $staff_attrs, 'Check first, staff' ); |
421 |
is_deeply( [ sort keys %{$libraries_privileged_representation->[1]} ], $staff_attrs, 'Check second, staff' ); |
422 |
}; |
464 |
|
423 |
|
465 |
$schema->storage->txn_rollback; |
424 |
$schema->storage->txn_rollback; |
466 |
}; |
425 |
}; |
467 |
- |
|
|