5 use RT::Test nodata => 1, tests => 31;
6 my ($baseurl, $agent) = RT::Test->started_ok;
8 # Create a user with basically no rights, to start.
9 my $user_obj = RT::User->new(RT->SystemUser);
10 my ($ret, $msg) = $user_obj->LoadOrCreateByEmail('customer-'.$$.'@example.com');
11 ok($ret, 'ACL test user creation');
12 $user_obj->SetName('customer-'.$$);
13 $user_obj->SetPrivileged(1);
14 ($ret, $msg) = $user_obj->SetPassword('customer');
15 ok($ret, "ACL test password set. $msg");
17 # Now test the web interface, making sure objects come and go as
21 my $cookie_jar = HTTP::Cookies->new;
23 # give the agent a place to stash the cookies
25 $agent->cookie_jar($cookie_jar);
28 $agent->login( $user_obj->Name, 'customer');
30 # Test for absence of Configure and Preferences tabs.
31 ok(!$agent->find_link( url => "$RT::WebPath/Admin/",
32 text => 'Admin'), "No admin tab" );
33 ok(!$agent->find_link( url => "$RT::WebPath/User/Prefs.html",
34 text => 'Preferences'), "No prefs pane" );
36 # Now test for their presence, one at a time. Sleep for a bit after
37 # ACL changes, thanks to the 10s ACL cache.
38 my ($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'ShowConfigTab', Object => RT->System);
40 ok($grantid,$grantmsg);
44 $agent->content_contains('Logout', "Reloaded page successfully");
45 ok($agent->find_link( url => "$RT::WebPath/Admin/",
46 text => 'Admin'), "Found admin tab" );
47 my ($revokeid,$revokemsg) =$user_obj->PrincipalObj->RevokeRight(Right => 'ShowConfigTab');
48 ok ($revokeid,$revokemsg);
49 ($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf');
50 ok ($grantid,$grantmsg);
52 $agent->content_contains('Logout', "Reloaded page successfully");
54 id => 'preferences-settings' ), "Found prefs pane" );
55 ($revokeid,$revokemsg) = $user_obj->PrincipalObj->RevokeRight(Right => 'ModifySelf');
56 ok ($revokeid,$revokemsg);
57 # Good. Now load the search page and test Load/Save Search.
58 $agent->follow_link( url => "$RT::WebPath/Search/Build.html",
60 is($agent->status, 200, "Fetched search builder page");
61 $agent->content_lacks("Load saved search", "No search loading box");
62 $agent->content_lacks("Saved searches", "No saved searches box");
64 ($grantid,$grantmsg) = $user_obj->PrincipalObj->GrantRight(Right => 'LoadSavedSearch');
65 ok($grantid,$grantmsg);
67 $agent->content_contains("Load saved search", "Search loading box exists");
68 $agent->content_unlike(qr/input\s+type=['"]submit['"][^>]+name=['"]SavedSearchSave['"]/i,
69 "Still no saved searches box");
71 ($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'CreateSavedSearch');
72 ok ($grantid,$grantmsg);
74 $agent->content_contains("Load saved search", "Search loading box still exists");
75 $agent->content_like(qr/input\s+type=['"]submit['"][^>]+name=['"]SavedSearchSave['"]/i,
76 "Saved searches box exists");
78 # Create a group, and a queue, so we can test limited user visibility
81 my $queue_obj = RT::Queue->new(RT->SystemUser);
82 ($ret, $msg) = $queue_obj->Create(Name => 'CustomerQueue-'.$$,
83 Description => 'queue for SelectOwner testing');
84 ok($ret, "SelectOwner test queue creation. $msg");
85 my $group_obj = RT::Group->new(RT->SystemUser);
86 ($ret, $msg) = $group_obj->CreateUserDefinedGroup(Name => 'CustomerGroup-'.$$,
87 Description => 'group for SelectOwner testing');
88 ok($ret, "SelectOwner test group creation. $msg");
90 # Add our customer to the customer group, and give it queue rights.
91 ($ret, $msg) = $group_obj->AddMember($user_obj->PrincipalObj->Id());
92 ok($ret, "Added customer to its group. $msg");
93 ($grantid,$grantmsg) =$group_obj->PrincipalObj->GrantRight(Right => 'OwnTicket',
94 Object => $queue_obj);
96 ok($grantid,$grantmsg);
97 ($grantid,$grantmsg) =$group_obj->PrincipalObj->GrantRight(Right => 'SeeQueue',
98 Object => $queue_obj);
99 ok ($grantid,$grantmsg);
100 # Now. When we look at the search page we should be able to see
101 # ourself in the list of possible owners.
104 ok($agent->form_name('BuildQuery'), "Yep, form is still there");
105 my $input = $agent->current_form->find_input('ValueOfActor');
106 ok(grep(/customer-$$/, $input->value_names()), "Found self in the actor listing");