Bug 24432: add Koha::Objects->from_api_mapping
authorAgustin Moyano <agustinmoyano@theke.io>
Wed, 15 Jan 2020 23:10:01 +0000 (20:10 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 23 Jan 2020 08:52:44 +0000 (08:52 +0000)
This patch adds from_api_mapping to Koha::Objects, in order to be able to get the mapping from a result set.

To test:
1. apply this patch
2. prove t/db_dependent/Koha/Objects.t
3. sign off

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/Objects.pm
t/db_dependent/Koha/Objects.t

index 121e6f5..4b08c79 100644 (file)
@@ -335,6 +335,21 @@ sub attributes_from_api {
     return $self->{_singular_object}->attributes_from_api( $attributes );
 }
 
+=head3 from_api_mapping
+
+    my $mapped_attributes_hash = $objects->from_api_mapping;
+
+Attributes map from the API to DBIC
+
+=cut
+
+sub from_api_mapping {
+    my ( $self ) = @_;
+
+    $self->{_singular_object} ||= $self->object_class->new();
+    return $self->{_singular_object}->from_api_mapping;
+}
+
 =head3 Koha::Objects->_wrap
 
 wraps the DBIC object in a corresponding Koha object
index f9f172e..d40d26b 100644 (file)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 19;
+use Test::More tests => 20;
 use Test::Exception;
 use Test::Warn;
 
@@ -760,3 +760,20 @@ subtest "attributes_from_api() tests" => sub {
 
     $schema->storage->txn_rollback;
 };
+
+subtest "from_api_mapping() tests" => sub {
+
+    plan tests => 1;
+
+    $schema->storage->txn_begin;
+
+    my $cities_rs = Koha::Cities->new;
+    my $city      = Koha::City->new;
+
+    is_deeply(
+        $cities_rs->from_api_mapping,
+        $city->from_api_mapping
+    );
+
+    $schema->storage->txn_rollback;
+};
\ No newline at end of file