/
testcase.class.php
8845 lines (7241 loc) · 295 KB
/
testcase.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.
*
* @filesource testcase.class.php
* @package TestLink
* @author Francisco Mancardi (francisco.mancardi@gmail.com)
* @copyright 2005-2018, TestLink community
* @link http://www.testlink.org/
*
*/
/** related functionality */
require_once( dirname(__FILE__) . '/requirement_mgr.class.php' );
require_once( dirname(__FILE__) . '/assignment_mgr.class.php' );
require_once( dirname(__FILE__) . '/attachments.inc.php' );
require_once( dirname(__FILE__) . '/users.inc.php' );
require_once( dirname(__FILE__) . '/event_api.php');
/** list of supported format for Test case import/export */
$g_tcFormatStrings = array ("XML" => lang_get('the_format_tc_xml_import'));
/**
* class for Test case CRUD
* @package TestLink
*/
class testcase extends tlObjectWithAttachments
{
const AUTOMATIC_ID=0;
const DEFAULT_ORDER=0;
const ALL_VERSIONS=0;
const LATEST_VERSION=-1;
const AUDIT_OFF=0;
const AUDIT_ON=1;
const CHECK_DUPLICATE_NAME=1;
const DONT_CHECK_DUPLICATE_NAME=0;
const ENABLED=1;
const ALL_TESTPLANS=null;
const ANY_BUILD=null;
const GET_NO_EXEC=1;
const ANY_PLATFORM=null;
const NOXMLHEADER=true;
const EXECUTION_TYPE_MANUAL = 1;
const EXECUTION_TYPE_AUTO = 2;
const NAME_PHOPEN = '[[';
const NAME_PHCLOSE = ']]';
const NAME_DIVIDE = '::';
const GHOSTBEGIN = '[ghost]';
const GHOSTEND = '[/ghost]';
const GHOSTMASK = self::GHOSTBEGIN .
'"TestCase":"%s","Version":"%s"' . self::GHOSTEND;
const GHOSTSTEPMASK = self::GHOSTBEGIN .
'"Step":"%s","TestCase":"%s","Version":"%s"' . self::GHOSTEND;
/** @var database handler */
var $db;
var $tree_manager;
var $tproject_mgr;
var $node_types_descr_id;
var $node_types_id_descr;
var $my_node_type;
var $assignment_mgr;
var $assignment_types;
var $assignment_status;
var $cfield_mgr;
var $import_file_types = array("XML" => "XML");
var $export_file_types = array("XML" => "XML");
var $execution_types = array();
var $cfg;
var $debugMsg;
var $layout;
var $XMLCfg;
/**
* testcase class constructor
*
* @param resource &$db reference to database handler
*/
function __construct(&$db) {
$this->db = &$db;
$this->tproject_mgr = new testproject($this->db);
$this->tree_manager = &$this->tproject_mgr->tree_manager;
$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->my_node_type=$this->node_types_descr_id['testcase'];
$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->execution_types = $this->getExecutionTypes();
$this->layout = $this->getLayout();
$this->cfg = new stdClass();
$this->cfg->testcase = config_get('testcase_cfg');
$this->cfg->execution = config_get('exec_cfg');
$this->cfg->cfield = config_get('custom_fields');
$this->debugMsg = ' Class:' . __CLASS__ . ' - Method: ';
$this->XMLCfg = new stdClass();
$this->XMLCfg->att = $this->getAttXMLCfg();
$this->XMLCfg->req = $this->getReqXMLCfg();
// ATTENTION:
// second argument is used to set $this->attachmentTableName,property that this calls
// get from his parent
// ORIGINAL
// parent::__construct($this->db,"nodes_hierarchy");
parent::__construct($this->db,"tcversions");
}
/**
*
*/
static function getExecutionTypes() {
$stdSet = array(self::EXECUTION_TYPE_MANUAL => lang_get('manual'),
self::EXECUTION_TYPE_AUTO => lang_get('automated'));
if( !is_null($customSet = config_get('custom_execution_types')) )
{
foreach($customSet as $code => $lbl)
{
$stdSet[$code] = lang_get($lbl);
}
}
return $stdSet;
}
/**
*
*/
function getName($tcase_id) {
$info = $this->tree_manager->get_node_hierarchy_info($tcase_id);
return $info['name'];
}
/**
*
*/
function getFileUploadRelativeURL($identity) {
$url = "lib/testcases/tcEdit.php?doAction=fileUpload&" .
"&tcase_id=" . intval($identity->tcase_id) .
"&tcversion_id=" . intval($identity->tcversion_id) .
"&tproject_id=" . intval($identity->tproject_id);
return $url;
}
/**
*
*/
function getDeleteAttachmentRelativeURL($identity) {
$url = "lib/testcases/tcEdit.php?doAction=deleteFile&tcase_id=" . intval($identity->tcase_id) .
"&tcversion_id=" . intval($identity->tcversion_id) .
"&tproject_id=" . intval($identity->tproject_id) . "&file_id=" ;
return $url;
}
/**
*
*/
function getDeleteAttachmentByIDRelativeURL($identity) {
$url = "lib/testcases/tcEdit.php?doAction=deleteFile&tcase_id=" .
intval($identity->tcase_id) .
"&tproject_id=" . intval($identity->tproject_id) . "&file_id=" ;
return $url;
}
/*
function: get_export_file_types
getter
args: -
returns: map
key: export file type code
value: export file type verbose description
*/
function get_export_file_types()
{
return $this->export_file_types;
}
/*
function: get_impor_file_types
getter
args: -
returns: map
key: import file type code
value: import file type verbose description
*/
function get_import_file_types()
{
return $this->import_file_types;
}
/*
function: get_execution_types
getter
args: -
returns: map
key: execution type code
value: execution type verbose description
*/
function get_execution_types()
{
return $this->execution_types;
}
/**
* just a wrapper
*
*/
function createFromObject($item) {
static $wkfstatus;
if(is_null($wkfstatus)) {
$wkfstatus = config_get('testCaseStatus');
}
$options = array('check_duplicate_name' => self::CHECK_DUPLICATE_NAME,
'action_on_duplicate_name' => 'block',
'estimatedExecDuration' => 0,
'status' => $wkfstatus['draft'], 'importLogic' => null);
if(property_exists($item, 'estimatedExecDuration')) {
$options['estimatedExecDuration'] = floatval($item->estimatedExecDuration);
}
if(property_exists($item, 'status')) {
$options['status'] = intval($item->status);
}
if(property_exists($item, 'importLogic')) {
$options['importLogic'] = $item->importLogic;
}
$ret = $this->create($item->testSuiteID,$item->name,$item->summary,$item->preconditions,
$item->steps,$item->authorID,'',$item->order,self::AUTOMATIC_ID,
$item->executionType,$item->importance,$options);
return $ret;
}
/**
* create a test case
*
*/
function create($parent_id,$name,$summary,$preconditions,$steps,$author_id,
$keywords_id='',$tc_order=self::DEFAULT_ORDER,$id=self::AUTOMATIC_ID,
$execution_type = TESTCASE_EXECUTION_TYPE_MANUAL,
$importance=2,$options=null)
{
$status_ok = 1;
$my['options'] = array( 'check_duplicate_name' => self::DONT_CHECK_DUPLICATE_NAME,
'action_on_duplicate_name' => 'generate_new',
'estimatedExecDuration' => null,'status' => null,'active' => null,'is_open' => null,
'importLogic' => null);
$my['options'] = array_merge($my['options'], (array)$options);
if( trim($summary) != '' ) {
if( strpos($summary,self::NAME_PHOPEN) !== FALSE && strpos($summary,self::NAME_PHCLOSE) !== FALSE ) {
$name = $this->buildTCName($name,$summary);
}
}
if( trim($preconditions) != '' ) {
if( strpos($preconditions,self::NAME_PHOPEN) !== FALSE &&
strpos($preconditions,self::NAME_PHCLOSE) !== FALSE ) {
$name = $this->buildTCName($name,$preconditions);
}
}
$ret = $this->create_tcase_only($parent_id,$name,$tc_order,$id,$my['options']);
$tcase_id = $ret['id'];
$ix = new stdClass();
if($ret["status_ok"]) {
$ix->version = 1;
if(isset($ret['version_number']) && $ret['version_number'] < 0) {
// We are in the special situation we are only creating a new version,
// useful when importing test cases. Need to get last version number.
// I do not use create_new_version() because it does a copy ot last version
// and do not allow to set new values in different fields while doing this operation.
$last_version_info = $this->get_last_version_info($ret['id'],array('output' => 'minimun'));
$ix->version = $last_version_info['version']+1;
$ret['msg'] = sprintf($ret['msg'],$ix->version);
$ret['version_number'] = $ix->version;
}
// Multiple Test Case Steps Feature
$version_number = $ret['version_number'];
$ix->id = $tcase_id;
$ix->externalID = $ret['external_id'];
$ix->summary = $summary;
$ix->preconditions = $preconditions;
$ix->steps = $steps;
$ix->authorID = $author_id;
$ix->executionType = $execution_type;
$ix->importance = $importance;
$ix->status = $my['options']['status'];
$ix->active = $my['options']['active'];
$ix->is_open = $my['options']['is_open'];
$ix->estimatedExecDuration = $my['options']['estimatedExecDuration'];
$op = $this->createVersion($ix);
if(trim($keywords_id) != "") {
$a_keywords = explode(",",$keywords_id);
$auditContext = array('on' => self::AUDIT_ON,
'version' => $version_number);
$this->addKeywords($tcase_id,$op['id'],$a_keywords,$auditContext);
}
if($ret['update_name']) {
$sql = " UPDATE {$this->tables['nodes_hierarchy']} SET name='" .
$this->db->prepare_string($name) . "' WHERE id= " . intval($ret['id']);
$this->db->exec_query($sql);
}
$ret['msg'] = $op['status_ok'] ? $ret['msg'] : $op['msg'];
$ret['tcversion_id'] = $op['status_ok'] ? $op['id'] : -1;
$ctx = array('test_suite_id' => $parent_id,'id' => $id,'name' => $name,
'summary' => $summary,'preconditions' => $preconditions,
'steps' => $steps,'author_id' => $author_id,
'keywords_id' => $keywords_id,
'order' => $tc_order, 'exec_type' => $execution_type,
'importance' => $importance,'options' => $options);
event_signal('EVENT_TEST_CASE_CREATE', $ctx);
}
return $ret;
}
/*
[$check_duplicate_name]
[$action_on_duplicate_name]
[$order]
[$id]
0 -> the id will be assigned by dbms
x -> this will be the id
Warning: no check is done before insert => can got error.
return:
$ret['id']
$ret['external_id']
$ret['status_ok']
$ret['msg'] = 'ok';
$ret['new_name']
rev:
*/
function create_tcase_only($parent_id,$name,$order=self::DEFAULT_ORDER,$id=self::AUTOMATIC_ID,
$options=null)
{
$dummy = config_get('field_size');
$name_max_len = $dummy->testcase_name;
$name = trim($name);
$originalNameLen = tlStringLen($name);
$getOptions = array();
$ret = array('id' => -1,'external_id' => 0, 'status_ok' => 1,'msg' => 'ok',
'new_name' => '', 'version_number' => 1, 'has_duplicate' => false,
'external_id_already_exists' => false, 'update_name' => false);
$my['options'] = array('check_duplicate_name' => self::DONT_CHECK_DUPLICATE_NAME,
'action_on_duplicate_name' => 'generate_new',
'external_id' => null, 'importLogic' => null);
$my['options'] = array_merge($my['options'], (array)$options);
$doCreate=true;
$forceGenerateExternalID = false;
$algo_cfg = config_get('testcase_cfg')->duplicated_name_algorithm;
$getDupOptions['check_criteria'] = ($algo_cfg->type == 'counterSuffix') ? 'like' : '=';
$getDupOptions['access_key'] = ($algo_cfg->type == 'counterSuffix') ? 'name' : 'id';
// If external ID has been provided, check if exists.
// If answer is yes, then
// 1. collect current info
// 2. if $my['options']['check_duplicate_name'] is create new version
// change to BLOCK
//
if( !is_null($my['options']['importLogic']) )
{
$doQuickReturn = false;
switch($my['options']['importLogic']['hitCriteria'])
{
case 'externalID':
if( ($sf = intval($my['options']['external_id'])) > 0 )
{
// check if already exists a test case with this external id
$info = $this->get_by_external($sf, $parent_id);
if( !is_null($info))
{
if( count($info) > 1)
{
// abort
throw new Exception("More than one test case with same external ID");
}
$doQuickReturn = true;
$ret['id'] = key($info);
$ret['external_id'] = $sf;
$ret['version_number'] = -1;
$ret['external_id_already_exists'] = true;
}
}
switch($my['options']['importLogic']['actionOnHit']) {
case 'create_new_version':
if($doQuickReturn) {
// I this situation we will need to also update test case name, if user
// has provided one on import file.
// Then we need to check that new name will not conflict with an existing one
$doCreate = false;
if( strcmp($info[key($info)]['name'],$name) != 0) {
$itemSet = $this->getDuplicatesByName($name,$parent_id,$getDupOptions);
if( is_null($itemSet) ) {
$ret['name'] = $name;
$ret['update_name'] = true;
}
}
return $ret;
}
break;
case 'generate_new':
// on GUI => create a new test case with a different title
// IMPORTANT:
// if name provided on import file does not hit an existent one
// then I'm going to use it, instead of generating a NEW NAME
$forceGenerateExternalID = true;
break;
}
break;
}
}
if ($my['options']['check_duplicate_name'])
{
$itemSet = $this->getDuplicatesByName($name,$parent_id,$getDupOptions);
if( !is_null($itemSet) && ($siblingQty=count($itemSet)) > 0 )
{
$ret['has_duplicate'] = true;
switch($my['options']['action_on_duplicate_name'])
{
case 'block':
$doCreate=false;
$ret['status_ok'] = 0;
$ret['msg'] = sprintf(lang_get('testcase_name_already_exists'),$name);
break;
case 'generate_new':
$doCreate=true;
// TICKET 5159: importing duplicate test suites
// Need to force use of generated External ID
// (this seems the best alternative)
$my['options']['external_id'] = null;
switch($algo_cfg->type)
{
case 'stringPrefix':
$doIt = true;
while($doIt)
{
if( $doIt = !is_null($itemSet) )
{
$prefix = strftime($algo_cfg->text,time());
$target = $prefix . " " . $name ;
$final_len = strlen($target);
if( $final_len > $name_max_len)
{
$target = substr($target,0,$name_max_len);
}
// Check new generated name
$itemSet = $this->getDuplicatesByName($target,$parent_id,$getDupOptions);
}
}
$name = $target;
break;
case 'counterSuffix':
$mask = !is_null($algo_cfg->text) ? $algo_cfg->text : '#%s';
$nameSet = array_flip(array_keys($itemSet));
// 20110109 - franciscom
// does not understand why I've choosen time ago
// to increment $siblingQty before using it
// This way if TC X exists on target parent
// I will create TC X [2] insteand of TC X [1]
// Anyway right now I will not change.
$target = $name . ($suffix = sprintf($mask,++$siblingQty));
$final_len = strlen($target);
if( $final_len > $name_max_len)
{
$target = substr($target,strlen($suffix),$name_max_len);
}
// Need to recheck if new generated name does not crash with existent name
// why? Suppose you have created:
// TC [1]
// TC [2]
// TC [3]
// Then you delete TC [2].
// When I got siblings il will got 2 siblings, if I create new progressive using next,
// it will be 3 => I will get duplicated name.
while( isset($nameSet[$target]) )
{
$target = $name . ($suffix = sprintf($mask,++$siblingQty));
$final_len = strlen($target);
if( $final_len > $name_max_len)
{
$target = substr($target,strlen($suffix),$name_max_len);
}
}
$name = $target;
break;
}
$ret['status_ok'] = 1;
$ret['new_name'] = $name;
$ret['msg'] = sprintf(lang_get('created_with_title'),$name);
break;
case 'create_new_version':
$doCreate = false;
// If we found more that one with same name and same parent,
// will take the first one.
$xx = current($itemSet);
$ret['id'] = $xx['id'];
$ret['external_id']=$xx['tc_external_id'];
$ret['status_ok'] = 1;
$ret['new_name'] = $name;
$ret['version_number'] = -1;
$ret['msg'] = lang_get('create_new_version');
break;
default:
break;
}
}
}
// 20120822 - think we have potencial issue, because we never check if
// duplicated EXTERNAL ID exists.
// Right now there is no time to try a fix
if( $ret['status_ok'] && $doCreate)
{
$safeLenName = tlSubStr($name, 0, $name_max_len);
// Get tproject id
$path2root = $this->tree_manager->get_path($parent_id);
$tproject_id = $path2root[0]['parent_id'];
$tcase_id = $this->tree_manager->new_node($parent_id,$this->my_node_type,$safeLenName,$order,$id);
$ret['id'] = $tcase_id;
$generateExtID = false;
if( $forceGenerateExternalID || is_null($my['options']['external_id']) )
{
$generateExtID = true;
}
else
{
// this need more work and checks (20140209)
$sf = intval($my['options']['external_id']);
if( is_null($this->get_by_external($sf, $parent_id)) )
{
$ret['external_id'] = $sf;
// CRITIC: setTestCaseCounter() will update only if new provided value > current value
$this->tproject_mgr->setTestCaseCounter($tproject_id,$ret['external_id']);
}
else
{
$generateExtID = true;
}
}
if( $generateExtID )
{
$ret['external_id'] = $this->tproject_mgr->generateTestCaseNumber($tproject_id);
}
if( !$ret['has_duplicate'] && ($originalNameLen > $name_max_len) )
{
$ret['new_name'] = $safeLenName;
$ret['msg'] = sprintf(lang_get('testcase_name_length_exceeded'),$originalNameLen,$name_max_len);
}
}
return $ret;
}
/**
* trying to solve <body id="cke_pastebin" issues
*
*/
private function createVersion($item) {
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$tcase_version_id = $this->tree_manager->new_node($item->id,
$this->node_types_descr_id['testcase_version']);
$this->CKEditorCopyAndPasteCleanUp($item,array('summary','preconditions'));
$sql = "/* $debugMsg */ INSERT INTO {$this->tables['tcversions']} " .
" (id,tc_external_id,version,summary,preconditions," .
" author_id,creation_ts,execution_type,importance ";
$sqlValues = " VALUES({$tcase_version_id},{$item->externalID},{$item->version},'" .
$this->db->prepare_string($item->summary) . "','" .
$this->db->prepare_string($item->preconditions) . "'," .
$this->db->prepare_int($item->authorID) . "," . $this->db->db_now() .
", {$item->executionType},{$item->importance} ";
if( !is_null($item->status) ) {
$wf = intval($item->status);
$sql .= ',status';
$sqlValues .= ",{$wf}";
}
if( !is_null($item->estimatedExecDuration) ) {
$v = trim($item->estimatedExecDuration);
if($v != '') {
$sql .= ", estimated_exec_duration";
$sqlValues .= "," . floatval($v);
}
}
if( property_exists($item,'active') && !is_null($item->active) ) {
$v = intval($item->active) > 0 ? 1 : 0;
$sql .= ", active";
$sqlValues .= "," . $v;
}
if( property_exists($item,'is_open') && !is_null($item->is_open) ) {
$v = intval($item->is_open) > 0 ? 1 : 0;
$sql .= ", is_open";
$sqlValues .= "," . $v;
}
$sql .= " )" . $sqlValues . " )";
$result = $this->db->exec_query($sql);
$ret['msg']='ok';
$ret['id'] = $tcase_version_id;
$ret['status_ok']=1;
if ($result && ( !is_null($item->steps) && is_array($item->steps) ) ) {
$steps2create = count($item->steps);
$op['status_ok'] = 1;
// need to this to manage call to this method for REST API.
$stepIsObject = is_object($item->steps[0]);
for($jdx=0 ; ($jdx < $steps2create && $op['status_ok']); $jdx++) {
if($stepIsObject) {
$item->steps[$jdx] = (array)$item->steps[$jdx];
}
$this->create_step($tcase_version_id,
$item->steps[$jdx]['step_number'],
$item->steps[$jdx]['actions'],
$item->steps[$jdx]['expected_results'],
$item->steps[$jdx]['execution_type']);
}
}
if (!$result) {
$ret['msg'] = $this->db->error_msg();
$ret['status_ok']=0;
$ret['id']=-1;
}
return $ret;
}
/*
function: getDuplicatesByname
args: $name
$parent_id
returns: hash
*/
function getDuplicatesByName($name, $parent_id, $options=null)
{
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$my['options'] = array( 'check_criteria' => '=', 'access_key' => 'id', 'id2exclude' => null);
$my['options'] = array_merge($my['options'], (array)$options);
$target = $this->db->prepare_string($name);
switch($my['options']['check_criteria'])
{
case '=':
default:
$check_criteria = " AND NHA.name = '{$target}' ";
break;
case 'like':
$check_criteria = " AND NHA.name LIKE '{$target}%' ";
break;
}
$sql = " SELECT DISTINCT NHA.id,NHA.name,TCV.tc_external_id" .
" FROM {$this->tables['nodes_hierarchy']} NHA, " .
" {$this->tables['nodes_hierarchy']} NHB, {$this->tables['tcversions']} TCV " .
" WHERE NHA.node_type_id = {$this->my_node_type} " .
" AND NHB.parent_id=NHA.id " .
" AND TCV.id=NHB.id " .
" AND NHB.node_type_id = {$this->node_types_descr_id['testcase_version']} " .
" AND NHA.parent_id=" . $this->db->prepare_int($parent_id) . " {$check_criteria}";
if( !is_null($my['options']['id2exclude']) )
{
$sql .= " AND NHA.id <> " . intval($my['options']['id2exclude']);
}
$rs = $this->db->fetchRowsIntoMap($sql,$my['options']['access_key']);
if( is_null($rs) || count($rs) == 0 )
{
$rs=null;
}
return $rs;
}
/*
function: get_by_name
args: $name
[$tsuite_name]: name of parent test suite
[$tproject_name]
returns: hash
@internal revisions
20100831 - franciscom - BUGID 3729
*/
function get_by_name($name, $tsuite_name = '', $tproject_name = '')
{
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$recordset = null;
$filters_on = array('tsuite_name' => false, 'tproject_name' => false);
$field_size = config_get('field_size');
$tsuite_name = tlSubStr(trim($tsuite_name),0, $field_size->testsuite_name);
$tproject_name = tlSubStr(trim($tproject_name),0,$field_size->testproject_name);
$name = tlSubStr(trim($name), 0, $field_size->testcase_name);
$sql = "/* $debugMsg */ " .
" SELECT DISTINCT NH_TCASE.id,NH_TCASE.name,NH_TCASE_PARENT.id AS parent_id," .
" NH_TCASE_PARENT.name AS tsuite_name, TCV.tc_external_id " .
" FROM {$this->tables['nodes_hierarchy']} NH_TCASE, " .
" {$this->tables['nodes_hierarchy']} NH_TCASE_PARENT, " .
" {$this->tables['nodes_hierarchy']} NH_TCVERSIONS," .
" {$this->tables['tcversions']} TCV " .
" WHERE NH_TCASE.node_type_id = {$this->my_node_type} " .
" AND NH_TCASE.name = '{$this->db->prepare_string($name)}' " .
" AND TCV.id=NH_TCVERSIONS.id " .
" AND NH_TCVERSIONS.parent_id=NH_TCASE.id " .
" AND NH_TCASE_PARENT.id=NH_TCASE.parent_id ";
if($tsuite_name != "")
{
$sql .= " AND NH_TCASE_PARENT.name = '{$this->db->prepare_string($tsuite_name)}' " .
" AND NH_TCASE_PARENT.node_type_id = {$this->node_types_descr_id['testsuite']} ";
}
$recordset = $this->db->get_recordset($sql);
if(count($recordset) && $tproject_name != "")
{
list($tproject_info)=$this->tproject_mgr->get_by_name($tproject_name);
foreach($recordset as $idx => $tcase_info)
{
if( $this->get_testproject($tcase_info['id']) != $tproject_info['id'] )
{
unset($recordset[$idx]);
}
}
}
return $recordset;
}
/*
get array of info for every test case
without any kind of filter.
Every array element contains an assoc array with testcase info
*/
function get_all() {
$sql = " SELECT nodes_hierarchy.name, nodes_hierarchy.id
FROM {$this->tables['nodes_hierarchy']} nodes_hierarchy
WHERE nodes_hierarchy.node_type_id={$my_node_type}";
$recordset = $this->db->get_recordset($sql);
return $recordset;
}
/**
* Show Test Case
*
*
*/
function show(&$smarty,$guiObj,$identity,$grants,$opt=null) {
static $cfg;
static $reqMgr;
if(!$cfg) {
$cfg = config_get('spec_cfg');
$reqMgr = new requirement_mgr($this->db);
}
$status_ok = ($identity->id > 0);
if( !$status_ok ) {
throw new Exception(__METHOD__ . ' EXCEPTION: Test Case ID is invalid ( <= 0)' );
}
$my = array('opt' => array('getAttachments' => false));
$my['opt'] = array_merge($my['opt'],(array)$opt);
$id = $identity->id;
$idSet = (array)$id;
$idCard = new stdClass();
$idCard->tcase_id = intval($id);
$idCard->tproject_id = intval($identity->tproject_id);
$idCard->tcversion_id = isset($identity->version_id) ? $identity->version_id : self::ALL_VERSIONS;
$getVersionID = $idCard->tcversion_id;
$gui = $this->initShowGui($guiObj,$grants,$idCard);
$userIDSet = array();
if($status_ok && sizeof($idSet)) {
$cfPlaces = $this->buildCFLocationMap();
$gui->linked_versions = null;
$gopt = array('renderGhost' => true, 'withGhostString' => true,
'renderImageInline' => true, 'renderVariables' => true,
'renderSpecialKW' => true,
'caller' => 'show()');
$cfx = 0;
$gui->otherVersionsKeywords = array();
$gui->fileUploadURL = array();
foreach($idSet as $key => $tc_id) {
// IMPORTANT NOTICE
// Deep Analysis is need to understand if there is an use case
// where this method really receive an array of test case ID.
//
// using an specific value for test case version id has sense
// only when we are working on ONE SPECIFIC Test Case.
//
// if we are working on a set of test cases, because this method
// does not manage in input couple of (test case, versio id),
// the only chance is to get ALL VERSIONS
//
if( !$tcvSet = $this->get_by_id($tc_id,$getVersionID,null,$gopt) ) {
continue;
}
if($cfg->show_tplan_usage) {
$gui->linked_versions[] = $this->get_linked_versions($tc_id);
}
// Position 0 is latest active version
$tcvSet[0]['tc_external_id'] =
$gui->tcasePrefix . $tcvSet[0]['tc_external_id'];
$tcvSet[0]['ghost'] =
sprintf(self::GHOSTMASK,$tcvSet[0]['tc_external_id'],$tcvSet[0]['version']);
// status quo of execution and links of tc versions
$gui->status_quo[] = $this->get_versions_status_quo($tc_id);
// Logic on Current/Latest Test Case Version
$tc_current = $tcvSet[0];
$tc_current['isTheLatest'] = 1;
$currentVersionID = $tc_current['id'];
$io = $idCard;
$io->tcversion_id = $currentVersionID;
$gui->delAttachmentURL = $_SESSION['basehref'] .
$this->getDeleteAttachmentByIDRelativeURL($io);
// Impacted for version management
$gui->fileUploadURL[$currentVersionID] =
$_SESSION['basehref'] . $this->getFileUploadRelativeURL($io);
$gui->tc_current_version[] = array($tc_current);
//
// REFACTORING - Following code uses tc_current!!!
//
// Get UserID and Updater ID for current Version
$userIDSet[$tc_current['author_id']] = null;
$userIDSet[$tc_current['updater_id']] = null;
$gui->req4current_version =
$reqMgr->getGoodForTCVersion($currentVersionID);
$gui->currentVersionKeywords =
$this->getKeywords($tc_id,$currentVersionID);
$whoami = array('tcase_id' => $tc_id,
'tcversion_id' => $currentVersionID);
$of = array('output' => 'html_options','add_blank' => true);
$gui->currentVersionFreeKeywords = $this->getFreeKeywords($whoami,$of);
if( $my['opt']['getAttachments'] ) {
$gui->attachments[$currentVersionID] =
getAttachmentInfosFrom($this,$currentVersionID);
}
// get linked testcase scripts
if($gui->codeTrackerEnabled) {
$scripts = $this->getScriptsForTestCaseVersion($gui->cts,$currentVersionID);
if(!is_null($scripts)) {
$gui->scripts[$currentVersionID] = $scripts;
}
}
if($this->cfg->testcase->relations->enable) {
$xm = array('tcase_id' => $tc_id, 'tcversion_id' => $currentVersionID);
$gui->relationSet[] = $this->getTCVersionRelations($xm);
}
$cfCtx = array('scope' => 'design','tproject_id' => $gui->tproject_id,'link_id' => $tc_current['id']);
foreach($cfPlaces as $cfpKey => $cfpFilter) {
$gui->cf_current_version[$cfx][$cfpKey] =
$this->htmlTableOfCFValues($tc_id,$cfCtx,$cfpFilter);
}
// Other versions (if exists)