Done with Macro test maintenance.
This commit is contained in:
parent
bd6677942c
commit
71548339de
11 changed files with 112 additions and 221 deletions
|
|
@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
|
||||||
|
|
||||||
use WebGUI::Test;
|
use WebGUI::Test;
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
|
use WebGUI::Macro::PageTitle;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
|
@ -22,13 +23,9 @@ use Test::MockObject;
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
my $numTests = 7;
|
my $numTests = 7;
|
||||||
$numTests += 1; #For the use_ok
|
|
||||||
|
|
||||||
plan tests => $numTests;
|
plan tests => $numTests;
|
||||||
|
|
||||||
my $macro = 'WebGUI::Macro::PageTitle';
|
|
||||||
my $loaded = use_ok($macro);
|
|
||||||
|
|
||||||
my $homeAsset = WebGUI::Asset->getDefault($session);
|
my $homeAsset = WebGUI::Asset->getDefault($session);
|
||||||
|
|
||||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||||
|
|
@ -45,10 +42,7 @@ my $snippet = $homeAsset->addChild({
|
||||||
});
|
});
|
||||||
|
|
||||||
$versionTag->commit;
|
$versionTag->commit;
|
||||||
|
addToCleanup($versionTag);
|
||||||
SKIP: {
|
|
||||||
|
|
||||||
skip "Unable to load $macro", $numTests-1 unless $loaded;
|
|
||||||
|
|
||||||
is(
|
is(
|
||||||
WebGUI::Macro::PageTitle::process($session),
|
WebGUI::Macro::PageTitle::process($session),
|
||||||
|
|
@ -66,7 +60,6 @@ $session->asset($snippet);
|
||||||
my $macroOutput = WebGUI::Macro::PageTitle::process($session);
|
my $macroOutput = WebGUI::Macro::PageTitle::process($session);
|
||||||
is($macroOutput, $snippet->get('title'), "testing title returned from localy created asset with known title");
|
is($macroOutput, $snippet->get('title'), "testing title returned from localy created asset with known title");
|
||||||
|
|
||||||
|
|
||||||
my $origSessionRequest = $session->{_request};
|
my $origSessionRequest = $session->{_request};
|
||||||
|
|
||||||
my ($operation, $function) = (0,0);
|
my ($operation, $function) = (0,0);
|
||||||
|
|
@ -105,9 +98,3 @@ $operation = 1;
|
||||||
$function = 1;
|
$function = 1;
|
||||||
$output = WebGUI::Macro::PageTitle::process($session);
|
$output = WebGUI::Macro::PageTitle::process($session);
|
||||||
is($output, $urlizedTitle, 'fetching urlized title via an operation and function');
|
is($output, $urlizedTitle, 'fetching urlized title via an operation and function');
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
END {
|
|
||||||
$versionTag->rollback;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
|
||||||
use WebGUI::Test;
|
use WebGUI::Test;
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
use WebGUI::Asset::Template;
|
use WebGUI::Asset::Template;
|
||||||
|
use WebGUI::Macro::PickLanguage;
|
||||||
|
|
||||||
use Test::More; # increment this value for each test you create
|
use Test::More; # increment this value for each test you create
|
||||||
use Test::Deep;
|
use Test::Deep;
|
||||||
|
|
@ -24,13 +25,8 @@ my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
my $numTests = 3;
|
my $numTests = 3;
|
||||||
|
|
||||||
$numTests += 1; #For the use_ok
|
|
||||||
|
|
||||||
plan tests => $numTests;
|
plan tests => $numTests;
|
||||||
|
|
||||||
my $macro = 'WebGUI::Macro::PickLanguage';
|
|
||||||
my $loaded = use_ok($macro);
|
|
||||||
|
|
||||||
my $macroMock = Test::MockObject->new({});
|
my $macroMock = Test::MockObject->new({});
|
||||||
$macroMock->set_isa('WebGUI::Macro::PickLanguage');
|
$macroMock->set_isa('WebGUI::Macro::PickLanguage');
|
||||||
$macroMock->set_true('process');
|
$macroMock->set_true('process');
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ use strict;
|
||||||
use lib "$FindBin::Bin/../lib";
|
use lib "$FindBin::Bin/../lib";
|
||||||
|
|
||||||
use WebGUI::Test;
|
use WebGUI::Test;
|
||||||
use WebGUI::Macro::RootTitle;
|
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
|
use WebGUI::Macro::RootTitle;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
use Test::More; # increment this value for each test you create
|
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);
|
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||||
$versionTag->set({name=>"Adding assets for RootTitle tests"});
|
$versionTag->set({name=>"Adding assets for RootTitle tests"});
|
||||||
|
addToCleanup($versionTag);
|
||||||
|
|
||||||
my $root = WebGUI::Asset->getRoot($session);
|
my $root = WebGUI::Asset->getRoot($session);
|
||||||
my %properties_A = (
|
my %properties_A = (
|
||||||
|
|
@ -160,17 +161,10 @@ my @testSets = (
|
||||||
);
|
);
|
||||||
|
|
||||||
my $numTests = scalar @testSets;
|
my $numTests = scalar @testSets;
|
||||||
$numTests += 2;
|
$numTests += 1;
|
||||||
|
|
||||||
plan tests => $numTests;
|
plan tests => $numTests;
|
||||||
|
|
||||||
my $macro = 'WebGUI::Macro::RootTitle';
|
|
||||||
my $loaded = use_ok($macro);
|
|
||||||
|
|
||||||
SKIP: {
|
|
||||||
|
|
||||||
skip "Unable to load $macro", $numTests-1 unless $loaded;
|
|
||||||
|
|
||||||
is(
|
is(
|
||||||
WebGUI::Macro::RootTitle::process($session),
|
WebGUI::Macro::RootTitle::process($session),
|
||||||
'',
|
'',
|
||||||
|
|
@ -183,12 +177,3 @@ foreach my $testSet (@testSets) {
|
||||||
my $output = WebGUI::Macro::RootTitle::process($session);
|
my $output = WebGUI::Macro::RootTitle::process($session);
|
||||||
is($output, $testSet->{title}, $testSet->{comment});
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ use WebGUI::Macro::Slash_gatewayUrl;
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
use WebGUI::International;
|
use WebGUI::International;
|
||||||
use WebGUI::DatabaseLink;
|
use WebGUI::DatabaseLink;
|
||||||
|
use WebGUI::Macro::SQL;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
use Test::More; # increment this value for each test you create
|
use Test::More; # increment this value for each test you create
|
||||||
|
|
@ -119,14 +120,10 @@ my @testSets = (
|
||||||
|
|
||||||
my $numTests = scalar @testSets;
|
my $numTests = scalar @testSets;
|
||||||
|
|
||||||
++$numTests; ##For the load check;
|
|
||||||
++$numTests; ##For the allow macro access test;
|
++$numTests; ##For the allow macro access test;
|
||||||
|
|
||||||
plan tests => $numTests;
|
plan tests => $numTests;
|
||||||
|
|
||||||
my $macro = 'WebGUI::Macro::SQL';
|
|
||||||
my $loaded = use_ok($macro);
|
|
||||||
|
|
||||||
$WebGUIdbLink->set({allowMacroAccess=>0});
|
$WebGUIdbLink->set({allowMacroAccess=>0});
|
||||||
|
|
||||||
# run one test to test allowMacroAccess
|
# 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
|
# set allowMacroAccess to 1 to allow other tests to run
|
||||||
$WebGUIdbLink->set({allowMacroAccess=>1});
|
$WebGUIdbLink->set({allowMacroAccess=>1});
|
||||||
|
|
||||||
SKIP: {
|
|
||||||
|
|
||||||
skip "Unable to load $macro", $numTests-1 unless $loaded;
|
|
||||||
|
|
||||||
foreach my $testSet (@testSets) {
|
foreach my $testSet (@testSets) {
|
||||||
# we know some of these will fail. Keep them quiet.
|
# we know some of these will fail. Keep them quiet.
|
||||||
local $SIG{__WARN__} = sub {};
|
local $SIG{__WARN__} = sub {};
|
||||||
|
|
@ -148,8 +141,6 @@ foreach my $testSet (@testSets) {
|
||||||
is($output, $testSet->{output}, $testSet->{comment});
|
is($output, $testSet->{output}, $testSet->{comment});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
# reset allowMacroAccess to original value
|
# reset allowMacroAccess to original value
|
||||||
$WebGUIdbLink->set({allowMacroAccess=>$originalMacroAccessValue});
|
$WebGUIdbLink->set({allowMacroAccess=>$originalMacroAccessValue});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
|
||||||
|
|
||||||
use WebGUI::Test;
|
use WebGUI::Test;
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
|
use WebGUI::Macro::SessionId;
|
||||||
use HTML::TokeParser;
|
use HTML::TokeParser;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
|
|
@ -21,16 +22,7 @@ use Test::More; # increment this value for each test you create
|
||||||
|
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
my $numTests = 1;
|
plan tests => 1;
|
||||||
$numTests += 1; #For the use_ok
|
|
||||||
plan tests => 2;
|
|
||||||
|
|
||||||
my $macro = 'WebGUI::Macro::SessionId';
|
my $output = WebGUI::Macro::SessionId::process( $session );
|
||||||
my $loaded = use_ok($macro);
|
is($session->getId, $output, 'Session macro works');
|
||||||
|
|
||||||
SKIP: {
|
|
||||||
|
|
||||||
skip "Unable to load $macro", $numTests-1 unless $loaded;
|
|
||||||
my $output = WebGUI::Macro::SessionId::process( $session );
|
|
||||||
is($session->getId, $output, 'Session macro works');
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
|
||||||
|
|
||||||
use WebGUI::Test;
|
use WebGUI::Test;
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
|
use WebGUI::Macro::Slash_gatewayUrl;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
use Test::More; # increment this value for each test you create
|
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
|
##in t/Session/Url.t All we need to do is make sure that the macro
|
||||||
##fetches the same thing as the method.
|
##fetches the same thing as the method.
|
||||||
|
|
||||||
my $numTests = 4;
|
plan tests => 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;
|
|
||||||
|
|
||||||
$session->setting->set('preventProxyCache', 0);
|
$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');
|
$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');
|
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 {
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ $asset->update({
|
||||||
$asset->generateThumbnail();
|
$asset->generateThumbnail();
|
||||||
|
|
||||||
$versionTag->commit;
|
$versionTag->commit;
|
||||||
|
addToCleanup($versionTag);
|
||||||
|
|
||||||
|
|
||||||
##Call the Thumbnail Macro with that Asset's URL and see if it returns
|
##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');
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,3 @@ sub setupTest {
|
||||||
}
|
}
|
||||||
return @testSets;
|
return @testSets;
|
||||||
}
|
}
|
||||||
|
|
||||||
END { ##Clean-up after yourself, always
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -29,130 +29,119 @@ my $template = setupJSONtemplate($session);
|
||||||
my @users = setupUsers($session);
|
my @users = setupUsers($session);
|
||||||
my $i18n = WebGUI::International->new($session,'Macro_UsersOnline');
|
my $i18n = WebGUI::International->new($session,'Macro_UsersOnline');
|
||||||
|
|
||||||
my $numTests = 1; # Module loading test
|
plan tests => 30;
|
||||||
$numTests += 30; # Static tests
|
|
||||||
|
|
||||||
plan tests => $numTests;
|
# Basic testing -----------------------------------------------------------
|
||||||
|
|
||||||
my $macro = 'WebGUI::Macro::UsersOnline';
|
# Check for default template
|
||||||
my $loaded = use_ok($macro);
|
my $defTemplate = WebGUI::Asset->new($session, 'h_T2xtOxGRQ9QJOR6ebLpQ');
|
||||||
|
ok(defined $defTemplate, 'default template is present');
|
||||||
|
|
||||||
SKIP: {
|
# Call with default values
|
||||||
|
my $html = WebGUI::Macro::UsersOnline::process($session);
|
||||||
skip "Unable to load $macro", $numTests-1 unless $loaded;
|
cmp_ok((length $html), '>', 0, 'call with default template and values returns some output');
|
||||||
|
|
||||||
# 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');
|
|
||||||
|
|
||||||
|
|
||||||
# Test labels -------------------------------------------------------------
|
# Test labels -------------------------------------------------------------
|
||||||
|
|
||||||
$session->user({userId => 1});
|
$session->user({userId => 1});
|
||||||
my $json = WebGUI::Macro::UsersOnline::process($session, $template->getId);
|
my $json = WebGUI::Macro::UsersOnline::process($session, $template->getId);
|
||||||
my $vars = JSON::from_json($json);
|
my $vars = JSON::from_json($json);
|
||||||
|
|
||||||
is($vars->{'usersOnline_label'}, $i18n->get('Users Online'), 'usersOnline_label');
|
is($vars->{'usersOnline_label'}, $i18n->get('Users Online'), 'usersOnline_label');
|
||||||
is($vars->{'members_label'}, $i18n->get('Members'), 'members_label');
|
is($vars->{'members_label'}, $i18n->get('Members'), 'members_label');
|
||||||
is($vars->{'visitors_label'}, $i18n->get('Visitors'), 'visitors_label');
|
is($vars->{'visitors_label'}, $i18n->get('Visitors'), 'visitors_label');
|
||||||
is($vars->{'total_label'}, $i18n->get('Total'), 'total_label');
|
is($vars->{'total_label'}, $i18n->get('Total'), 'total_label');
|
||||||
is($vars->{'membersOnline_label'}, $i18n->get('Members Online'), 'membersOnline_label');
|
is($vars->{'membersOnline_label'}, $i18n->get('Members Online'), 'membersOnline_label');
|
||||||
is($vars->{'visitorsOnline_label'}, $i18n->get('Visitors Online'), 'visitorsOnline_label');
|
is($vars->{'visitorsOnline_label'}, $i18n->get('Visitors Online'), 'visitorsOnline_label');
|
||||||
is($vars->{'avatar_label'}, $i18n->get('Avatar'), 'avatar_label');
|
is($vars->{'avatar_label'}, $i18n->get('Avatar'), 'avatar_label');
|
||||||
is($vars->{'name_label'}, $i18n->get('Name'), 'name_label');
|
is($vars->{'name_label'}, $i18n->get('Name'), 'name_label');
|
||||||
is($vars->{'alias_label'}, $i18n->get('Alias'), 'alias_label');
|
is($vars->{'alias_label'}, $i18n->get('Alias'), 'alias_label');
|
||||||
is($vars->{'session_label'}, $i18n->get('Session'), 'session_label');
|
is($vars->{'session_label'}, $i18n->get('Session'), 'session_label');
|
||||||
is($vars->{'ip_label'}, $i18n->get('IP'), 'ip_label');
|
is($vars->{'ip_label'}, $i18n->get('IP'), 'ip_label');
|
||||||
is($vars->{'lastActivity_label'}, $i18n->get('Last Activity'), 'lastActivity_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,
|
# Does not work in testing environments that run on the loopback interface,
|
||||||
# since these queries are filtered out by the macro.
|
# since these queries are filtered out by the macro.
|
||||||
# is($vars->{'visitors'} > 0, 1, 'visitors > 0 when calling as visitor');
|
# is($vars->{'visitors'} > 0, 1, 'visitors > 0 when calling as visitor');
|
||||||
like($vars->{'members'}, qr/[0-9]+/, 'members is numeric');
|
like($vars->{'members'}, qr/[0-9]+/, 'members is numeric');
|
||||||
cmp_ok($vars->{'members'}, '>', 0, 'members > 0 since we have created one visible active member');
|
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');
|
is($vars->{'total'}, $vars->{'visitors'} + $vars->{'members'}, 'total == visitors + members');
|
||||||
ok($vars->{'isVisitor'}, 'isVisitor is true when calling as visitor');
|
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');
|
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 $allFieldsSet = 1;
|
||||||
my $firstUserPresent = 0;
|
my $firstUserPresent = 0;
|
||||||
my $secondUserAbsent = 1;
|
my $secondUserAbsent = 1;
|
||||||
|
|
||||||
foreach (@{$vars->{'member_loop'}}) {
|
foreach (@{$vars->{'member_loop'}}) {
|
||||||
# Check whether first user is present
|
# Check whether first user is present
|
||||||
if ($_->{'username'} eq 'tester1') {
|
if ($_->{'username'} eq 'tester1') {
|
||||||
# Indicate success
|
# Indicate success
|
||||||
$firstUserPresent = 1;
|
$firstUserPresent = 1;
|
||||||
# Check whether alias and name have been set correctly
|
# Check whether alias and name have been set correctly
|
||||||
$allFieldsSet = $_->{'alias'} eq 'alias1';
|
$allFieldsSet = $_->{'alias'} eq 'alias1';
|
||||||
$allFieldsSet &&= $_->{'firstName'} eq 'first1';
|
$allFieldsSet &&= $_->{'firstName'} eq 'first1';
|
||||||
$allFieldsSet &&= $_->{'middleName'} eq 'middle1';
|
$allFieldsSet &&= $_->{'middleName'} eq 'middle1';
|
||||||
$allFieldsSet &&= $_->{'lastName'} eq 'last1';
|
$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'} =~ /.*/;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check booleans indicating errors
|
# Check whether second user is present
|
||||||
ok($allFieldsSet, 'fields in the visitor loop have been set correctly');
|
if ($_->{'username'} eq 'tester2') {
|
||||||
|
# Indicate failure
|
||||||
|
$secondUserAbsent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check whether remaining fields have been set. Note that we cannot
|
||||||
# Test macro parameters ---------------------------------------------------
|
# check for the alias, name or avatar, since these values may be
|
||||||
|
# optional.
|
||||||
# Call with zero max limits
|
$allFieldsSet &&= $_->{'uid'} =~ /.*/;
|
||||||
$json = WebGUI::Macro::UsersOnline::process($session, $template->getId, undef, 0, 0);
|
$allFieldsSet &&= $_->{'sessionId'} =~ /.*/;
|
||||||
$vars = JSON::from_json($json);
|
# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user
|
||||||
ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when display limit is set to zero');
|
$allFieldsSet &&= $_->{'lastActivity'} =~ /.*/;
|
||||||
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 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 {
|
sub setupUsers {
|
||||||
|
|
@ -192,7 +181,7 @@ sub setupUsers {
|
||||||
my $newSession = WebGUI::Session->open(WebGUI::Test::root, WebGUI::Test::file);
|
my $newSession = WebGUI::Session->open(WebGUI::Test::root, WebGUI::Test::file);
|
||||||
$newSession->user({user => $_});
|
$newSession->user({user => $_});
|
||||||
}
|
}
|
||||||
WebGUI::Test->usersToDelete(@users);
|
addToCleanup(@users);
|
||||||
return @users;
|
return @users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -246,10 +235,6 @@ sub setupJSONtemplate {
|
||||||
}
|
}
|
||||||
EOTMPL
|
EOTMPL
|
||||||
my $template = WebGUI::Asset->getImportNode($session)->addChild({className=>'WebGUI::Asset::Template', namespace => 'Macro/UsersOnline', template=>$templateBody});
|
my $template = WebGUI::Asset->getImportNode($session)->addChild({className=>'WebGUI::Asset::Template', namespace => 'Macro/UsersOnline', template=>$templateBody});
|
||||||
|
addToCleanup($template);
|
||||||
return $template;
|
return $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
END { ##Clean-up after yourself, always
|
|
||||||
$template->purge;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
|
||||||
|
|
||||||
use WebGUI::Test;
|
use WebGUI::Test;
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
|
use WebGUI::Macro::ViewCart;
|
||||||
use HTML::TokeParser;
|
use HTML::TokeParser;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
|
|
@ -21,8 +22,6 @@ use Test::More; # increment this value for each test you create
|
||||||
|
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
my @testSets = (
|
my @testSets = (
|
||||||
{
|
{
|
||||||
comment => 'default',
|
comment => 'default',
|
||||||
|
|
@ -41,17 +40,8 @@ foreach my $testSet (@testSets) {
|
||||||
$numTests += 1 + (ref $testSet->{output} eq 'CODE');
|
$numTests += 1 + (ref $testSet->{output} eq 'CODE');
|
||||||
}
|
}
|
||||||
|
|
||||||
$numTests += 1; #For the use_ok
|
|
||||||
|
|
||||||
plan tests => $numTests;
|
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) {
|
foreach my $testSet (@testSets) {
|
||||||
my $output = WebGUI::Macro::ViewCart::process( $session, $testSet->{label});
|
my $output = WebGUI::Macro::ViewCart::process( $session, $testSet->{label});
|
||||||
if (ref $testSet->{output} eq 'CODE') {
|
if (ref $testSet->{output} eq 'CODE') {
|
||||||
|
|
@ -64,9 +54,6 @@ foreach my $testSet (@testSets) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub simpleHTMLParser {
|
sub simpleHTMLParser {
|
||||||
my ($text) = @_;
|
my ($text) = @_;
|
||||||
my $p = HTML::TokeParser->new(\$text);
|
my $p = HTML::TokeParser->new(\$text);
|
||||||
|
|
@ -86,6 +73,3 @@ sub simpleTextParser {
|
||||||
|
|
||||||
return ($url, $label);
|
return ($url, $label);
|
||||||
}
|
}
|
||||||
|
|
||||||
END {
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
my $homeAsset = WebGUI::Asset->getDefault($session);
|
my $homeAsset = WebGUI::Asset->getDefault($session);
|
||||||
$session->asset($homeAsset);
|
$session->asset($homeAsset);
|
||||||
my ($versionTag, $template) = setupTest($session, $homeAsset);
|
my $template = setupTest($session, $homeAsset);
|
||||||
|
|
||||||
my $i18n = WebGUI::International->new($session, 'Macro_r_printable');
|
my $i18n = WebGUI::International->new($session, 'Macro_r_printable');
|
||||||
|
|
||||||
|
|
@ -125,8 +125,9 @@ sub setupTest {
|
||||||
};
|
};
|
||||||
my $asset = $defaultNode->addChild($properties, $properties->{id});
|
my $asset = $defaultNode->addChild($properties, $properties->{id});
|
||||||
$versionTag->commit;
|
$versionTag->commit;
|
||||||
|
addToCleanup($versionTag);
|
||||||
|
|
||||||
return $versionTag, $asset;
|
return $asset;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub simpleHTMLParser {
|
sub simpleHTMLParser {
|
||||||
|
|
@ -148,9 +149,3 @@ sub simpleTextParser {
|
||||||
|
|
||||||
return ($url, $label);
|
return ($url, $label);
|
||||||
}
|
}
|
||||||
|
|
||||||
END { ##Clean-up after yourself, always
|
|
||||||
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
|
|
||||||
$versionTag->rollback;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue