Browse Source

Bug 26555: (QA follow-up) Add a 'payload' attribute for carrying useful things

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
Tomás Cohen Arazi 4 years ago
committed by Jonathan Druart
parent
commit
8f815e748f
  1. 9
      Koha/Object/Message.pm
  2. 7
      t/Koha/Object/Message.t

9
Koha/Object/Message.pm

@ -21,7 +21,7 @@ use base qw(Class::Accessor);
use Koha::Exceptions; use Koha::Exceptions;
__PACKAGE__->mk_ro_accessors(qw( message type )); __PACKAGE__->mk_ro_accessors(qw( message payload type ));
=head1 NAME =head1 NAME
@ -41,7 +41,8 @@ Koha::Object::Message - Class encapsulating action feedback messages in Koha::Ob
my $message = Koha::Object::Message->new( my $message = Koha::Object::Message->new(
{ {
message => $some_message, message => $some_message,
[ type => 'error' ] [ type => 'error',
payload => $payload ]
} }
); );
@ -54,6 +55,7 @@ sub new {
my $message = $params->{message}; my $message = $params->{message};
my $type = $params->{type} // 'error'; my $type = $params->{type} // 'error';
my $payload = $params->{payload};
Koha::Exceptions::MissingParameter->throw( "Mandatory parameter missing: 'message'" ) Koha::Exceptions::MissingParameter->throw( "Mandatory parameter missing: 'message'" )
unless $message; unless $message;
@ -61,7 +63,8 @@ sub new {
my $self = $class->SUPER::new( my $self = $class->SUPER::new(
{ {
message => $message, message => $message,
type => $type type => $type,
payload => $payload,
} }
); );

7
t/Koha/Object/Message.t

@ -28,7 +28,7 @@ BEGIN {
subtest 'new() tests' => sub { subtest 'new() tests' => sub {
plan tests => 8; plan tests => 11;
my $some_error = 'Some error'; 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->message, $some_error, 'The message attribute has the right value' );
is( $message->type, 'callback', 'type is correct' ); 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 throws_ok
{ Koha::Object::Message->new({ blah => 'ohh' }); } { Koha::Object::Message->new({ blah => 'ohh' }); }
'Koha::Exceptions::MissingParameter', 'Koha::Exceptions::MissingParameter',

Loading…
Cancel
Save