3 # Copyright 2020 Koha Development team
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Test::More tests => 2;
26 use_ok('Koha::Object::Message');
29 subtest 'new() tests' => sub {
33 my $some_error = 'Some error';
35 my $message = Koha::Object::Message->new({ message => $some_error });
36 is( ref($message), 'Koha::Object::Message', 'Type is correct' );
37 is( $message->message, $some_error, 'The message attribute has the right value' );
38 is( $message->type, 'error', 'If omitted, the type is error' );
40 $message = Koha::Object::Message->new({ message => $some_error, type => 'callback' });
41 is( ref($message), 'Koha::Object::Message', 'Type is correct' );
42 is( $message->message, $some_error, 'The message attribute has the right value' );
43 is( $message->type, 'callback', 'type is correct' );
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' );
51 { Koha::Object::Message->new({ blah => 'ohh' }); }
52 'Koha::Exceptions::MissingParameter',
53 'Exception thrown if required parameter missing';
55 like( "$@", qr/Mandatory parameter missing: 'message'/, 'Expected exception message' );