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

kevinr at bestpractical.com kevinr at bestpractical.com
Thu Jun 9 13:47:50 EDT 2005


Author: kevinr
Date: Thu Jun  9 13:47:49 2005
New Revision: 3127

Modified:
   RT-Action-ExtractSubjectTag/   (props changed)
   RT-Action-ExtractSubjectTag/t/02custom_tags.t
Log:
 r4122 at SAD-GIRL-IN-SNOW:  kevinr | 2005-06-09 13:43:34 -0400
 * Wrote the custom-regex tests, though they still need some debugging.


Modified: RT-Action-ExtractSubjectTag/t/02custom_tags.t
==============================================================================
--- RT-Action-ExtractSubjectTag/t/02custom_tags.t	(original)
+++ RT-Action-ExtractSubjectTag/t/02custom_tags.t	Thu Jun  9 13:47:49 2005
@@ -9,6 +9,7 @@
 use RT::EmailParser;
 use RT::Tickets;
 use RT::Action::SendEmail;
+use RT::Action::ExtractSubjectTag;
 
 my @_outgoing_messages;
 my @scrips_fired;
@@ -16,6 +17,9 @@
 # much of the top of this file is blatantly stolen from '04send_email.t' in
 # the main RT regression suite.
 
+# make sure the module is installed
+BEGIN { use_ok('RT::Action::ExtractSubjectTag'); }
+
 # 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");
@@ -51,10 +55,12 @@
 }
 ok ($id, "create scrip? " . $message);
 
-### test default action (extract other RT instances' tags) ###
+### test custom action ###
 
-# parse a test e-mail
+# match a & followed by a number surrounded by { }
+$RT::Action::ExtractSubjectTag::ExtractSubjectTagMatch = qr/\{(?:\&|\$|\@)\d+\}/; 
 
+# parse a test e-mail with the old tag style
 my $email = 
 ('Subject: [foo.example #12] ExtractSubjectTag test
 From: root at example.com
@@ -83,18 +89,73 @@
                     );
 ok ($id, "create new ticket? $message");
 
-# add the tag on correspond
-($id, $message, $transaction_obj) = $ticket->Correspond(MIMEObj=>$parser->Entity);
+# make sure the old tag *isn't* added on correspond
+($id, $message, $transaction_obj) = $ticket->Correspond(MIMEObj => $parser->Entity);
+ok($id, "conduct transaction? $message");
+ok($ticket->Subject !~ /\Q[foo.example #12]\E/, "Old tag was not added to ticket's subject");
+
+# parse an email with the new tag style
+$email =~ s/\Q[foo.example #12]\E/{&32}/;
+($id, $message) = $parser->SmartParseMIMEEntityFromScalar( Message => $email, 
+  Decode => 1 );
+ok($parser->Entity, "Parser returned a MIME entity");
+ok($parser->Entity->head, "Entity had a header");
+
+# make sure the new tag *is* added
+($id, $message, $transaction_obj) = $ticket->Correspond(MIMEObj => $parser->Entity);
+ok($id, "conduct transaction? $message");
+ok($ticket->Subject =~ /\Q{&32}\E/, "New tag was added to ticket's subject");
+
+# don't match certain numbers
+$RT::Action::ExtractSubjectTag::ExtractSubjectTagNoMatch = qr/\{(?:\&3{0-9}|\@{0-99})\}/;
+
+# parse an email with an excluded tag
+$email =~ s/\Q{&32}\E/{&38}/;
+($id, $message) = $parser->SmartParseMIMEEntityFromScalar( Message => $email, 
+  Decode => 1 );
+ok($parser->Entity, "Parser returned a MIME entity");
+ok($parser->Entity->head, "Entity had a header");
+
+# make sure the excluded tag isn't added
+($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");
+ok($ticket->Subject !~ /\Q{&38}\E/, "First excluded tag was not added");
+
+# parse another email with an excluded tag
+$email =~ s/\Q{&38}\E/{@73}/;
+($id, $message) = $parser->SmartParseMIMEEntityFromScalar( Message => $email, 
+  Decode => 1 );
+ok($parser->Entity, "Parser returned a MIME entity");
+ok($parser->Entity->head, "Entity had a header:\n@{[$parser->Head->stringify]}");
+
+# make sure the second excluded tag isn't added
+($id, $message, $transaction_obj) = $ticket->Correspond(MIMEObj => $parser->Entity);
+ok($id, "conduct transaction? $message");
+ok($ticket->Subject !~ /\Q{@73}\E/, "Second excluded tag was not added");
+
+# parse an e-mail with an included tag
+$email =
+('Subject: {&42} ExtractSubjectTag test
+From: root at example.com
+To: rt at example.com
+
+Foo Bar,
+
+Blah blah blah.
+
+Baz,
+Quux
+');
+($id, $message) = $parser->SmartParseMIMEEntityFromScalar( Message => $email, 
+  Decode => 1 );
+ok($parser->Entity, "Parser returned a MIME entity");
+ok($parser->Entity->head, "Entity had a header:\n@{[$parser->Head->stringify]}");
+
+# make sure that included tags can still be added
+($id, $message, $transaction_obj) = $ticket->Correspond(MIMEObj => $parser->Entity);
+ok($id, "conduct transaction? $message");
+ok($ticket->Subject =~ /\Q{&42}\E/, "Included tags can still be added");
+
 
-# 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