-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportPythonFile.php
111 lines (93 loc) · 3.3 KB
/
exportPythonFile.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
<?php
/* @file exportPythonFile.php
* @brief Allow to write the Python File using the TestCase ID and the Test Plan XML File
* From TestLink 1.9.12 XML TestSuite export
* @author Samuel Salas (2015)
* @version 01.01
*/
header('content-type: plain/text; charset=utf-8');
/* Receiving GET info */
header("Content-Disposition: attachment; filename=".(string) $_GET["filename"]);
$fichier = $_GET["path"];
$testCaseId = (int) $_GET["testcaseid"];
$testCaseId_str = (string) $_GET["testcaseid"];
$testSuiteId = (int) $_GET["testsuiteid"];
$testSuiteId_str = (string) $_GET["testsuiteid"];
/* Reading Decription XML */
$python = simplexml_load_file($fichier);
// ----------------------------
// Global functions
// ----------------------------
/** @brief Return string without tags and special chars
* @param $comment string to process
* @return Return the string without the special char in the array
*/
function extract_tagsAndSpecialChar($comment) {
$tag = array("<p>", "</p>", "\n", "\t");
return str_replace($tag, "", $comment);
}
// ----------------------------
// TEXT format functions
// ----------------------------
function function_python($word) {
return "\tdef "
.$word
."(self):\n";
}
function class_python($word) {
return "class "
.$word
."(object):\n";
}
function comment_file_python($word) {
$retVal = '""" '."\n"
.' '.$word."\n"
.'"""'."\n";
return $retVal;
}
function comment_class_python($word) {
$retVal = "\t".'""" '.$word."\n"
."\t".'"""'."\n";
return $retVal;
}
function comment_def_python($word) {
$retVal = "\t\t".'""" '.rtrim($word)."\n"
."\t\t".'"""'."\n";
return $retVal;
}
// ----------------------------
// MAIN : writing the file
// ----------------------------
include("headerPython.txt");
// Loop on the test suites
foreach($python->testsuites->testsuite as $suite) {
// filtering with the test suite node order
if(((int) $suite->node_order == $testSuiteId)||($testSuiteId_str == "all")) {
echo comment_file_python($suite["name"]);
// Loop on the test case (
foreach($suite->testcase as $case) {
// Filtering with the test case ID
if(($case["internalid"] == $testCaseId_str)||($testCaseId_str == "all")) {
echo class_python("TestCase".$case['internalid']);
echo comment_class_python($case["name"]);
echo function_python("__init__");
echo comment_def_python("Initialization of the class");
echo "\t\tpass\n\n";
echo function_python("setUp");
echo comment_def_python("Put here actions before the first test case");
echo "\t\tpass\n\n";
echo function_python("tearDown");
echo comment_def_python("Put here actions after the last test case");
echo "\t\tpass\n\n";
foreach($case->steps->step as $step) {
echo function_python("test_".(string) $step->step_number);
$tmpStr = extract_tagsAndSpecialChar((string) $step->actions);
echo comment_def_python($tmpStr);
echo "\t\tasset False #Expected result ".extract_tagsAndSpecialChar((string) $step->expectedresults);
echo "\n\n";
}
}
}
}
}
?>