@@ -, +, @@ $ kshell k$ prove t/db_dependent/Koha/Object.t --- Koha/Object.pm | 7 ++++++- t/db_dependent/Koha/Object.t | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) --- a/Koha/Object.pm +++ a/Koha/Object.pm @@ -545,7 +545,12 @@ sub attributes_from_api { ? $from_api_mapping->{$key} : $key; - if ( _date_or_datetime_column_type( $columns_info->{$koha_field_name}->{data_type} ) ) { + if ( $columns_info->{$koha_field_name}->{is_boolean} ) { + # TODO: Remove when D8 is formally deprecated + # Handle booleans gracefully + $value = ( $value ) ? 1 : 0; + } + elsif ( _date_or_datetime_column_type( $columns_info->{$koha_field_name}->{data_type} ) ) { try { $value = dt_from_string($value, 'rfc3339'); } --- a/t/db_dependent/Koha/Object.t +++ a/t/db_dependent/Koha/Object.t @@ -455,15 +455,13 @@ subtest 'new_from_api() tests' => sub { subtest 'attributes_from_api() tests' => sub { - plan tests => 8; + plan tests => 12; my $patron = Koha::Patron->new(); - use Data::Printer colored => 1; - my $attrs = $patron->attributes_from_api( { - updated_on => '2019-12-27T14:53:00' + updated_on => '2019-12-27T14:53:00', } ); @@ -519,6 +517,19 @@ subtest 'attributes_from_api() tests' => sub { 'date_of_birth', 'Exception parameter is the API field name, not the DB one' ); + + # Booleans + $attrs = $patron->attributes_from_api( + { + incorrect_address => Mojo::JSON->true, + patron_card_lost => Mojo::JSON->false, + } + ); + + ok( exists $attrs->{gonenoaddress}, 'Attribute gets translated' ); + is( $attrs->{gonenoaddress}, 1, 'Boolean correctly translated to integer (true => 1)' ); + ok( exists $attrs->{lost}, 'Attribute gets translated' ); + is( $attrs->{lost}, 0, 'Boolean correctly translated to integer (false => 0)' ); }; subtest "Test update method" => sub { --