[Rt-commit] r12825 - in rt/branches/3.8-TESTING: . t/api

elacour at bestpractical.com elacour at bestpractical.com
Tue Jun 3 01:53:19 EDT 2008


Author: elacour
Date: Tue Jun  3 01:53:17 2008
New Revision: 12825

Added:
   rt/branches/3.8-TESTING/t/api/reminders.t
Modified:
   rt/branches/3.8-TESTING/   (props changed)
   rt/branches/3.8-TESTING/lib/RT/Reminders.pm
   rt/branches/3.8-TESTING/lib/RT/Ticket_Overlay.pm

Log:
 r9087 at datura:  manu | 2008-06-03 07:51:00 +0200
 * Add reminder tests.
 * Disable uneeded filter on queue in RT::Reminders::Collection
 * Move code to change reminders queue, after queue change of concerned ticket
 


Modified: rt/branches/3.8-TESTING/lib/RT/Reminders.pm
==============================================================================
--- rt/branches/3.8-TESTING/lib/RT/Reminders.pm	(original)
+++ rt/branches/3.8-TESTING/lib/RT/Reminders.pm	Tue Jun  3 01:53:17 2008
@@ -88,8 +88,7 @@
     my $self = shift;
     my $col = RT::Tickets->new($self->CurrentUser);
 
-     my $query =     'Queue = "'. $self->TicketObj->QueueObj->Name .'" AND Type = "reminder"';
-    $query .= ' AND RefersTo = "'.$self->Ticket.'"';
+     my $query = 'Type = "reminder" AND RefersTo = "'.$self->Ticket.'"';
    
     $col->FromSQL($query);
     

Modified: rt/branches/3.8-TESTING/lib/RT/Ticket_Overlay.pm
==============================================================================
--- rt/branches/3.8-TESTING/lib/RT/Ticket_Overlay.pm	(original)
+++ rt/branches/3.8-TESTING/lib/RT/Ticket_Overlay.pm	Tue Jun  3 01:53:17 2008
@@ -1703,14 +1703,18 @@
         $RT::Logger->error("Couldn't set owner on queue change: $msg") unless $status;
     }
 
-    # On queue change, change queue for reminders too
-    my $reminder_collection = $self->Reminders->Collection;
-    while ( my $reminder = $reminder_collection->Next ) {
-        my ($status, $msg) = $reminder->SetQueue($NewQueue);
-        $RT::Logger->error('Queue change failed for reminder #' . $reminder->Id . ': ' . $msg) unless $status;
-    }
+    my ($status, $msg) = $self->_Set( Field => 'Queue', Value => $NewQueueObj->Id() );
 
-    return ( $self->_Set( Field => 'Queue', Value => $NewQueueObj->Id() ) );
+    if ( $status ) {
+        # On queue change, change queue for reminders too
+        my $reminder_collection = $self->Reminders->Collection;
+        while ( my $reminder = $reminder_collection->Next ) {
+            my ($status, $msg) = $reminder->SetQueue($NewQueue);
+            $RT::Logger->error('Queue change failed for reminder #' . $reminder->Id . ': ' . $msg) unless $status;
+        }
+    }
+    
+    return ($status, $msg);
 }
 
 # }}}

Added: rt/branches/3.8-TESTING/t/api/reminders.t
==============================================================================
--- (empty file)
+++ rt/branches/3.8-TESTING/t/api/reminders.t	Tue Jun  3 01:53:17 2008
@@ -0,0 +1,88 @@
+
+use strict;
+use warnings;
+use Test::More; 
+plan tests => 20;
+use RT;
+use RT::Test;
+
+
+{
+
+# Create test queues
+use_ok ('RT::Queue');
+
+ok(my $testqueue = RT::Queue->new($RT::SystemUser), 'Instantiate RT::Queue');
+ok($testqueue->Create( Name => 'reminders tests'), 'Create new queue: reminders tests');
+isnt($testqueue->Id , 0, 'Success creating queue');
+
+ok($testqueue->Create( Name => 'reminders tests 2'), 'Create new queue: reminders tests 2');
+isnt($testqueue->Id , 0, 'Success creating queue');
+
+# Create test ticket
+use_ok('RT::Ticket');
+
+my $u = RT::User->new($RT::SystemUser);
+$u->Load("root");
+ok ($u->Id, "Found the root user");
+ok(my $t = RT::Ticket->new($RT::SystemUser), 'Instantiate RT::Ticket');
+ok(my ($id, $msg) = $t->Create( Queue => $testqueue->Id,
+               Subject => 'Testing',
+               Owner => $u->Id
+              ), 'Create sample ticket');
+isnt($id , 0, 'Success creating ticket');
+
+# Add reminder
+my $due_obj = RT::Date->new( $RT::SystemUser );
+$due_obj->SetToNow;
+ok(my ( $add_id, $add_msg, $txnid ) = $t->Reminders->Add(
+    Subject => 'TestReminder',
+    Owner   => 'root',
+    Due     => $due_obj->ISO
+    ), 'Add reminder');
+
+# Check that the new Reminder is here
+ok(my $reminders = $t->Reminders->Collection, 'Loading reminders for this ticket');
+my $found = 0;
+while ( my $reminder = $reminders->Next ) {
+    next unless $found == 0;
+    $found = 1 if ( $reminder->Subject =~ m/TestReminder/ );
+}
+
+is($found, 1, 'Reminder successfully added');
+
+# Change queue
+ok (my ($move_val, $move_msg) = $t->SetQueue('reminders tests 2'), 'Moving ticket from queue "reminders tests" to "reminders tests 2"');
+
+is ($t->QueueObj->Name, 'reminders tests 2', 'Ticket successfully moved');
+
+# Check that the new reminder is still there and moved to the new queue
+ok(my $reminders = $t->Reminders->Collection, 'Loading reminders for this ticket');
+$found = 0;
+my $ok_queue = 0;
+while ( my $reminder = $reminders->Next ) {
+    next unless $found == 0;
+    if ( $reminder->Subject =~ m/TestReminder/ ) {
+        $found = 1;
+        $ok_queue = 1 if ( $reminder->QueueObj->Name eq 'reminders tests 2' );
+    }
+}
+is($found, 1, 'Reminder successfully added');
+
+is($ok_queue, 1, 'Reminder automatically moved to new queue');
+
+# Resolve reminder
+my $r_resolved = 0;
+while ( my $reminder = $reminders->Next ) {
+    if ( $reminder->Subject =~ m/TestReminder/ ) {
+        if ( $reminder->Status ne 'resolved' ) {
+            $t->Reminders->Resolve($reminder);
+            $r_resolved = 1 if ( $reminder->Status eq 'resolved' );
+        }
+    }
+}
+
+is($r_resolved, 1, 'Reminder resolved');
+
+}
+1;


More information about the Rt-commit mailing list