This commit was generated by cvs2svn to compensate for changes in r8690,
[freeside.git] / rt / t / api / action-createtickets.t
1
2 use strict;
3 use warnings;
4 use RT;
5 use RT::Test tests => 49;
6
7
8 {
9
10 ok (require RT::Action::CreateTickets);
11 use_ok('RT::Scrip');
12 use_ok('RT::Template');
13 use_ok('RT::ScripAction');
14 use_ok('RT::ScripCondition');
15 use_ok('RT::Ticket');
16
17 my $approvalsq = RT::Queue->new($RT::SystemUser);
18 $approvalsq->Create(Name => 'Approvals');
19 ok ($approvalsq->Id, "Created Approvals test queue");
20
21
22 my $approvals = 
23 '===Create-Ticket: approval
24 Queue: Approvals
25 Type: approval
26 AdminCc: {join ("\nAdminCc: ",@admins) }
27 Depended-On-By: {$Tickets{"TOP"}->Id}
28 Refers-To: TOP 
29 Subject: Approval for ticket: {$Tickets{"TOP"}->Id} - {$Tickets{"TOP"}->Subject}
30 Due: {time + 86400}
31 Content-Type: text/plain
32 Content: Your approval is requested for the ticket {$Tickets{"TOP"}->Id}: {$Tickets{"TOP"}->Subject}
33 Blah
34 Blah
35 ENDOFCONTENT
36 ===Create-Ticket: two
37 Subject: Manager approval.
38 Depended-On-By: approval
39 Queue: Approvals
40 Content-Type: text/plain
41 Content: 
42 Your minion approved ticket {$Tickets{"TOP"}->Id}. you ok with that?
43 ENDOFCONTENT
44 ';
45
46 like ($approvals , qr/Content/, "Read in the approvals template");
47
48 my $apptemp = RT::Template->new($RT::SystemUser);
49 $apptemp->Create( Content => $approvals, Name => "Approvals", Queue => "0");
50
51 ok ($apptemp->Id);
52
53 my $q = RT::Queue->new($RT::SystemUser);
54 $q->Create(Name => 'WorkflowTest');
55 ok ($q->Id, "Created workflow test queue");
56
57 my $scrip = RT::Scrip->new($RT::SystemUser);
58 my ($sval, $smsg) =$scrip->Create( ScripCondition => 'On Transaction',
59                 ScripAction => 'Create Tickets',
60                 Template => 'Approvals',
61                 Queue => $q->Id);
62 ok ($sval, $smsg);
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");
67
68 my $t = RT::Ticket->new($RT::SystemUser);
69 my($tid, $ttrans, $tmsg) = $t->Create(Subject => "Sample workflow test",
70            Owner => "root",
71            Queue => $q->Id);
72
73 ok ($tid,$tmsg);
74
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);
84
85 # comma-delimited templates
86 my $commas = <<"EOF";
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
92 EOF
93
94
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
104 EOF
105
106
107 # tab-delimited templates
108 my $tabs = <<"EOF";
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
114 EOF
115
116 my %expected;
117
118 $expected{ticket1} = <<EOF;
119 Queue: General
120 Subject: foo, bar
121 Owner: root
122 Content: blah
123 ENDOFCONTENT
124 EOF
125
126 $expected{ticket2} = <<EOF;
127 Queue: General
128 Subject: foo bar
129 Owner: root
130 Content: blah
131 ENDOFCONTENT
132 EOF
133
134 $expected{ticket3} = <<EOF;
135 Queue: General
136 Subject: foo' bar
137 Owner: root
138 Content: blah'boo
139 ENDOFCONTENT
140 EOF
141
142 $expected{ticket4} = <<EOF;
143 Queue: General
144 Subject: foo' bar
145 Owner: 
146 Content: blah'boo
147 ENDOFCONTENT
148 EOF
149
150 $expected{ticket10} = <<EOF;
151 Queue: General
152 Subject: foo' bar
153 Owner: root
154 Content: blah'
155 ENDOFCONTENT
156 EOF
157
158 $expected{ticket11} = <<EOF;
159 Queue: General
160 Subject: foo, bar
161 Owner: root
162 Content: blah
163 ENDOFCONTENT
164 EOF
165
166 $expected{ticket12} = <<EOF;
167 Queue: General
168 Subject: foo' bar
169 Owner: root
170 Content: blah'boo
171 ENDOFCONTENT
172 EOF
173
174 $expected{ticket13} = <<EOF;
175 Queue: General
176 Subject: foo' bar
177 Owner: 
178 Content: blah'boo
179 ENDOFCONTENT
180 EOF
181
182
183 $expected{'ticket14'} = <<EOF;
184 Queue: General
185 Subject: 
186 Owner: 
187 Requestor: bobby
188 EOF
189 $expected{'ticket15'} = <<EOF;
190 Queue: General
191 Subject: 
192 Owner: 
193 Requestor: tommy
194 EOF
195 $expected{'ticket16'} = <<EOF;
196 Queue: General
197 Subject: 
198 Owner: suzie
199 Requestor: tommy
200 EOF
201 $expected{'ticket17'} = <<EOF;
202 Queue: General
203 Subject: Foo "bar" baz
204 Owner: suzie
205 Requestor: tommy
206 EOF
207 $expected{'ticket18'} = <<EOF;
208 Queue: General
209 Subject: Foo "bar" baz
210 Owner: suzie
211 Requestor: tommy
212 EOF
213 $expected{'ticket19'} = <<EOF;
214 Queue: General
215 Subject: 'Foo bar' baz
216 Owner: suzie
217 Requestor: tommy
218 EOF
219
220
221
222
223 $action->Parse(Content =>$commas);
224 $action->Parse(Content =>$sparse_commas);
225 $action->Parse(Content => $tabs);
226
227 my %got;
228 foreach (@{ $action->{'create_tickets'} }) {
229   $got{$_} = $action->{'templates'}->{$_};
230 }
231
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");
235 }
236
237
238 }
239
240 1;