File: total-time-worked.t

package info (click to toggle)
request-tracker4 4.4.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 62,888 kB
  • sloc: javascript: 130,444; perl: 65,442; sh: 1,350; makefile: 480; python: 37; php: 30
file content (183 lines) | stat: -rw-r--r-- 5,651 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
use strict;
use warnings;
use RT;
use RT::Test tests => undef;

my $scrip = RT::Scrip->new(RT->SystemUser);
$scrip->LoadByCols(Description => 'On TimeWorked Change Update Parent TimeWorked');
$scrip->SetDisabled(1);


diag("Test tickets total time worked");
{
    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 $grandchild = RT::Ticket->new(RT->SystemUser);
    my ($ok3,$msg3) = $grandchild->Create(
        Queue => 'general',
        Subject => 'total time worked test child child',
    );
    ok($ok3,"Created grandchild ticket $msg3");

    my ($ok4,$msg4) = $parent->AddLink(
        Type => 'MemberOf',
        Base => $child->id,
    );
    ok($ok4,"Created parent -> child link $msg4");

    my ($ok5,$msg5) = $child->AddLink(
        Type => 'MemberOf',
        Base => $grandchild->id,
    );
    ok($ok5,"Created child -> grandchild link $msg5");

    my $grandchild2 = RT::Ticket->new(RT->SystemUser);
    my ($ok6,$msg6) = $grandchild2->Create(
        Queue => 'general',
        Subject => 'total time worked test other child child',
    );
    ok($ok6,"Create second grandchild $msg6");

    my ($ok7,$msg7) = $child->AddLink(
        Type => 'MemberOf',
        Base => $grandchild2->id,
    );
    ok($ok7,"Create child -> second grandchild link $msg7");

    $parent->SetTimeWorked(10);
    $child->SetTimeWorked(20);
    $grandchild->SetTimeWorked(40);
    $grandchild2->SetTimeWorked(50);

    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 $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 $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 total time worked");
{
    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 $grandchild = RT::Ticket->new(RT->SystemUser);
    my ($ok3,$msg3) = $grandchild->Create(
        Queue => 'general',
        Subject => 'total time worked test child child, and test child',
    );
    ok $ok3, "created grandchild ticket $msg3";

    $parent->SetTimeWorked(10);
    $child->SetTimeWorked(20);
    $grandchild->SetTimeWorked(40);

    my ($ok4,$msg4) = $parent->AddLink(
        Type => 'MemberOf',
        Base => $child->id,
    );
    ok $ok4, "Create parent -> child link $msg4";

    my ($ok5,$msg5) = $child->AddLink(
        Type => 'MemberOf',
        Base => $grandchild->id,
    );
    ok $ok5, "Create child -> grandchild link $msg5";

     my ($ok6,$msg6) = $parent->AddLink(
        Type => 'MemberOf',
        Base => $grandchild->id,
    );
    ok $ok6, "Created parent -> grandchild link $msg6";

    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;

    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";

    {
        local $SIG{__WARN__} = sub {
            push @warnings, @_;
        };

        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;