5 use RT::Test tests => 49;
10 ok (require RT::Action::CreateTickets);
12 use_ok('RT::Template');
13 use_ok('RT::ScripAction');
14 use_ok('RT::ScripCondition');
17 my $approvalsq = RT::Queue->new($RT::SystemUser);
18 $approvalsq->Create(Name => 'Approvals');
19 ok ($approvalsq->Id, "Created Approvals test queue");
23 '===Create-Ticket: approval
26 AdminCc: {join ("\nAdminCc: ",@admins) }
27 Depended-On-By: {$Tickets{"TOP"}->Id}
29 Subject: Approval for ticket: {$Tickets{"TOP"}->Id} - {$Tickets{"TOP"}->Subject}
31 Content-Type: text/plain
32 Content: Your approval is requested for the ticket {$Tickets{"TOP"}->Id}: {$Tickets{"TOP"}->Subject}
37 Subject: Manager approval.
38 Depended-On-By: approval
40 Content-Type: text/plain
42 Your minion approved ticket {$Tickets{"TOP"}->Id}. you ok with that?
46 like ($approvals , qr/Content/, "Read in the approvals template");
48 my $apptemp = RT::Template->new($RT::SystemUser);
49 $apptemp->Create( Content => $approvals, Name => "Approvals", Queue => "0");
53 my $q = RT::Queue->new($RT::SystemUser);
54 $q->Create(Name => 'WorkflowTest');
55 ok ($q->Id, "Created workflow test queue");
57 my $scrip = RT::Scrip->new($RT::SystemUser);
58 my ($sval, $smsg) =$scrip->Create( ScripCondition => 'On Transaction',
59 ScripAction => 'Create Tickets',
60 Template => 'Approvals',
63 ok ($scrip->Id, "Created the scrip");
64 ok ($scrip->TemplateObj->Id, "Created the scrip template");
65 ok ($scrip->ConditionObj->Id, "Created the scrip condition");
66 ok ($scrip->ActionObj->Id, "Created the scrip action");
68 my $t = RT::Ticket->new($RT::SystemUser);
69 my($tid, $ttrans, $tmsg) = $t->Create(Subject => "Sample workflow test",
75 my $deps = $t->DependsOn;
76 is ($deps->Count, 1, "The ticket we created depends on one other ticket");
77 my $dependson= $deps->First->TargetObj;
78 ok ($dependson->Id, "It depends on a real ticket");
79 unlike ($dependson->Subject, qr/{/, "The subject doesn't have braces in it. that means we're interpreting expressions");
80 is ($t->ReferredToBy->Count,1, "It's only referred to by one other ticket");
81 is ($t->ReferredToBy->First->BaseObj->Id,$t->DependsOn->First->TargetObj->Id, "The same ticket that depends on it refers to it.");
82 use RT::Action::CreateTickets;
83 my $action = RT::Action::CreateTickets->new( CurrentUser => $RT::SystemUser);
85 # comma-delimited templates
87 id,Queue,Subject,Owner,Content
88 ticket1,General,"foo, bar",root,blah
89 ticket2,General,foo bar,root,blah
90 ticket3,General,foo' bar,root,blah'boo
91 ticket4,General,foo' bar,,blah'boo
95 # Comma delimited templates with missing data
96 my $sparse_commas = <<"EOF";
97 id,Queue,Subject,Owner,Requestor
98 ticket14,General,,,bobby
99 ticket15,General,,,tommy
100 ticket16,General,,suzie,tommy
101 ticket17,General,Foo "bar" baz,suzie,tommy
102 ticket18,General,'Foo "bar" baz',suzie,tommy
103 ticket19,General,'Foo bar' baz,suzie,tommy
107 # tab-delimited templates
109 id\tQueue\tSubject\tOwner\tContent
110 ticket10\tGeneral\t"foo' bar"\troot\tblah'
111 ticket11\tGeneral\tfoo, bar\troot\tblah
112 ticket12\tGeneral\tfoo' bar\troot\tblah'boo
113 ticket13\tGeneral\tfoo' bar\t\tblah'boo
118 $expected{ticket1} = <<EOF;
126 $expected{ticket2} = <<EOF;
134 $expected{ticket3} = <<EOF;
142 $expected{ticket4} = <<EOF;
150 $expected{ticket10} = <<EOF;
158 $expected{ticket11} = <<EOF;
166 $expected{ticket12} = <<EOF;
174 $expected{ticket13} = <<EOF;
183 $expected{'ticket14'} = <<EOF;
189 $expected{'ticket15'} = <<EOF;
195 $expected{'ticket16'} = <<EOF;
201 $expected{'ticket17'} = <<EOF;
203 Subject: Foo "bar" baz
207 $expected{'ticket18'} = <<EOF;
209 Subject: Foo "bar" baz
213 $expected{'ticket19'} = <<EOF;
215 Subject: 'Foo bar' baz
223 $action->Parse(Content =>$commas);
224 $action->Parse(Content =>$sparse_commas);
225 $action->Parse(Content => $tabs);
228 foreach (@{ $action->{'create_tickets'} }) {
229 $got{$_} = $action->{'templates'}->{$_};
232 foreach my $id ( sort keys %expected ) {
233 ok(exists($got{"create-$id"}), "template exists for $id");
234 is($got{"create-$id"}, $expected{$id}, "template is correct for $id");