7 BEGIN {require 't/lifecycles/utils.pl'};
9 my $general = RT::Test->load_or_create_queue(
12 ok $general && $general->id, 'loaded or created a queue';
15 DBIx::SearchBuilder::Record::Cachable->FlushCache;
16 my $ticket = RT::Ticket->new( RT->SystemUser );
17 $ticket->Load( $_[0] );
18 return $ticket->Status;
21 diag "check basic API";
23 my $schema = $general->Lifecycle;
24 isa_ok($schema, 'RT::Lifecycle');
25 is $schema->Name, 'default', "it's a default schema";
26 is_deeply [$schema->Valid],
27 [qw(new open stalled resolved rejected deleted)],
28 'this is the default set from our config file';
30 foreach my $s ( qw(new open stalled resolved rejected deleted) ) {
31 ok $schema->IsValid($s), "valid";
33 ok !$schema->IsValid(), 'invalid';
34 ok !$schema->IsValid(''), 'invalid';
35 ok !$schema->IsValid(undef), 'invalid';
36 ok !$schema->IsValid('foo'), 'invalid';
38 is_deeply [$schema->Initial], ['new'], 'initial set';
39 ok $schema->IsInitial('new'), "initial";
40 ok !$schema->IsInitial('open'), "not initial";
41 ok !$schema->IsInitial, "not initial";
42 ok !$schema->IsInitial(''), "not initial";
43 ok !$schema->IsInitial(undef), "not initial";
44 ok !$schema->IsInitial('foo'), "not initial";
46 is_deeply [$schema->Active], [qw(open stalled)], 'active set';
47 ok( $schema->IsActive($_), "active" )
48 foreach qw(open stalled);
49 ok !$schema->IsActive('new'), "not active";
50 ok !$schema->IsActive, "not active";
51 ok !$schema->IsActive(''), "not active";
52 ok !$schema->IsActive(undef), "not active";
53 ok !$schema->IsActive('foo'), "not active";
55 is_deeply [$schema->Inactive], [qw(resolved rejected deleted)], 'inactive set';
56 ok( $schema->IsInactive($_), "inactive" )
57 foreach qw(resolved rejected deleted);
58 ok !$schema->IsInactive('new'), "not inactive";
59 ok !$schema->IsInactive, "not inactive";
60 ok !$schema->IsInactive(''), "not inactive";
61 ok !$schema->IsInactive(undef), "not inactive";
62 ok !$schema->IsInactive('foo'), "not inactive";
64 is_deeply [$schema->Transitions('')], [qw(new open resolved)], 'on create transitions';
65 ok $schema->IsTransition('' => $_), 'good transition'
66 foreach qw(new open resolved);
69 my ($baseurl, $m) = RT::Test->started_ok;
70 ok $m->login, 'logged in';
72 diag "check status input on create";
74 $m->goto_create_ticket( $general );
76 my $form = $m->form_name('TicketCreate');
77 ok my $input = $form->find_input('Status'), 'found status selector';
79 my @form_values = $input->possible_values;
80 ok scalar @form_values, 'some options in the UI';
83 foreach ( @form_values ) {
84 next if $general->Lifecycle->IsValid($_);
86 diag("$_ doesn't appear to be a valid status, but it was in the form");
90 ok $valid, 'all statuses in the form are valid';
93 diag "create a ticket";
96 my $ticket = RT::Ticket->new( RT->SystemUser );
97 ($tid) = $ticket->Create( Queue => $general->id, Subject => 'test' );
98 ok $tid, "created a ticket #$tid";
99 is $ticket->Status, 'new', 'correct status';
102 diag "new ->(open it)-> open";
104 ok $m->goto_ticket( $tid ), 'opened a ticket';
106 has => ['Open It', 'Resolve', 'Reject', 'Delete'],
107 has_no => ['Stall', 'Re-open', 'Undelete'],
110 $m->follow_link_ok({text => 'Open It'});
111 $m->form_name('TicketUpdate');
112 $m->click('SubmitTicket');
114 is $tstatus->($tid), 'open', 'changed status';
117 diag "open ->(stall)-> stalled";
119 is $tstatus->($tid), 'open', 'ticket is open';
121 ok $m->goto_ticket( $tid ), 'opened a ticket';
124 has => ['Stall', 'Resolve', 'Reject'],
125 has_no => ['Open It', 'Delete', 'Re-open', 'Undelete'],
128 $m->follow_link_ok({text => 'Stall'});
129 $m->form_name('TicketUpdate');
130 $m->click('SubmitTicket');
132 is $tstatus->($tid), 'stalled', 'changed status';
135 diag "stall ->(open it)-> open";
137 is $tstatus->($tid), 'stalled', 'ticket is stalled';
139 ok $m->goto_ticket( $tid ), 'opened a ticket';
142 has_no => ['Delete', 'Re-open', 'Undelete', 'Stall', 'Resolve', 'Reject'],
145 $m->follow_link_ok({text => 'Open It'});
147 is $tstatus->($tid), 'open', 'changed status';
150 diag "open -> deleted, only via modify";
152 is $tstatus->($tid), 'open', 'ticket is open';
154 $m->get_ok( '/Ticket/Modify.html?id='. $tid );
155 my $form = $m->form_name('TicketModify');
156 ok my $input = $form->find_input('Status'), 'found status selector';
158 my @form_values = $input->possible_values;
159 ok scalar @form_values, 'some options in the UI';
161 ok grep($_ eq 'deleted', @form_values), "has deleted";
163 $m->select( Status => 'deleted' );
166 is $tstatus->($tid), 'deleted', 'deleted ticket';
169 diag "deleted -> X via modify, only open is available";
171 is $tstatus->($tid), 'deleted', 'ticket is deleted';
173 $m->get_ok( '/Ticket/Modify.html?id='. $tid );
174 my $form = $m->form_name('TicketModify');
175 ok my $input = $form->find_input('Status'), 'found status selector';
177 my @form_values = $input->possible_values;
178 ok scalar @form_values, 'some options in the UI';
180 is join('-', @form_values), '-deleted-open', 'only default, current and open available';
183 diag "check illegal values and transitions";
186 my $ticket = RT::Ticket->new( RT->SystemUser );
187 my ($id, $msg) = $ticket->Create(
188 Queue => $general->id,
192 ok !$id, 'have not created a ticket';
195 my $ticket = RT::Ticket->new( RT->SystemUser );
196 my ($id, $msg) = $ticket->Create(
197 Queue => $general->id,
201 ok $id, 'created a ticket';
204 my $ticket = RT::Ticket->new( RT->SystemUser );
205 my ($id, $msg) = $ticket->Create(
206 Queue => $general->id,
210 ok $id, 'created a ticket';
212 (my $status, $msg) = $ticket->SetStatus( 'illeagal' );
213 ok !$status, "couldn't set illeagal status";
214 is $ticket->Status, 'new', 'status is steal the same';
216 ($status, $msg) = $ticket->SetStatus( 'stalled' );
217 ok !$status, "couldn't set status, transition is illeagal";
218 is $ticket->Status, 'new', 'status is steal the same';
222 diag "'!inactive -> inactive' actions are shown even if ticket has unresolved dependencies";
224 my $child_ticket = RT::Test->create_ticket(
225 Queue => $general->id,
228 my $cid = $child_ticket->id;
229 my $parent_ticket = RT::Test->create_ticket(
230 Queue => $general->id,
232 DependsOn => $child_ticket->id,
234 my $pid = $parent_ticket->id;
236 ok $m->goto_ticket( $pid ), 'opened a ticket';
238 has => ['Open It', 'Resolve', 'Reject', 'Delete' ],
239 has_no => ['Stall', 'Re-open', 'Undelete', ],
241 ok $m->goto_ticket( $cid ), 'opened a ticket';
243 has => ['Open It', 'Resolve', 'Reject', 'Delete'],
244 has_no => ['Stall', 'Re-open', 'Undelete'],