@@ -, +, @@ $ kshell k$ prove t/db_dependent/Koha/Objects.t --- Koha/Objects.pm | 15 +++++++++++++++ t/db_dependent/Koha/Objects.t | 24 +++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) --- a/Koha/Objects.pm +++ a/Koha/Objects.pm @@ -320,6 +320,21 @@ sub to_api { return [ map { $_->to_api } $self->as_list ]; } +=head3 attributes_from_api + + my $attributes = $objects->attributes_from_api( $api_attributes ); + +Translates attributes from the API to DBIC + +=cut + +sub attributes_from_api { + my ( $self, $attributes ) = @_; + + $self->{_singular_object} ||= $self->object_class->new(); + return $self->{_singular_object}->attributes_from_api( $attributes ); +} + =head3 Koha::Objects->_wrap wraps the DBIC object in a corresponding Koha object --- a/t/db_dependent/Koha/Objects.t +++ a/t/db_dependent/Koha/Objects.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 17; +use Test::More tests => 18; use Test::Exception; use Test::Warn; @@ -330,3 +330,25 @@ subtest "TO_JSON() tests" => sub { $schema->storage->txn_rollback; }; + +subtest "attributes_from_api() tests" => sub { + + plan tests => 1; + + $schema->storage->txn_begin; + + my $cities_rs = Koha::Cities->new; + my $city = Koha::City->new; + + my $api_attributes = { + name => 'Cordoba', + postal_code => 5000 + }; + + is_deeply( + $cities_rs->attributes_from_api($api_attributes), + $city->attributes_from_api($api_attributes) + ); + + $schema->storage->txn_rollback; +}; --