View | Details | Raw Unified | Return to bug 24366
Collapse All | Expand All

(-)a/Koha/Biblio.pm (-1 / +9 lines)
Lines 737-744 on the API. Link Here
737
sub to_api {
737
sub to_api {
738
    my ($self, $args) = @_;
738
    my ($self, $args) = @_;
739
739
740
    my @embeds = keys %{ $args->{embed} };
741
    my $remaining_embeds = {};
742
743
    foreach my $embed (@embeds) {
744
        $remaining_embeds = delete $args->{embed}->{$embed}
745
            unless $self->can($embed);
746
    }
747
740
    my $response = $self->SUPER::to_api( $args );
748
    my $response = $self->SUPER::to_api( $args );
741
    my $biblioitem = $self->biblioitem->to_api( $args );
749
    my $biblioitem = $self->biblioitem->to_api({ embed => $remaining_embeds });
742
750
743
    return { %$response, %$biblioitem };
751
    return { %$response, %$biblioitem };
744
}
752
}
(-)a/t/db_dependent/Koha/Biblio.t (-2 / +6 lines)
Lines 440-453 subtest 'to_api() tests' => sub { Link Here
440
    $schema->storage->txn_begin;
440
    $schema->storage->txn_begin;
441
441
442
    my $biblio = $builder->build_sample_biblio();
442
    my $biblio = $builder->build_sample_biblio();
443
    my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
444
443
    my $biblioitem_api = $biblio->biblioitem->to_api;
445
    my $biblioitem_api = $biblio->biblioitem->to_api;
444
    my $biblio_api     = $biblio->to_api;
446
    my $biblio_api     = $biblio->to_api;
445
447
446
    plan tests => scalar keys %{ $biblioitem_api };
448
    plan tests => (scalar keys %{ $biblioitem_api }) + 1;
447
449
448
    foreach my $key ( keys %{ $biblioitem_api } ) {
450
    foreach my $key ( keys %{ $biblioitem_api } ) {
449
        is( $biblio_api->{$key}, $biblioitem_api->{$key}, "$key is added to the biblio object" );
451
        is( $biblio_api->{$key}, $biblioitem_api->{$key}, "$key is added to the biblio object" );
450
    }
452
    }
451
453
454
    $biblio_api = $biblio->to_api({ embed => { items => {} } });
455
    is_deeply( $biblio_api->{items}, [ $item->to_api ], 'Item correctly embedded' );
456
452
    $schema->storage->txn_rollback;
457
    $schema->storage->txn_rollback;
453
};
458
};
454
- 

Return to bug 24366