Lines 31-37
use Koha::Database;
Link Here
|
31 |
use Koha::Acquisition::Orders; |
31 |
use Koha::Acquisition::Orders; |
32 |
use Koha::DateUtils qw( dt_from_string ); |
32 |
use Koha::DateUtils qw( dt_from_string ); |
33 |
use Koha::Libraries; |
33 |
use Koha::Libraries; |
34 |
use Koha::Library::Allowlist; |
34 |
use Koha::Object::ColumnSet; |
35 |
use Koha::Patrons; |
35 |
use Koha::Patrons; |
36 |
use Koha::ApiKeys; |
36 |
use Koha::ApiKeys; |
37 |
|
37 |
|
Lines 376-424
subtest "to_api() tests" => sub {
Link Here
|
376 |
|
376 |
|
377 |
subtest 'unprivileged request tests' => sub { |
377 |
subtest 'unprivileged request tests' => sub { |
378 |
|
378 |
|
379 |
my @all_attrs = Koha::Libraries->columns(); |
379 |
# Create a sample library |
380 |
my $allowlist = Koha::Library::Allowlist->new({ interface => 'opac' })->load(); |
380 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
381 |
my $public_attrs = $allowlist->{_entries}; |
381 |
|
|
|
382 |
my @all_attrs = @{ $library->_columns }; |
383 |
my $public_attrs = { map { ( $_ => 1 ) } @{$library->_result->get_column_set('public_read')} }; |
384 |
my $staff_attrs = { map { ( $_ => 1 ) } @{$library->_result->get_column_set('staff_read')} }; |
382 |
my $mapping = Koha::Library->to_api_mapping; |
385 |
my $mapping = Koha::Library->to_api_mapping; |
383 |
|
386 |
|
384 |
plan tests => scalar @all_attrs * 2; |
387 |
plan tests => scalar @all_attrs * 2; |
385 |
|
388 |
|
386 |
# Create a sample library |
389 |
my $public_representation = $library->to_api({ public => 1 }); |
387 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
|
|
388 |
|
389 |
my $unprivileged_representation = $library->to_api({ public => 1 }); |
390 |
my $privileged_representation = $library->to_api; |
390 |
my $privileged_representation = $library->to_api; |
391 |
|
391 |
|
392 |
foreach my $attr (@all_attrs) { |
392 |
foreach my $attr (@all_attrs) { |
393 |
my $mapped = exists $mapping->{$attr} ? $mapping->{$attr} : $attr; |
393 |
my $mapped = $mapping->{$attr} // $attr; |
394 |
if ( defined($mapped) ) { |
394 |
is( exists $privileged_representation->{$mapped}, |
395 |
ok( |
395 |
exists $staff_attrs->{$attr}, "Verify $attr in privileged" ); |
396 |
exists $privileged_representation->{$mapped}, |
396 |
is( exists $public_representation->{$mapped}, |
397 |
"Attribute '$attr' is present when privileged" |
397 |
exists $public_attrs->{$attr}, "Verify $attr in public" ); |
398 |
); |
|
|
399 |
if ( exists $public_attrs->{$attr} ) { |
400 |
ok( |
401 |
exists $unprivileged_representation->{$mapped}, |
402 |
"Attribute '$attr' is present when public" |
403 |
); |
404 |
} |
405 |
else { |
406 |
ok( |
407 |
!exists $unprivileged_representation->{$mapped}, |
408 |
"Attribute '$attr' is not present when public" |
409 |
); |
410 |
} |
411 |
} |
412 |
else { |
413 |
ok( |
414 |
!exists $privileged_representation->{$attr}, |
415 |
"Unmapped attribute '$attr' is not present when privileged" |
416 |
); |
417 |
ok( |
418 |
!exists $unprivileged_representation->{$attr}, |
419 |
"Unmapped attribute '$attr' is not present when public" |
420 |
); |
421 |
} |
422 |
} |
398 |
} |
423 |
}; |
399 |
}; |
424 |
|
400 |
|
425 |
- |
|
|