5 use RT::Test nodata => 1, tests => undef;
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: ' . $user_a->Name;
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: ' . $user_b->Name;
20 # To give ReassignTicket
21 my $user_c = RT::Test->load_or_create_user(
22 Name => 'user_c', Password => 'password',
24 ok $user_c && $user_c->id, 'loaded or created user: ' . $user_c->Name;
26 my ($baseurl, $agent_a) = RT::Test->started_ok;
28 ok( RT::Test->set_rights(
29 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket ReplyToTicket)] },
30 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
33 ok $agent_a->login('user_a', 'password'), 'logged in as user A';
35 diag "current user has no right to own, nobody selected as owner on create";
37 $agent_a->get_ok('/', 'open home page');
38 $agent_a->form_name('CreateTicketInQueue');
39 $agent_a->select( 'Queue', $queue->id );
42 $agent_a->content_contains('Create a new ticket', 'opened create ticket page');
43 my $form = $agent_a->form_name('TicketCreate');
44 is $form->value('Owner'), RT->Nobody->id, 'correct owner selected';
45 ok !grep($_ == $user_a->id, $form->find_input('Owner')->possible_values),
46 'user A can not own tickets';
49 $agent_a->content_like(qr/Ticket \d+ created in queue/i, 'created ticket');
50 my ($id) = ($agent_a->content =~ /Ticket (\d+) created in queue/);
51 ok $id, 'found id of the ticket';
53 my $ticket = RT::Ticket->new( RT->SystemUser );
55 ok $ticket->id, 'loaded the ticket';
56 is $ticket->Owner, RT->Nobody->id, 'correct owner';
59 diag "user can chose owner of a new ticket";
61 $agent_a->get_ok('/', 'open home page');
62 $agent_a->form_name('CreateTicketInQueue');
63 $agent_a->select( 'Queue', $queue->id );
66 $agent_a->content_contains('Create a new ticket', 'opened create ticket page');
67 my $form = $agent_a->form_name('TicketCreate');
68 is $form->value('Owner'), RT->Nobody->id, 'correct owner selected';
70 ok grep($_ == $user_b->id, $form->find_input('Owner')->possible_values),
71 'user B is listed as potential owner';
72 $agent_a->select('Owner', $user_b->id);
75 $agent_a->content_like(qr/Ticket \d+ created in queue/i, 'created ticket');
76 my ($id) = ($agent_a->content =~ /Ticket (\d+) created in queue/);
77 ok $id, 'found id of the ticket';
79 my $ticket = RT::Ticket->new( RT->SystemUser );
81 ok $ticket->id, 'loaded the ticket';
82 is $ticket->Owner, $user_b->id, 'correct owner';
85 my $agent_b = RT::Test::Web->new;
86 ok $agent_b->login('user_b', 'password'), 'logged in as user B';
88 diag "user A can not change owner after create";
90 my $ticket = RT::Ticket->new( $user_a );
91 my ($id, $txn, $msg) = $ticket->Create(
96 ok $id, 'created a ticket #'. $id or diag "error: $msg";
97 is $ticket->Owner, $user_b->id, 'correct owner';
99 # try the following group of tests twice with different agents(logins)
102 $agent->get("/Ticket/Modify.html?id=$id");
103 my $form = $agent->form_name('TicketModify');
104 is $form->value('Owner'), $user_b->id, 'correct owner selected';
105 $agent->select('Owner', RT->Nobody->id);
108 $agent->content_contains(
110 'no way to change owner after create if you have no rights'
113 my $ticket = RT::Ticket->new( RT->SystemUser );
114 $ticket->Load( $id );
115 ok $ticket->id, 'loaded the ticket';
116 is $ticket->Owner, $user_b->id, 'correct owner';
119 $test_cb->($agent_a);
120 diag "even owner(user B) can not change owner";
121 $test_cb->($agent_b);
124 diag "on reply correct owner is selected";
126 my $ticket = RT::Ticket->new( $user_a );
127 my ($id, $txn, $msg) = $ticket->Create(
129 Owner => $user_b->id,
132 ok $id, 'created a ticket #'. $id or diag "error: $msg";
133 is $ticket->Owner, $user_b->id, 'correct owner';
135 $agent_a->goto_ticket( $id );
136 $agent_a->follow_link_ok({text => 'Reply'}, 'Ticket -> Reply');
138 my $form = $agent_a->form_name('TicketUpdate');
139 is $form->value('Owner'), '', 'empty value selected';
142 $ticket = RT::Ticket->new( RT->SystemUser );
143 $ticket->Load( $id );
144 ok $ticket->id, 'loaded the ticket';
145 is $ticket->Owner, $user_b->id, 'correct owner';
148 ok( RT::Test->set_rights(
149 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket)] },
150 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
153 diag "Couldn't take without coresponding right";
155 my $ticket = RT::Ticket->new( $user_a );
156 my ($id, $txn, $msg) = $ticket->Create(
160 ok $id, 'created a ticket #'. $id or diag "error: $msg";
161 is $ticket->Owner, RT->Nobody->id, 'correct owner';
163 $agent_a->goto_ticket( $id );
164 ok !($agent_a->find_all_links( text => 'Take' ))[0],
166 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
167 'no Steal link as well';
170 diag "Couldn't steal without coresponding right";
172 my $ticket = RT::Ticket->new( $user_a );
173 my ($id, $txn, $msg) = $ticket->Create(
175 Owner => $user_b->id,
178 ok $id, 'created a ticket #'. $id or diag "error: $msg";
179 is $ticket->Owner, $user_b->id, 'correct owner';
181 $agent_a->goto_ticket( $id );
182 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
184 ok !($agent_a->find_all_links( text => 'Take' ))[0],
185 'no Take link as well';
188 ok( RT::Test->set_rights(
189 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket TakeTicket)] },
192 diag "TakeTicket require OwnTicket to work";
194 my $ticket = RT::Ticket->new( $user_a );
195 my ($id, $txn, $msg) = $ticket->Create(
199 ok $id, 'created a ticket #'. $id or diag "error: $msg";
200 is $ticket->Owner, RT->Nobody->id, 'correct owner';
202 $agent_a->goto_ticket( $id );
203 ok !($agent_a->find_all_links( text => 'Take' ))[0],
205 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
206 'no Steal link as well';
209 ok( RT::Test->set_rights(
210 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket TakeTicket)] },
211 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
214 diag "TakeTicket+OwnTicket work";
216 my $ticket = RT::Ticket->new( $user_a );
217 my ($id, $txn, $msg) = $ticket->Create(
221 ok $id, 'created a ticket #'. $id or diag "error: $msg";
222 is $ticket->Owner, RT->Nobody->id, 'correct owner';
224 $agent_a->goto_ticket( $id );
225 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
227 $agent_a->follow_link_ok({text => 'Take'}, 'Ticket -> Take');
229 $ticket = RT::Ticket->new( RT->SystemUser );
230 $ticket->Load( $id );
231 ok $ticket->id, 'loaded the ticket';
232 is $ticket->Owner, $user_a->id, 'correct owner';
235 diag "TakeTicket+OwnTicket don't work when owner is not nobody";
237 my $ticket = RT::Ticket->new( $user_a );
238 my ($id, $txn, $msg) = $ticket->Create(
240 Owner => $user_b->id,
243 ok $id, 'created a ticket #'. $id or diag "error: $msg";
244 is $ticket->Owner, $user_b->id, 'correct owner';
246 $agent_a->goto_ticket( $id );
247 ok !($agent_a->find_all_links( text => 'Take' ))[0],
249 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
253 ok( RT::Test->set_rights(
254 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket StealTicket)] },
255 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
258 diag "StealTicket require OwnTicket to work";
260 my $ticket = RT::Ticket->new( $user_a );
261 my ($id, $txn, $msg) = $ticket->Create(
263 Owner => $user_b->id,
266 ok $id, 'created a ticket #'. $id or diag "error: $msg";
267 is $ticket->Owner, $user_b->id, 'correct owner';
269 $agent_a->goto_ticket( $id );
270 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
272 ok !($agent_a->find_all_links( text => 'Take' ))[0],
276 ok( RT::Test->set_rights(
277 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket StealTicket)] },
278 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
281 diag "StealTicket+OwnTicket work";
283 my $ticket = RT::Ticket->new( $user_a );
284 my ($id, $txn, $msg) = $ticket->Create(
286 Owner => $user_b->id,
289 ok $id, 'created a ticket #'. $id or diag "error: $msg";
290 is $ticket->Owner, $user_b->id, 'correct owner';
292 $agent_a->goto_ticket( $id );
293 ok !($agent_a->find_all_links( text => 'Take' ))[0],
295 $agent_a->follow_link_ok({text => 'Steal'}, 'Ticket -> Steal');
297 $ticket = RT::Ticket->new( RT->SystemUser );
298 $ticket->Load( $id );
299 ok $ticket->id, 'loaded the ticket';
300 is $ticket->Owner, $user_a->id, 'correct owner';
303 diag "StealTicket+OwnTicket don't work when owner is nobody";
305 my $ticket = RT::Ticket->new( $user_a );
306 my ($id, $txn, $msg) = $ticket->Create(
310 ok $id, 'created a ticket #'. $id or diag "error: $msg";
311 is $ticket->Owner, RT->Nobody->id, 'correct owner';
313 $agent_a->goto_ticket( $id );
314 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
316 ok !($agent_a->find_all_links( text => 'Take' ))[0],
317 'no Take link as well (no right)';
320 ok( RT::Test->set_rights(
321 { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket TakeTicket StealTicket)] },
322 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
325 diag "no Steal link when owner nobody";
327 my $ticket = RT::Ticket->new( $user_a );
328 my ($id, $txn, $msg) = $ticket->Create(
332 ok $id, 'created a ticket #'. $id or diag "error: $msg";
333 is $ticket->Owner, RT->Nobody->id, 'correct owner';
335 $agent_a->goto_ticket( $id );
336 ok !($agent_a->find_all_links( text => 'Steal' ))[0],
338 ok( ($agent_a->find_all_links( text => 'Take' ))[0],
339 'but have Take link');
342 diag "no Take link when owner is not nobody";
344 my $ticket = RT::Ticket->new( $user_a );
345 my ($id, $txn, $msg) = $ticket->Create(
347 Owner => $user_b->id,
350 ok $id, 'created a ticket #'. $id or diag "error: $msg";
351 is $ticket->Owner, $user_b->id, 'correct owner';
353 $agent_a->goto_ticket( $id );
354 ok !($agent_a->find_all_links( text => 'Take' ))[0],
356 ok( ($agent_a->find_all_links( text => 'Steal' ))[0],
357 'but have Steal link');
361 RT::Test->set_rights(
363 Principal => $user_a,
365 qw(SeeQueue ShowTicket CreateTicket ReplyToTicket OwnTicket TakeTicket StealTicket)
368 { Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
369 { Principal => $user_c, Right => [qw(SeeQueue ShowTicket ReassignTicket)] },
375 "action is Take if old owner is nobody and new owner is current user in update page";
377 my $ticket = RT::Ticket->new( $user_a );
378 my ( $id, $txn, $msg ) = $ticket->Create(
382 ok $id, 'created a ticket #'. $id or diag "error: $msg";
383 is $ticket->Owner, RT->Nobody->id, 'correct owner';
385 $agent_a->goto_ticket( $id );
386 $agent_a->content_lacks('Taken', 'no Taken');
387 $agent_a->follow_link_ok({text => 'Reply'}, 'Ticket -> Reply');
388 $agent_a->submit_form(
389 form_name => 'TicketUpdate',
390 fields => { Owner => $user_a->id },
391 button => 'SubmitTicket',
393 like($agent_a->dom->at('.transaction.people .description')->all_text,
394 qr/user_a\s*-\s*Taken/, 'got user_a Taken message' );
396 $agent_b->goto_ticket($id);
397 like($agent_b->dom->at('.transaction.people .description')->all_text,
398 qr/user_a\s*-\s*Taken/, 'got user_a Taken message for user b' );
402 "action is Take if old owner is nobody and new owner is current user in basics page";
404 my $ticket = RT::Ticket->new($user_a);
405 my ( $id, $txn, $msg ) = $ticket->Create(
409 ok $id, 'created a ticket #' . $id or diag "error: $msg";
410 is $ticket->Owner, RT->Nobody->id, 'correct owner';
412 $agent_a->goto_ticket($id);
413 $agent_a->content_lacks('Taken', 'no Taken');
414 $agent_a->follow_link_ok( { text => 'Basics' }, 'Ticket -> Basics' );
415 $agent_a->submit_form(
416 form_name => 'TicketModify',
417 fields => { Owner => $user_a->id },
419 $agent_a->content_contains( 'Owner changed from Nobody to user_a',
420 'got set message in Basics' );
421 $agent_a->goto_ticket($id);
422 like($agent_a->dom->at('.transaction.people .description')->all_text,
423 qr/user_a\s*-\s*Taken/, 'got user_a Taken message' );
425 $agent_b->goto_ticket($id);
426 like($agent_b->dom->at('.transaction.people .description')->all_text,
427 qr/user_a\s*-\s*Taken/, 'got user_a Taken message for user b' );
430 my $agent_c = RT::Test::Web->new;
431 ok $agent_c->login('user_c', 'password'), 'logged in as user C';
433 diag "user can assign ticket to new owner with ReassignTicket right";
435 my $ticket = RT::Ticket->new($user_a);
436 my ( $id, $txn, $msg ) = $ticket->Create(
440 ok $id, 'created a ticket #' . $id or diag "error: $msg";
441 is $ticket->Owner, RT->Nobody->id, 'correct owner';
443 $agent_c->goto_ticket($id);
444 ok !($agent_c->find_all_links( text => 'Take' ))[0], 'no Take link';
445 ok !($agent_c->find_all_links( text => 'Steal' ))[0], 'no Steal link';
447 $agent_a->goto_ticket($id);
448 $agent_a->content_lacks('Taken', 'no Taken');
449 $agent_a->follow_link_ok( { text => 'Basics' }, 'Ticket -> Basics' );
450 $agent_a->submit_form(
451 form_name => 'TicketModify',
452 fields => { Owner => $user_a->id },
454 $agent_a->content_contains( 'Owner changed from Nobody to user_a',
455 'got set message in Basics' );
456 $agent_a->goto_ticket($id);
457 like($agent_a->dom->at('.transaction.people .description')->all_text,
458 qr{user_a\s*-\s*Taken}, 'got user_a Taken message' );
460 $agent_c->goto_ticket($id);
461 ok !($agent_c->find_all_links( text => 'Take' ))[0], 'no Take link';
462 ok !($agent_c->find_all_links( text => 'Steal' ))[0], 'no Steal link';
463 $agent_c->follow_link_ok( { text => 'Basics' }, 'Ticket -> Basics' );
464 my $form = $agent_c->form_name('TicketModify');
465 is $form->value('Owner'), $user_a->id, 'correct owner selected';
467 ok grep($_ == $user_b->id, $form->find_input('Owner')->possible_values),
468 'user B is listed as potential owner';
469 $agent_c->select('Owner', $user_b->id);
471 $agent_c->content_contains( 'Owner changed from user_a to user_b',
472 'got set message in Basics' );
473 $agent_c->goto_ticket($id);
474 $agent_c->content_like( qr{Owner forcibly changed}, 'got owner forcibly changed message' );
475 ok !($agent_c->find_all_links( text => 'Take' ))[0], 'no Take link';
479 RT::Test->add_rights(
480 { Principal => $user_c, Right => [qw(OwnTicket)] },
484 diag "user can take/steal ticket with ReassignTicket+OwnTicket right";
486 my $ticket = RT::Ticket->new($user_a);
487 my ( $id, $txn, $msg ) = $ticket->Create(
491 ok $id, 'created a ticket #' . $id or diag "error: $msg";
492 is $ticket->Owner, RT->Nobody->id, 'correct owner';
494 $agent_c->goto_ticket($id);
495 ok( ($agent_c->find_all_links( text => 'Take' ))[0], 'has Take link' );
496 ok !($agent_c->find_all_links( text => 'Steal' ))[0], 'no Steal link';
498 $agent_a->goto_ticket($id);
499 $agent_a->content_lacks('Taken', 'no Taken');
500 $agent_a->follow_link_ok( { text => 'Basics' }, 'Ticket -> Basics' );
501 $agent_a->submit_form(
502 form_name => 'TicketModify',
503 fields => { Owner => $user_a->id },
505 $agent_a->content_contains( 'Owner changed from Nobody to user_a',
506 'got set message in Basics' );
507 $agent_a->goto_ticket($id);
508 like($agent_a->dom->at('.transaction.people .description')->all_text,
509 qr{user_a\s*-\s*Taken}, 'got user_a Taken message' );
511 $agent_c->goto_ticket($id);
512 ok !($agent_c->find_all_links( text => 'Take' ))[0], 'no Take link';
513 ok( ($agent_c->find_all_links( text => 'Steal' ))[0], 'has Steal link' );
514 $agent_c->follow_link_ok( { text => 'Steal' }, 'Ticket -> Steal' );
515 $agent_c->content_contains( 'Owner changed from user_a to user_c', 'steal message' );
516 ok !($agent_c->find_all_links( text => 'Take' ))[0], 'no Take link';
517 ok !($agent_c->find_all_links( text => 'Steal' ))[0], 'no Steal link';