From 31521c6f54301eb2d2742c66501657f857cc6b40 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 6 Mar 2014 08:47:59 +0100 Subject: [PATCH] Bug 11904: Unit tests for Koha::Messages --- t/db_dependent/Koha/Messages.t | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 t/db_dependent/Koha/Messages.t diff --git a/t/db_dependent/Koha/Messages.t b/t/db_dependent/Koha/Messages.t new file mode 100755 index 0000000..ac5ab3e --- /dev/null +++ b/t/db_dependent/Koha/Messages.t @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +use Modern::Perl; +use Test::More tests => 4; +use Test::MockModule; +use C4::Auth qw(get_session); + +use_ok('Koha::Messages'); + +# Create a new session and save it immediately in database. +my $session = get_session(''); +$session->flush; + +# Mock CGI::cookie to return the CGISESSID of just created session. +my $cgi_module = new Test::MockModule('CGI'); +$cgi_module->mock('cookie', sub { + my ($self, $name) = @_; + return $session->id if ($name eq 'CGISESSID'); +}); + +my $messages = messages_get(); +is_deeply($messages, {}, "no messages at beginning"); + +messages_set('ok 1'); +messages_set('warning 1', 'warning'); +messages_set('error 1', 'error'); +messages_set('ok 2'); +messages_set('warning 2', 'warning'); +messages_set('error 2', 'error'); + +$messages = messages_get(); +my $expected = { + 'ok' => ['ok 1', 'ok 2'], + 'warning' => ['warning 1', 'warning 2'], + 'error' => ['error 1', 'error 2'], +}; +is_deeply($messages, $expected, "messages successfully retrieved"); + +$messages = messages_get(); +is_deeply($messages, {}, "messages emptied automatically"); -- 1.7.10.4