tests to add 100% coverage to Privilege

This commit is contained in:
Colin Kuskie 2006-10-19 16:49:19 +00:00
parent 6c24ea7aeb
commit b7ff72d27b

View file

@ -14,11 +14,48 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::International;
use Test::More; # increment this value for each test you create
use Test::Deep;
my $num_tests = 3;
my @simpleTests = (
{
method => 'adminOnly',
status => 401,
description => 'Admin Only',
titleCode => 35,
},
{
method => 'insufficient',
status => 401,
description => 'Insufficient Privileges',
titleCode => 37,
},
{
method => 'notMember',
status => 400,
description => 'Not A Member',
titleCode => 345,
},
{
method => 'vitalComponent',
status => 403,
description => 'Vital Component',
titleCode => 40,
},
{
method => 'noAccess',
status => 401,
description => 'No Access',
titleCode => 37,
},
);
my $num_tests = 1;
$num_tests += 3 * scalar @simpleTests; ##For each simple privilege validation
$num_tests += 3; ##For noAccess as Visitor tests
plan tests => $num_tests;
@ -36,9 +73,32 @@ isa_ok($privilege, 'WebGUI::Session::Privilege', 'session has correct object typ
my $origUserStyle = $session->setting->get('userFunctionStyleId');
$session->setting->set('userFunctionStyleId', $userTemplate->getId);
my $adminOnly = $privilege->adminOnly;
is($session->http->getStatus(), '401', 'adminOnly: status set to 401');
is($session->http->getStatusDescription(), 'Admin Only', 'adminOnly: description set to Admin Only');
#One of the tests has different behavior depending on how it is called.
#If the user is visitor, it passes them to the login screen. We'll set
#the user to a different user to do simple testing on that method, then
#we'll come back and do the specialized testing.
$session->user({userId=>3});
my $i18n = WebGUI::International->new($session);
foreach my $test (@simpleTests) {
my $method = $test->{method};
my $output = $privilege->$method;
is($session->http->getStatus(), $test->{status}, "$method: status code");
is($session->http->getStatusDescription(), $test->{description}, "$method: description");
my $title = $i18n->get($test->{titleCode});
like($output, qr{<h1>$title</h1>}, "$method: correct title");
}
##Now, retest noAccess with Visitor and see if we get an auth-type screen
$session->user({userId=>1});
my $output = $privilege->noAccess;
is($session->http->getStatus(), '401', 'noAccess: status code with Visitor');
is($session->http->getStatusDescription(), 'No Access', 'noAccess: description with Visitor');
##Is the auth screen returned, not validating the auth screen
is($output, WebGUI::Operation::Auth::www_auth($session, "init"), 'noAccess: visitor sees auth screen');
sub setup_assets {
my $session = shift;