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

(-)a/t/db_dependent/Koha/Messages.t (-1 / +40 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Test::More tests => 4;
5
use Test::MockModule;
6
use C4::Auth qw(get_session);
7
8
use_ok('Koha::Messages');
9
10
# Create a new session and save it immediately in database.
11
my $session = get_session('');
12
$session->flush;
13
14
# Mock CGI::cookie to return the CGISESSID of just created session.
15
my $cgi_module = new Test::MockModule('CGI');
16
$cgi_module->mock('cookie', sub {
17
    my ($self, $name) = @_;
18
    return $session->id if ($name eq 'CGISESSID');
19
});
20
21
my $messages = messages_get();
22
is_deeply($messages, {}, "no messages at beginning");
23
24
messages_set('ok 1');
25
messages_set('warning 1', 'warning');
26
messages_set('error 1', 'error');
27
messages_set('ok 2');
28
messages_set('warning 2', 'warning');
29
messages_set('error 2', 'error');
30
31
$messages = messages_get();
32
my $expected = {
33
    'ok' => ['ok 1', 'ok 2'],
34
    'warning' => ['warning 1', 'warning 2'],
35
    'error' => ['error 1', 'error 2'],
36
};
37
is_deeply($messages, $expected, "messages successfully retrieved");
38
39
$messages = messages_get();
40
is_deeply($messages, {}, "messages emptied automatically");

Return to bug 11904