Lines 400-423
subtest "to_api() tests" => sub {
Link Here
|
400 |
|
400 |
|
401 |
subtest 'unprivileged request tests' => sub { |
401 |
subtest 'unprivileged request tests' => sub { |
402 |
|
402 |
|
403 |
my @privileged_attrs = @{ Koha::Library->api_privileged_attrs }; |
403 |
my @all_attrs = Koha::Libraries->columns(); |
|
|
404 |
my $public_attrs = { map { $_ => 1 } @{ Koha::Library->public_read_list() } }; |
405 |
my $mapping = Koha::Library->to_api_mapping; |
404 |
|
406 |
|
405 |
# Create sample libraries |
407 |
# Create sample libraries |
406 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
408 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
407 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
409 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
408 |
my $library_3 = $builder->build_object({ class => 'Koha::Libraries' }); |
|
|
409 |
my $libraries = Koha::Libraries->search( |
410 |
my $libraries = Koha::Libraries->search( |
410 |
{ |
411 |
{ |
411 |
branchcode => { |
412 |
branchcode => { |
412 |
'-in' => [ |
413 |
'-in' => [ |
413 |
$library_1->branchcode, $library_2->branchcode, |
414 |
$library_1->branchcode, $library_2->branchcode |
414 |
$library_3->branchcode |
|
|
415 |
] |
415 |
] |
416 |
} |
416 |
} |
417 |
} |
417 |
} |
418 |
); |
418 |
); |
419 |
|
419 |
|
420 |
plan tests => scalar @privileged_attrs * 2 * $libraries->count; |
420 |
plan tests => scalar @all_attrs * 2 * $libraries->count; |
421 |
|
421 |
|
422 |
my $libraries_unprivileged_representation = $libraries->to_api({ public => 1 }); |
422 |
my $libraries_unprivileged_representation = $libraries->to_api({ public => 1 }); |
423 |
my $libraries_privileged_representation = $libraries->to_api(); |
423 |
my $libraries_privileged_representation = $libraries->to_api(); |
Lines 425-435
subtest "to_api() tests" => sub {
Link Here
|
425 |
for (my $i = 0; $i < $libraries->count; $i++) { |
425 |
for (my $i = 0; $i < $libraries->count; $i++) { |
426 |
my $privileged_representation = $libraries_privileged_representation->[$i]; |
426 |
my $privileged_representation = $libraries_privileged_representation->[$i]; |
427 |
my $unprivileged_representation = $libraries_unprivileged_representation->[$i]; |
427 |
my $unprivileged_representation = $libraries_unprivileged_representation->[$i]; |
428 |
foreach my $privileged_attr ( @privileged_attrs ) { |
428 |
foreach my $attr (@all_attrs) { |
429 |
ok( exists $privileged_representation->{$privileged_attr}, |
429 |
my $mapped = exists $mapping->{$attr} ? $mapping->{$attr} : $attr; |
430 |
"Attribute $privileged_attr' is present" ); |
430 |
if ( defined($mapped) ) { |
431 |
ok( !exists $unprivileged_representation->{$privileged_attr}, |
431 |
ok( |
432 |
"Attribute '$privileged_attr' is not present" ); |
432 |
exists $privileged_representation->{$mapped}, |
|
|
433 |
"Attribute '$attr' is present when privileged" |
434 |
); |
435 |
if ( exists $public_attrs->{$attr} ) { |
436 |
ok( |
437 |
exists $unprivileged_representation->{$mapped}, |
438 |
"Attribute '$attr' is present when public" |
439 |
); |
440 |
} |
441 |
else { |
442 |
ok( |
443 |
!exists $unprivileged_representation->{$mapped}, |
444 |
"Attribute '$attr' is not present when public" |
445 |
); |
446 |
} |
447 |
} |
448 |
else { |
449 |
ok( |
450 |
!exists $privileged_representation->{$attr}, |
451 |
"Unmapped attribute '$attr' is not present when privileged" |
452 |
); |
453 |
ok( |
454 |
!exists $unprivileged_representation->{$attr}, |
455 |
"Unmapped attribute '$attr' is not present when public" |
456 |
); |
457 |
} |
433 |
} |
458 |
} |
434 |
} |
459 |
} |
435 |
}; |
460 |
}; |
436 |
- |
|
|