3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 4;
22 use_ok('Koha::Result::Boolean');
24 subtest 'new() tests' => sub {
28 subtest 'bool context' => sub {
32 ok( Koha::Result::Boolean->new,
33 'Defaults to true if initialized without the parameter' );
34 ok( Koha::Result::Boolean->new('Martin'),
35 'Evals to true in boolean context if set an expression that evals to true' );
36 ok( !Koha::Result::Boolean->new(0),
37 'Evals to false in boolean context if set a false expression' );
38 ok( !Koha::Result::Boolean->new(""),
39 'Evals to false in boolean context if set a false expression' );
42 subtest '== context' => sub {
46 cmp_ok( Koha::Result::Boolean->new, '==', 1,
47 'Defaults 1 if initialized without the parameter' );
48 cmp_ok( Koha::Result::Boolean->new('Martin'), '==', 1,
49 'Evals 1 if set an expression that evals to true' );
50 cmp_ok( Koha::Result::Boolean->new(0), '==', 0,
51 'Evals 0 if set a false expression' );
52 cmp_ok( Koha::Result::Boolean->new(""), '==', 0,
53 'Evals 0 if set a false expression' );
57 subtest 'set_value() tests' => sub {
61 my $bool = Koha::Result::Boolean->new;
63 ok( !$bool->set_value(),
64 'Undef makes it eval to false' );
65 ok( $bool->set_value('Martin'),
66 'Evals to true in boolean context if set an expression that evals to true' );
67 ok( !$bool->set_value(0),
68 'Evals to false in boolean context if set a false expression' );
69 ok( !$bool->set_value(""),
70 'Evals to false in boolean context if set a false expression' );
74 subtest 'messages() and add_message() tests' => sub {
78 my $bool = Koha::Result::Boolean->new();
80 my @messages = @{ $bool->messages };
81 is( scalar @messages, 0, 'No messages' );
83 $bool->add_message({ message => "message_1" });
84 $bool->add_message({ message => "message_2" });
86 @messages = @{ $bool->messages };
88 is( scalar @messages, 2, 'Messages are returned' );
89 is( ref($messages[0]), 'Koha::Object::Message', 'Right type returned' );
90 is( ref($messages[1]), 'Koha::Object::Message', 'Right type returned' );
91 is( $messages[0]->message, 'message_1', 'Right message recorded' );