[Rt-commit] rt branch, 4.4/total-time-worked, updated. rt-4.4.1-311-g24de490

Dave Goehrig dave at bestpractical.com
Thu Mar 9 11:06:03 EST 2017


The branch, 4.4/total-time-worked has been updated
       via  24de490d67665bfedfa4a7919b7eded88187a3e9 (commit)
      from  247ee2012d26ca53355d14f5705060340cd62cae (commit)

Summary of changes:
 lib/RT/Ticket.pm                      |   1 +
 share/html/Ticket/Elements/ShowBasics |   2 +-
 t/api/total-time-worked.t             | 190 ++++++++++++++++++++++------------
 3 files changed, 127 insertions(+), 66 deletions(-)

- Log -----------------------------------------------------------------
commit 24de490d67665bfedfa4a7919b7eded88187a3e9
Author: Dave Goehrig <dave at bestpractical.com>
Date:   Thu Mar 9 11:05:39 2017 -0500

    Add recursive ticket check, and cleanup

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 1aeb0f8..01e4791 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -1424,6 +1424,7 @@ sub TotalTimeWorked {
     my $links = $self->Members;
     LINK: while (my $link = $links->Next) {
         my $obj = $link->BaseObj;
+        next LINK unless $obj && UNIVERSAL::isa($obj,'RT::Ticket');
         next LINK if $seen->{$obj->Id};
         $seen->{ $obj->Id } = 1;
         $time += $obj->TotalTimeWorked($seen);
diff --git a/share/html/Ticket/Elements/ShowBasics b/share/html/Ticket/Elements/ShowBasics
index 78cf152..3d8bd10 100644
--- a/share/html/Ticket/Elements/ShowBasics
+++ b/share/html/Ticket/Elements/ShowBasics
@@ -75,7 +75,7 @@
   </tr>
 % }
 % if (RT->Config->Get('DisplayTotalTimeWorked') && $Ticket->TotalTimeWorked) {
-  <tr class="project time worked sum">
+  <tr class="total time worked sum">
     <td class="label"><&|/l&>Total Time Worked</&>:</td>
     <td class="value"><& ShowTime, minutes => $Ticket->TotalTimeWorked &></td>
   </tr>
diff --git a/t/api/total-time-worked.t b/t/api/total-time-worked.t
index 87a96d2..8cabbb0 100644
--- a/t/api/total-time-worked.t
+++ b/t/api/total-time-worked.t
@@ -3,118 +3,178 @@ use warnings;
 use RT;
 use RT::Test tests => undef;
 
-diag("Test tickets project time worked");
-{
-    my $scrip = RT::Scrip->new(RT->SystemUser);
-    $scrip->LoadByCols(Description => 'On TimeWorked Change Update Parent TimeWorked');
-    $scrip->SetDisabled(1);
+my $scrip = RT::Scrip->new(RT->SystemUser);
+$scrip->LoadByCols(Description => 'On TimeWorked Change Update Parent TimeWorked');
+$scrip->SetDisabled(1);
+
 
-    my $t1 = RT::Ticket->new(RT->SystemUser);
-    my ($ok1) = $t1->Create(
+diag("Test tickets total time worked");
+{
+    my $parent = RT::Ticket->new(RT->SystemUser);
+    my ($ok1,$msg1) = $parent->Create(
         Queue => 'general',
-        Subject => 'project time worked test parent',
+        Subject => 'total time worked test parent',
     );
+    ok($ok1,"Created parent ticket $msg1");
 
-    my $t2 = RT::Ticket->new(RT->SystemUser);
-    my ($ok2) = $t2->Create(
+    my $child = RT::Ticket->new(RT->SystemUser);
+    my ($ok2,$msg2) = $child->Create(
         Queue => 'general',
-        Subject => 'project time worked test child',
+        Subject => 'total time worked test child',
     );
+    ok($ok2,"Created child ticket $msg2");
 
-    my $t3 = RT::Ticket->new(RT->SystemUser);
-    my ($ok3) = $t3->Create(
+    my $grandchild = RT::Ticket->new(RT->SystemUser);
+    my ($ok3,$msg3) = $grandchild->Create(
         Queue => 'general',
-        Subject => 'project time worked test child child',
+        Subject => 'total time worked test child child',
     );
+    ok($ok3,"Created grandchild ticket $msg3");
 
-    my ($status1,$msg1) = $t1->AddLink(
+    my ($ok4,$msg4) = $parent->AddLink(
         Type => 'MemberOf',
-        Base => $t2->id,
+        Base => $child->id,
     );
-
-    my ($status2,$msg2) = $t2->AddLink(
+    ok($ok4,"Created parent -> child link $msg4");
+    
+    my ($ok5,$msg5) = $child->AddLink(
         Type => 'MemberOf',
-        Base => $t3->id,
+        Base => $grandchild->id,
     );
+    ok($ok5,"Created child -> grandchild link $msg5");
 
-    my $t4 = RT::Ticket->new(RT->SystemUser);
-    my ($ok4) = $t4->Create(
+    my $grandchild2 = RT::Ticket->new(RT->SystemUser);
+    my ($ok6,$msg6) = $grandchild2->Create(
         Queue => 'general',
-        Subject => 'project time worked test other child child',
+        Subject => 'total time worked test other child child',
     );
+    ok($ok6,"Create second grandchild $msg6");
 
-    my ($status4,$msg4) = $t2->AddLink(
+    my ($ok7,$msg7) = $child->AddLink(
         Type => 'MemberOf',
-        Base => $t4->id,
+        Base => $grandchild2->id,
     );
+    ok($ok7,"Create child -> second grandchild link $msg7");
 
-    $t1->SetTimeWorked(10);
-    $t2->SetTimeWorked(20);
-    $t3->SetTimeWorked(40);
-    $t4->SetTimeWorked(50);
+    $parent->SetTimeWorked(10);
+    $child->SetTimeWorked(20);
+    $grandchild->SetTimeWorked(40);
+    $grandchild2->SetTimeWorked(50);
 
-    is $t4->TimeWorked, 50, 'set other child child time worked';
-    is $t4->TimeWorked, 50, 'check other child child time worked';
-    is $t3->TimeWorked, 40, 'check child child time worked';
-    is $t2->TimeWorked, 20, 'check child time worked';
-    is $t1->TimeWorked, 10, 'check parent time worked';
+    is $grandchild2->TimeWorked, 50, 'check other child child time worked';
+    is $grandchild->TimeWorked, 40, 'check child child time worked';
+    is $child->TimeWorked, 20, 'check child time worked';
+    is $parent->TimeWorked, 10, 'check parent time worked';
 
-    is $t1->TotalTimeWorked, 120, 'check parent project time worked';
-    is $t2->TotalTimeWorked, 110, 'check child project time worked';
-    is $t3->TotalTimeWorked, 40, 'check child child project time worked';
-    is $t4->TotalTimeWorked, 50, 'check other child child project time worked';
+    is $parent->TotalTimeWorked, 120, 'check parent total time worked';
+    is $child->TotalTimeWorked, 110, 'check child total time worked';
+    is $grandchild->TotalTimeWorked, 40, 'check child child total time worked';
+    is $grandchild2->TotalTimeWorked, 50, 'check other child child total time worked';
 
-    is $t1->TotalTimeWorkedAsString, '2 hours (120 minutes)', 'check parent project time worked as string';
-    is $t3->TotalTimeWorkedAsString, '40 minutes', 'check child child project time workd as string';
+    is $parent->TotalTimeWorkedAsString, '2 hours (120 minutes)', 'check parent total time worked as string';
+    is $grandchild->TotalTimeWorkedAsString, '40 minutes', 'check child child total time workd as string';
 }
 
-diag("Test multiple inheritance project time worked");
+diag("Test multiple inheritance total time worked");
 {
-    my $scrip = RT::Scrip->new(RT->SystemUser);
-    $scrip->LoadByCols(Description => 'On TimeWorked Change Update Parent TimeWorked');
-    $scrip->SetDisabled(1);
-
-    my $t1 = RT::Ticket->new(RT->SystemUser);
-    my ($ok1) = $t1->Create(
+    my $parent = RT::Ticket->new(RT->SystemUser);
+    my ($ok1,$msg1) = $parent->Create(
         Queue => 'general',
-        Subject => 'project time worked test parent',
+        Subject => 'total time worked test parent',
     );
+    ok $ok1, "created parent ticket $msg1";
 
-    my $t2 = RT::Ticket->new(RT->SystemUser);
-    my ($ok2) = $t2->Create(
+    my $child = RT::Ticket->new(RT->SystemUser);
+    my ($ok2,$msg2) = $child->Create(
         Queue => 'general',
-        Subject => 'project time worked test child',
+        Subject => 'total time worked test child',
     );
+    ok $ok2, "created child ticket $msg2";
 
-    my $t3 = RT::Ticket->new(RT->SystemUser);
-    my ($ok3) = $t3->Create(
+    my $grandchild = RT::Ticket->new(RT->SystemUser);
+    my ($ok3,$msg3) = $grandchild->Create(
         Queue => 'general',
-        Subject => 'project time worked test child child, and test child',
+        Subject => 'total time worked test child child, and test child',
     );
+    ok $ok3, "created grandchild ticket $msg3";
 
-    $t1->SetTimeWorked(10);
-    $t2->SetTimeWorked(20);
-    $t3->SetTimeWorked(40);
+    $parent->SetTimeWorked(10);
+    $child->SetTimeWorked(20);
+    $grandchild->SetTimeWorked(40);
 
-    my ($status1,$msg1) = $t1->AddLink(
+    my ($ok4,$msg4) = $parent->AddLink(
         Type => 'MemberOf',
-        Base => $t2->id,
+        Base => $child->id,
     );
+    ok $ok4, "Create parent -> child link $msg4";
 
-    my ($status2,$msg2) = $t2->AddLink(
+    my ($ok5,$msg5) = $child->AddLink(
         Type => 'MemberOf',
-        Base => $t3->id,
+        Base => $grandchild->id,
     );
+    ok $ok5, "Create child -> grandchild link $msg5";
 
-     my ($status3,$msg3) = $t1->AddLink(
+     my ($ok6,$msg6) = $parent->AddLink(
         Type => 'MemberOf',
-        Base => $t3->id,
+        Base => $grandchild->id,
     );
+    ok $ok6, "Created parent -> grandchild link $msg6";
 
-    is $t1->TotalTimeWorked, 70, 'check parent project time worked';
-    is $t2->TotalTimeWorked, 60, 'check child project time worked';
-    is $t3->TotalTimeWorked, 40, 'check child child project time worked';
+    is $parent->TotalTimeWorked, 70, 'check parent total time worked';
+    is $child->TotalTimeWorked, 60, 'check child total time worked';
+    is $grandchild->TotalTimeWorked, 40, 'check child child total time worked';
 
 }
 
+diag("Test inheritance total time worked");
+{
+    my @warnings;
+    local $SIG{__WARN__} = sub {
+        push @warnings, @_;
+    };
+
+    my $parent = RT::Ticket->new(RT->SystemUser);
+    my ($ok1,$msg1) = $parent->Create(
+        Queue => 'general',
+        Subject => 'total time worked test parent',
+    );
+    ok $ok1, "created parent ticket $msg1";
+
+    my $child = RT::Ticket->new(RT->SystemUser);
+    my ($ok2,$msg2) = $child->Create(
+        Queue => 'general',
+        Subject => 'total time worked test child',
+    );
+    ok $ok2, "created child ticket $msg2";
+  
+    my ($ok3,$msg3) = $parent->AddLink(
+        Type => 'MemberOf',
+        Base => $child->id,
+    );
+    ok $ok3, "Created parent -> child link $msg3";  
+    my ($ok4,$msg4) = $parent->AddLink(
+        Type => 'MemberOf',
+        Base => 'http://bestpractical.com',
+    );
+    ok $ok4, "Create parent -> url link $msg4";
+
+    my ($ok5,$msg5) = $child->AddLink(
+        Type => 'MemberOf',
+        Base => 'http://docs.bestpractical.com/',
+    );
+    ok $ok5, "Created child -> url link $msg5";
+
+    $parent->SetTimeWorked(10);
+    $child->SetTimeWorked(20);
+
+    is $parent->TotalTimeWorked, 30, 'check parent total time worked';
+    is $child->TotalTimeWorked, 20, 'check child total time worked';
+
+   TODO: {
+       local $TODO = "this warns because of the unrelated I#31399";
+       is(@warnings, 0, "no warnings");
+   }
+} 
+   
+
 done_testing;

-----------------------------------------------------------------------


More information about the rt-commit mailing list