5 use RT::Test tests => 54;
10 ok (require RT::Action::CreateTickets);
12 use_ok('RT::Template');
13 use_ok('RT::ScripAction');
14 use_ok('RT::ScripCondition');
18 use_ok('RT::CustomField');
20 my $global_cf = RT::CustomField->new($RT::SystemUser);
21 my ($id, $msg)= $global_cf->Create( Name => 'GlobalCF',
24 Description => 'A Testing custom field',
25 Type=> 'SelectSingle');
26 ok($id, 'Global custom field correctly created');
29 my $approvalsq = RT::Queue->new(RT->SystemUser);
30 $approvalsq->Create(Name => 'Approvals');
31 ok ($approvalsq->Id, "Created Approvals test queue");
33 my $queue_cf = RT::CustomField->new($RT::SystemUser);
34 ($id) = $queue_cf->Create(
36 Queue => $approvalsq->Id,
38 Description => 'A testing queue-specific custom field',
39 Type => 'SelectSingle',
41 ok($id, 'Queue-specific custom field correctly created');
46 '===Create-Ticket: approval
49 AdminCc: {join ("\nAdminCc: ",@admins) }
50 Depended-On-By: {$Tickets{"TOP"}->Id}
52 CustomField-GlobalCF: A Value
53 CustomField-QueueCF: Another Value
54 Subject: Approval for ticket: {$Tickets{"TOP"}->Id} - {$Tickets{"TOP"}->Subject}
56 Content-Type: text/plain
57 Content: Your approval is requested for the ticket {$Tickets{"TOP"}->Id}: {$Tickets{"TOP"}->Subject}
62 Subject: Manager approval.
63 Depended-On-By: approval
65 Content-Type: text/plain
67 Your minion approved ticket {$Tickets{"TOP"}->Id}. you ok with that?
71 like ($approvals , qr/Content/, "Read in the approvals template");
73 my $apptemp = RT::Template->new(RT->SystemUser);
74 $apptemp->Create( Content => $approvals, Name => "Approvals", Queue => "0");
78 my $q = RT::Queue->new(RT->SystemUser);
79 $q->Create(Name => 'WorkflowTest');
80 ok ($q->Id, "Created workflow test queue");
82 my $scrip = RT::Scrip->new(RT->SystemUser);
83 my ($sval, $smsg) =$scrip->Create( ScripCondition => 'On Transaction',
84 ScripAction => 'Create Tickets',
85 Template => 'Approvals',
88 ok ($scrip->Id, "Created the scrip");
89 ok ($scrip->TemplateObj->Id, "Created the scrip template");
90 ok ($scrip->ConditionObj->Id, "Created the scrip condition");
91 ok ($scrip->ActionObj->Id, "Created the scrip action");
93 my $t = RT::Ticket->new(RT->SystemUser);
94 my($tid, $ttrans, $tmsg) = $t->Create(Subject => "Sample workflow test",
100 my $deps = $t->DependsOn;
101 is ($deps->Count, 1, "The ticket we created depends on one other ticket");
102 my $dependson= $deps->First->TargetObj;
103 ok ($dependson->Id, "It depends on a real ticket");
104 is ($dependson->FirstCustomFieldValue('GlobalCF'), 'A Value',
105 'global custom field was set');
106 is ($dependson->FirstCustomFieldValue('QueueCF'), 'Another Value',
107 'queue custom field was set');
108 unlike ($dependson->Subject, qr/\{/, "The subject doesn't have braces in it. that means we're interpreting expressions");
109 is ($t->ReferredToBy->Count,1, "It's only referred to by one other ticket");
110 is ($t->ReferredToBy->First->BaseObj->Id,$t->DependsOn->First->TargetObj->Id, "The same ticket that depends on it refers to it.");
111 use RT::Action::CreateTickets;
112 my $action = RT::Action::CreateTickets->new( CurrentUser => RT->SystemUser);
114 # comma-delimited templates
115 my $commas = <<"EOF";
116 id,Queue,Subject,Owner,Content
117 ticket1,General,"foo, bar",root,blah
118 ticket2,General,foo bar,root,blah
119 ticket3,General,foo' bar,root,blah'boo
120 ticket4,General,foo' bar,,blah'boo
124 # Comma delimited templates with missing data
125 my $sparse_commas = <<"EOF";
126 id,Queue,Subject,Owner,Requestor
127 ticket14,General,,,bobby
128 ticket15,General,,,tommy
129 ticket16,General,,suzie,tommy
130 ticket17,General,Foo "bar" baz,suzie,tommy
131 ticket18,General,'Foo "bar" baz',suzie,tommy
132 ticket19,General,'Foo bar' baz,suzie,tommy
136 # tab-delimited templates
138 id\tQueue\tSubject\tOwner\tContent
139 ticket10\tGeneral\t"foo' bar"\troot\tblah'
140 ticket11\tGeneral\tfoo, bar\troot\tblah
141 ticket12\tGeneral\tfoo' bar\troot\tblah'boo
142 ticket13\tGeneral\tfoo' bar\t\tblah'boo
147 $expected{ticket1} = <<EOF;
155 $expected{ticket2} = <<EOF;
163 $expected{ticket3} = <<EOF;
171 $expected{ticket4} = <<EOF;
179 $expected{ticket10} = <<EOF;
187 $expected{ticket11} = <<EOF;
195 $expected{ticket12} = <<EOF;
203 $expected{ticket13} = <<EOF;
212 $expected{'ticket14'} = <<EOF;
218 $expected{'ticket15'} = <<EOF;
224 $expected{'ticket16'} = <<EOF;
230 $expected{'ticket17'} = <<EOF;
232 Subject: Foo "bar" baz
236 $expected{'ticket18'} = <<EOF;
238 Subject: Foo "bar" baz
242 $expected{'ticket19'} = <<EOF;
244 Subject: 'Foo bar' baz
252 $action->Parse(Content =>$commas);
253 $action->Parse(Content =>$sparse_commas);
254 $action->Parse(Content => $tabs);
257 foreach (@{ $action->{'create_tickets'} }) {
258 $got{$_} = $action->{'templates'}->{$_};
261 foreach my $id ( sort keys %expected ) {
262 ok(exists($got{"create-$id"}), "template exists for $id");
263 is($got{"create-$id"}, $expected{$id}, "template is correct for $id");