6 use Test::More qw/no_plan/;
11 # Create a user with basically no rights, to start.
12 my $user_obj = RT::User->new($RT::SystemUser);
13 my ($ret, $msg) = $user_obj->LoadOrCreateByEmail('customer-'.$$.'@example.com');
14 ok($ret, 'ACL test user creation');
15 $user_obj->SetName('customer-'.$$);
16 $user_obj->SetPrivileged(1);
17 ($ret, $msg) = $user_obj->SetPassword('customer');
18 ok($ret, "ACL test password set. $msg");
20 # Now test the web interface, making sure objects come and go as
23 my $cookie_jar = HTTP::Cookies->new;
24 my $agent = WWW::Mechanize->new();
26 # give the agent a place to stash the cookies
28 $agent->cookie_jar($cookie_jar);
32 my $url = $RT::WebURL;
35 is ($agent->{'status'}, 200, "Loaded a page - $RT::WebURL");
38 # follow the link marked "Login"
40 ok($agent->{form}->find_input('user'));
42 ok($agent->{form}->find_input('pass'));
43 ok ($agent->{'content'} =~ /username:/i);
44 $agent->field( 'user' => 'customer-'.$$ );
45 $agent->field( 'pass' => 'customer' );
46 # the field isn't named, so we have to click link 0
48 is($agent->{'status'}, 200, "Fetched the page ok");
49 ok($agent->{'content'} =~ /Logout/i, "Found a logout link");
51 # Test for absence of Configure and Preferences tabs.
52 ok(!$agent->find_link( url => "$RT::WebPath/Admin/",
53 text => 'Configuration'), "No config tab" );
54 ok(!$agent->find_link( url => "$RT::WebPath/User/Prefs.html",
55 text => 'Preferences'), "No prefs pane" );
57 # Now test for their presence, one at a time. Sleep for a bit after
58 # ACL changes, thanks to the 10s ACL cache.
59 $user_obj->PrincipalObj->GrantRight(Right => 'ShowConfigTab');
61 ok($agent->{'content'} =~ /Logout/i, "Reloaded page successfully");
62 ok($agent->find_link( url => "$RT::WebPath/Admin/",
63 text => 'Configuration'), "Found config tab" );
64 $user_obj->PrincipalObj->RevokeRight(Right => 'ShowConfigTab');
65 $user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf');
67 ok($agent->{'content'} =~ /Logout/i, "Reloaded page successfully");
68 ok($agent->find_link( url => "$RT::WebPath/User/Prefs.html",
69 text => 'Preferences'), "Found prefs pane" );
70 $user_obj->PrincipalObj->RevokeRight(Right => 'ModifySelf');
72 # Good. Now load the search page and test Load/Save Search.
73 $agent->follow_link( url => "$RT::WebPath/Search/Build.html",
75 is($agent->{'status'}, 200, "Fetched search builder page");
76 ok($agent->{'content'} !~ /Load saved search/i, "No search loading box");
77 ok($agent->{'content'} !~ /Saved searches/i, "No saved searches box");
79 $user_obj->PrincipalObj->GrantRight(Right => 'LoadSavedSearch');
81 ok($agent->{'content'} =~ /Load saved search/i, "Search loading box exists");
82 ok($agent->{'content'} !~ /input\s+type=.submit.\s+name=.Save./i,
83 "Still no saved searches box");
85 $user_obj->PrincipalObj->GrantRight(Right => 'CreateSavedSearch');
87 ok($agent->{'content'} =~ /Load saved search/i,
88 "Search loading box still exists");
89 ok($agent->{'content'} =~ /input\s+type=.submit.\s+name=.Save./i,
90 "Saved searches box exists");
92 # Create a group, and a queue, so we can test limited user visibility
95 my $queue_obj = RT::Queue->new($RT::SystemUser);
96 ($ret, $msg) = $queue_obj->Create(Name => 'CustomerQueue',
97 Description => 'queue for SelectOwner testing');
98 ok($ret, "SelectOwner test queue creation. $msg");
99 my $group_obj = RT::Group->new($RT::SystemUser);
100 ($ret, $msg) = $group_obj->CreateUserDefinedGroup(Name => 'CustomerGroup',
101 Description => 'group for SelectOwner testing');
102 ok($ret, "SelectOwner test group creation. $msg");
104 # Add our customer to the customer group, and give it queue rights.
105 ($ret, $msg) = $group_obj->AddMember($user_obj->PrincipalObj->Id());
106 ok($ret, "Added customer to its group. $msg");
107 $group_obj->PrincipalObj->GrantRight(Right => 'OwnTicket',
108 Object => $queue_obj);
109 $group_obj->PrincipalObj->GrantRight(Right => 'SeeQueue',
110 Object => $queue_obj);
112 # Now. When we look at the search page we should be able to see
113 # ourself in the list of possible owners.
116 ok($agent->form_name('BuildQuery'), "Yep, form is still there");
117 my $input = $agent->current_form->find_input('ValueOfActor');
118 ok(grep(/customer-$$/, $input->value_names()), "Found self in the actor listing");