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

(-)a/t/Koha/Result/Boolean.t (-1 / +74 lines)
Line 0 Link Here
0
- 
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 => 4;
27
28
    ok( Koha::Result::Boolean->new,
29
        'Defaults to true if initialized without the parameter' );
30
    ok( Koha::Result::Boolean->new('Martin'),
31
        'Evals to true in boolean context if set an expression that evals to true' );
32
    ok( !Koha::Result::Boolean->new(0),
33
        'Evals to false in boolean context if set a false expression' );
34
    ok( !Koha::Result::Boolean->new(""),
35
        'Evals to false in boolean context if set a false expression' );
36
37
};
38
39
subtest 'set_value() tests' => sub {
40
41
    plan tests => 4;
42
43
    my $bool = Koha::Result::Boolean->new;
44
45
    ok( !$bool->set_value(),
46
        'Undef makes it eval to false' );
47
    ok( $bool->set_value('Martin'),
48
        'Evals to true in boolean context if set an expression that evals to true' );
49
    ok( !$bool->set_value(0),
50
        'Evals to false in boolean context if set a false expression' );
51
    ok( !$bool->set_value(""),
52
        'Evals to false in boolean context if set a false expression' );
53
54
};
55
56
subtest 'messages() and add_message() tests' => sub {
57
58
    plan tests => 5;
59
60
    my $bool = Koha::Result::Boolean->new();
61
62
    my @messages = @{ $bool->messages };
63
    is( scalar @messages, 0, 'No messages' );
64
65
    $bool->add_message({ message => "message_1" });
66
    $bool->add_message({ message => "message_2" });
67
68
    @messages = @{ $bool->messages };
69
70
    is( scalar @messages, 2, 'Messages are returned' );
71
    is( ref($messages[0]), 'Koha::Object::Message', 'Right type returned' );
72
    is( ref($messages[1]), 'Koha::Object::Message', 'Right type returned' );
73
    is( $messages[0]->message, 'message_1', 'Right message recorded' );
74
};

Return to bug 29746