View | Details | Raw Unified | Return to bug 26555
Collapse All | Expand All

(-)a/Koha/Object/Message.pm (-3 / +6 lines)
Lines 21-27 use base qw(Class::Accessor); Link Here
21
21
22
use Koha::Exceptions;
22
use Koha::Exceptions;
23
23
24
__PACKAGE__->mk_ro_accessors(qw( message type ));
24
__PACKAGE__->mk_ro_accessors(qw( message payload type ));
25
25
26
=head1 NAME
26
=head1 NAME
27
27
Lines 41-47 Koha::Object::Message - Class encapsulating action feedback messages in Koha::Ob Link Here
41
    my $message = Koha::Object::Message->new(
41
    my $message = Koha::Object::Message->new(
42
        {
42
        {
43
            message => $some_message,
43
            message => $some_message,
44
          [ type    => 'error' ]
44
          [ type    => 'error',
45
            payload => $payload ]
45
        }
46
        }
46
    );
47
    );
47
48
Lines 54-59 sub new { Link Here
54
55
55
    my $message = $params->{message};
56
    my $message = $params->{message};
56
    my $type    = $params->{type} // 'error';
57
    my $type    = $params->{type} // 'error';
58
    my $payload = $params->{payload};
57
59
58
    Koha::Exceptions::MissingParameter->throw( "Mandatory parameter missing: 'message'" )
60
    Koha::Exceptions::MissingParameter->throw( "Mandatory parameter missing: 'message'" )
59
        unless $message;
61
        unless $message;
Lines 61-67 sub new { Link Here
61
    my $self = $class->SUPER::new(
63
    my $self = $class->SUPER::new(
62
        {
64
        {
63
            message => $message,
65
            message => $message,
64
            type    => $type
66
            type    => $type,
67
            payload => $payload,
65
        }
68
        }
66
    );
69
    );
67
70
(-)a/t/Koha/Object/Message.t (-2 / +6 lines)
Lines 28-34 BEGIN { Link Here
28
28
29
subtest 'new() tests' => sub {
29
subtest 'new() tests' => sub {
30
30
31
    plan tests => 8;
31
    plan tests => 11;
32
32
33
    my $some_error = 'Some error';
33
    my $some_error = 'Some error';
34
34
Lines 42-47 subtest 'new() tests' => sub { Link Here
42
    is( $message->message, $some_error, 'The message attribute has the right value' );
42
    is( $message->message, $some_error, 'The message attribute has the right value' );
43
    is( $message->type, 'callback', 'type is correct' );
43
    is( $message->type, 'callback', 'type is correct' );
44
44
45
    $message = Koha::Object::Message->new({ message => $some_error, payload => { some => 'structure' } });
46
    is( ref($message), 'Koha::Object::Message', 'Type is correct' );
47
    is( $message->message, $some_error, 'The message attribute has the right value' );
48
    is_deeply( $message->payload, { some => 'structure' }, 'payload is correct' );
49
45
    throws_ok
50
    throws_ok
46
        { Koha::Object::Message->new({ blah => 'ohh' }); }
51
        { Koha::Object::Message->new({ blah => 'ohh' }); }
47
        'Koha::Exceptions::MissingParameter',
52
        'Koha::Exceptions::MissingParameter',
48
- 

Return to bug 26555