fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / ticket_owner_issues_16656.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => 19;
5
6 my $queue = RT::Test->load_or_create_queue( Name => 'Test' );
7 ok $queue && $queue->id, 'loaded or created queue';
8
9 my $user_a = RT::Test->load_or_create_user(
10     Name            => 'user_a',
11     EmailAddress    => 'user_a@example.com',
12     Password        => 'password',
13 );
14 ok $user_a && $user_a->id, 'loaded or created user';
15
16 RT->Config->Set( AutocompleteOwners => 0 );
17 my ($baseurl, $agent_root) = RT::Test->started_ok;
18
19 ok( RT::Test->set_rights({
20     Principal   => 'Requestor',
21     Object      => $queue,
22     Right       => [qw(OwnTicket)]
23 }), 'set rights');
24
25 ok $agent_root->login('root', 'password'), 'logged in as user root';
26
27 diag "user_a doesn't show up in create form";
28 {
29     $agent_root->get_ok('/', 'open home page');
30     $agent_root->form_name('CreateTicketInQueue');
31     $agent_root->select( 'Queue', '1' );
32     $agent_root->submit;
33
34     $agent_root->content_contains('Create a new ticket', 'opened create ticket page');
35     my $form = $agent_root->form_name('TicketCreate');
36     my $input = $form->find_input('Owner');
37     is $input->value, RT->Nobody->Id, 'correct owner selected';
38     ok((not scalar grep { $_ == $user_a->Id } $input->possible_values), 'no user_a value in dropdown');
39     $form->value('Requestors', 'user_a@example.com');
40     $agent_root->submit;
41
42     $agent_root->content_like(qr/Ticket \d+ created in queue/i, 'created ticket');
43     my ($id) = ($agent_root->content =~ /Ticket (\d+) created in queue/);
44     ok $id, 'found id of the ticket';
45
46     my $ticket = RT::Ticket->new( RT->SystemUser );
47     $ticket->Load( $id );
48     ok $ticket->id, 'loaded the ticket';
49     is $ticket->Queue, '1', 'correct queue';
50     is $ticket->Owner, RT->Nobody->Id, 'correct owner';
51     is $ticket->RequestorAddresses, 'user_a@example.com', 'correct requestor';
52 }
53
54 diag "user_a doesn't appear in owner list after being made requestor";
55 {
56     $agent_root->get("/Ticket/Modify.html?id=1");
57     my $form = $agent_root->form_name('TicketModify');
58     my $input = $form->find_input('Owner');
59     is $input->value, RT->Nobody->Id, 'correct owner selected';
60     ok((not scalar grep { $_ == $user_a->Id } $input->possible_values), 'no user_a value in dropdown');
61 }
62