[Rt-commit] r3122 - in RT-Action-ExtractSubjectTag: . t

kevinr at bestpractical.com kevinr at bestpractical.com
Thu Jun 9 02:18:32 EDT 2005


Author: kevinr
Date: Thu Jun  9 02:18:32 2005
New Revision: 3122

Added:
   RT-Action-ExtractSubjectTag/t/02custom_tags.t   (contents, props changed)
Modified:
   RT-Action-ExtractSubjectTag/   (props changed)
Log:
 r4106 at SAD-GIRL-IN-SNOW:  kevinr | 2005-06-08 23:27:45 -0400
 * started a new test file to test the effect of customizations on the scrip


Added: RT-Action-ExtractSubjectTag/t/02custom_tags.t
==============================================================================
--- (empty file)
+++ RT-Action-ExtractSubjectTag/t/02custom_tags.t	Thu Jun  9 02:18:32 2005
@@ -0,0 +1,96 @@
+#!/sw/bin/perl5.8.6
+
+use strict;
+use Test::More qw/no_plan/;
+#use Test::More tests => 3;
+use RT;
+RT::LoadConfig();
+RT::Init;
+use RT::EmailParser;
+use RT::Tickets;
+use RT::Action::SendEmail;
+
+my @_outgoing_messages;
+my @scrips_fired;
+
+# much of the top of this file is blatantly stolen from '04send_email.t' in
+# the main RT regression suite.
+
+# no idea if this test is useful in this context or not, but it's a nice one
+# to start with since it succeeds :)
+is (__PACKAGE__, 'main', "We're operating in the main package");
+
+my ($id, $message);
+
+### set up the action and the scrip ###
+
+# add the action to the database
+my $action = RT::ScripAction->new($RT::SystemUser);
+($id, $message) = $action->Create( Name           => 'ExtractSubjectTag',
+                                   Description    => '',
+                                   ExecModule     => 'ExtractSubjectTag',
+                                 );
+ok ($id, "create action? " . $message);
+
+# add the scrip to the database
+
+my $scrip = RT::Scrip->new($RT::SystemUser);
+($id, $message) 
+  = $scrip->Create( 
+                    Description     => 'OnTransactionExtractSubjectTag',
+                    Queue           => 0,
+                    ScripCondition  => 'On Transaction',
+                    ScripAction     => 'ExtractSubjectTag',
+                    Template        => 'Blank',
+                    Stage           => 'TransactionCreate',
+                  );
+#ok ($scrip->Description eq 'OnTransactionExtractSubjectTag', 'can create scrip');
+ok ($id, "create scrip? " . $message);
+
+### test default action (extract other RT instances' tags) ###
+
+# parse a test e-mail
+
+my $email = 
+('Subject: [foo.example #12] ExtractSubjectTag test
+From: root at example.com
+To: rt at example.com
+
+Foo Bar,
+
+Blah blah blah.
+
+Baz,
+Quux
+');
+my $parser = RT::EmailParser->new($RT::SystemUser);
+($id, $message) = $parser->SmartParseMIMEEntityFromScalar( Message => $email, 
+  Decode => 1 );
+ok($parser->Entity, "Parser returned a MIME entity");
+ok($parser->Entity->head, "Entity had a header");
+
+# create a new ticket
+my $ticket = RT::Ticket->new($RT::SystemUser);
+my $transaction_obj;
+($id, $transaction_obj, $message) 
+   = $ticket->Create(  Requestor   => ['root at example.com'],
+                       Queue       => 'general',
+                       Subject     => 'ExtractSubjectTag test',
+                    );
+ok ($id, "create new ticket? $message");
+
+# add the tag on correspond
+($id, $message, $transaction_obj) = $ticket->Correspond(MIMEObj=>$parser->Entity);
+ok($id, "conduct transaction? $message");
+ok($ticket->Subject =~ /\Q[foo.example #12]\E/, "Tag was added to ticket's subject");
+
+# check to make sure it doesn't add the tag a second time
+($id, $message, $transaction_obj) = $ticket->Correspond(MIMEObj=>$parser->Entity);
+ok($id, "conduct transaction 2? $message");
+#it feels like a kludge but it works
+my $match_count = 0;
+my $subject = $ticket->Subject;
+while ($subject =~ /\Q[foo.example #12]\E/g) { $match_count++; }
+ok($match_count eq 1, "The same tag was not added a second time");
+
+1;


More information about the Rt-commit mailing list