Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add tests for NewMail macro. Small refactoring for NewMail macro.
  • Loading branch information
perlDreamer committed Nov 8, 2009
1 parent d4ca728 commit 7b5b493
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/WebGUI/Macro/NewMail.pm
Expand Up @@ -11,6 +11,7 @@ package WebGUI::Macro::NewMail;
#-------------------------------------------------------------------

use strict;
use WebGUI::Inbox;

=head1 NAME
Expand Down Expand Up @@ -48,22 +49,18 @@ optional css class to assign to the hyperlink

sub process {
my $session = shift;
my @param = @_;
my $class = $param[0];
my $class = $_[0];

my $db = $session->db;
my $i18n = WebGUI::International->new($session);
my $count = WebGUI::Inbox->new($session)->getUnreadMessageCount;
my $output = "";

if($count > 0) {
my $i18n = WebGUI::International->new($session);
$output = sprintf($i18n->get("private message unread display message"),$count);
$output = _createURL($session,$output,$class);
}

return $output;
}


1;

67 changes: 67 additions & 0 deletions t/Macro/NewMail.t
@@ -0,0 +1,67 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------

use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";

use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::NewMail;
use WebGUI::Inbox;

use Test::More; # increment this value for each test you create

my $session = WebGUI::Test->session;

my $numTests = 3;

plan tests => $numTests;

my $inboxUser = WebGUI::User->create($session);
$session->user({userId => $inboxUser->getId});
addToCleanup($inboxUser);

my $inbox = WebGUI::Inbox->new($session);

is(WebGUI::Macro::NewMail::process($session), '', 'NewMail macro returns "" if user has no messages');

$inbox->addMessage(
{
userId => $inboxUser->getId,
subject => 'test message 1',
message => 'test message 1',
},
{
no_email => 1,
},
);
$inbox->addMessage(
{
userId => $inboxUser->getId,
subject => 'test message 2',
message => 'test message 2',
},
{
no_email => 1,
},
);

like(
WebGUI::Macro::NewMail::process($session),
qr{<a href=".+?op=account;module=inbox">.+?</a>},
q{... returns URL to view user's inbox}
);

like(
WebGUI::Macro::NewMail::process($session, "cssClass"),
qr{<a href=".+?op=account;module=inbox"\s+class="cssClass">.+?</a>},
q{... returns URL to view user's inbox}
);

0 comments on commit 7b5b493

Please sign in to comment.