[Rt-commit] r5252 - RT-Extension-CommandByEmail/t

ruz at bestpractical.com ruz at bestpractical.com
Thu May 18 18:15:24 EDT 2006


Author: ruz
Date: Thu May 18 18:15:23 2006
New Revision: 5252

Added:
   RT-Extension-CommandByEmail/t/03.update.t
Modified:
   RT-Extension-CommandByEmail/t/02.create.t

Log:
new tests

Modified: RT-Extension-CommandByEmail/t/02.create.t
==============================================================================
--- RT-Extension-CommandByEmail/t/02.create.t	(original)
+++ RT-Extension-CommandByEmail/t/02.create.t	Thu May 18 18:15:23 2006
@@ -217,7 +217,3 @@
     is($obj->FirstCustomFieldValue($cf_name), 'foo', 'correct cf value' );
 }
 
-
-
-
-

Added: RT-Extension-CommandByEmail/t/03.update.t
==============================================================================
--- (empty file)
+++ RT-Extension-CommandByEmail/t/03.update.t	Thu May 18 18:15:23 2006
@@ -0,0 +1,237 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More qw(no_plan);
+
+BEGIN { require 't/utils.pl' }
+RT::Init();
+
+my $test_ticket_id;
+
+diag("simle test of the mailgate") if $ENV{'TEST_VERBOSE'};
+{
+    my $text = <<END;
+Subject: test
+From: root\@localhost
+
+test
+END
+    my $id = create_ticket_via_gate( $text );
+    ok($id, "created ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+    $test_ticket_id = $id;
+}
+
+# XXX: use statuses from config/libs
+diag("set status on update") if $ENV{'TEST_VERBOSE'};
+foreach my $status ( qw(new open stalled rejected) ) {
+    my $text = <<END;
+Subject: [$RT::rtname #$test_ticket_id] test
+From: root\@localhost
+
+Status: $status
+
+test
+END
+    my $id = create_ticket_via_gate( $text );
+    is($id, $test_ticket_id, "updated ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+    is($obj->Status, $status, 'set status' );
+}
+
+diag("set priority and final_priority on create") if $ENV{'TEST_VERBOSE'};
+foreach my $priority ( 10, 20 ) { foreach my $final_priority ( 5, 15, 20 ) {
+    my $text = <<END;
+Subject: [$RT::rtname #$test_ticket_id] test
+From: root\@localhost
+
+Priority: $priority
+FinalPriority: $final_priority
+
+test
+END
+    my $id = create_ticket_via_gate( $text );
+    is($id, $test_ticket_id, "updated ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+    is($obj->Priority, $priority, 'set priority' );
+    is($obj->FinalPriority, $final_priority, 'set final priority' );
+} }
+
+diag("set date on update") if $ENV{'TEST_VERBOSE'};
+foreach my $date ( qw(Due Starts Started) ) {
+    my $value = '2005-12-01 12:34:00';
+    my $text = <<END;
+Subject: [$RT::rtname #$test_ticket_id] test
+From: root\@localhost
+
+$date: $value
+
+test
+END
+    my $id = create_ticket_via_gate( $text );
+    is($id, $test_ticket_id, "updated ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+    my $method = $date .'Obj';
+    is($obj->$method->ISO, $value, 'set date' );
+}
+
+diag("set time on update") if $ENV{'TEST_VERBOSE'};
+foreach my $field ( qw(TimeWorked TimeEstimated TimeLeft) ) {
+    my $value = int rand 10;
+    my $text = <<END;
+Subject: [$RT::rtname #$test_ticket_id] test
+From: root\@localhost
+
+$field: $value
+
+test
+END
+    my $id = create_ticket_via_gate( $text );
+    is($id, $test_ticket_id, "updated ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+    is($obj->$field(), $value, 'set time' );
+}
+
+
+diag("set watchers on update") if $ENV{'TEST_VERBOSE'};
+foreach my $field ( qw(Requestor Cc AdminCc) ) {
+    my $value = 'test at localhost';
+    my $text = <<END;
+Subject: [$RT::rtname #$test_ticket_id] test
+From: root\@localhost
+
+$field: $value
+
+test
+END
+    my $id = create_ticket_via_gate( $text );
+    is($id, $test_ticket_id, "updated ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+    my $method = $field .'Addresses';
+    is($obj->$method(), $value, 'set '. $field );
+}
+
+diag("add requestor on update") if $ENV{'TEST_VERBOSE'};
+{
+    my $value = 'test at localhost';
+    my $text = <<END;
+Subject: [$RT::rtname #$test_ticket_id] test
+From: root\@localhost
+
+AddRequestor: root\@localhost
+AddRequestor: $value
+
+test
+END
+    my $id = create_ticket_via_gate( $text );
+    is($id, $test_ticket_id, "updated ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+    is($obj->RequestorAddresses, "root\@localhost, $value", 'add requestor' );
+}
+
+diag("del requestor on update") if $ENV{'TEST_VERBOSE'};
+{
+    my $text = <<END;
+Subject: [$RT::rtname #$test_ticket_id] test
+From: root\@localhost
+
+DelRequestor: root\@localhost
+
+test
+END
+    my $id = create_ticket_via_gate( $text );
+    is($id, $test_ticket_id, "updated ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+    is($obj->RequestorAddresses, 'test at localhost', 'del requestor' );
+}
+
+my $link_ticket_id;
+diag("create ticket for linking") if $ENV{'TEST_VERBOSE'};
+{
+    my $text = <<END;
+Subject: test
+From: root\@localhost
+
+test
+END
+    my $id = create_ticket_via_gate( $text );
+    ok($id, "created ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+    $link_ticket_id = $id;
+}
+
+diag("set links on update") if $ENV{'TEST_VERBOSE'};
+foreach my $field ( qw(DependsOn DependedOnBy RefersTo ReferredToBy Members MemberOf) ) {
+    diag("test $field command") if $ENV{'TEST_VERBOSE'};
+    my $text = <<END;
+Subject: [$RT::rtname #$test_ticket_id] test
+From: root\@localhost
+
+$field: $link_ticket_id
+
+test
+END
+    my $id = create_ticket_via_gate( $text );
+    is($id, $test_ticket_id, "updated ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+
+    my $links = $obj->$field();
+    ok($links, "ticket has links");
+    is($links->Count, 1, "one link");
+
+    my $link_type = $obj->LINKTYPEMAP->{ $field }->{'Type'};
+    my $link_mode = $obj->LINKTYPEMAP->{ $field }->{'Mode'};
+
+    my $link = $links->First;
+    is($link->Type, $link_type, "correct type");
+    isa_ok($link, 'RT::Link');
+    my $method = $link_mode .'Obj';
+    is($link->$method()->Id, $link_ticket_id, 'set '. $field );
+}
+
+diag("set custom fields on update") if $ENV{'TEST_VERBOSE'};
+{
+    require RT::CustomField;
+    my $cf = RT::CustomField->new( $RT::SystemUser );
+    my $cf_name = 'test'.rand $$;
+    $cf->Create( Name => $cf_name, Queue => 0, Type => 'Freeform' );
+    ok($cf->id, "created global CF");
+
+    my $text = <<END;
+Subject: [$RT::rtname #$test_ticket_id] test
+From: root\@localhost
+
+CustomField.{$cf_name}: foo
+
+test
+END
+    my $id = create_ticket_via_gate( $text );
+    is($id, $test_ticket_id, "updated ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+    is($obj->FirstCustomFieldValue($cf_name), 'foo', 'correct cf value' );
+}
+


More information about the Rt-commit mailing list