Bug 34972: Add tests for ModReservesCancelAll
[koha.git] / t / Koha / Object / Message.t
1 #!/usr/bin/perl
2
3 # Copyright 2020 Koha Development team
4 #
5 # This file is part of Koha
6 #
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.
11 #
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.
16 #
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>.
19
20 use Modern::Perl;
21
22 use Test::More tests => 2;
23 use Test::Exception;
24
25 BEGIN {
26     use_ok('Koha::Object::Message');
27 }
28
29 subtest 'new() tests' => sub {
30
31     plan tests => 11;
32
33     my $some_error = 'Some error';
34
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' );
39
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' );
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
50     throws_ok
51         { Koha::Object::Message->new({ blah => 'ohh' }); }
52         'Koha::Exceptions::MissingParameter',
53         'Exception thrown if required parameter missing';
54
55     like( "$@", qr/Mandatory parameter missing: 'message'/, 'Expected exception message' );
56 };