Done with Macro test maintenance.

This commit is contained in:
Colin Kuskie 2009-10-31 19:02:52 -07:00
parent bd6677942c
commit 71548339de
11 changed files with 112 additions and 221 deletions

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::PageTitle;
use Data::Dumper;
use Test::More;
@ -22,13 +23,9 @@ use Test::MockObject;
my $session = WebGUI::Test->session;
my $numTests = 7;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::PageTitle';
my $loaded = use_ok($macro);
my $homeAsset = WebGUI::Asset->getDefault($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
@ -45,10 +42,7 @@ my $snippet = $homeAsset->addChild({
});
$versionTag->commit;
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
addToCleanup($versionTag);
is(
WebGUI::Macro::PageTitle::process($session),
@ -66,7 +60,6 @@ $session->asset($snippet);
my $macroOutput = WebGUI::Macro::PageTitle::process($session);
is($macroOutput, $snippet->get('title'), "testing title returned from localy created asset with known title");
my $origSessionRequest = $session->{_request};
my ($operation, $function) = (0,0);
@ -105,9 +98,3 @@ $operation = 1;
$function = 1;
$output = WebGUI::Macro::PageTitle::process($session);
is($output, $urlizedTitle, 'fetching urlized title via an operation and function');
}
END {
$versionTag->rollback;
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Asset::Template;
use WebGUI::Macro::PickLanguage;
use Test::More; # increment this value for each test you create
use Test::Deep;
@ -24,13 +25,8 @@ my $session = WebGUI::Test->session;
my $numTests = 3;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::PickLanguage';
my $loaded = use_ok($macro);
my $macroMock = Test::MockObject->new({});
$macroMock->set_isa('WebGUI::Macro::PickLanguage');
$macroMock->set_true('process');

View file

@ -13,8 +13,8 @@ use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro::RootTitle;
use WebGUI::Session;
use WebGUI::Macro::RootTitle;
use Data::Dumper;
use Test::More; # increment this value for each test you create
@ -32,6 +32,7 @@ my $session = WebGUI::Test->session;
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Adding assets for RootTitle tests"});
addToCleanup($versionTag);
my $root = WebGUI::Asset->getRoot($session);
my %properties_A = (
@ -160,17 +161,10 @@ my @testSets = (
);
my $numTests = scalar @testSets;
$numTests += 2;
$numTests += 1;
plan tests => $numTests;
my $macro = 'WebGUI::Macro::RootTitle';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
is(
WebGUI::Macro::RootTitle::process($session),
'',
@ -183,12 +177,3 @@ foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::RootTitle::process($session);
is($output, $testSet->{title}, $testSet->{comment});
}
}
END { ##Clean-up after yourself, always
$session->db->write('update asset set lineage=? where assetId=?',[$origLineage, $asset_->getId]);
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
}

View file

@ -17,6 +17,7 @@ use WebGUI::Macro::Slash_gatewayUrl;
use WebGUI::Session;
use WebGUI::International;
use WebGUI::DatabaseLink;
use WebGUI::Macro::SQL;
use Data::Dumper;
use Test::More; # increment this value for each test you create
@ -119,14 +120,10 @@ my @testSets = (
my $numTests = scalar @testSets;
++$numTests; ##For the load check;
++$numTests; ##For the allow macro access test;
plan tests => $numTests;
my $macro = 'WebGUI::Macro::SQL';
my $loaded = use_ok($macro);
$WebGUIdbLink->set({allowMacroAccess=>0});
# run one test to test allowMacroAccess
@ -136,10 +133,6 @@ is($output, $i18n->get('database access not allowed'), 'Test allow access from m
# set allowMacroAccess to 1 to allow other tests to run
$WebGUIdbLink->set({allowMacroAccess=>1});
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
# we know some of these will fail. Keep them quiet.
local $SIG{__WARN__} = sub {};
@ -148,8 +141,6 @@ foreach my $testSet (@testSets) {
is($output, $testSet->{output}, $testSet->{comment});
}
}
# reset allowMacroAccess to original value
$WebGUIdbLink->set({allowMacroAccess=>$originalMacroAccessValue});

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::SessionId;
use HTML::TokeParser;
use Data::Dumper;
@ -21,16 +22,7 @@ use Test::More; # increment this value for each test you create
my $session = WebGUI::Test->session;
my $numTests = 1;
$numTests += 1; #For the use_ok
plan tests => 2;
plan tests => 1;
my $macro = 'WebGUI::Macro::SessionId';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
my $output = WebGUI::Macro::SessionId::process( $session );
is($session->getId, $output, 'Session macro works');
}
my $output = WebGUI::Macro::SessionId::process( $session );
is($session->getId, $output, 'Session macro works');

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::Slash_gatewayUrl;
use Data::Dumper;
use Test::More; # increment this value for each test you create
@ -24,17 +25,7 @@ my $session = WebGUI::Test->session;
##in t/Session/Url.t All we need to do is make sure that the macro
##fetches the same thing as the method.
my $numTests = 4;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::Slash_gatewayUrl';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
plan tests => 4;
$session->setting->set('preventProxyCache', 0);
@ -54,9 +45,3 @@ like($output, qr{/\?noCache=\d+:\d+$}, 'checking the cache settings in the URL')
$output = WebGUI::Macro::Slash_gatewayUrl::process($session, '/foo/bar');
like($output, qr{/foo/bar\?noCache=\d+:\d+$}, 'checking the cache settings in the URL are at the end of the URL');
$session->setting->set('preventProxyCache', 0);
}
END {
}

View file

@ -68,6 +68,7 @@ $asset->update({
$asset->generateThumbnail();
$versionTag->commit;
addToCleanup($versionTag);
##Call the Thumbnail Macro with that Asset's URL and see if it returns
@ -95,10 +96,3 @@ SKIP: {
cmp_bag([$thumbImg->GetPixels(width=>1, height=>1, x=>50, y=>50, map=>'RGB', normalize=>'true')], [0,0,1], 'blue pixel #3');
}
END {
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
##Storage is cleaned up by rolling back the version tag
}

View file

@ -79,6 +79,3 @@ sub setupTest {
}
return @testSets;
}
END { ##Clean-up after yourself, always
}

View file

@ -29,130 +29,119 @@ my $template = setupJSONtemplate($session);
my @users = setupUsers($session);
my $i18n = WebGUI::International->new($session,'Macro_UsersOnline');
my $numTests = 1; # Module loading test
$numTests += 30; # Static tests
plan tests => 30;
plan tests => $numTests;
# Basic testing -----------------------------------------------------------
my $macro = 'WebGUI::Macro::UsersOnline';
my $loaded = use_ok($macro);
# Check for default template
my $defTemplate = WebGUI::Asset->new($session, 'h_T2xtOxGRQ9QJOR6ebLpQ');
ok(defined $defTemplate, 'default template is present');
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
# Basic testing -----------------------------------------------------------
# Check for default template
my $defTemplate = WebGUI::Asset->new($session, 'h_T2xtOxGRQ9QJOR6ebLpQ');
ok(defined $defTemplate, 'default template is present');
# Call with default values
my $html = WebGUI::Macro::UsersOnline::process($session);
cmp_ok((length $html), '>', 0, 'call with default template and values returns some output');
# Call with default values
my $html = WebGUI::Macro::UsersOnline::process($session);
cmp_ok((length $html), '>', 0, 'call with default template and values returns some output');
# Test labels -------------------------------------------------------------
# Test labels -------------------------------------------------------------
$session->user({userId => 1});
my $json = WebGUI::Macro::UsersOnline::process($session, $template->getId);
my $vars = JSON::from_json($json);
$session->user({userId => 1});
my $json = WebGUI::Macro::UsersOnline::process($session, $template->getId);
my $vars = JSON::from_json($json);
is($vars->{'usersOnline_label'}, $i18n->get('Users Online'), 'usersOnline_label');
is($vars->{'members_label'}, $i18n->get('Members'), 'members_label');
is($vars->{'visitors_label'}, $i18n->get('Visitors'), 'visitors_label');
is($vars->{'total_label'}, $i18n->get('Total'), 'total_label');
is($vars->{'membersOnline_label'}, $i18n->get('Members Online'), 'membersOnline_label');
is($vars->{'visitorsOnline_label'}, $i18n->get('Visitors Online'), 'visitorsOnline_label');
is($vars->{'avatar_label'}, $i18n->get('Avatar'), 'avatar_label');
is($vars->{'name_label'}, $i18n->get('Name'), 'name_label');
is($vars->{'alias_label'}, $i18n->get('Alias'), 'alias_label');
is($vars->{'session_label'}, $i18n->get('Session'), 'session_label');
is($vars->{'ip_label'}, $i18n->get('IP'), 'ip_label');
is($vars->{'lastActivity_label'}, $i18n->get('Last Activity'), 'lastActivity_label');
is($vars->{'usersOnline_label'}, $i18n->get('Users Online'), 'usersOnline_label');
is($vars->{'members_label'}, $i18n->get('Members'), 'members_label');
is($vars->{'visitors_label'}, $i18n->get('Visitors'), 'visitors_label');
is($vars->{'total_label'}, $i18n->get('Total'), 'total_label');
is($vars->{'membersOnline_label'}, $i18n->get('Members Online'), 'membersOnline_label');
is($vars->{'visitorsOnline_label'}, $i18n->get('Visitors Online'), 'visitorsOnline_label');
is($vars->{'avatar_label'}, $i18n->get('Avatar'), 'avatar_label');
is($vars->{'name_label'}, $i18n->get('Name'), 'name_label');
is($vars->{'alias_label'}, $i18n->get('Alias'), 'alias_label');
is($vars->{'session_label'}, $i18n->get('Session'), 'session_label');
is($vars->{'ip_label'}, $i18n->get('IP'), 'ip_label');
is($vars->{'lastActivity_label'}, $i18n->get('Last Activity'), 'lastActivity_label');
# Test logic --------------------------------------------------------------
# Test logic --------------------------------------------------------------
like($vars->{'visitors'}, qr/[0-9]+/, 'visitors is numeric');
like($vars->{'visitors'}, qr/[0-9]+/, 'visitors is numeric');
# Does not work in testing environments that run on the loopback interface,
# since these queries are filtered out by the macro.
# is($vars->{'visitors'} > 0, 1, 'visitors > 0 when calling as visitor');
like($vars->{'members'}, qr/[0-9]+/, 'members is numeric');
cmp_ok($vars->{'members'}, '>', 0, 'members > 0 since we have created one visible active member');
is($vars->{'total'}, $vars->{'visitors'} + $vars->{'members'}, 'total == visitors + members');
ok($vars->{'isVisitor'}, 'isVisitor is true when calling as visitor');
ok(defined $vars->{'hasMembers'}, 'hasMembers is defined since we have created one visible active member');
like($vars->{'members'}, qr/[0-9]+/, 'members is numeric');
cmp_ok($vars->{'members'}, '>', 0, 'members > 0 since we have created one visible active member');
is($vars->{'total'}, $vars->{'visitors'} + $vars->{'members'}, 'total == visitors + members');
ok($vars->{'isVisitor'}, 'isVisitor is true when calling as visitor');
ok(defined $vars->{'hasMembers'}, 'hasMembers is defined since we have created one visible active member');
# Check member loop -------------------------------------------------------
# Check member loop -------------------------------------------------------
my $allFieldsSet = 1;
my $firstUserPresent = 0;
my $secondUserAbsent = 1;
my $allFieldsSet = 1;
my $firstUserPresent = 0;
my $secondUserAbsent = 1;
foreach (@{$vars->{'member_loop'}}) {
# Check whether first user is present
if ($_->{'username'} eq 'tester1') {
# Indicate success
$firstUserPresent = 1;
# Check whether alias and name have been set correctly
$allFieldsSet = $_->{'alias'} eq 'alias1';
$allFieldsSet &&= $_->{'firstName'} eq 'first1';
$allFieldsSet &&= $_->{'middleName'} eq 'middle1';
$allFieldsSet &&= $_->{'lastName'} eq 'last1';
}
# Check whether second user is present
if ($_->{'username'} eq 'tester2') {
# Indicate failure
$secondUserAbsent = 0;
}
# Check whether remaining fields have been set. Note that we cannot
# check for the alias, name or avatar, since these values may be
# optional.
$allFieldsSet &&= $_->{'uid'} =~ /.*/;
$allFieldsSet &&= $_->{'sessionId'} =~ /.*/;
# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user
$allFieldsSet &&= $_->{'lastActivity'} =~ /.*/;
}
# Check booleans indicating errors
ok($allFieldsSet, 'fields in the member loop have been set correctly');
ok($firstUserPresent, 'the first user is present in the member loop');
ok($secondUserAbsent, 'the second user is absent from the member loop');
# Check visitor loop ------------------------------------------------------
$allFieldsSet = 1;
foreach (@{$vars->{'visitor_loop'}}) {
# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user
$allFieldsSet &&= $_->{'sessionId'} =~ /.*/;
$allFieldsSet &&= $_->{'lastActivity'} =~ /.*/;
foreach (@{$vars->{'member_loop'}}) {
# Check whether first user is present
if ($_->{'username'} eq 'tester1') {
# Indicate success
$firstUserPresent = 1;
# Check whether alias and name have been set correctly
$allFieldsSet = $_->{'alias'} eq 'alias1';
$allFieldsSet &&= $_->{'firstName'} eq 'first1';
$allFieldsSet &&= $_->{'middleName'} eq 'middle1';
$allFieldsSet &&= $_->{'lastName'} eq 'last1';
}
# Check booleans indicating errors
ok($allFieldsSet, 'fields in the visitor loop have been set correctly');
# Check whether second user is present
if ($_->{'username'} eq 'tester2') {
# Indicate failure
$secondUserAbsent = 0;
}
# Test macro parameters ---------------------------------------------------
# Call with zero max limits
$json = WebGUI::Macro::UsersOnline::process($session, $template->getId, undef, 0, 0);
$vars = JSON::from_json($json);
ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when display limit is set to zero');
is(@{$vars->{'member_loop'}} == 0, 1, 'empty member loop when display limit is set to zero');
is(@{$vars->{'visitor_loop'}} == 0, 1, 'empty visitor loop when display limit is set to zero');
# Call with zero max inactivity time
$json = WebGUI::Macro::UsersOnline::process($session, $template->getId, 0, undef, undef);
$vars = JSON::from_json($json);
ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when max inactivity time is set to zero');
is(@{$vars->{'member_loop'}} == 0, 1, 'empty member loop when max inactivity time is set to zero');
is(@{$vars->{'visitor_loop'}} == 0, 1, 'empty visitor loop when max inactivity time is set to zero');
# Check whether remaining fields have been set. Note that we cannot
# check for the alias, name or avatar, since these values may be
# optional.
$allFieldsSet &&= $_->{'uid'} =~ /.*/;
$allFieldsSet &&= $_->{'sessionId'} =~ /.*/;
# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user
$allFieldsSet &&= $_->{'lastActivity'} =~ /.*/;
}
# Check booleans indicating errors
ok($allFieldsSet, 'fields in the member loop have been set correctly');
ok($firstUserPresent, 'the first user is present in the member loop');
ok($secondUserAbsent, 'the second user is absent from the member loop');
# Check visitor loop ------------------------------------------------------
$allFieldsSet = 1;
foreach (@{$vars->{'visitor_loop'}}) {
# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user
$allFieldsSet &&= $_->{'sessionId'} =~ /.*/;
$allFieldsSet &&= $_->{'lastActivity'} =~ /.*/;
}
# Check booleans indicating errors
ok($allFieldsSet, 'fields in the visitor loop have been set correctly');
# Test macro parameters ---------------------------------------------------
# Call with zero max limits
$json = WebGUI::Macro::UsersOnline::process($session, $template->getId, undef, 0, 0);
$vars = JSON::from_json($json);
ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when display limit is set to zero');
is(@{$vars->{'member_loop'}} == 0, 1, 'empty member loop when display limit is set to zero');
is(@{$vars->{'visitor_loop'}} == 0, 1, 'empty visitor loop when display limit is set to zero');
# Call with zero max inactivity time
$json = WebGUI::Macro::UsersOnline::process($session, $template->getId, 0, undef, undef);
$vars = JSON::from_json($json);
ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when max inactivity time is set to zero');
is(@{$vars->{'member_loop'}} == 0, 1, 'empty member loop when max inactivity time is set to zero');
is(@{$vars->{'visitor_loop'}} == 0, 1, 'empty visitor loop when max inactivity time is set to zero');
sub setupUsers {
@ -192,7 +181,7 @@ sub setupUsers {
my $newSession = WebGUI::Session->open(WebGUI::Test::root, WebGUI::Test::file);
$newSession->user({user => $_});
}
WebGUI::Test->usersToDelete(@users);
addToCleanup(@users);
return @users;
}
@ -246,10 +235,6 @@ sub setupJSONtemplate {
}
EOTMPL
my $template = WebGUI::Asset->getImportNode($session)->addChild({className=>'WebGUI::Asset::Template', namespace => 'Macro/UsersOnline', template=>$templateBody});
addToCleanup($template);
return $template;
}
END { ##Clean-up after yourself, always
$template->purge;
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::ViewCart;
use HTML::TokeParser;
use Data::Dumper;
@ -21,8 +22,6 @@ use Test::More; # increment this value for each test you create
my $session = WebGUI::Test->session;
my @testSets = (
{
comment => 'default',
@ -41,17 +40,8 @@ foreach my $testSet (@testSets) {
$numTests += 1 + (ref $testSet->{output} eq 'CODE');
}
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::ViewCart';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::ViewCart::process( $session, $testSet->{label});
if (ref $testSet->{output} eq 'CODE') {
@ -64,9 +54,6 @@ foreach my $testSet (@testSets) {
}
}
}
sub simpleHTMLParser {
my ($text) = @_;
my $p = HTML::TokeParser->new(\$text);
@ -86,6 +73,3 @@ sub simpleTextParser {
return ($url, $label);
}
END {
}

View file

@ -25,7 +25,7 @@ my $session = WebGUI::Test->session;
my $homeAsset = WebGUI::Asset->getDefault($session);
$session->asset($homeAsset);
my ($versionTag, $template) = setupTest($session, $homeAsset);
my $template = setupTest($session, $homeAsset);
my $i18n = WebGUI::International->new($session, 'Macro_r_printable');
@ -125,8 +125,9 @@ sub setupTest {
};
my $asset = $defaultNode->addChild($properties, $properties->{id});
$versionTag->commit;
addToCleanup($versionTag);
return $versionTag, $asset;
return $asset;
}
sub simpleHTMLParser {
@ -148,9 +149,3 @@ sub simpleTextParser {
return ($url, $label);
}
END { ##Clean-up after yourself, always
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
}