6 use Test::More tests => 34;
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
24 my $cookie_jar = HTTP::Cookies->new;
25 my $agent = WWW::Mechanize->new();
27 # give the agent a place to stash the cookies
29 $agent->cookie_jar($cookie_jar);
33 login($agent, $user_obj);
35 # Test for absence of Configure and Preferences tabs.
36 ok(!$agent->find_link( url => $RT::WebPath . "/Admin/",
37 text => 'Configuration'), "No config tab" );
38 ok(!$agent->find_link( url => $RT::WebPath . "/User/Prefs.html",
39 text => 'Preferences'), "No prefs pane" );
41 # Now test for their presence, one at a time. Sleep for a bit after
42 # ACL changes, thanks to the 10s ACL cache.
43 my ($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'ShowConfigTab', Object => $RT::System);
45 ok($grantid,$grantmsg);
49 ok($agent->{'content'} =~ /Logout/i, "Reloaded page successfully");
50 ok($agent->find_link( url => $RT::WebPath . "/Admin/",
51 text => 'Configuration'), "Found config tab" );
52 my ($revokeid,$revokemsg) =$user_obj->PrincipalObj->RevokeRight(Right => 'ShowConfigTab');
53 ok ($revokeid,$revokemsg);
54 ($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf');
55 ok ($grantid,$grantmsg);
57 ok($agent->{'content'} =~ /Logout/i, "Reloaded page successfully");
58 ok($agent->find_link( url => $RT::WebPath . "/User/Prefs.html",
59 text => 'Preferences'), "Found prefs pane" );
60 ($revokeid,$revokemsg) = $user_obj->PrincipalObj->RevokeRight(Right => 'ModifySelf');
61 ok ($revokeid,$revokemsg);
62 # Good. Now load the search page and test Load/Save Search.
63 $agent->follow_link( url => $RT::WebPath . "/Search/Build.html",
65 is($agent->{'status'}, 200, "Fetched search builder page");
66 ok($agent->{'content'} !~ /Load saved search/i, "No search loading box");
67 ok($agent->{'content'} !~ /Saved searches/i, "No saved searches box");
69 ($grantid,$grantmsg) = $user_obj->PrincipalObj->GrantRight(Right => 'LoadSavedSearch');
70 ok($grantid,$grantmsg);
72 ok($agent->{'content'} =~ /Load saved search/i, "Search loading box exists");
73 ok($agent->{'content'} !~ /input\s+type=.submit.\s+name=.Save./i,
74 "Still no saved searches box");
76 ($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'CreateSavedSearch');
77 ok ($grantid,$grantmsg);
79 ok($agent->{'content'} =~ /Load saved search/i,
80 "Search loading box still exists");
81 ok($agent->{'content'} =~ /input\s+type=.submit.\s+name=.Save./i,
82 "Saved searches box exists");
84 # Create a group, and a queue, so we can test limited user visibility
87 my $queue_obj = RT::Queue->new($RT::SystemUser);
88 ($ret, $msg) = $queue_obj->Create(Name => 'CustomerQueue-'.$$,
89 Description => 'queue for SelectOwner testing');
90 ok($ret, "SelectOwner test queue creation. $msg");
91 my $group_obj = RT::Group->new($RT::SystemUser);
92 ($ret, $msg) = $group_obj->CreateUserDefinedGroup(Name => 'CustomerGroup-'.$$,
93 Description => 'group for SelectOwner testing');
94 ok($ret, "SelectOwner test group creation. $msg");
96 # Add our customer to the customer group, and give it queue rights.
97 ($ret, $msg) = $group_obj->AddMember($user_obj->PrincipalObj->Id());
98 ok($ret, "Added customer to its group. $msg");
99 ($grantid,$grantmsg) =$group_obj->PrincipalObj->GrantRight(Right => 'OwnTicket',
100 Object => $queue_obj);
102 ok($grantid,$grantmsg);
103 ($grantid,$grantmsg) =$group_obj->PrincipalObj->GrantRight(Right => 'SeeQueue',
104 Object => $queue_obj);
105 ok ($grantid,$grantmsg);
106 # Now. When we look at the search page we should be able to see
107 # ourself in the list of possible owners.
110 ok($agent->form_name('BuildQuery'), "Yep, form is still there");
111 my $input = $agent->current_form->find_input('ValueOfActor');
112 ok(grep(/customer-$$/, $input->value_names()), "Found self in the actor listing");
117 my $url = $RT::WebURL;
119 is( $agent->{'status'}, 200,
120 "Loaded a page - $url" );
124 # follow the link marked "Login"
126 ok( $agent->{form}->find_input('user') );
128 ok( $agent->{form}->find_input('pass') );
129 ok( $agent->{'content'} =~ /username:/i );
130 $agent->field( 'user' => $user_obj->Name );
131 $agent->field( 'pass' => 'customer' );
133 # the field isn't named, so we have to click link 0
135 is( $agent->{'status'}, 200, "Fetched the page ok" );
136 ok( $agent->{'content'} =~ /Logout/i, "Found a logout link" );