5 use RT::Test nodata => 1, tests => 105;
7 my $queue = RT::Test->load_or_create_queue( Name => 'Regression' );
8 ok $queue && $queue->id, 'loaded or created queue';
10 my $user_a = RT::Test->load_or_create_user(
11 Name => 'user_a', Password => 'password',
13 ok $user_a && $user_a->id, 'loaded or created user';
15 my $user_b = RT::Test->load_or_create_user(
16 Name => 'user_b', Password => 'password',
18 ok $user_b && $user_b->id, 'loaded or created user';
20 my ($baseurl, $agent_a) = RT::Test->started_ok;
22 ok( RT::Test->set_rights(
23 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket ReplyToTicket)] },
24 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
27 ok $agent_a->login('user_a', 'password'), 'logged in as user A';
29 diag "current user has no right to own, nobody selected as owner on create";
31 $agent_a->get_ok('/', 'open home page');
32 $agent_a->form_name('CreateTicketInQueue');
33 $agent_a->select( 'Queue', $queue->id );
36 $agent_a->content_contains('Create a new ticket', 'opened create ticket page');
37 my $form = $agent_a->form_name('TicketCreate');
38 is $form->value('Owner'), RT->Nobody->id, 'correct owner selected';
39 ok !grep($_ == $user_a->id, $form->find_input('Owner')->possible_values),
40 'user A can not own tickets';
43 $agent_a->content_like(qr/Ticket \d+ created in queue/i, 'created ticket');
44 my ($id) = ($agent_a->content =~ /Ticket (\d+) created in queue/);
45 ok $id, 'found id of the ticket';
47 my $ticket = RT::Ticket->new( RT->SystemUser );
49 ok $ticket->id, 'loaded the ticket';
50 is $ticket->Owner, RT->Nobody->id, 'correct owner';
53 diag "user can chose owner of a new ticket";
55 $agent_a->get_ok('/', 'open home page');
56 $agent_a->form_name('CreateTicketInQueue');
57 $agent_a->select( 'Queue', $queue->id );
60 $agent_a->content_contains('Create a new ticket', 'opened create ticket page');
61 my $form = $agent_a->form_name('TicketCreate');
62 is $form->value('Owner'), RT->Nobody->id, 'correct owner selected';
64 ok grep($_ == $user_b->id, $form->find_input('Owner')->possible_values),
65 'user B is listed as potential owner';
66 $agent_a->select('Owner', $user_b->id);
69 $agent_a->content_like(qr/Ticket \d+ created in queue/i, 'created ticket');
70 my ($id) = ($agent_a->content =~ /Ticket (\d+) created in queue/);
71 ok $id, 'found id of the ticket';
73 my $ticket = RT::Ticket->new( RT->SystemUser );
75 ok $ticket->id, 'loaded the ticket';
76 is $ticket->Owner, $user_b->id, 'correct owner';
79 my $agent_b = RT::Test::Web->new;
80 ok $agent_b->login('user_b', 'password'), 'logged in as user B';
82 diag "user A can not change owner after create";
84 my $ticket = RT::Ticket->new( $user_a );
85 my ($id, $txn, $msg) = $ticket->Create(
90 ok $id, 'created a ticket #'. $id or diag "error: $msg";
91 is $ticket->Owner, $user_b->id, 'correct owner';
93 # try the following group of tests twice with different agents(logins)
96 $agent->get("/Ticket/Modify.html?id=$id");
97 my $form = $agent->form_name('TicketModify');
98 is $form->value('Owner'), $user_b->id, 'correct owner selected';
99 $agent->select('Owner', RT->Nobody->id);
102 $agent->content_contains(
104 'no way to change owner after create if you have no rights'
107 my $ticket = RT::Ticket->new( RT->SystemUser );
108 $ticket->Load( $id );
109 ok $ticket->id, 'loaded the ticket';
110 is $ticket->Owner, $user_b->id, 'correct owner';
113 $test_cb->($agent_a);
114 diag "even owner(user B) can not change owner";
115 $test_cb->($agent_b);
118 diag "on reply correct owner is selected";
120 my $ticket = RT::Ticket->new( $user_a );
121 my ($id, $txn, $msg) = $ticket->Create(
123 Owner => $user_b->id,
126 ok $id, 'created a ticket #'. $id or diag "error: $msg";
127 is $ticket->Owner, $user_b->id, 'correct owner';
129 $agent_a->goto_ticket( $id );
130 $agent_a->follow_link_ok({text => 'Reply'}, 'Ticket -> Reply');
132 my $form = $agent_a->form_name('TicketUpdate');
133 is $form->value('Owner'), '', 'empty value selected';
136 $ticket = RT::Ticket->new( RT->SystemUser );
137 $ticket->Load( $id );
138 ok $ticket->id, 'loaded the ticket';
139 is $ticket->Owner, $user_b->id, 'correct owner';
142 ok( RT::Test->set_rights(
143 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket)] },
144 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
147 diag "Couldn't take without coresponding right";
149 my $ticket = RT::Ticket->new( $user_a );
150 my ($id, $txn, $msg) = $ticket->Create(
154 ok $id, 'created a ticket #'. $id or diag "error: $msg";
155 is $ticket->Owner, RT->Nobody->id, 'correct owner';
157 $agent_a->goto_ticket( $id );
158 ok !($agent_a->find_all_links( text => 'Take' ))[0],
160 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
161 'no Steal link as well';
164 diag "Couldn't steal without coresponding right";
166 my $ticket = RT::Ticket->new( $user_a );
167 my ($id, $txn, $msg) = $ticket->Create(
169 Owner => $user_b->id,
172 ok $id, 'created a ticket #'. $id or diag "error: $msg";
173 is $ticket->Owner, $user_b->id, 'correct owner';
175 $agent_a->goto_ticket( $id );
176 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
178 ok !($agent_a->find_all_links( text => 'Take' ))[0],
179 'no Take link as well';
182 ok( RT::Test->set_rights(
183 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket TakeTicket)] },
186 diag "TakeTicket require OwnTicket to work";
188 my $ticket = RT::Ticket->new( $user_a );
189 my ($id, $txn, $msg) = $ticket->Create(
193 ok $id, 'created a ticket #'. $id or diag "error: $msg";
194 is $ticket->Owner, RT->Nobody->id, 'correct owner';
196 $agent_a->goto_ticket( $id );
197 ok !($agent_a->find_all_links( text => 'Take' ))[0],
199 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
200 'no Steal link as well';
203 ok( RT::Test->set_rights(
204 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket TakeTicket)] },
205 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
208 diag "TakeTicket+OwnTicket work";
210 my $ticket = RT::Ticket->new( $user_a );
211 my ($id, $txn, $msg) = $ticket->Create(
215 ok $id, 'created a ticket #'. $id or diag "error: $msg";
216 is $ticket->Owner, RT->Nobody->id, 'correct owner';
218 $agent_a->goto_ticket( $id );
219 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
221 $agent_a->follow_link_ok({text => 'Take'}, 'Ticket -> Take');
223 $ticket = RT::Ticket->new( RT->SystemUser );
224 $ticket->Load( $id );
225 ok $ticket->id, 'loaded the ticket';
226 is $ticket->Owner, $user_a->id, 'correct owner';
229 diag "TakeTicket+OwnTicket don't work when owner is not nobody";
231 my $ticket = RT::Ticket->new( $user_a );
232 my ($id, $txn, $msg) = $ticket->Create(
234 Owner => $user_b->id,
237 ok $id, 'created a ticket #'. $id or diag "error: $msg";
238 is $ticket->Owner, $user_b->id, 'correct owner';
240 $agent_a->goto_ticket( $id );
241 ok !($agent_a->find_all_links( text => 'Take' ))[0],
243 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
247 ok( RT::Test->set_rights(
248 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket StealTicket)] },
249 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
252 diag "StealTicket require OwnTicket to work";
254 my $ticket = RT::Ticket->new( $user_a );
255 my ($id, $txn, $msg) = $ticket->Create(
257 Owner => $user_b->id,
260 ok $id, 'created a ticket #'. $id or diag "error: $msg";
261 is $ticket->Owner, $user_b->id, 'correct owner';
263 $agent_a->goto_ticket( $id );
264 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
266 ok !($agent_a->find_all_links( text => 'Take' ))[0],
270 ok( RT::Test->set_rights(
271 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket StealTicket)] },
272 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
275 diag "StealTicket+OwnTicket work";
277 my $ticket = RT::Ticket->new( $user_a );
278 my ($id, $txn, $msg) = $ticket->Create(
280 Owner => $user_b->id,
283 ok $id, 'created a ticket #'. $id or diag "error: $msg";
284 is $ticket->Owner, $user_b->id, 'correct owner';
286 $agent_a->goto_ticket( $id );
287 ok !($agent_a->find_all_links( text => 'Take' ))[0],
289 $agent_a->follow_link_ok({text => 'Steal'}, 'Ticket -> Steal');
291 $ticket = RT::Ticket->new( RT->SystemUser );
292 $ticket->Load( $id );
293 ok $ticket->id, 'loaded the ticket';
294 is $ticket->Owner, $user_a->id, 'correct owner';
297 diag "StealTicket+OwnTicket don't work when owner is nobody";
299 my $ticket = RT::Ticket->new( $user_a );
300 my ($id, $txn, $msg) = $ticket->Create(
304 ok $id, 'created a ticket #'. $id or diag "error: $msg";
305 is $ticket->Owner, RT->Nobody->id, 'correct owner';
307 $agent_a->goto_ticket( $id );
308 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
310 ok !($agent_a->find_all_links( text => 'Take' ))[0],
311 'no Take link as well (no right)';
314 ok( RT::Test->set_rights(
315 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket TakeTicket StealTicket)] },
316 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
319 diag "no Steal link when owner nobody";
321 my $ticket = RT::Ticket->new( $user_a );
322 my ($id, $txn, $msg) = $ticket->Create(
326 ok $id, 'created a ticket #'. $id or diag "error: $msg";
327 is $ticket->Owner, RT->Nobody->id, 'correct owner';
329 $agent_a->goto_ticket( $id );
330 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
332 ok( ($agent_a->find_all_links( text => 'Take' ))[0],
333 'but have Take link');
336 diag "no Take link when owner is not nobody";
338 my $ticket = RT::Ticket->new( $user_a );
339 my ($id, $txn, $msg) = $ticket->Create(
341 Owner => $user_b->id,
344 ok $id, 'created a ticket #'. $id or diag "error: $msg";
345 is $ticket->Owner, $user_b->id, 'correct owner';
347 $agent_a->goto_ticket( $id );
348 ok !($agent_a->find_all_links( text => 'Take' ))[0],
350 ok( ($agent_a->find_all_links( text => 'Steal' ))[0],
351 'but have Steal link');
355 RT::Test->set_rights(
357 Principal => $user_a,
359 qw(SeeQueue ShowTicket CreateTicket ReplyToTicket OwnTicket TakeTicket StealTicket)
362 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
368 "action is Take if old owner is nobody and new owner is current user in update page";
370 my $ticket = RT::Ticket->new( $user_a );
371 my ( $id, $txn, $msg ) = $ticket->Create(
375 ok $id, 'created a ticket #'. $id or diag "error: $msg";
376 is $ticket->Owner, RT->Nobody->id, 'correct owner';
378 $agent_a->goto_ticket( $id );
379 $agent_a->content_lacks('Taken', 'no Taken');
380 $agent_a->follow_link_ok({text => 'Reply'}, 'Ticket -> Reply');
381 $agent_a->submit_form(
382 form_name => 'TicketUpdate',
383 fields => { Owner => $user_a->id },
384 button => 'SubmitTicket',
386 $agent_a->content_like( qr/user_a\s+-\s+Taken/, 'got user_a Taken message' );
388 $agent_b->goto_ticket($id);
389 $agent_b->content_like( qr/user_a\s+-\s+Taken/, 'got user_a Taken message for user b ' );
393 "action is Take if old owner is nobody and new owner is current user in basics page";
395 my $ticket = RT::Ticket->new($user_a);
396 my ( $id, $txn, $msg ) = $ticket->Create(
400 ok $id, 'created a ticket #' . $id or diag "error: $msg";
401 is $ticket->Owner, RT->Nobody->id, 'correct owner';
403 $agent_a->goto_ticket($id);
404 $agent_a->content_lacks('Taken', 'no Taken');
405 $agent_a->follow_link_ok( { text => 'Basics' }, 'Ticket -> Basics' );
406 $agent_a->submit_form(
407 form_name => 'TicketModify',
408 fields => { Owner => $user_a->id },
410 $agent_a->content_contains( 'Owner changed from Nobody to user_a',
411 'got set message in Basics' );
412 $agent_a->goto_ticket($id);
413 $agent_a->content_like( qr/user_a\s+-\s+Taken/, 'got user_a Taken message' );
415 $agent_b->goto_ticket($id);
416 $agent_b->content_like( qr/user_a\s+-\s+Taken/, 'got user_a Taken message for user b ' );