From 1ec315b1de2f86d4df2b2527010e461f54e23c3a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 15 Oct 2020 09:35:43 -0300 Subject: [PATCH] Bug 26555: (QA follow-up) Add a 'payload' attribute for carrying useful things Signed-off-by: Tomas Cohen Arazi --- Koha/Object/Message.pm | 9 ++++++--- t/Koha/Object/Message.t | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Koha/Object/Message.pm b/Koha/Object/Message.pm index 42349c98644..987abe4551b 100644 --- a/Koha/Object/Message.pm +++ b/Koha/Object/Message.pm @@ -21,7 +21,7 @@ use base qw(Class::Accessor); use Koha::Exceptions; -__PACKAGE__->mk_ro_accessors(qw( message type )); +__PACKAGE__->mk_ro_accessors(qw( message payload type )); =head1 NAME @@ -41,7 +41,8 @@ Koha::Object::Message - Class encapsulating action feedback messages in Koha::Ob my $message = Koha::Object::Message->new( { message => $some_message, - [ type => 'error' ] + [ type => 'error', + payload => $payload ] } ); @@ -54,6 +55,7 @@ sub new { my $message = $params->{message}; my $type = $params->{type} // 'error'; + my $payload = $params->{payload}; Koha::Exceptions::MissingParameter->throw( "Mandatory parameter missing: 'message'" ) unless $message; @@ -61,7 +63,8 @@ sub new { my $self = $class->SUPER::new( { message => $message, - type => $type + type => $type, + payload => $payload, } ); diff --git a/t/Koha/Object/Message.t b/t/Koha/Object/Message.t index 04bbe5e7967..6eb2f2e8724 100755 --- a/t/Koha/Object/Message.t +++ b/t/Koha/Object/Message.t @@ -28,7 +28,7 @@ BEGIN { subtest 'new() tests' => sub { - plan tests => 8; + plan tests => 11; my $some_error = 'Some error'; @@ -42,6 +42,11 @@ subtest 'new() tests' => sub { is( $message->message, $some_error, 'The message attribute has the right value' ); is( $message->type, 'callback', 'type is correct' ); + $message = Koha::Object::Message->new({ message => $some_error, payload => { some => 'structure' } }); + is( ref($message), 'Koha::Object::Message', 'Type is correct' ); + is( $message->message, $some_error, 'The message attribute has the right value' ); + is_deeply( $message->payload, { some => 'structure' }, 'payload is correct' ); + throws_ok { Koha::Object::Message->new({ blah => 'ohh' }); } 'Koha::Exceptions::MissingParameter', -- 2.28.0