-
Notifications
You must be signed in to change notification settings - Fork 625
Expand file tree
/
Copy pathexecSetResults.php
More file actions
2523 lines (2054 loc) · 83.3 KB
/
Copy pathexecSetResults.php
File metadata and controls
2523 lines (2054 loc) · 83.3 KB
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/
*
* @filesource execSetResults.php
*
* IMPORTANT DEVELOPMENT NOTICE - about $args->testcases_to_show
*
* Normally this script is called from the tree.
* Filters and other conditions (example display test cases just assigned to me,etc)
* can be applied, creating a set of test cases that can be used.
* Due to size restrictions on POST variables this info is transfered via $_SESSION.
*
* But because we have choosen to add access to this script from other features
* we have forgot to populate this info.
* This is the reason for several issues.
* The approach will be to understand who is the caller and apply different logics
* instead of recreate the logic to populate $_SESSION
* (I think this approach will be simpler).
*
*
* Note about step info
* is present in gui->map_last_exec
*
*
**/
require_once('../../config.inc.php');
require_once('common.php');
require_once('exec.inc.php');
require_once("attachments.inc.php");
require_once("specview.php");
require_once("web_editor.php");
require_once('event_api.php');
$cfg = getCfg();
require_once(require_web_editor($cfg->editorCfg['type']));
if( $cfg->exec_cfg->enable_test_automation ) {
require_once('remote_exec.php');
}
// CRITIC:
// If call to testlinkInitPage() is done AFTER require_once for BTS
// log to event viewer fails, but log to file works ok
testlinkInitPage($db);
$templateCfg = templateConfiguration();
$tcversion_id = null;
$submitResult = null;
list($args,$its,$cts) = init_args($db,$cfg);
// ------------------------------------------------------------------------------
// the default -1 create an out of range error on TC execution without platform
if ($args->platform_id == -1){
$args->platform_id = 0;
}
// ------------------------------------------------------------------------------
$smarty = new TLSmarty();
$smarty->assign('tsuite_info',null);
$tree_mgr = new tree($db);
$tplan_mgr = new testplan($db);
$tcase_mgr = new testcase($db);
$exec_cfield_mgr = new exec_cfield_mgr($db,$args->tproject_id);
$fileRepo = tlAttachmentRepository::create($db);
$req_mgr = new requirement_mgr($db);
$gui = initializeGui($db,$args,$cfg,$tplan_mgr,$tcase_mgr,$its,$cts);
$_SESSION['history_on'] = $gui->history_on;
$attachmentInfos = null;
$do_show_instructions = ($args->level == "" || $args->level == 'testproject') ? 1 : 0;
if ($do_show_instructions) {
show_instructions('executeTest');
exit();
}
// Testplan executions and result archiving.
// Checks whether execute cases button was clicked
if($args->doExec == 1 && !is_null($args->tc_versions) && count($args->tc_versions)) {
$gui->remoteExecFeedback = launchRemoteExec($db,$args,$gui->tcasePrefix,$tplan_mgr,$tcase_mgr);
}
// link Update will be done on Context
// Context = testplan
//
// @20210901 -> CRITIC
// because we do not allow different versions on different platforms
// for same test plan -> platform MUST NOT BE USED
if( $args->linkLatestVersion && $args->level == 'testcase') {
$args->version_id = $tcase_mgr->updateTPlanLinkToLatestTCV($args->TCVToUpdate, $args->tplan_id);
}
// LOAD What To Display
list($linked_tcversions,$itemSet) =
getLinkedItems($args,$gui->history_on,$cfg,$tcase_mgr,$tplan_mgr);
$tcase_id = 0;
$userid_array = null;
if(!is_null($linked_tcversions)) {
$items_to_exec = array();
$_SESSION['s_lastAttachmentInfos'] = null;
if($args->level == 'testcase') {
// passed by reference to be updated inside function
// $gui, $args
$tcase = null;
list($tcase_id,$tcversion_id,$latestExecIDInContext,$hasCFOnExec) =
processTestCase($tcase,$gui,$args,$cfg,$linked_tcversions,
$tree_mgr,$tcase_mgr,$fileRepo);
} else {
processTestSuite($db,$gui,$args,$itemSet,$tree_mgr,$tcase_mgr,$fileRepo);
$tcase_id = $itemSet->tcase_id;
$tcversion_id = $itemSet->tcversion_id;
}
// Send Event for Drawing UI from plugins
$ctx = array('tplan_id' => $args->tplan_id,
'build_id' => $args->build_id,
'tcase_id' => $tcase_id,
'tcversion_id' => $tcversion_id);
$gui->plugins = array();
$gui->plugins['EVENT_TESTRUN_DISPLAY'] =
event_signal('EVENT_TESTRUN_DISPLAY', $ctx);
// check if value is an array before calling implode to avoid warnings in event log
$gui->tcversionSet = is_array($tcversion_id) ? implode(',',$tcversion_id) : $tcversion_id;
// will create a record even if the testcase version has not been executed (GET_NO_EXEC)
//
// Can be DONE JUST ONCE AFTER write results to DB
// --------------------------------------------------------------------------
// Results to DB
//
// 20130917 - this implementation regarding save_results is confusing.
// why ?
// because in some situations args->save_results is a number (0) an in other is an array
// with just one element with key => test case version ID executed.
//
if ($args->doSave || $args->doNavigate || $args->saveStepsPartialExec) {
// this has to be done to do not break logic present on write_execution()
$args->save_results = $args->save_and_next ? $args->save_and_next :
($args->save_results ? $args->save_results : $args->save_and_exit);
if( $args->save_results || $args->do_bulk_save) {
// Need to get Latest execution ID before writing
$lexidSysWide = 0;
if($args->copyIssues && $args->level == 'testcase') {
$lexidSysWide = $tcase_mgr->getSystemWideLastestExecutionID($args->version_id);
}
$_REQUEST['save_results'] = $args->save_results;
// Steps Partial Execution Feature
if (isset($_REQUEST['step_notes'])) {
$ctx = new stdClass();
$ctx->testplan_id = $args->tplan_id;
$ctx->platform_id = $args->platform_id;
$ctx->build_id = $args->build_id;
$tcase_mgr->deleteStepsPartialExec(array_keys($_REQUEST['step_notes']),$ctx);
}
list($execSet,$gui->addIssueOp,$gui->uploadOp) =
write_execution($db,$args,$_REQUEST,$its);
// Copy Attachments from latest exec ?
if ($args->copyAttFromLEXEC && $cfg->exec_cfg->exec_mode->new_exec
&& $args->level == 'testcase') {
// we have got Latest Execution on Context on processTestCase()
if( $latestExecIDInContext > 0 ) {
// need to copy :
// attachments at execution level
// attachments at step execution level
// attachments at execution level
$fileRepo->copyAttachments($latestExecIDInContext,
$execSet[$tcversion_id],'executions');
// attachments at step execution level
$tbl = array();
$tbl['exec_tcsteps'] = DB_TABLE_PREFIX . 'execution_tcsteps';
$tbl['tcsteps'] = DB_TABLE_PREFIX . 'tcsteps';
$sql = "SELECT step_number,tcstep_id,
EXTCS.id AS tcsexe_id
FROM {$tbl['tcsteps']} TCS
JOIN {$tbl['exec_tcsteps']} EXTCS ON
EXTCS.tcstep_id = TCS.id
WHERE EXTCS.execution_id = ";
$from = (array)$db->fetchRowsIntoMap($sql . $latestExecIDInContext,'step_number');
$to = (array)$db->fetchRowsIntoMap($sql . $execSet[$tcversion_id],'step_number');
foreach($from as $step_num => $sxelem) {
if( isset($to[$step_num]) ) {
$fileRepo->copyAttachments($sxelem['tcsexe_id'],
$to[$step_num]['tcsexe_id'],'execution_tcsteps');
}
}
}
}
if($args->assignTask) {
$fid = $tplan_mgr->getFeatureID($args->tplan_id,$args->platform_id,$args->version_id);
$taskMgr = new assignment_mgr($db);
$taskDomain = $taskMgr->get_available_types();
$taskStatusDomain = $taskMgr->get_available_status();
$fmap[$fid]['user_id'] = $fmap[$fid]['assigner_id'] = $args->user_id;
$fmap[$fid]['build_id'] = $args->build_id;
$fmap[$fid]['type'] = $taskDomain['testcase_execution']['id'];
$fmap[$fid]['status'] = $taskStatusDomain['open']['id'];
$taskMgr->assign($fmap);
}
if ($lexidSysWide > 0 && $args->copyIssues
&& $args->level == 'testcase') {
copyIssues($db,$lexidSysWide,$execSet[$args->version_id]);
}
if ($args->level == 'testcase') {
// Propagate events
$ctx = array('id' => $execSet[$tcversion_id],
'tplan_id' => $args->tplan_id,
'build_id' => $args->build_id,
'tcase_id' => $tcase_id,
'status' => $args->statusSingle[$args->version_id],
'directLink' => $args->direct_link);
event_signal('EVENT_EXECUTE_TEST', $ctx);
$tc_info = $tcase_mgr->getExternalID($tcase_id);
$tp_info = $tplan_mgr->get_by_id($args->tplan_id);
$build_info = $tplan_mgr->get_build_by_id($args->tplan_id,$args->build_id);
logAuditEvent(TLS("audit_exec_saved",$tc_info[0],$build_info['name'],$tp_info['name']),"CREATE",$execSet[$tcversion_id],"execution");
}
}
// Need to re-read to update test case status
if ($args->save_and_next || $args->doMoveNext || $args->doMovePrevious) {
$nextInChain = -1;
if( $cfg->exec_cfg->exec_mode->save_and_move == 'unlimited' ) {
if( $args->caller == 'tcAssignedToMe') {
$optz = array('order_by' => 'ORDER BY TPTCV.node_order');
$filters['build_id'] = $args->build_id;
$xx = $tcase_mgr->get_assigned_to_user(
$args->user_id, $args->tproject_id,
array($args->tplan_id), $optz, $filters);
$xx = current($xx);
// key test case id
// inside an idx array
$args->testcases_to_show = array_keys($xx);
}
$chainLen = count($args->testcases_to_show);
foreach($args->testcases_to_show as $ix => $val) {
if( $val == $args->tc_id) {
$nextInChain = $ix+1;
if($nextInChain == $chainLen) {
$nextInChain = 0;
}
break;
}
}
}
// IMPORTANT DEVELOPMENT NOTICE
// Normally this script is called from the tree.
// Filters and other conditions (example display test cases just assigned to me,etc)
// can be applied, creating a set of test cases that can be used.
// Due to size restrictions on POST variables this info is transfered via $_SESSION.
//
// But because we have choosen to add access to this script from other features
// we have forgot to populate this info.
// This is the reason for several issues.
// The approach will be to understand who is the caller and apply different logics
// instead of recreate the logic to populate $_SESSION (I think this approach
// will be simpler).
$doSingleStep = is_null($args->testcases_to_show);
$args->testcases_to_show = (array)$args->testcases_to_show;
$opt4sibling = array('move' => $args->moveTowards);
switch ($args->caller) {
case 'tcAssignedToMe':
$doSingleStep = true;
$opt4sibling['assigned_to'] = array('user_id' => $args->user_id, 'build_id' => $args->build_id);
break;
default:
break;
}
switch($cfg->exec_cfg->exec_mode->save_and_move) {
case 'unlimited':
// get position on chain
$opx = array('tcase_id' =>
$args->testcases_to_show[$nextInChain]);
$nextItem = $tplan_mgr->get_linked_tcvid($args->tplan_id,$args->platform_id,$opx);
$nextItem = current($nextItem);
break;
case 'limited':
$nextItem = $tplan_mgr->getTestCaseNextSibling($args->tplan_id,$tcversion_id,$args->platform_id,$opt4sibling);
if(!$doSingleStep)
{
while (!is_null($nextItem) && !in_array($nextItem['tcase_id'], $args->testcases_to_show))
{
$nextItem = $tplan_mgr->getTestCaseNextSibling($args->tplan_id,$nextItem['tcversion_id'],
$args->platform_id,$opt4sibling);
}
}
break;
} // cfg
if( !is_null($nextItem) )
{
$tcase_id = $nextItem['tcase_id'];
$tcversion_id = $nextItem['tcversion_id'];
// Save and Next - Issues with display CF for test plan design - always EMPTY
// need info about this test case => need to update linked_tcversions info
$identity = array('id' => $nextItem['tcase_id'], 'version_id' => $nextItem['tcversion_id']);
list($lt,$xdm) = getLinkedItems($args,$gui->history_on,$cfg,$tcase_mgr,$tplan_mgr,$identity);
processTestCase($nextItem,$gui,$args,$cfg,$lt,$tree_mgr,$tcase_mgr,$fileRepo);
}
}
else if($args->save_and_exit) {
$args->reload_caller = true;
}
else if ($args->saveStepsPartialExec) {
$partialExec = array("notes" => $_REQUEST['step_notes'],
"status" => $_REQUEST['step_status'] );
$ctx = new stdClass();
$ctx->testplan_id = $args->tplan_id;
$ctx->platform_id = $args->platform_id;
$ctx->build_id = $args->build_id;
$ctx->tester_id = $args->user_id;
$tcase_mgr->saveStepsPartialExec($partialExec,$ctx);
}
}
if(!$args->reload_caller) {
if ($args->doDelete) {
$dummy = $tcase_mgr->deleteExecution($args->exec_to_delete);
if ($dummy){
$tc_info = $tcase_mgr->getExternalID($tcase_id);
$tp_info = $tplan_mgr->get_by_id($args->tplan_id);
$build_info = $tplan_mgr->get_build_by_id($args->tplan_id,$args->build_id);
logAuditEvent(TLS("audit_exec_deleted",$tc_info[0],$build_info['name'],$tp_info['name']),"DELETE",$args->exec_to_delete,"execution");
}
}
// Important Notice:
// $tcase_id and $tcversions_id, can be ARRAYS
// when user enable bulk execution
if( is_array($tcase_id)) {
$tcase_id = array_intersect($tcase_id, $args->testcases_to_show);
}
$gui->map_last_exec =
getLatestExec($db,$tcase_id,$tcversion_id,$gui,$args,$tcase_mgr);
$gui->map_last_exec_any_build = null;
// need to get step info from gui
$stepSet = array();
foreach($gui->map_last_exec as $tcID => $dummy) {
if( null != $gui->map_last_exec[$tcID]['steps'] ) {
foreach ($gui->map_last_exec[$tcID]['steps'] as $step) {
$stepSet[] = $step["id"];
}
}
}
if( count($stepSet) > 0 ) {
// test case version under exec has steps
$ctx = new stdClass();
$ctx->testplan_id = $args->tplan_id;
$ctx->platform_id = $args->platform_id;
$ctx->build_id = $args->build_id;
$gui->stepsPartialExec =
$tcase_mgr->getStepsPartialExec($stepSet,$ctx);
if( null != $gui->stepsPartialExec ) {
// will reload it!
$kij = current(array_keys($gui->map_last_exec));
$cucu = &$gui->map_last_exec[$kij];
foreach($cucu['steps'] as $ccx => $se) {
$stepID = $se['id'];
if( isset($gui->stepsPartialExec[$stepID]) ) {
$cucu['steps'][$ccx]['execution_notes'] =
$gui->stepsPartialExec[$stepID]['notes'];
$cucu['steps'][$ccx]['execution_status'] =
$gui->stepsPartialExec[$stepID]['status'];
}
}
}
}
$testerIdKey = 'tester_id';
$gui->other_execs=null;
$testerid = null;
if($args->level == 'testcase') {
// @TODO 20090815 - franciscom check what to do with platform
if( $cfg->exec_cfg->show_last_exec_any_build ) {
$options=array('getNoExecutions' => 1, 'groupByBuild' => 0);
$gui->map_last_exec_any_build = $tcase_mgr->get_last_execution($tcase_id,$tcversion_id,$args->tplan_id,testcase::ANY_BUILD,
$args->platform_id,$options);
// Get UserID and Updater ID for current Version
$tc_current = $gui->map_last_exec_any_build;
foreach ($tc_current as $key => $value) {
$testerid = $value[$testerIdKey];
$userid_array[$testerid] = $testerid;
}
}
$gui->req_details = null;
if( $args->reqEnabled ) {
$gui->req_details = $req_mgr->getActiveForTCVersion($tcversion_id);
}
$idCard = array('tcase_id' => $tcase_id, 'tcversion_id' => $tcversion_id);
$gui->relations = $tcase_mgr->getTCVersionRelations($idCard);
$gui->kw = $tcase_mgr->getKeywordsByIdCard($idCard,array('output' => 'kwfull'));
if(!is_null($cts)) {
$gui->scripts[$tcversion_id]=$tcase_mgr->getScriptsForTestCaseVersion($cts, $tcversion_id);
}
$gui->other_execs = getOtherExecutions($db,$tcase_id,$tcversion_id,$gui,$args,$cfg,$tcase_mgr);
// Get attachment,bugs, etc
if(!is_null($gui->other_execs)) {
//Get the Tester ID for all previous executions
foreach ($gui->other_execs as $key => $execution) {
foreach ($execution as $singleExecution) {
$testerid = $singleExecution[$testerIdKey];
$userid_array[$testerid] = $testerid;
}
}
$other_info = exec_additional_info($db,$fileRepo,$tcase_mgr,$gui->other_execs,
$args->tplan_id,$args->tproject_id,
$args->issue_tracker_enabled,$its);
$gui->attachments=$other_info['attachment'];
$gui->bugs=$other_info['bugs'];
$gui->other_exec_cfields=$other_info['cfexec_values'];
// this piece of code is useful to avoid error on smarty template due to undefined value
if( is_array($tcversion_id) && (count($gui->other_execs) != count($gui->map_last_exec)) ) {
foreach($tcversion_id as $version_id) {
if( !isset($gui->other_execs[$version_id]) ) {
$gui->other_execs[$version_id]=null;
}
}
}
} // if(!is_null($gui->other_execs))
}
}
} // if(!is_null($linked_tcversions))
if($args->reload_caller) {
windowCloseAndOpenerReload();
exit();
} else {
// Removing duplicate and NULL id's
unset($userid_array['']);
$userSet = null;
if ($userid_array) {
foreach($userid_array as $value) {
$userSet[] = $value;
}
}
$gui->headsUpTSuite =
smarty_assign_tsuite_info($smarty,$tree_mgr,$tcase_id,$args->tproject_id,$cfg);
if ($args->doSave || $args->saveStepsPartialExec) {
$gui->headsUpTSuite = false;
}
// Bulk is possible when test suite is selected (and is allowed in config)
if( $gui->can_use_bulk_op = ($args->level == 'testsuite') ) {
$xx = null;
if( property_exists($gui, 'execution_time_cfields') ) {
$xx = current((array)$gui->execution_time_cfields);
}
$gui->execution_time_cfields = null;
if( !is_null($xx) ) {
$gui->execution_time_cfields[0] = $xx;
}
}
// has sense only if there are cf for execution
// may be can improve check
if( $gui->can_use_bulk_op == false &&
$cfg->exec_cfg->exec_mode->new_exec == 'latest' ) {
list($tcase_id,$tcversion_id,$latestExecIDInContext,$hasCFOnExec) =
processTestCase($tcase,$gui,$args,$cfg,$linked_tcversions,
$tree_mgr,$tcase_mgr,$fileRepo);
if($latestExecIDInContext > 0) {
$tbl = DB_TABLE_PREFIX . 'executions';
$sql = "SELECT notes FROM $tbl
WHERE id = $latestExecIDInContext";
$rs = $db->get_recordset($sql);
$gui->lexNotes = $rs != null ? $rs[0]['notes'] : null;
}
}
initWebEditors($gui,$cfg,$_SESSION['basehref']);
// To silence smarty errors
// future must be initialized in a right way
$smarty->assign('test_automation_enabled',0);
$smarty->assign('gui',$gui);
$smarty->assign('cfg',$cfg);
$smarty->assign('users',tlUser::getByIDs($db,$userSet));
$smarty->display($templateCfg->template_dir . $templateCfg->default_template);
}
/**
*
*
*/
function init_args(&$dbHandler,$cfgObj) {
$args = new stdClass();
$_REQUEST = strings_stripSlashes($_REQUEST);
// Settings and Filters that we put on session to create some
// sort of persistent scope, because we have had issues when passing this info
// using GET mode (size limits)
//
// we get info about build_id, platform_id, etc ...
getSettingsAndFilters($args);
manageCookies($args,$cfgObj);
// need to comunicate with left frame, will do via $_SESSION and form_token
if( ($args->treeFormToken = isset($_REQUEST['form_token']) ? $_REQUEST['form_token'] : 0) > 0 )
{
// do not understand why this do not works OK
// $_SESSION[$args->treeFormToken]['loadExecDashboard'] = false;
$_SESSION['loadExecDashboard'][$args->treeFormToken] = false;
}
$args->followTheWhiteRabbit = isset($_REQUEST['followTheWhiteRabbit']) ? 1 : 0;
if(is_null($args->refreshTree)) {
$args->refreshTree = isset($_REQUEST['refresh_tree']) ? intval($_REQUEST['refresh_tree']) : 0;
}
$args->basehref = $_SESSION['basehref'];
$args->assignTask = isset($_REQUEST['assignTask']) ? 1: 0;
$args->createIssue = isset($_REQUEST['createIssue']) ? 1: 0;
$args->copyIssues = isset($_REQUEST['copyIssues']) ? 1: 0;
$args->copyAttFromLEXEC = isset($_REQUEST['copyAttFromLEXEC']) ? 1: 0;
$args->tc_id = null;
$args->tsuite_id = null;
$args->user = $_SESSION['currentUser'];
$args->user_id = intval($args->user->dbID);
$args->id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
$args->caller = isset($_REQUEST['caller']) ? $_REQUEST['caller'] : 'exec_feature';
$args->reload_caller = false;
$args->doExec = isset($_REQUEST['execute_cases']) ? 1 : 0;
$args->doDelete = isset($_REQUEST['do_delete']) ? $_REQUEST['do_delete'] : 0;
$args->doMoveNext = isset($_REQUEST['move2next']) ? 1 : 0;
$args->doMovePrevious = isset($_REQUEST['move2previous']) ? $_REQUEST['move2previous'] : 0;
$args->moveTowards = $args->doMoveNext ? 'forward' : ($args->doMovePrevious ? 'backward' : null);
// can be a list, will arrive via form POST
$args->tc_versions = isset($_REQUEST['tc_version']) ? $_REQUEST['tc_version'] : null;
// it's a submit button!
$args->saveStepsPartialExec = isset($_REQUEST['saveStepsPartialExec']);
$key2loop = array('level' => '','status' => null, 'statusSingle' => null,
'do_bulk_save' => 0,'save_results' => 0,'save_and_next' => 0,
'save_and_exit' => 0);
foreach($key2loop as $key => $value) {
$args->$key = isset($_REQUEST[$key]) ? $_REQUEST[$key] : $value;
}
$args->doSave = $args->save_results || $args->save_and_next ||
$args->save_and_exit || $args->do_bulk_save;
$args->doNavigate = $args->doMoveNext || $args->doMovePrevious;
// See details on: "When nullify filter_status - 20080504" in this file
if( $args->level == 'testcase' || is_null($args->filter_status) ||
(!is_array($args->filter_status) && trim($args->filter_status)=='')
) {
$args->filter_status = null;
}
else {
// 20130306 - franciscom
// This (without the strlen() check) generated issue 5541: When "Result" filter is used ...
// at least when result DIFFERENT that NOT RUN is used on filter
//
// 20120616 - franciscom
// some strange thing to investigate, seems that unserialize is invoked
// under the hood when getting data from $_REQUEST, then this piece
// of code not only will be useless BUT WRONG, because will try
// to unserialize something that IS NOT SERIALIZED!!!!
// After TICKET 6651, may be need to limit size of $args->filter_status
if(is_string($args->filter_status) && strlen($args->filter_status) > 1) {
$args->filter_status = json_decode($args->filter_status);
}
}
switch($args->level) {
case 'testcase':
$args->tc_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
if( !is_null($args->tc_versions) ) {
$args->tc_id = current($args->tc_versions);
$args->id = $args->tc_id;
$args->version_id = key($args->tc_versions);
}
$args->tsuite_id = null;
break;
case 'testsuite':
$args->tsuite_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
$args->tc_id = null;
break;
}
//
$args->updateTCVToThis = isset($_REQUEST['updateTCVToThis']) ? $_REQUEST['updateTCVToThis'] : null;
if( null != $args->updateTCVToThis ) {
$args->version_id = intval($args->updateTCVToThis);
}
$args->tsuitesInBranch = null;
if( !is_null($args->tsuite_id) ) {
// will get all test suites in this branch, in order to limit amount of data returned
// by functions/method that collect linked tcversions
// THIS COLLECT ONLY FIRST LEVEL UNDER test suite, do not do deep search
// Need to understand is still needed
$tsuite_mgr = new testsuite($dbHandler);
$xx = $tsuite_mgr->get_children($args->tsuite_id,array('details' => 'id'));
$ldx = count($xx);
$xx[$ldx] = $args->tsuite_id;
$args->tsuitesInBranch = $xx;
unset($tsuite_mgr);
}
// TICKET 5630: Test Results by direct link ...
$args->tplan_id = intval(isset($_REQUEST['tplan_id']) ? $_REQUEST['tplan_id'] : $_SESSION['testplanID']);
$args->tproject_id = intval(isset($_REQUEST['tproject_id']) ? $_REQUEST['tproject_id'] : $_SESSION['testprojectID']);
if($args->tproject_id <= 0) {
$tree_mgr = new tree($dbHandler);
$dm = $tree_mgr->get_node_hierarchy_info($args->tplan_id);
$args->tproject_id = $dm['parent_id'];
}
$args->addLinkToTL = isset($_REQUEST['addLinkToTL']) ? TRUE : FALSE;
$args->addLinkToTLPrintView = isset($_REQUEST['addLinkToTLPrintView']) ? TRUE : FALSE;
// Do this only on single execution mode
// get issue tracker config and object to manage TestLink - BTS integration
$args->itsCfg = null;
$its = null;
$tproject_mgr = new testproject($dbHandler);
$info = $tproject_mgr->get_by_id($args->tproject_id);
$args->reqEnabled = intval($info['option_reqs']);
unset($tproject_mgr);
$bug_summary['minLengh'] = 1;
$bug_summary['maxLengh'] = 1;
if( ($args->issue_tracker_enabled = $info['issue_tracker_enabled']) ) {
$it_mgr = new tlIssueTracker($dbHandler);
$args->itsCfg = $it_mgr->getLinkedTo($args->tproject_id);
$its = $it_mgr->getInterfaceObject($args->tproject_id);
if(!is_null($args->itsCfg) && !is_null($its)) {
$bug_summary['maxLengh'] = $its->getBugSummaryMaxLength();
}
unset($it_mgr);
}
initArgsIssueOnTestCase($args,$bug_summary);
initArgsIssueOnSteps($args,$bug_summary);
// get code tracker config and object to manage TestLink - CTS integration
$args->ctsCfg = null;
$cts = null;
if( ($args->codeTrackerEnabled = intval($info['code_tracker_enabled'])) ) {
$ct_mgr = new tlCodeTracker($dbHandler);
$args->ctsCfg = $ct_mgr->getLinkedTo($args->tproject_id);
$cts = $ct_mgr->getInterfaceObject($args->tproject_id);
unset($ct_mgr);
}
// is a submit button
$prop = 'linkLatestVersion';
$args->$prop = isset($_REQUEST[$prop]);
$prop = 'TCVToUpdate';
$args->$prop = intval(isset($_REQUEST[$prop]) ? $_REQUEST[$prop] : 0);
$prop = 'updateTCVToThis';
$args->$prop = intval(isset($_REQUEST[$prop]) ? $_REQUEST[$prop] : 0);
return array($args,$its,$cts);
}
/**
*
*
*/
function initArgsIssueOnTestCase(&$argsObj,$bugSummaryProp) {
$inputCfg = array("bug_notes" => array("POST",tlInputParameter::STRING_N),
"issueType" => array("POST",tlInputParameter::INT_N),
"issuePriority" => array("POST",tlInputParameter::INT_N),
"artifactComponent" => array("POST",tlInputParameter::ARRAY_INT),
"artifactVersion" => array("POST",tlInputParameter::ARRAY_INT));
$inputCfg["bug_summary"] = array("POST",tlInputParameter::STRING_N);
// hmm this MAGIC needs to be commented
if(!$argsObj->do_bulk_save) {
$inputCfg["bug_summary"][2] = $bugSummaryProp['minLengh'];
$inputCfg["bug_summary"][3] = $bugSummaryProp['maxLengh'];
}
I_PARAMS($inputCfg,$argsObj);
}
/**
*
*
*/
function initArgsIssueOnSteps(&$argsObj,$bugSummaryProp) {
$arrayOfInt = array("POST",tlInputParameter::ARRAY_INT);
$cfg = array("issueBodyForStep" => array("POST",tlInputParameter::ARRAY_STRING_N),
"issueTypeForStep" => $arrayOfInt,
"issuePriorityForStep" => $arrayOfInt);
$cfg["issueSummaryForStep"] = array("POST",tlInputParameter::ARRAY_STRING_N);
// hmm this MAGIC needs to be commented
if(!$argsObj->do_bulk_save) {
$cfg["issueSummaryForStep"][2] = $bugSummaryProp['minLengh'];
$cfg["issueSummaryForStep"][3] = $bugSummaryProp['maxLengh'];
}
I_PARAMS($cfg,$argsObj);
// Special
// Array of Check Boxes:
// 'issueForStep','addLinkToTLForStep'
$sk = array('issueForStep','addLinkToTLForStep',
'artifactComponentForStep','artifactVersionForStep');
foreach($sk as $kt) {
$argsObj->$kt = null;
if(isset($_REQUEST[$kt])) {
$argsObj->$kt = $_REQUEST[$kt];
}
}
}
/*
function:
args :
returns:
*/
function manage_history_on($hash_REQUEST,$hash_SESSION,
$exec_cfg,$btn_on_name,$btn_off_name,$hidden_on_name)
{
if( isset($hash_REQUEST[$btn_on_name]) )
{
$history_on = true;
}
elseif(isset($_REQUEST[$btn_off_name]))
{
$history_on = false;
}
elseif (isset($_REQUEST[$hidden_on_name]))
{
$history_on = $_REQUEST[$hidden_on_name];
}
elseif (isset($_SESSION[$hidden_on_name]))
{
$history_on = $_SESSION[$hidden_on_name];
}
else
{
$history_on = $exec_cfg->history_on;
}
return $history_on ? true : false;
}
/*
function: get_ts_name_details
args :
returns: map with key=TCID
values= assoc_array([tsuite_id => 5341
[details] => my detailas ts1
[tcid] => 5343
[tsuite_name] => ts1)
*/
function get_ts_name_details(&$db,$tcase_id) {
$tables = array();
$tables['testsuites'] = DB_TABLE_PREFIX . 'testsuites';
$tables['nodes_hierarchy'] = DB_TABLE_PREFIX . 'nodes_hierarchy';
$rs = '';
$do_query = true;
$sql = "SELECT TS.id AS tsuite_id, TS.details,
NHA.id AS tc_id, NHB.name AS tsuite_name
FROM {$tables['testsuites']} TS,
{$tables['nodes_hierarchy']} NHA,
{$tables['nodes_hierarchy']} NHB
WHERE TS.id=NHA.parent_id
AND NHB.id=NHA.parent_id ";
if( is_array($tcase_id) && count($tcase_id) > 0) {
$in_list = implode(",",$tcase_id);
$sql .= "AND NHA.id IN (" . $in_list . ")";
} else if(!is_null($tcase_id)) {
$sql .= "AND NHA.id={$tcase_id}";
} else {
$do_query = false;
}
if ($do_query) {
$rs = $db->fetchRowsIntoMap($sql,'tc_id');
}
return $rs;
}
/*
function:
args :
returns:
*/
function smarty_assign_tsuite_info(&$smarty,&$tree_mgr,$tcase_id,$tproject_id,$cfgObj)
{
if( ($safeTCaseID = intval($tcase_id)) <= 0) {
// hmm, no good
return;
}
$fpath = $tree_mgr->get_full_path_verbose($tcase_id, array('output_format' => 'id_name'));
$tsuite_info = get_ts_name_details($tree_mgr->db,$tcase_id);
foreach($fpath as $key => $value) {
unset($value['name'][0]); // Remove test plan name
unset($value['node_id'][0]); // Remove test plan name
$str='';
foreach($value['name'] as $jdx => $elem) {
$str .= "<a href=\"javascript:openTestSuiteWindow(" . $value['node_id'][$jdx] . ")\"> ";
$str .= htmlspecialchars($elem,ENT_QUOTES) . '</a>/';
}
$tsuite_info[$key]['tsuite_name']=$str;
}
$smarty->assign('tsuite_info',$tsuite_info);
$headsUp = false;
// --------------------------------------------------------------------------
if (!is_null($tsuite_info)) {
$ckObj = new stdClass();
$ckCfg = config_get('cookie');
$cookieKey = $ckCfg->prefix . 'TL_execSetResults_tsdetails_view_status';
$exec_cfg = config_get('exec_cfg');
$a_tsvw=array();
$a_ts=array();
$a_tsval=array();
$tsuite_mgr = new testsuite($tree_mgr->db);
$tsid = current($tsuite_info)['tsuite_id'];
if ($cfgObj->kwHeadsUpTSuiteOnExec != '') {
$headsUp = $tsuite_mgr->keywordIsLinked($tsid,
$cfgObj->kwHeadsUpTSuiteOnExec);
}
foreach($tsuite_info as $key => $elem) {
$main_k = 'tsdetails_view_status_' . $key;
$a_tsvw[] = $main_k;
$a_ts[] = 'tsdetails_' . $key;
$expand_collapse = 0;
if( !isset($_REQUEST[$main_k]) ){
// First time we are entered here =>
// we can need to understand how to proceed
switch($exec_cfg->expand_collapse->testsuite_details) {
case LAST_USER_CHOICE:
if (isset($_COOKIE[$cookieKey]) ) {
$expand_collapse = $_COOKIE[$cookieKey];
}
break;
default:
$expand_collapse = $exec_cfg->expand_collapse->testsuite_details;
break;
}
}
$a_tsval[] = isset($_REQUEST[$main_k]) ?
$_REQUEST[$main_k] : $expand_collapse;
$tsuite_id = $elem['tsuite_id'];
$tc_id = $elem['tc_id'];
if (!isset($cached_cf[$tsuite_id])) {
$cached_cf[$tsuite_id] = $tsuite_mgr->html_table_of_custom_field_values($tsuite_id,'design',null,$tproject_id);
}
$ts_cf_smarty[$tc_id] = $cached_cf[$tsuite_id];
}
if( count($a_tsval) > 0 ) {
$ckObj->value = $a_tsval[0];
tlSetCookie($ckObj);
}
$smarty->assign('tsd_div_id_list',implode(",",$a_ts));
$smarty->assign('tsd_hidden_id_list',implode(",",$a_tsvw));
$smarty->assign('tsd_val_for_hidden_list',implode(",",$a_tsval));
$smarty->assign('ts_cf_smarty',$ts_cf_smarty);
}
return $headsUp;
}
// ----------------------------------------------------------------------------
/*
function:
args :
returns:
@internal revisions:
*/
function exec_additional_info(&$db, $fileRepo, &$tcase_mgr, $other_execs,
$tplan_id, $tproject_id, $bugInterfaceOn, $bugInterface)
{
$attachmentInfos = null;
$bugs = null;
$cfexec_values = null;