From b7ff72d27b6e93aa9f9ba0ce99afc1e9cfd5783a Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 19 Oct 2006 16:49:19 +0000 Subject: [PATCH] tests to add 100% coverage to Privilege --- t/Session/Privilege.t | 68 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/t/Session/Privilege.t b/t/Session/Privilege.t index 7c1dba871..351e0658c 100644 --- a/t/Session/Privilege.t +++ b/t/Session/Privilege.t @@ -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{

$title

}, "$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;