-
Notifications
You must be signed in to change notification settings - Fork 565
/
testplan.class.php
8886 lines (7351 loc) · 299 KB
/
testplan.class.php
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* TestLink Open Source Project - http://testlink.sourceforge.net/
* This script is distributed under the GNU General Public License 2 or later.
*
* Manages test plan operations and related items like Custom fields,
* Builds, Custom fields, etc
*
* @filesource testplan.class.php
* @package TestLink
* @author franciscom
* @copyright 2007-2019, TestLink community
* @link http://testlink.sourceforge.net/
*
**/
/** related functionality */
require_once( dirname(__FILE__) . '/tree.class.php' );
require_once( dirname(__FILE__) . '/assignment_mgr.class.php' );
require_once( dirname(__FILE__) . '/attachments.inc.php' );
/**
* class to coordinate and manage Test Plans
* @package TestLink
*/
class testplan extends tlObjectWithAttachments
{
/** query options */
const GET_ALL=null;
const GET_ACTIVE_BUILD=1;
const GET_INACTIVE_BUILD=0;
const GET_OPEN_BUILD=1;
const GET_CLOSED_BUILD=0;
const ACTIVE_BUILDS=1;
const OPEN_BUILDS=1;
const ENABLED=1;
const IGNORE=-1;
/** @var database handler */
var $db;
var $tree_manager;
var $assignment_mgr;
var $cfield_mgr;
var $tcase_mgr;
var $tproject_mgr;
var $assignment_types;
var $assignment_status;
/** message to show on GUI */
var $user_feedback_message = '';
var $node_types_descr_id;
var $node_types_id_descr;
var $import_file_types = array("XML" => "XML"); // array("XML" => "XML", "XLS" => "XLS" );
var $resultsCfg;
var $tcaseCfg;
var $notRunStatusCode;
var $execTaskCode;
// Nodes to exclude when do test plan tree traversal
var $nt2exclude=array('testplan' => 'exclude_me',
'requirement_spec'=> 'exclude_me',
'requirement'=> 'exclude_me');
var $nt2exclude_children=array('testcase' => 'exclude_my_children',
'requirement_spec'=> 'exclude_my_children');
/**
* testplan class constructor
*
* @param resource &$db reference to database handler
*/
function __construct(&$db)
{
$this->db = &$db;
$this->tree_manager = new tree($this->db);
$this->node_types_descr_id = $this->tree_manager->get_available_node_types();
$this->node_types_id_descr = array_flip($this->node_types_descr_id);
$this->assignment_mgr = new assignment_mgr($this->db);
$this->assignment_types = $this->assignment_mgr->get_available_types();
$this->assignment_status = $this->assignment_mgr->get_available_status();
$this->cfield_mgr = new cfield_mgr($this->db);
$this->tcase_mgr = New testcase($this->db);
$this->platform_mgr = new tlPlatform($this->db);
$this->tproject_mgr = new testproject($this->db);
$this->resultsCfg = config_get('results');
$this->tcaseCfg = config_get('testcase_cfg');
// special values used too many times
$this->notRunStatusCode = $this->resultsCfg['status_code']['not_run'];
$this->execTaskCode = intval($this->assignment_types['testcase_execution']['id']);
tlObjectWithAttachments::__construct($this->db,'testplans');
}
/**
* getter for import types
* @return array key: import file type code, value: import file type verbose description
*/
function get_import_file_types()
{
return $this->import_file_types;
}
/**
* creates a tesplan on Database, for a testproject.
*
* @param string $name: testplan name
* @param string $notes: testplan notes
* @param string $testproject_id: testplan parent
*
* @return integer status code
* if everything ok -> id of new testplan (node id).
* if problems -> 0.
*/
function create($name,$notes,$testproject_id,$is_active=1,$is_public=1)
{
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$node_types=$this->tree_manager->get_available_node_types();
$tplan_id = $this->tree_manager->new_node($testproject_id,$node_types['testplan'],$name);
$active_status=intval($is_active) > 0 ? 1 : 0;
$public_status=intval($is_public) > 0 ? 1 : 0;
$api_key = md5(rand()) . md5(rand());
$sql = "/* $debugMsg */ " .
" INSERT INTO {$this->tables['testplans']} (id,notes,api_key,testproject_id,active,is_public) " .
" VALUES ( {$tplan_id} " . ", '" . $this->db->prepare_string($notes) . "'," .
"'" . $this->db->prepare_string($api_key) . "'," .
$testproject_id . "," . $active_status . "," . $public_status . ")";
$result = $this->db->exec_query($sql);
$id = 0;
if ($result)
{
$id = $tplan_id;
}
return $id;
}
/**
*
*/
function createFromObject($item,$opt=null) {
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$my['opt'] = array('doChecks' => false, 'setSessionProject' => true);
$my['opt'] = array_merge($my['opt'],(array)$opt);
try {
// mandatory checks
if(strlen($item->name)==0) {
throw new Exception('Empty name is not allowed');
}
// what checks need to be done ?
// 1. test project exist
$pinfo = null;
if( is_numeric($item->testProjectID) ) {
$pinfo = $this->tproject_mgr->get_by_id(intval($item->testProjectID));
}
if( null == $pinfo || count($pinfo) == 0 ) {
$pinfo = $this->tproject_mgr->get_by_prefix($item->testProjectID);
}
if( is_null($pinfo) || count($pinfo) == 0 ) {
throw new Exception('Test project ID does not exist');
}
$tproject_id = intval($pinfo['id']);
// 2. there is NO other test plan on test project with same name
$name = trim($item->name);
$op = $this->checkNameExistence($name,$tproject_id);
if(!$op['status_ok']) {
throw new Exception('Test plan name is already in use on Test project');
}
} catch (Exception $e) {
throw $e; // rethrow
}
// seems OK => go
$active_status = intval($item->active) > 0 ? 1 : 0;
$public_status = intval($item->is_public) > 0 ? 1 : 0;
$api_key = md5(rand()) . md5(rand());
$id = $this->tree_manager->new_node($tproject_id,$this->node_types_descr_id['testplan'],$name);
$sql = "/* $debugMsg */ " .
" INSERT INTO {$this->tables['testplans']} (id,notes,api_key,testproject_id,active,is_public) " .
" VALUES ( {$id} " . ", '" . $this->db->prepare_string($item->notes) . "'," .
"'" . $this->db->prepare_string($api_key) . "'," .
$tproject_id . "," .
$active_status . "," . $public_status . ")";
$result = $this->db->exec_query($sql);
return $result ? $id : 0;
}
/**
*
*/
function updateFromObject($item,$opt=null) {
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$my['opt'] = array('doChecks' => false, 'setSessionProject' => true);
$my['opt'] = array_merge($my['opt'],(array)$opt);
if( !property_exists($item, 'id') ) {
throw new Exception('Test plan ID is missing');
}
if( ($safeID = intval($item->id)) == 0 ) {
throw new Exception('Test plan ID 0 is not allowed');
}
$pinfo = $this->get_by_id($safeID, array( 'output' => 'minimun'));
if(is_null($pinfo)) {
throw new Exception('Test plan ID does not exist');
}
$attr = array();
$upd = '';
try {
if( property_exists($item, 'name') ) {
$name = trim($item->name);
if(strlen($name)==0) {
throw new Exception('Empty name is not allowed');
}
// 1. NO other test plan on test project with same name
$op = $this->checkNameExistence($name,$pinfo['testproject_id'],$safeID);
if(!$op['status_ok']) {
throw new Exception('Test plan name is already in use on Test project');
}
$sql = "/* $debugMsg */ " .
" UPDATE {$this->tables['nodes_hierarchy']} " .
" SET name='" . $this->db->prepare_string($name) . "'" .
" WHERE id={$safeID}";
$result = $this->db->exec_query($sql);
}
if( property_exists($item, 'notes') ) {
$upd = ($upd != '' ? ',' : '') . " notes = '" . $this->db->prepare_string($item->notes) . "' ";
}
$intAttr = array('active','is_public');
foreach($intAttr as $key) {
if( property_exists($item, $key) ) {
$upd = ($upd != '' ? ',' : '') . $key . ' = ' . (intval($item->$key) > 0 ? 1 : 0);
}
}
if($upd != '') {
$sql = " UPDATE {$this->tables['testplans']} " .
" SET {$upd} WHERE id=" . $safeID;
$result = $this->db->exec_query($sql);
}
} catch (Exception $e) {
throw $e; // rethrow
}
return $safeID;
}
/**
* Checks is there is another test plan inside test project
* with different id but same name
*
**/
function checkNameExistence($name,$tprojectID,$id=0) {
$check_op['msg'] = '';
$check_op['status_ok'] = 1;
if($this->get_by_name($name,intval($tprojectID), array('id' => intval($id))) ) {
$check_op['msg'] = sprintf(lang_get('error_product_name_duplicate'),$name);
$check_op['status_ok'] = 0;
}
return $check_op;
}
/**
* update testplan information
*
* @param integer $id Test plan identifier
* @param string $name: testplan name
* @param string $notes: testplan notes
* @param boolean $is_active
*
* @return integer result code (1=ok)
*/
function update($id,$name,$notes,$is_active=null,$is_public=null) {
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$do_update = 1;
$result = null;
// $active = to_boolean($is_active);
$name = trim($name);
// two tables to update and we have no transaction yet.
$rsa = $this->get_by_id($id);
$duplicate_check = (strcmp($rsa['name'],$name) != 0 );
if($duplicate_check)
{
$rs = $this->get_by_name($name,$rsa['parent_id']);
$do_update = is_null($rs);
}
if($do_update)
{
// Update name
$sql = "/* $debugMsg */ ";
$sql .= "UPDATE {$this->tables['nodes_hierarchy']} " .
"SET name='" . $this->db->prepare_string($name) . "'" .
"WHERE id={$id}";
$result = $this->db->exec_query($sql);
if($result)
{
$add_upd='';
if( !is_null($is_active) )
{
$add_upd .=',active=' . (intval($is_active) > 0 ? 1 : 0);
}
if( !is_null($is_public) )
{
$add_upd .=',is_public=' . (intval($is_public) > 0 ? 1:0);
}
$sql = " UPDATE {$this->tables['testplans']} " .
" SET notes='" . $this->db->prepare_string($notes). "' " .
" {$add_upd} WHERE id=" . $id;
$result = $this->db->exec_query($sql);
}
}
return ($result ? 1 : 0);
}
/*
function: get_by_name
get information about a testplan using name as access key.
Search can be narrowed, givin a testproject id as filter criteria.
args: name: testplan name
[tproject_id]: default:0 -> system wide search i.e. inside all testprojects
returns: if nothing found -> null
if found -> array where every element is a map with following keys:
id: testplan id
notes:
active: active status
is_open: open status
name: testplan name
testproject_id
*/
function get_by_name($name,$tproject_id=0,$opt=null)
{
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$my = array();
$my['opt'] = array('output' => 'full', 'id' => 0);
$my['opt'] = array_merge($my['opt'],(array)$opt);
$sql = "/* $debugMsg */ ";
switch($my['opt']['output'])
{
case 'minimun':
$sql .= " SELECT testplans.id, NH.name ";
break;
case 'full':
default:
$sql .= " SELECT testplans.*, NH.name ";
break;
}
$sql .= " FROM {$this->tables['testplans']} testplans, " .
" {$this->tables['nodes_hierarchy']} NH" .
" WHERE testplans.id = NH.id " .
" AND NH.name = '" . $this->db->prepare_string($name) . "'";
if( ($safe_id = intval($tproject_id)) > 0 )
{
$sql .= " AND NH.parent_id={$safe_id} ";
}
// useful when trying to check for duplicates ?
if( ($my['opt']['id'] = intval($my['opt']['id'])) > 0)
{
$sql .= " AND testplans.id != {$my['opt']['id']} ";
}
$rs = $this->db->get_recordset($sql);
return($rs);
}
/*
function: get_by_id
args : id: testplan id
returns: map with following keys:
id: testplan id
name: testplan name
notes: testplan notes
testproject_id
active
is_open
parent_id
*/
function get_by_id($id, $opt=null) {
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$my = array();
$my['opt'] = array('output' => 'full','active' => null, 'testPlanFields' => '');
$my['opt'] = array_merge($my['opt'],(array)$opt);
$safe_id = intval($id);
switch($my['opt']['output']) {
case 'testPlanFields':
$sql = "/* $debugMsg */ " .
" SELECT {$my['opt']['testPlanFields']} FROM {$this->tables['testplans']} " .
" WHERE id = " . $safe_id;
break;
case 'minimun':
$sql = "/* $debugMsg */ " .
" SELECT NH_TPLAN.name," .
" NH_TPROJ.id AS tproject_id, NH_TPROJ.name AS tproject_name,TPROJ.prefix" .
" FROM {$this->tables['nodes_hierarchy']} NH_TPLAN " .
" JOIN {$this->tables['nodes_hierarchy']} NH_TPROJ ON NH_TPROJ.id = NH_TPLAN.parent_id " .
" JOIN {$this->tables['testprojects']} TPROJ ON TPROJ.ID = NH_TPROJ.id " .
" WHERE NH_TPLAN.id = " . $safe_id;
break;
case 'full':
default:
$sql = "/* $debugMsg */ " .
" SELECT TPLAN.*,NH_TPLAN.name,NH_TPLAN.parent_id,
NH_TPROJ.id AS tproject_id,
NH_TPROJ.name AS tproject_name,TPROJ.prefix
FROM {$this->tables['testplans']} TPLAN,
{$this->tables['nodes_hierarchy']} NH_TPLAN
JOIN {$this->tables['nodes_hierarchy']} NH_TPROJ
ON NH_TPROJ.id = NH_TPLAN.parent_id
JOIN {$this->tables['testprojects']} TPROJ
ON TPROJ.ID = NH_TPROJ.id
WHERE TPLAN.id = NH_TPLAN.id AND
TPLAN.id = " . $safe_id;
break;
}
if(!is_null($my['opt']['active'])) {
$sql .= " AND active=" . (intval($my['opt']['active']) > 0 ? 1 : 0) . " ";
}
$rs = $this->db->get_recordset($sql);
return ($rs ? $rs[0] : null);
}
/*
function: get_all
get array of info for every test plan,
without considering Test Project and any other kind of filter.
Every array element contains an assoc array
args : -
returns: array, every element is a map with following keys:
id: testplan id
name: testplan name
notes: testplan notes
testproject_id
active
is_open
parent_id
*/
function get_all()
{
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$sql = "/* $debugMsg */ " . " SELECT testplans.*, NH.name " .
" FROM {$this->tables['testplans']} testplans, " .
" {$this->tables['nodes_hierarchy']} NH " .
" WHERE testplans.id=NH.id";
$recordset = $this->db->get_recordset($sql);
return $recordset;
}
/*
function: count_testcases
get number of testcases linked to a testplan
args: id: testplan id, can be array of id,
[platform_id]: null => do not filter by platform
can be array of platform id
returns: number
*/
public function count_testcases($id,$platform_id=null,$opt=null)
{
// output:
// 'number', just the count
// 'groupByTestPlan' => map: key test plan id
// element: count
//
// 'groupByTestPlanPlatform' => map: first level key test plan id
// second level key platform id
//
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
// protect yourself :) - 20140607
if( is_null($id) || (is_int($id) && intval($id) <= 0 ) || (is_array($id) && count($id) == 0) )
{
return 0; // >>>----> Bye
}
$my['opt'] = array('output' => 'number');
$my['opt'] = array_merge($my['opt'],(array)$opt);
$sql_filter = '';
if( !is_null($platform_id) )
{
$sql_filter = ' AND platform_id IN (' . implode(',',(array)$platform_id) . ')';
}
$out = null;
$outfields = "/* $debugMsg */ " . ' SELECT COUNT(testplan_id) AS qty ';
$dummy = " FROM {$this->tables['testplan_tcversions']} " .
" WHERE testplan_id IN (" . implode(',',(array)$id) . ") {$sql_filter}";
switch( $my['opt']['output'] )
{
case 'groupByTestPlan':
$sql = $outfields . ', testplan_id' . $dummy . ' GROUP BY testplan_id ';
$out = $this->db->fetchRowsIntoMap($sql,'testplan_id');
break;
case 'groupByTestPlanPlatform':
$groupBy = ' GROUP BY testplan_id, platform_id ';
$sql = $outfields . ', testplan_id, platform_id' . $dummy .
' GROUP BY testplan_id,platform_id ';
$out = $this->db->fetchMapsRowsIntoMap($sql,'testplan_id','platform_id');
break;
case 'number':
default:
$sql = $outfields . $dummy;
$rs = $this->db->get_recordset($sql);
$out = 0;
if(!is_null($rs))
{
$out = $rs[0]['qty'];
}
break;
}
return $out;
}
/*
function: tcversionInfoForAudit
get info regarding tcversions, to generate useful audit messages
args :
$tplan_id: test plan id
$items_to_link: map key=tc_id
value: tcversion_id
returns: -
rev: 20080629 - franciscom - audit message improvements
*/
function tcversionInfoForAudit($tplan_id,&$items)
{
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
// Get human readeable info for audit
$ret=array();
// $tcase_cfg = config_get('testcase_cfg');
$dummy=reset($items);
list($ret['tcasePrefix'],$tproject_id) = $this->tcase_mgr->getPrefix($dummy);
$ret['tcasePrefix'] .= $this->tcaseCfg->glue_character;
$sql = "/* $debugMsg */ " .
" SELECT TCV.id, tc_external_id, version, NHB.name " .
" FROM {$this->tables['tcversions']} TCV,{$this->tables['nodes_hierarchy']} NHA, " .
" {$this->tables['nodes_hierarchy']} NHB " .
" WHERE NHA.id=TCV.id " .
" AND NHB.id=NHA.parent_id " .
" AND TCV.id IN (" . implode(',',$items) . ")";
$ret['info']=$this->db->fetchRowsIntoMap($sql,'id');
$ret['tplanInfo']=$this->get_by_id($tplan_id);
return $ret;
}
/**
* associates version of different test cases to a test plan.
* this is the way to populate a test plan
args :
$id: test plan id
$items_to_link: map key=tc_id
value= map with
key: platform_id (can be 0)
value: tcversion_id
passed by reference for speed
returns: -
rev: 20080629 - franciscom - audit message improvements
*/
function link_tcversions($id,&$items_to_link,$userId)
{
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
// Get human readeable info for audit
$title_separator = config_get('gui_title_separator_1');
$auditInfo=$this->tcversionInfoForAudit($id,$items_to_link['tcversion']);
$platformInfo = $this->platform_mgr->getLinkedToTestplanAsMap($id);
$platformLabel = lang_get('platform');
// Important: MySQL do not support default values on datetime columns that are functions
// that's why we are using db_now().
$sql = "/* $debugMsg */ " .
"INSERT INTO {$this->tables['testplan_tcversions']} " .
"(testplan_id,author_id,creation_ts,tcversion_id,platform_id) " .
" VALUES ({$id},{$userId},{$this->db->db_now()},";
$features=null;
foreach($items_to_link['items'] as $tcase_id => $items)
{
foreach($items as $platform_id => $tcversion)
{
$addInfo='';
$result = $this->db->exec_query($sql . "{$tcversion}, {$platform_id})");
if ($result)
{
$features[$platform_id][$tcversion]=$this->db->insert_id($this->tables['testplan_tcversions']);
if( isset($platformInfo[$platform_id]) )
{
$addInfo = ' - ' . $platformLabel . ':' . $platformInfo[$platform_id];
}
$auditMsg=TLS("audit_tc_added_to_testplan",
$auditInfo['tcasePrefix'] . $auditInfo['info'][$tcversion]['tc_external_id'] .
$title_separator . $auditInfo['info'][$tcversion]['name'],
$auditInfo['info'][$tcversion]['version'],
$auditInfo['tplanInfo']['name'] . $addInfo );
logAuditEvent($auditMsg,"ASSIGN",$id,"testplans");
}
}
}
return $features;
}
/*
function: setExecutionOrder
args :
$id: test plan id
$executionOrder: assoc array key=tcversion_id value=order
passed by reference for speed
returns: -
*/
function setExecutionOrder($id,&$executionOrder)
{
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
foreach($executionOrder as $tcVersionID => $execOrder)
{
$execOrder=intval($execOrder);
$sql="/* $debugMsg */ UPDATE {$this->tables['testplan_tcversions']} " .
"SET node_order={$execOrder} " .
"WHERE testplan_id={$id} " .
"AND tcversion_id={$tcVersionID}";
$result = $this->db->exec_query($sql);
}
}
/**
* Ignores Platforms, then if a test case version is linked to a test plan
* and two platforms, we will get item once.
* Need to understand if in context where we want to use this method this is
* a problem
*
*
* @internal revisions:
*/
function get_linked_items_id($id) {
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$sql = " /* $debugMsg */ ".
" SELECT DISTINCT parent_id FROM {$this->tables['nodes_hierarchy']} NHTC " .
" JOIN {$this->tables['testplan_tcversions']} TPTCV ON TPTCV.tcversion_id = NHTC.id " .
" WHERE TPTCV.testplan_id = " . intval($id);
$linked_items = $this->db->fetchRowsIntoMap($sql,'parent_id');
return $linked_items;
}
/**
* @internal revisions
*
*/
function get_linked_tcvid($id,$platformID,$opt=null){
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$options = array('addEstimatedExecDuration' => false,
'tcase_id' => 0);
$options = array_merge($options,(array)$opt);
$addFields = '';
$addSql = '';
$addWhere = '';
if($options['addEstimatedExecDuration'])
{
$addFields = ',TCV.estimated_exec_duration ';
$addSql .= " JOIN {$this->tables['tcversions']} TCV ON TCV.id = tcversion_id ";
}
if($options['tcase_id'] > 0)
{
$addFields = ', NHTCV.parent_id AS tcase_id ';
$addSql .= " JOIN {$this->tables['nodes_hierarchy']} NHTCV " .
" ON NHTCV.id = tcversion_id ";
$addWhere = ' AND NHTCV.parent_id = ' .
intval($options['tcase_id']);
}
$sql = " /* $debugMsg */ " .
" SELECT tcversion_id {$addFields} " .
" FROM {$this->tables['testplan_tcversions']} " .
$addSql;
$sql .= " WHERE testplan_id = " . intval($id) .
" AND platform_id = " . intval($platformID) .
$addWhere;
$items = $this->db->fetchRowsIntoMap($sql,'tcversion_id');
return $items;
}
/**
*
*
*/
function getLinkedCount($id)
{
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$sql = " /* $debugMsg */ ".
" SELECT COUNT( DISTINCT(TPTCV.tcversion_id) ) AS qty " .
" FROM {$this->tables['testplan_tcversions']} TPTCV " .
" WHERE TPTCV.testplan_id = " . intval($id);
$rs = $this->db->get_recordset($sql);
return $rs[0]['qty'];
}
/**
* @internal revisions:
*
*/
function getFeatureID($id,$platformID,$tcversionID)
{
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$sql = " /* $debugMsg */ ".
" SELECT id FROM {$this->tables['testplan_tcversions']} " .
" WHERE testplan_id = " . intval($id) .
" AND tcversion_id = " . intval($tcversionID) .
" AND platform_id = " . intval($platformID) ;
$linked_items = $this->db->fetchRowsIntoMap($sql,'id');
return !is_null($linked_items) ? key($linked_items) : -1;
}
/**
* @internal revisions:
*
*/
function getRootTestSuites($id,$tproject_id,$opt=null)
{
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$my = array('opt' => array('output' => 'std'));
$my['opt'] = array_merge($my['opt'],(array)$opt);
$sql = " /* $debugMsg */ ".
" SELECT DISTINCT NHTCASE.parent_id AS tsuite_id" .
" FROM {$this->tables['nodes_hierarchy']} NHTCV " .
" JOIN {$this->tables['testplan_tcversions']} TPTCV " .
" ON TPTCV.tcversion_id = NHTCV.id " .
" JOIN {$this->tables['nodes_hierarchy']} NHTCASE " .
" ON NHTCASE.id = NHTCV.parent_id " .
" WHERE TPTCV.testplan_id = {$id} ";
$items = $this->db->fetchRowsIntoMap($sql,'tsuite_id',database::CUMULATIVE);
$xsql = " SELECT COALESCE(parent_id,0) AS parent_id,id,name" .
" FROM {$this->tables['nodes_hierarchy']} " .
" WHERE id IN (" . implode(',',array_keys($items)) . ") AND parent_id IS NOT NULL";
unset($items);
$xmen = $this->db->fetchMapRowsIntoMap($xsql,'parent_id','id');
$tlnodes = array();
foreach($xmen as $parent_id => &$children)
{
if($parent_id == $tproject_id)
{
foreach($children as $item_id => &$elem)
{
$tlnodes[$item_id] = '';
}
}
else
{
$paty = $this->tree_manager->get_path($parent_id);
if( !isset($tlnodes[$paty[0]['id']]) )
{
$tlnodes[$paty[0]['id']] = '';
}
unset($paty);
}
}
unset($xmen);
// Now with node list get order
$xsql = " SELECT id,name,node_order " .
" FROM {$this->tables['nodes_hierarchy']} " .
" WHERE id IN (" . implode(',',array_keys($tlnodes)) . ")" .
" ORDER BY node_order,name ";
$xmen = $this->db->fetchRowsIntoMap($xsql,'id');
switch($my['opt']['output'])
{
case 'std':
foreach($xmen as $xid => $elem)
{
$xmen[$xid] = $elem['name'];
}
break;
}
unset($tlnodes);
return $xmen;
}
/**
*
*
*/
function helper_keywords_sql($filter,$options=null) {
$sql = array('filter' => '', 'join' => '');
if( is_array($filter) ) {
// 0 -> no keyword, remove
if( $filter[0] == 0 ) {
array_shift($filter);
}
if(count($filter)) {
$sql['filter'] = " AND TK.keyword_id IN (" . implode(',',$filter) . ")";
}
}
else if($filter > 0) {
$sql['filter'] = " AND TK.keyword_id = {$filter} ";
}
if( $sql['filter'] != '' ) {
$sql['join'] = " JOIN {$this->tables['testcase_keywords']} TK
ON TK.tcversion_id = NH_TCV.id ";
}
// mmm, here there is missing documentation
$ret = is_null($options) ? $sql : array($sql['join'],$sql['filter']);
return $ret;
}
/**
*
*
*/
function helper_urgency_sql($filter)
{
$cfg = config_get("urgencyImportance");
$sql = '';
if ($filter == HIGH)
{
$sql .= " AND (urgency * importance) >= " . $cfg->threshold['high'];
}
else if($filter == LOW)
{
$sql .= " AND (urgency * importance) < " . $cfg->threshold['low'];
}
else
{
$sql .= " AND ( ((urgency * importance) >= " . $cfg->threshold['low'] .
" AND ((urgency * importance) < " . $cfg->threshold['high']."))) ";
}
return $sql;
}
/**
*
*
*/
function helper_assigned_to_sql($filter,$opt,$build_id)
{
$join = " JOIN {$this->tables['user_assignments']} UA " .
" ON UA.feature_id = TPTCV.id " .
" AND UA.build_id = " . $build_id .
" AND UA.type = {$this->execTaskCode} ";
// Warning!!!:
// If special user id TL_USER_NOBODY is present in set of user id
// we will ignore any other user id present on set.
$ff = (array)$filter;
$sql = " UA.user_id ";
if( in_array(TL_USER_NOBODY,$ff) )
{
$sql .= " IS NULL ";
$join = ' LEFT OUTER ' . $join;
}
else if( in_array(TL_USER_SOMEBODY,$ff) )
{
$sql .= " IS NOT NULL ";
}
else
{
$sql_unassigned="";
$sql = '';
if( $opt['include_unassigned'] )
{
$join = ' LEFT OUTER ' . $join; // 20130729
$sql = "(";
$sql_unassigned=" OR UA.user_id IS NULL)";
}
$sql .= " UA.user_id IN (" . implode(",",$ff) . ") " . $sql_unassigned;
}
return array($join, ' AND ' . $sql);
}
/**
*
*
*/
function helper_exec_status_filter($filter,$lastExecSql)
{
$notRunFilter = null;
$execFilter = '';