Bug 25815: SIP Checkout: add more information on why the patron is blocked.
[koha.git] / t / Koha / Result / Boolean.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 4;
21
22 use_ok('Koha::Result::Boolean');
23
24 subtest 'new() tests' => sub {
25
26     plan tests => 2;
27
28     subtest 'bool context' => sub {
29
30         plan tests => 4;
31
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' );
40     };
41
42     subtest '== context' => sub {
43
44         plan tests => 4;
45
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' );
54     };
55 };
56
57 subtest 'set_value() tests' => sub {
58
59     plan tests => 4;
60
61     my $bool = Koha::Result::Boolean->new;
62
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' );
71
72 };
73
74 subtest 'messages() and add_message() tests' => sub {
75
76     plan tests => 5;
77
78     my $bool = Koha::Result::Boolean->new();
79
80     my @messages = @{ $bool->messages };
81     is( scalar @messages, 0, 'No messages' );
82
83     $bool->add_message({ message => "message_1" });
84     $bool->add_message({ message => "message_2" });
85
86     @messages = @{ $bool->messages };
87
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' );
92 };