blib/lib/TestLink/API.pm

filter: Statementstmt 25.4% 105 / 413 Branchbran 12.2% 38 / 310 Conditioncond 3.0% 3 / 97 MC/DCmcdc 0.0% 0 / 54 Subroutinesub 95.4% 42 / 44 Podpod 100% 30 / 30 totaltotal 23.0% 218 / 948 CC 204 SCAR 45.9
CC
204
Cov
18%
_cacheProjectTree
405.4
getTLDTestSuitesForProject
264.1
getTestSuitesForTestSuite
230.2
CRAP 98.3
↑ Summary
1 # ABSTRACT: Provides an interface to TestLink's XMLRPC api via HTTP
2 # PODNAME: TestLink::API
3  
4 package TestLink::API;
5 2 $TestLink::API::VERSION = '0.011';
6  
7 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Scalar::Util qw{reftype looks_like_number}; #boo, some functions return hashes and arrays depending on # of results (1 or many)
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Data::Validate::URI 'is_uri';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Clone 'clone';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use XMLRPC::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 2 ▶sub new {
Subroutine new: called CC=7 SCAR=21.1
Pod documented
20 2 my ($class,$apiurl,$apikey) = @_;
21 2 ▶ confess("Constructor must be called statically, not by an instance") if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 1 1 2
22 1 ▶ $apiurl ||= $ENV{'TESTLINK_SERVER_ADDR'};
Condition33%1/3
$apiurl ||= $ENV{"TESTLINK_SERVER_ADDR"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$apiurl ||= $ENV{"TESTLINK_SERVER_ADDR"}
$apiurl $ENV{"TESTLINK_SERVER_ADDR"}
Truth table33%1/3
A ||= B
A= $apiurlB= $ENV{"TESTLINK_SERVER_ADDR"}
ABresult
1X1
011
000
23 1 ▶ $apikey ||= $ENV{'TESTLINK_API_KEY'};
Condition33%1/3
$apikey ||= $ENV{"TESTLINK_API_KEY"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$apikey ||= $ENV{"TESTLINK_API_KEY"}
$apikey $ENV{"TESTLINK_API_KEY"}
Truth table33%1/3
A ||= B
A= $apikeyB= $ENV{"TESTLINK_API_KEY"}
ABresult
1X1
011
000
24  
25 1 ▶ confess("No API key provided.") if !$apiurl;
Branch: 1 branch
BranchTrueFalseTotal
unless $apiurl 0 1 1
26 1 ▶ confess("No API URL provided.") if !$apikey;
Branch: 1 branch
BranchTrueFalseTotal
unless $apikey 0 1 1
27 1 ▶ confess("API URL provided not valid.") unless is_uri($apiurl);
Branch: 1 branch
BranchTrueFalseTotal
unless is_uri($apiurl) 0 1 1
28  
29 1 my $self = {
30 apiurl => $apiurl,
31 apikey => $apikey,
32 testtree => [],
33 flattree => [],
34 invalidate_cache => 1 #since we don't have a cache right now... #TODO this should be granular down to project rather than global
35 };
36  
37 1 bless $self, $class;
38 1 return $self;
39 }
40  
41  
42 #EZ get/set of obj vars
43 1 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=20.6
44 1 my %public_elements = map {$_,1} qw{apiurl apikey}; #Public element access
45 1 our $AUTOLOAD;
46  
47 1 ▶ if ($AUTOLOAD =~ /::(\w+)$/ and exists $public_elements{$1} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($TestLink::API::AUTOLOAD =~ /::(\w+)$/ and exists $public_elements{$1}) 0 1 1
Condition33%1/3
$TestLink::API::AUTOLOAD =~ /::(\w+)$/ and exists $public_elements{$1}
!ll&&!rl&&r
010
MC/DC0%0/2
$TestLink::API::AUTOLOAD =~ /::(\w+)$/ and exists $public_elements{$1}
$TestLink::API::AUTOLOAD =~ /::(\w+)$/ exists $public_elements{$1}
Truth table33%1/3
A and B
A= $TestLink::API::AUTOLOAD =~ /::(\w+)$/B= exists $public_elements{$1}
ABresult
0X0
100
111
48 0 my $field = $1;
49 {
50 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
51 0 ▶ *{$AUTOLOAD} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
52 0 ▶ confess("Object parameters must be called by an instance") unless ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 0 0
53 0 ▶ return $_[0]->{$field} unless defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 0 0
54 0 $_[0]->{$field} = $_[1];
55 0 return $_[0];
56 0 };
57 }
58 0 goto &{$AUTOLOAD};
59 }
60 1 ▶ confess("$AUTOLOAD not accessible property") unless $AUTOLOAD =~ /DESTROY$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $TestLink::API::AUTOLOAD =~ /DESTROY$/ 0 1 1
61 }
62  
63  
64 1 ▶sub createTestPlan {
Subroutine createTestPlan: called CC=9 SCAR=42.1
Pod documented
65 1 my ($self,$name,$project,$notes,$active,$public) = @_;
66 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
67  
68 0 ▶ confess("Desired Test Plan Name is a required argument (0th).") if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
69 0 ▶ confess("Parent Project Name is a required argument (1st).") if !$project;
Branch: 1 branch
BranchTrueFalseTotal
unless $project 0 0 0
70  
71 0 ▶ $notes ||= 'res ipsa loquiter';
Condition0%0/2
$notes ||= "res ipsa loquiter"
l!l
00
MC/DC0%0/1
$notes ||= "res ipsa loquiter"
$notes
Truth table0%0/2
A
A= $notes
Aresult
11
00
72 0 ▶ $active ||= 1;
Condition0%0/2
$active ||= 1
l!l
00
MC/DC0%0/1
$active ||= 1
$active
Truth table0%0/2
A
A= $active
Aresult
11
00
73 0 ▶ $public ||= 1;
Condition0%0/2
$public ||= 1
l!l
00
MC/DC0%0/1
$public ||= 1
$public
Truth table0%0/2
A
A= $public
Aresult
11
00
74  
75 0 my $input = {
76 devKey => $self->apikey,
77 testplanname => $name,
78 testprojectname => $project,
79 notes => $notes,
80 active => $active,
81 public => $public
82 };
83  
84 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
85 0 my $result = $rpc->call('tl.createTestPlan',$input);
86 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
87 0 ▶ return $result->result->[0]->{'id'} if $result->result->[0]->{'id'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"id"} 0 0 0
88 0 return 0;
89 }
90  
91  
92 1 ▶sub createBuild {
Subroutine createBuild: called CC=7 SCAR=36.7
Pod documented
93 1 my ($self,$plan_id,$name,$notes) = @_;
94 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
95 0 ▶ confess("Plan ID must be integer") unless looks_like_number($plan_id);
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($plan_id) 0 0 0
96 0 ▶ confess("Build name is a required argument (1st)") if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
97 0 ▶ $notes ||= 'res ipsa loquiter';
Condition0%0/2
$notes ||= "res ipsa loquiter"
l!l
00
MC/DC0%0/1
$notes ||= "res ipsa loquiter"
$notes
Truth table0%0/2
A
A= $notes
Aresult
11
00
98  
99 0 my $input = {
100 devKey => $self->apikey,
101 testplanid => $plan_id,
102 buildname => $name,
103 buildnotes => $notes
104 };
105  
106 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
107 0 my $result = $rpc->call('tl.createBuild',$input);
108 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
109 0 ▶ return $result->result->[0]->{'id'} if $result->result->[0]->{'id'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"id"} 0 0 0
110 0 return 0;
111 }
112  
113  
114 1 ▶sub createTestSuite {
Subroutine createTestSuite: called CC=9 SCAR=42.1
Pod documented
115 1 my ($self,$project_id,$name,$details,$parent_id,$order) = @_;
116 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
117 0 ▶ confess("Parent Project ID (arg 0) must be an integer") unless looks_like_number($project_id);
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($project_id) 0 0 0
118 0 ▶ confess("Name (arg 1) cannot be undefined") unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
119  
120 0 ▶ $details ||= 'res ipsa loquiter';
Condition0%0/2
$details ||= "res ipsa loquiter"
l!l
00
MC/DC0%0/1
$details ||= "res ipsa loquiter"
$details
Truth table0%0/2
A
A= $details
Aresult
11
00
121 0 ▶ $order ||= -1;
Condition0%0/2
$order ||= -1
l!l
00
MC/DC0%0/1
$order ||= -1
$order
Truth table0%0/2
A
A= $order
Aresult
11
00
122  
123 0 my $input = {
124 devKey => $self->apikey,
125 testprojectid => $project_id,
126 testsuitename => $name,
127 details => $details,
128 parentid => $parent_id,
129 order => $order
130 };
131  
132 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
133 0 my $result = $rpc->call('tl.createTestSuite',$input);
134 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
135 0 ▶ $self->{'invalidate_cache'} = 1 if $result->result->[0]->{'id'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"id"} 0 0 0
136 0 ▶ return $result->result->[0]->{'id'} if $result->result->[0]->{'id'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"id"} 0 0 0
137 0 return 0;
138 }
139  
140  
141 #XXX probably should not use
142 1 ▶sub createTestProject {
Subroutine createTestProject: called CC=9 SCAR=42.1
Pod documented
143 1 my ($self,$name,$case_prefix,$notes,$options,$active,$public) = @_;
144 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
145 0 ▶ $notes //= 'res ipsa loquiter';
Condition0%0/2
$notes //= "res ipsa loquiter"
l!l
00
MC/DC0%0/1
$notes //= "res ipsa loquiter"
$notes
Truth table0%0/2
A
A= $notes
Aresult
11
00
146 0 ▶ $options //= {};
Condition0%0/2
$options //= {}
l!l
00
MC/DC0%0/1
$options //= {}
$options
Truth table0%0/2
A
A= $options
Aresult
11
00
147 0 ▶ $public //= 1;
Condition0%0/2
$public //= 1
l!l
00
MC/DC0%0/1
$public //= 1
$public
Truth table0%0/2
A
A= $public
Aresult
11
00
148 0 ▶ $active //= 1;
Condition0%0/2
$active //= 1
l!l
00
MC/DC0%0/1
$active //= 1
$active
Truth table0%0/2
A
A= $active
Aresult
11
00
149  
150 0 my $input = {
151 devKey => $self->apikey,
152 testprojectname => $name,
153 testcaseprefix => $case_prefix,
154 notes => $notes,
155 options => $options,
156 active => $active,
157 public => $public
158 };
159  
160 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
161 0 my $result = $rpc->call('tl.createTestProject',$input);
162 #XXX i'm being very safe (haha), there's probably a better check
163 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
164 0 ▶ $self->{'invalidate_cache'} = 1 if $result->result->[0]->{'id'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"id"} 0 0 0
165 0 ▶ return $result->result->[0]->{'id'} if $result->result->[0]->{'id'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"id"} 0 0 0
166 0 return 0;
167  
168 }
169  
170  
171 1 ▶sub createTestCase {
Subroutine createTestCase: called CC=4 SCAR=24.6
Pod documented
172 1 my ($self,$test_name,$test_suite_id,$test_project_id,$author_name,$summary,$steps,$preconditions,$execution,$order) = @_;
173 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
174  
175 0 my $input = {
176 devKey => $self->apikey,
177 testcasename => $test_name,
178 testsuiteid => $test_suite_id,
179 testprojectid => $test_project_id,
180 authorlogin => $author_name,
181 summary => $summary,
182 steps => $steps,
183 preconditions => $preconditions,
184 execution => $execution,
185 order => $order
186 };
187  
188 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
189 0 my $result = $rpc->call('tl.createTestCase',$input);
190 #XXX i'm being very safe (haha), there's probably a better check
191 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
192 0 ▶ return $result->result->[0] if $result->result->[0]->{'id'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"id"} 0 0 0
193 0 return 0;
194  
195 }
196  
197  
198 1 ▶sub reportTCResult {
Subroutine reportTCResult: called CC=7 SCAR=37.0
Pod documented
199 1 my ($self,$case_id,$plan_id,$build_id,$status,$platform,$notes,$bugid) = @_;
200 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
201  
202 0 my $input = {
203 devKey => $self->apikey,
204 testcaseid => $case_id,
205 testplanid => $plan_id,
206 buildid => $build_id,
207 status => $status,
208 notes => $notes,
209 bugid => $bugid
210 };
211  
212 0 ▶ if (defined($platform) && !ref $platform) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $platform and not ref $platform) 0 0 0
Condition0%0/3
defined $platform and not ref $platform
!ll&&!rl&&r
000
MC/DC0%0/2
defined $platform and not ref $platform
defined $platform not ref $platform
Truth table0%0/3
A and not(B)
A= defined $platformB= not ref $platform
ABresult
0X0
100
111
213 0 ▶ if (looks_like_number($platform)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($platform)) { } 0 0 0
214 0 $input->{'platformid'} = $platform;
215 } else {
216 0 $input->{'platformname'} = $platform;
217 }
218 }
219  
220 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
221 0 my $result = $rpc->call('tl.reportTCResult',$input);
222 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
223 0 ▶ return $result->result->[0] unless $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->[0]{"code"} 0 0 0
224 0 return 0;
225 }
226  
227  
228 #XXX this should be able to be done in batch
229 1 ▶sub addTestCaseToTestPlan {
Subroutine addTestCaseToTestPlan: called CC=4 SCAR=24.6
Pod documented
230 1 my ($self,$plan_id,$case_id,$project_id,$version,$platform,$order,$urgency) = @_;
231 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
232  
233 0 my $input = {
234 devKey => $self->apikey,
235 testplanid => $plan_id,
236 testcaseexternalid => $case_id,
237 testprojectid => $project_id,
238 version => $version,
239 platformid => $platform,
240 executionorder => $order,
241 urgency => $urgency
242 };
243  
244 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
245 0 my $result = $rpc->call('tl.addTestCaseToTestPlan',$input);
246 0 ▶ warn $result->result->{'message'} if $result->result->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->{"code"} 0 0 0
247 0 ▶ return 1 unless $result->result->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->{"code"} 0 0 0
248 0 return 0;
249 }
250  
251  
252 1 ▶sub uploadExecutionAttachment {
Subroutine uploadExecutionAttachment: called CC=4 SCAR=24.6
Pod documented
253 1 my ($self,$execution_id,$filename,$filetype,$content,$title,$description) = @_;
254 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
255  
256 0 my $input = {
257 devKey => $self->apikey,
258 executionid => $execution_id,
259 title => $title,
260 description => $description,
261 filename => $filename,
262 filetype => $filetype,
263 content => $content
264 };
265  
266 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
267 0 my $result = $rpc->call('tl.uploadExecutionAttachment',$input);
268 0 ▶ warn $result->result->{'message'} if $result->result->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->{"code"} 0 0 0
269 0 ▶ return 1 unless $result->result->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->{"code"} 0 0 0
270 0 return 0;
271 }
272  
273  
274 1 ▶sub uploadTestCaseAttachment {
Subroutine uploadTestCaseAttachment: called CC=4 SCAR=24.6
Pod documented
275 1 my ($self,$case_id,$filename,$filetype,$content,$title,$description) = @_;
276 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
277  
278 0 my $input = {
279 devKey => $self->apikey,
280 testcaseid => $case_id,
281 title => $title,
282 description => $description,
283 filename => $filename,
284 filetype => $filetype,
285 content => $content
286 };
287  
288 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
289 0 my $result = $rpc->call('tl.uploadTestCaseAttachment',$input);
290 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
291 0 ▶ return 1 unless $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->[0]{"code"} 0 0 0
292 0 return 0;
293 }
294  
295  
296  
297 1 ▶sub getProjects {
Subroutine getProjects: called CC=7 SCAR=37.0
Pod documented
298 1 my $self = shift;
299 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
300  
301 0 my $input = {
302 devKey => $self->apikey
303 };
304  
305 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
306 0 my $result = $rpc->call('tl.getProjects',$input);
307 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
308  
309 #Save state for future use, if needed
310 0 ▶ if (!scalar(@{$self->{'testtree'}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @{$self->{"testtree"};}) 0 0 0
311 0 ▶ $self->{'testtree'} = $result->result unless $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->[0]{"code"} 0 0 0
312 }
313  
314 0 ▶ if (!exists($result->result->[0]->{'code'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $result->result->[0]{"code"}) 0 0 0
315 #Note that it's a project for future reference by recursive tree search
316 0 for my $pj (@{$result->result}) {
317 0 $pj->{'type'} = 'project';
318 }
319 0 return $result->result;
320 }
321  
322 0 return 0;
323 }
324  
325  
326 1 ▶sub getProjectByName {
Subroutine getProjectByName: called CC=6 SCAR=32.3
Pod documented
327 1 my ($self,$project) = @_;
328 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
329 0 ▶ confess "No project provided." unless $project;
Branch: 1 branch
BranchTrueFalseTotal
unless $project 0 0 0
330  
331 #See if we already have the project list...
332 0 my $projects = $self->{'testtree'};
333 0 ▶ $projects = $self->getProjects() unless scalar(@$projects);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$projects 0 0 0
334  
335 #Search project list for project
336 0 for my $candidate (@$projects) {
337 0 ▶ return $candidate if ($candidate->{'name'} eq $project);
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->{"name"} eq $project 0 0 0
338 }
339  
340 0 return 0;
341 }
342  
343  
344 1 ▶sub getProjectByID {
Subroutine getProjectByID: called CC=6 SCAR=32.3
Pod documented
345 1 my ($self,$project) = @_;
346 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
347 0 ▶ confess "No project provided." unless $project;
Branch: 1 branch
BranchTrueFalseTotal
unless $project 0 0 0
348  
349 #See if we already have the project list...
350 0 my $projects = $self->{'testtree'};
351 0 ▶ $projects = $self->getProjects() unless scalar(@$projects);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$projects 0 0 0
352  
353 #Search project list for project
354 0 for my $candidate (@$projects) {
355 0 ▶ return $candidate if ($candidate->{'id'} eq $project);
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->{"id"} eq $project 0 0 0
356 }
357  
358 0 return 0;
359 }
360  
361  
362  
363 1 ▶sub getTLDTestSuitesForProject {
Subroutine getTLDTestSuitesForProject: called CC=17 SCAR=55.8
Pod documented
364 1 my ($self,$project,$get_tests) = @_;
365 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
366 0 ▶ confess "No project ID provided." unless $project;
Branch: 1 branch
BranchTrueFalseTotal
unless $project 0 0 0
367  
368 0 my $input = {
369 devKey => $self->apikey,
370 testprojectid => $project
371 };
372  
373 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
374 0 my $result = $rpc->call('tl.getFirstLevelTestSuitesForTestProject',$input);
375  
376 #Error condition, return right away
377 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
378 0 ▶ return [] if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
379  
380 #Handle bizarre output
381 0 ▶ if ($result->result && !(reftype($result->result) eq 'HASH' || reftype($result->result) eq 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->result and not builtin::reftype($result->result) eq "HASH" || builtin::reftype($result->result) eq "ARRAY") 0 0 0
Condition0%0/6
$result->result and not builtin::reftype($result->result) eq "HASH" || builtin::reftype($result->result) eq "ARRAY"
!ll&&!rl&&r
000
builtin::reftype($result->result) eq 'HASH' || builtin::reftype($result->result) eq 'ARRAY'
l!l&&r!l&&!r
000
MC/DC0%0/3
$result->result and not builtin::reftype($result->result) eq "HASH" || builtin::reftype($result->result) eq "ARRAY"
$result->result builtin::reftype($result->result) eq 'HASH' builtin::reftype($result->result) eq 'ARRAY'
Truth table0%0/4
A and not(B || C)
A= $result->resultB= builtin::reftype($result->result) eq 'HASH'C= builtin::reftype($result->result) eq 'ARRAY'
ABCresult
0XX0
11X0
1010
1001
382 0 return [];
383 }
384 0 ▶ return [] if !$result->result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result 0 0 0
385  
386 #Handle mixed return type for this function -- this POS will return arrayrefs, and 2 types of hashrefs.
387 0 my $res = [];
388 0 ▶ $res = $result->result if reftype($result->result) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($result->result) eq "ARRAY" 0 0 0
389 0 ▶ @$res = values(%{$result->result}) if reftype($result->result) eq 'HASH' && !defined($result->result->{'id'});
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($result->result) eq "HASH" and not defined $result->result->{"id"} 0 0 0
Condition0%0/3
builtin::reftype($result->result) eq "HASH" and not defined $result->result->{"id"}
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::reftype($result->result) eq "HASH" and not defined $result->result->{"id"}
builtin::reftype($result->result) eq "HASH" not defined $result->result->{"id"}
Truth table0%0/3
A and not(B)
A= builtin::reftype($result->result) eq "HASH"B= not defined $result->result->{"id"}
ABresult
0X0
100
111
390 0 ▶ $res = [$result->result] if reftype($result->result) eq 'HASH' && defined($result->result->{'id'});
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($result->result) eq "HASH" and defined $result->result->{"id"} 0 0 0
Condition0%0/3
builtin::reftype($result->result) eq "HASH" and defined $result->result->{"id"}
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::reftype($result->result) eq "HASH" and defined $result->result->{"id"}
builtin::reftype($result->result) eq "HASH" defined $result->result->{"id"}
Truth table0%0/3
A and B
A= builtin::reftype($result->result) eq "HASH"B= defined $result->result->{"id"}
ABresult
0X0
100
111
391 0 ▶ return [] if (!scalar(keys(%{$res->[0]}))); #Catch bizarre edge case of blank hash being only thing there
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %{$$res[0];} 0 0 0
392  
393 0 ▶ if ($get_tests) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get_tests) 0 0 0
394 0 ▶ for (my $i=0; $i < scalar(@{$result->result}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$result->result;}) 0 0 0
395 0 $result->result->[$i]->{'tests'} = $self->getTestCasesForTestSuite($result->result->[$i]->{'id'},0,1);
396 }
397 }
398  
399 0 return $result->result;
400 }
401  
402  
403 1 ▶sub getTestSuitesForTestSuite {
Subroutine getTestSuitesForTestSuite: called CC=16 SCAR=54.4
Pod documented
404 1 my ($self,$tsid,$get_tests) = @_;
405 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
406 0 ▶ confess "No TestSuite ID provided." unless $tsid;
Branch: 1 branch
BranchTrueFalseTotal
unless $tsid 0 0 0
407  
408 0 my $input = {
409 devKey => $self->apikey,
410 testsuiteid => $tsid
411 };
412  
413 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
414 0 my $result = $rpc->call('tl.getTestSuitesForTestSuite',$input);
415  
416 #Handle bizarre output
417 0 ▶ if ($result->result && !(reftype($result->result) eq 'HASH' || reftype($result->result) eq 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->result and not builtin::reftype($result->result) eq "HASH" || builtin::reftype($result->result) eq "ARRAY") 0 0 0
Condition0%0/6
$result->result and not builtin::reftype($result->result) eq "HASH" || builtin::reftype($result->result) eq "ARRAY"
!ll&&!rl&&r
000
builtin::reftype($result->result) eq 'HASH' || builtin::reftype($result->result) eq 'ARRAY'
l!l&&r!l&&!r
000
MC/DC0%0/3
$result->result and not builtin::reftype($result->result) eq "HASH" || builtin::reftype($result->result) eq "ARRAY"
$result->result builtin::reftype($result->result) eq 'HASH' builtin::reftype($result->result) eq 'ARRAY'
Truth table0%0/4
A and not(B || C)
A= $result->resultB= builtin::reftype($result->result) eq 'HASH'C= builtin::reftype($result->result) eq 'ARRAY'
ABCresult
0XX0
11X0
1010
1001
418 0 return [];
419 }
420 0 ▶ return [] if !$result->result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result 0 0 0
421  
422 #Handle mixed return type for this function -- this POS will return arrayrefs, and 2 types of hashrefs.
423 0 my $res = [];
424 0 ▶ $res = $result->result if reftype($result->result) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($result->result) eq "ARRAY" 0 0 0
425 0 ▶ @$res = values(%{$result->result}) if reftype($result->result) eq 'HASH' && !defined($result->result->{'id'});
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($result->result) eq "HASH" and not defined $result->result->{"id"} 0 0 0
Condition0%0/3
builtin::reftype($result->result) eq "HASH" and not defined $result->result->{"id"}
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::reftype($result->result) eq "HASH" and not defined $result->result->{"id"}
builtin::reftype($result->result) eq "HASH" not defined $result->result->{"id"}
Truth table0%0/3
A and not(B)
A= builtin::reftype($result->result) eq "HASH"B= not defined $result->result->{"id"}
ABresult
0X0
100
111
426 0 ▶ $res = [$result->result] if reftype($result->result) eq 'HASH' && defined($result->result->{'id'});
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($result->result) eq "HASH" and defined $result->result->{"id"} 0 0 0
Condition0%0/3
builtin::reftype($result->result) eq "HASH" and defined $result->result->{"id"}
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::reftype($result->result) eq "HASH" and defined $result->result->{"id"}
builtin::reftype($result->result) eq "HASH" defined $result->result->{"id"}
Truth table0%0/3
A and B
A= builtin::reftype($result->result) eq "HASH"B= defined $result->result->{"id"}
ABresult
0X0
100
111
427  
428 0 ▶ if ($get_tests) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get_tests) 0 0 0
429 0 foreach my $row (@$res) {
430 0 $row->{'tests'} = $self->getTestCasesForTestSuite($row->{'id'},0,1);
431 }
432 }
433  
434 #Error condition, return false and don't bother searching arrays
435 0 ▶ warn $res->{'message'} if $res->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $res->[0]{"code"} 0 0 0
436 0 ▶ return [] if $res->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $res->[0]{"code"} 0 0 0
437 0 return $res;
438 }
439  
440  
441  
442 1 ▶sub getTestSuitesByName {
Subroutine getTestSuitesByName: called CC=9 SCAR=41.8
Pod documented
443 1 my ($self,$project_id,$testsuite_name,$do_regex) = @_;
444 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
445 0 ▶ return 0 if (!$project_id || !$testsuite_name); #GIGO
Branch: 1 branch
BranchTrueFalseTotal
unless $project_id and $testsuite_name 0 0 0
Condition0%0/3
$project_id and $testsuite_name
!ll&&!rl&&r
000
MC/DC0%0/2
$project_id and $testsuite_name
$project_id $testsuite_name
Truth table0%0/3
A and B
A= $project_idB= $testsuite_name
ABresult
0X0
100
111
446  
447 #use caching methods here to speed up subsequent calls
448 0 ▶ $self->_cacheProjectTree($project_id,1,1,0) if $self->{'invalidate_cache'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"invalidate_cache"} 0 0 0
449  
450 #my $tld = $self->getTLDTestSuitesForProject($project_id);
451 0 my $candidates = [];
452  
453 #Walk the whole tree. No other way to be sure.
454 0 foreach my $ts (@{$self->{'flattree'}}) {
455 0 ▶ if ($do_regex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_regex) { } 0 0 0
456 0 ▶ push(@$candidates,$ts) if $ts->{'name'} =~ $testsuite_name;
Branch: 1 branch
BranchTrueFalseTotal
if $ts->{"name"} =~ /$testsuite_name/ 0 0 0
457 } else {
458 0 ▶ push(@$candidates,$ts) if $ts->{'name'} eq $testsuite_name;
Branch: 1 branch
BranchTrueFalseTotal
if $ts->{"name"} eq $testsuite_name 0 0 0
459 }
460 }
461 0 return $candidates;
462  
463 }
464  
465  
466 1 ▶sub getTestSuiteByID {
Subroutine getTestSuiteByID: called CC=4 SCAR=24.6
Pod documented
467 1 my ($self,$testsuite_id) = @_;
468 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
469  
470 0 my $input = {
471 devKey => $self->apikey,
472 testsuiteid => $testsuite_id
473 };
474  
475 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
476 0 my $result = $rpc->call('tl.getTestSuiteByID',$input);
477 0 ▶ warn $result->result->{'message'} if $result->result->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->{"code"} 0 0 0
478 0 ▶ return $result->result unless $result->result->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->{"code"} 0 0 0
479 0 return 0;
480 }
481  
482  
483 1 ▶sub getTestCasesForTestSuite {
Subroutine getTestCasesForTestSuite: called CC=7 SCAR=36.8
Pod documented
484 1 my ($self,$testsuite_id,$deep,$details) = @_;
485 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
486  
487 0 ▶ $details = 'full' if $details;
Branch: 1 branch
BranchTrueFalseTotal
if $details 0 0 0
488  
489 0 my $input = {
490 devKey => $self->apikey,
491 testsuiteid => $testsuite_id,
492 deep => $deep,
493 details => $details
494 };
495  
496 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
497 0 my $result = $rpc->call('tl.getTestCasesForTestSuite',$input);
498 0 ▶ return [] if !$result->result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result 0 0 0
499  
500 0 ▶ return [] if !scalar(keys(%{$result->result->[0]})); # No tests
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %{$result->result->[0];} 0 0 0
501  
502 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
503 0 ▶ return $result->result unless $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->[0]{"code"} 0 0 0
504 0 return [];
505 }
506  
507  
508 1 ▶sub getTestCaseByExternalId {
Subroutine getTestCaseByExternalId: called CC=4 SCAR=24.6
Pod documented
509 1 my ($self,$case_id,$version) = @_;
510 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
511  
512 0 my $input = {
513 devKey => $self->apikey,
514 testcaseexternalid => $case_id,
515 version => $version
516 };
517  
518 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
519 0 my $result = $rpc->call('tl.getTestCase',$input);
520 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
521 0 ▶ return $result->result->[0] unless $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->[0]{"code"} 0 0 0
522 0 return 0;
523 }
524  
525  
526 1 ▶sub getTestCaseById {
Subroutine getTestCaseById: called CC=4 SCAR=24.6
Pod documented
527 1 my ($self,$case_id,$version) = @_;
528 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
529  
530 0 my $input = {
531 devKey => $self->apikey,
532 testcaseid => $case_id,
533 version => $version
534 };
535  
536 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
537 0 my $result = $rpc->call('tl.getTestCase',$input);
538 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
539 0 ▶ return $result->result->[0] unless $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->[0]{"code"} 0 0 0
540 0 return 0;
541 }
542  
543  
544 1 ▶sub getTestCaseByName {
Subroutine getTestCaseByName: called CC=4 SCAR=24.6
Pod documented
545 1 my ($self, $casename, $suitename, $projectname, $testcasepathname) = @_;
546 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
547  
548 0 my $input = {
549 devKey => $self->apikey,
550 testcasename => $casename,
551 testsuitename => $suitename,
552 testprojectname => $projectname,
553 testcasepathname => $testcasepathname
554 };
555  
556 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
557 0 my $result = $rpc->call('tl.getTestCaseIDByName',$input);
558 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
559 0 ▶ return $result->result->[0] unless $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->[0]{"code"} 0 0 0
560 0 return 0;
561 }
562  
563  
564 1 ▶sub getTestCaseAttachments {
Subroutine getTestCaseAttachments: called CC=5 SCAR=29.4
Pod documented
565 1 my ($self, $case_ext_id) = @_;
566 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
567  
568 0 my $input = {
569 devKey => $self->apikey,
570 testcaseexternalid => $case_ext_id,
571 };
572  
573 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
574 0 my $result = $rpc->call('tl.getTestCaseAttachments',$input);
575 0 ▶ return 0 if (!$result->result);
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result 0 0 0
576 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
577 0 ▶ return $result->result->[0] unless $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->[0]{"code"} 0 0 0
578 0 return 0;
579 }
580  
581  
582 1 ▶sub getTestPlansForProject {
Subroutine getTestPlansForProject: called CC=4 SCAR=24.6
Pod documented
583 1 my ($self,$project_id) = @_;
584 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
585  
586 0 my $input = {
587 devKey => $self->apikey,
588 testprojectid => $project_id
589 };
590  
591 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
592 0 my $result = $rpc->call('tl.getProjectTestPlans',$input);
593 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
594 0 ▶ return $result->result unless $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->[0]{"code"} 0 0 0
595 0 return 0;
596 }
597  
598  
599 # I find it highly bizarre that the only 'by name' method exists for test plans, and it's the only test plan getter.
600 1 ▶sub getTestPlanByName {
Subroutine getTestPlanByName: called CC=4 SCAR=24.6
Pod documented
601 1 my ($self,$plan_name,$project_name) = @_;
602 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
603  
604 0 my $input = {
605 devKey => $self->apikey,
606 testplanname => $plan_name,
607 testprojectname => $project_name
608 };
609  
610 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
611 0 my $result = $rpc->call('tl.getTestPlanByName',$input);
612 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
613 0 ▶ return $result->result->[0] unless $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->[0]{"code"} 0 0 0
614 0 return 0;
615 }
616  
617  
618 1 ▶sub getBuildsForTestPlan {
Subroutine getBuildsForTestPlan: called CC=4 SCAR=24.6
Pod documented
619 1 my ($self,$plan_id) = @_;
620 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
621  
622 0 my $input = {
623 devKey => $self->apikey,
624 testplanid => $plan_id
625 };
626  
627 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
628 0 my $result = $rpc->call('tl.getBuildsForTestPlan',$input);
629 0 ▶ warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->[0]{"code"} 0 0 0
630 0 ▶ return $result->result unless $result->result->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->[0]{"code"} 0 0 0
631 0 return 0;
632 }
633  
634  
635 1 ▶sub getTestCasesForTestPlan {
Subroutine getTestCasesForTestPlan: called CC=4 SCAR=24.6
Pod documented
636 1 my ($self,$plan_id) = @_;
637 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
638  
639 0 my $input = {
640 devKey => $self->apikey,
641 testplanid => $plan_id
642 };
643  
644 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
645 0 my $result = $rpc->call('tl.getTestCasesForTestPlan',$input);
646 0 ▶ warn $result->result->{'message'} if $result->result->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->{"code"} 0 0 0
647 0 ▶ return $result->result unless $result->result->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->{"code"} 0 0 0
648 0 return 0;
649 }
650  
651  
652 1 ▶sub getLatestBuildForTestPlan {
Subroutine getLatestBuildForTestPlan: called CC=5 SCAR=29.7
Pod documented
653 1 my ($self,$plan_id) = @_;
654 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
655  
656 0 my $input = {
657 devKey => $self->apikey,
658 tplanid => $plan_id, #documented arg, but that's LIES, apparently it wants the next one
659 testplanid => $plan_id
660 };
661  
662 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
663 0 my $result = $rpc->call('tl.getLatestBuildForTestPlan',$input);
664  
665 #Handle mixed return type
666 0 my $res = $result->result;
667 0 ▶ $res = [$res] if reftype($res) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($res) eq "HASH" 0 0 0
668  
669 0 ▶ warn $res->[0]->{'message'} if $res->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $res->[0]{"code"} 0 0 0
670 0 ▶ return $res->[0] unless $res->[0]->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0]{"code"} 0 0 0
671 0 return 0;
672 }
673  
674  
675 #TODO cache stuff, don't require proj id?
676 1 ▶sub getBuildByName {
Subroutine getBuildByName: called CC=5 SCAR=27.4
Pod documented
677 1 my ($self,$build_name,$project_id) = @_;
678 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
679  
680 0 my $plans = $self->getTestPlansForProject($project_id);
681 0 for my $plan (@$plans) {
682 0 my $builds = $self->getBuildsForTestPlan($plan->{'id'});
683 0 for my $build (@$builds) {
684 0 ▶ return $build if $build->{'name'} eq $build_name;
Branch: 1 branch
BranchTrueFalseTotal
if $build->{"name"} eq $build_name 0 0 0
685 }
686 }
687 0 return 0;
688 }
689  
690  
691 1 ▶sub getTotalsForTestPlan {
Subroutine getTotalsForTestPlan: called CC=4 SCAR=24.6
Pod documented
692 1 my ($self,$plan_id) = @_;
693 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
694  
695 0 my $input = {
696 devKey => $self->apikey,
697 tplanid => $plan_id, #documented arg, but that's LIES, apparently it wants the next one
698 testplanid => $plan_id
699 };
700  
701 0 my $rpc = XMLRPC::Lite->proxy($self->apiurl);
702 0 my $result = $rpc->call('tl.getTotalsForTestPlan',$input);
703  
704 0 ▶ warn $result->result->{'message'} if $result->result->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
if $result->result->{"code"} 0 0 0
705 0 ▶ return $result->result unless $result->result->{'code'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->result->{"code"} 0 0 0
706 0 return 0;
707 }
708  
709  
710 1 ▶sub dump {
Subroutine dump: called CC=8 SCAR=39.1
Pod documented
711 1 my ($self,$project,$attachment,$flat) = @_;
712 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
713 0 ▶ confess("Getting attachments not yet implemented") if $attachment;
Branch: 1 branch
BranchTrueFalseTotal
if $attachment 0 0 0
714  
715 0 my $res = $self->_cacheProjectTree($project,$flat);
716 0 ▶ return [] if !$res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
717  
718 0 ▶ return $res if !$project || $flat;
Branch: 1 branch
BranchTrueFalseTotal
if not $project or $flat 0 0 0
Condition0%0/3
not $project or $flat
l!l&&r!l&&!r
000
MC/DC0%0/2
not $project or $flat
not $project $flat
Truth table0%0/3
not(A) or B
A= not $projectB= $flat
ABresult
1X1
011
000
719 0 foreach my $pj (@{$res}) {
720 0 ▶ return $pj if $pj->{'name'} eq $project;
Branch: 1 branch
BranchTrueFalseTotal
if $pj->{"name"} eq $project 0 0 0
721 }
722 0 croak "COULD NOT DUMP, SOMETHING HORRIBLY WRONG";
723 }
724  
725 1 ▶sub _cacheProjectTree {
Subroutine _cacheProjectTree: called CC=21 SCAR=60.0
726 1 my ($self,$project,$flat,$use_project_id,$get_tests) = @_;
727 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
728  
729 0 ▶ $flat //= 0;
Condition0%0/2
$flat //= 0
l!l
00
MC/DC0%0/1
$flat //= 0
$flat
Truth table0%0/2
A
A= $flat
Aresult
11
00
730 0 ▶ $use_project_id //= 0;
Condition0%0/2
$use_project_id //= 0
l!l
00
MC/DC0%0/1
$use_project_id //= 0
$use_project_id
Truth table0%0/2
A
A= $use_project_id
Aresult
11
00
731 0 ▶ $get_tests //= 1;
Condition0%0/2
$get_tests //= 1
l!l
00
MC/DC0%0/1
$get_tests //= 1
$get_tests
Truth table0%0/2
A
A= $get_tests
Aresult
11
00
732  
733 #Cache Projects
734 0 ▶ if (!scalar(@{$self->{'testtree'}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @{$self->{"testtree"};}) 0 0 0
735 0 $self->getProjects();
736 }
737  
738 0 my @flattener = @{$self->{'testtree'}};
739  
740 0 for my $projhash (@flattener) {
741 0 ▶ if ($use_project_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_project_id) { } 0 0 0
742 0 ▶ next if $project && $project ne $projhash->{'id'} && (defined($projhash->{'type'}) && $projhash->{'type'} eq 'project');
Branch: 1 branch
BranchTrueFalseTotal
if $project and $project ne $projhash->{"id"} and (defined $projhash->{"type"} and $projhash->{"type"} eq "project") 0 0 0
Condition0%0/9
$project and $project ne $projhash->{"id"} and (defined $projhash->{"type"} and $projhash->{"type"} eq "project")
!ll&&!rl&&r
000
$project and $project ne $projhash->{"id"}
!ll&&!rl&&r
000
defined $projhash->{"type"} and $projhash->{"type"} eq "project"
!ll&&!rl&&r
000
MC/DC0%0/4
$project and $project ne $projhash->{"id"} and (defined $projhash->{"type"} and $projhash->{"type"} eq "project")
$project $project ne $projhash->{"id"} defined $projhash->{"type"} $projhash->{"type"} eq "project"
Truth table0%0/5
A and B and C and D
A= $projectB= $project ne $projhash->{"id"}C= defined $projhash->{"type"}D= $projhash->{"type"} eq "project"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
743 } else {
744 0 ▶ next if $project && $project ne $projhash->{'name'} && (defined($projhash->{'type'}) && $projhash->{'type'} eq 'project');
Branch: 1 branch
BranchTrueFalseTotal
if $project and $project ne $projhash->{"name"} and (defined $projhash->{"type"} and $projhash->{"type"} eq "project") 0 0 0
Condition0%0/9
$project and $project ne $projhash->{"name"} and (defined $projhash->{"type"} and $projhash->{"type"} eq "project")
!ll&&!rl&&r
000
$project and $project ne $projhash->{"name"}
!ll&&!rl&&r
000
defined $projhash->{"type"} and $projhash->{"type"} eq "project"
!ll&&!rl&&r
000
MC/DC0%0/4
$project and $project ne $projhash->{"name"} and (defined $projhash->{"type"} and $projhash->{"type"} eq "project")
$project $project ne $projhash->{"name"} defined $projhash->{"type"} $projhash->{"type"} eq "project"
Truth table0%0/5
A and B and C and D
A= $projectB= $project ne $projhash->{"name"}C= defined $projhash->{"type"}D= $projhash->{"type"} eq "project"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
745 }
746  
747 #If TestSuites are not defined, this must be a TS which we have not traversed yet, so go and get it
748 0 ▶ if (exists($projhash->{'type'}) && $projhash->{'type'} eq 'project') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $projhash->{'type'} and $projhash->{'type'} eq 'project') { } 0 0 0
Condition0%0/3
exists $projhash->{"type"} and $projhash->{"type"} eq "project"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $projhash->{"type"} and $projhash->{"type"} eq "project"
exists $projhash->{"type"} $projhash->{"type"} eq "project"
Truth table0%0/3
A and B
A= exists $projhash->{"type"}B= $projhash->{"type"} eq "project"
ABresult
0X0
100
111
749 0 $projhash->{'testsuites'} = $self->getTLDTestSuitesForProject($projhash->{'id'},$get_tests);
750 } else {
751 0 $projhash->{'testsuites'} = $self->getTestSuitesForTestSuite($projhash->{'id'},$get_tests);
752 }
753  
754 0 ▶ $projhash->{'testsuites'} = [] if !$projhash->{'testsuites'};
Branch: 1 branch
BranchTrueFalseTotal
unless $projhash->{"testsuites"} 0 0 0
755 0 for my $tshash (@{$projhash->{'testsuites'}}) {
756 #Otherwise, push it's children to the end of our array so we can recurse as needed.
757 #I hope the designers of TL's schema were smart enough to not allow self-referential or circular suites..
758 0 push(@flattener,clone $tshash);
759 }
760  
761 }
762  
763 #Keep this for simple searches in the future.
764 0 $self->{'flattree'} = clone \@flattener;
765 0 ▶ return $self->{'flattree'} if $flat;
Branch: 1 branch
BranchTrueFalseTotal
if $flat 0 0 0
766 0 return $self->_expandTree($project,@flattener);
767 }
768  
769 1 ▶sub _expandTree {
Subroutine _expandTree: called CC=13 SCAR=50.8
770 1 my $self = shift;
771 1 ▶ confess("Object parameters must be called by an instance") unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
772 0 my $project = shift;
773 0 my @flattener = @_;
774 #The following algorithm relies implicitly on pass-by-reference.
775 #So we have a flat array of testsuites we want to map into parent-child relationships.
776 0 my ($i,$j);
777 0 foreach my $suite (@flattener) {
778 0 ▶ if (defined($suite->{'type'}) && $suite->{'type'} eq 'project') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $suite->{"type"} and $suite->{"type"} eq "project") 0 0 0
Condition0%0/3
defined $suite->{"type"} and $suite->{"type"} eq "project"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $suite->{"type"} and $suite->{"type"} eq "project"
defined $suite->{"type"} $suite->{"type"} eq "project"
Truth table0%0/3
A and B
A= defined $suite->{"type"}B= $suite->{"type"} eq "project"
ABresult
0X0
100
111
779 #Then skip it, since it's not a suite.
780 0 shift @flattener;
781 0 next;
782 }
783  
784 #This means we need to walk the hierarchy of every project, or just the one we passed
785 0 ▶ for ($j=0; $j < scalar(@{$self->{'testtree'}}); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$self->{"testtree"};}) 0 0 0
786 #If we have a project, skip the other ones
787 0 ▶ next unless $project && $self->{'testtree'}->[$j]->{'name'} eq $project;
Branch: 1 branch
BranchTrueFalseTotal
unless $project and $self->{"testtree"}[$j]{"name"} eq $project 0 0 0
Condition0%0/3
$project and $self->{"testtree"}[$j]{"name"} eq $project
!ll&&!rl&&r
000
MC/DC0%0/2
$project and $self->{"testtree"}[$j]{"name"} eq $project
$project $self->{"testtree"}[$j]{"name"} eq $project
Truth table0%0/3
A and B
A= $projectB= $self->{"testtree"}[$j]{"name"} eq $project
ABresult
0X0
100
111
788  
789 #Get the ball rolling if we have to
790 0 ▶ $self->{'testtree'}->[$j]->{'testsuites'} = $self->getTLDTestSuitesForProject($self->{'testtree'}->[$j]->{'id'},1) if !defined($self->{'testtree'}->[$j]->{'testsuites'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"testtree"}[$j]{"testsuites"} 0 0 0
791  
792 #So, let's tail recurse over the testsuites.
793 0 ▶ for ($i=0; $i < scalar(@{$self->{'testtree'}->[$j]->{'testsuites'}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"testtree"}[$j]{"testsuites"};}) 0 0 0
794 0 ▶ my $tailRecurseTSWalker = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
795 0 my ($ts,$desired_ts) = @_;
796  
797 #Mark it down if we found it
798 0 ▶ if ($ts->{'id'} eq $desired_ts->{'parent_id'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ts->{"id"} eq $desired_ts->{"parent_id"}) 0 0 0
799  
800 #Set the REF's 'testsuites' param, and quit searching
801 0 ▶ $ts->{'testsuites'} = [] if !defined($ts->{'testsuites'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ts->{"testsuites"} 0 0 0
802 0 push(@{$ts->{'testsuites'}},$desired_ts);
803 0 $desired_ts->{'found'} = 1;
804 0 return;
805 }
806  
807 #If there's already (nonblank) hierarchy in the passed TS, then WE HAVE TO GO DEEPER
808 0 ▶ if (defined($ts->{'testsuites'}) && scalar(@{$desired_ts->{'testsuites'}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ts->{"testsuites"} and scalar @{$desired_ts->{"testsuites"};}) 0 0 0
Condition0%0/2
defined $ts->{"testsuites"} and scalar @{$desired_ts->{"testsuites"};}
!ll
00
MC/DC0%0/1
defined $ts->{"testsuites"} and scalar @{$desired_ts->{"testsuites"};}
defined $ts->{"testsuites"}
Truth table0%0/2
A
A= defined $ts->{"testsuites"}
Aresult
00
11
809 0 ▶ for (my $i=0; $i < scalar(@{$ts->{'testsuites'}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$ts->{"testsuites"};}) 0 0 0
810 0 _tailRecurseTSWalker($ts->{'testsuites'}->[$i],$desired_ts);
811 }
812 }
813  
814 0 return;
815 0 };
816  
817 0 &$tailRecurseTSWalker($self->{'testtree'}->[$j]->{'testsuites'}->[$i],$suite);
818 #OPTIMIZE: break out if we found it already
819 0 ▶ last if $suite->{'found'};
Branch: 1 branch
BranchTrueFalseTotal
if $suite->{"found"} 0 0 0
820 }
821 0 ▶ last if $suite->{'found'};
Branch: 1 branch
BranchTrueFalseTotal
if $suite->{"found"} 0 0 0
822 }
823  
824 #If we didn't find this one yet, as the hierarchy build is progressive, add it to the end until it gets picked up.
825 0 ▶ if (!$suite->{'found'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $suite->{'found'}) { } 0 0 0
826 0 push(@flattener,shift @flattener); # If it wasn't found, push it on to the end of the array so the walk might find it next time.
827 } else {
828 0 shift @flattener;
829 }
830 }
831 0 return $self->{'testtree'};
832 }
833  
834 2 1;
835  
836 __END__
↑ Summary