Skip to content

Commit

Permalink
Add test for SpectreTest macro. Handle fall-through condition in Macr…
Browse files Browse the repository at this point in the history
…o itself.
  • Loading branch information
perlDreamer committed Dec 1, 2009
1 parent d535e74 commit ad67b8a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/WebGUI/Macro/SpectreCheck.pm
Expand Up @@ -35,8 +35,8 @@ sub process {
my $i18n = WebGUI::International->new($session, "Macro_SpectreCheck");
if (defined $status) {
return $i18n->get('success') if($status eq 'success');
return $i18n->get('subnet') if($status eq 'subnet');
return $i18n->get('spectre') if($status eq 'spectre');
return $i18n->get('subnet') if($status eq 'subnet');
return $i18n->get('spectre');
}
else {
return $i18n->get('spectre');
Expand Down
44 changes: 44 additions & 0 deletions t/Macro/SpectreCheck.t
@@ -0,0 +1,44 @@
#-------------------------------------------------------------------
# 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::Operation::Spectre;

my $original_spectreCheck = \&WebGUI::Operation::Spectre::spectreTest;
my $spectreStatus;
*WebGUI::Operation::Spectre::spectreTest = sub {
return $spectreStatus;
};

use WebGUI::Macro::SpectreCheck;

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

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

plan tests => 4;

my $i18n = WebGUI::International->new($session, 'Macro_SpectreCheck');

is WebGUI::Macro::SpectreCheck::process($session), $i18n->get('spectre'), 'with no status, get an i18n message for a bad spectre';

$spectreStatus = 'success';
is WebGUI::Macro::SpectreCheck::process($session), $i18n->get('success'), 'good status';
$spectreStatus = 'subnet';
is WebGUI::Macro::SpectreCheck::process($session), $i18n->get('subnet'), 'bad subnet';
$spectreStatus = 'spectre';
is WebGUI::Macro::SpectreCheck::process($session), $i18n->get('spectre'), 'bad spectre';

*WebGUI::Operation::Spectre::spectreTest = $original_spectreCheck;

0 comments on commit ad67b8a

Please sign in to comment.