function exportTestCaseDataToXML($tcase_id, $tcversion_id, $tproject_id = null, $bNoXMLHeader = false, $optExport = array()) { static $reqMgr; static $keywordMgr; static $cfieldMgr; if (is_null($reqMgr)) { $reqMgr = new requirement_mgr($this->db); $keywordMgr = new tlKeyword(); $cfieldMgr = new cfield_mgr($this->db); } // Useful when you need to get info but do not have tcase id $tcase_id = intval((int) $tcase_id); $tcversion_id = intval((int) $tcversion_id); if ($tcase_id <= 0 && $tcversion_id > 0) { $info = $this->tree_manager->get_node_hierarchy_info($tcversion_id); $tcase_id = $info['parent_id']; } $tc_data = $this->get_by_id($tcase_id, $tcversion_id); $testCaseVersionID = $tc_data[0]['id']; if (!$tproject_id) { $tproject_id = $this->getTestProjectFromTestCase($tcase_id); } if (isset($optExport['CFIELDS']) && $optExport['CFIELDS']) { $cfMap = $this->get_linked_cfields_at_design($tcase_id, $testCaseVersionID, null, null, $tproject_id); // ||yyy||-> tags, {{xxx}} -> attribute // tags and attributes receive different treatment on exportDataToXML() // // each UPPER CASE word in this map KEY, MUST HAVE AN OCCURENCE on $elemTpl // value is a key inside $tc_data[0] // if (!is_null($cfMap) && count($cfMap) > 0) { // $cfRootElem = "<custom_fields>{{XMLCODE}}</custom_fields>"; // $cfElemTemplate = "\t" . "<custom_field>\n" . // "\t<name><![CDATA[||NAME||]]></name>\n" . // "\t<value><![CDATA[||VALUE||]]></value>\n</custom_field>\n"; // $cfDecode = array ("||NAME||" => "name","||VALUE||" => "value"); // $tc_data[0]['xmlcustomfields'] = $cfieldMgr->exportDataToXML($cfMap,$cfRootElem,$cfElemTemplate,$cfDecode,true); $tc_data[0]['xmlcustomfields'] = $cfieldMgr->exportValueAsXML($cfMap); } } if (isset($optExport['KEYWORDS']) && $optExport['KEYWORDS']) { $keywords = $this->getKeywords($tcase_id); if (!is_null($keywords)) { $xmlKW = "<keywords>" . $keywordMgr->toXMLString($keywords, true) . "</keywords>"; $tc_data[0]['xmlkeywords'] = $xmlKW; } } if (isset($optExport['REQS']) && $optExport['REQS']) { $requirements = $reqMgr->get_all_for_tcase($tcase_id); if (!is_null($requirements) && count($requirements) > 0) { $reqRootElem = "\t<requirements>\n{{XMLCODE}}\t</requirements>\n"; $reqElemTemplate = "\t\t<requirement>\n" . "\t\t\t<req_spec_title><![CDATA[||REQ_SPEC_TITLE||]]></req_spec_title>\n" . "\t\t\t<doc_id><![CDATA[||REQ_DOC_ID||]]></doc_id>\n" . "\t\t\t<title><![CDATA[||REQ_TITLE||]]></title>\n" . "\t\t</requirement>\n"; $reqDecode = array("||REQ_SPEC_TITLE||" => "req_spec_title", "||REQ_DOC_ID||" => "req_doc_id", "||REQ_TITLE||" => "title"); $tc_data[0]['xmlrequirements'] = exportDataToXML($requirements, $reqRootElem, $reqElemTemplate, $reqDecode, true); } } // ------------------------------------------------------------------------------------ $stepRootElem = "<steps>{{XMLCODE}}</steps>"; $stepTemplate = "\n" . '<step>' . "\n" . "\t<step_number><![CDATA[||STEP_NUMBER||]]></step_number>\n" . "\t<actions><![CDATA[||ACTIONS||]]></actions>\n" . "\t<expectedresults><![CDATA[||EXPECTEDRESULTS||]]></expectedresults>\n" . "\t<execution_type><![CDATA[||EXECUTIONTYPE||]]></execution_type>\n" . "</step>\n"; $stepInfo = array("||STEP_NUMBER||" => "step_number", "||ACTIONS||" => "actions", "||EXPECTEDRESULTS||" => "expected_results", "||EXECUTIONTYPE||" => "execution_type"); $stepSet = $tc_data[0]['steps']; $xmlsteps = exportDataToXML($stepSet, $stepRootElem, $stepTemplate, $stepInfo, true); $tc_data[0]['xmlsteps'] = $xmlsteps; // ------------------------------------------------------------------------------------ $rootElem = "{{XMLCODE}}"; if (isset($optExport['ROOTELEM'])) { $rootElem = $optExport['ROOTELEM']; } $elemTpl = "\n" . '<testcase internalid="{{TESTCASE_ID}}" name="{{NAME}}">' . "\n" . "\t<node_order><![CDATA[||NODE_ORDER||]]></node_order>\n"; if (!isset($optExport['EXTERNALID']) || $optExport['EXTERNALID']) { $elemTpl .= "\t<externalid><![CDATA[||EXTERNALID||]]></externalid>\n"; } $elemTpl .= "\t<version><![CDATA[||VERSION||]]></version>\n" . "\t<summary><![CDATA[||SUMMARY||]]></summary>\n" . "\t<preconditions><![CDATA[||PRECONDITIONS||]]></preconditions>\n" . "\t<execution_type><![CDATA[||EXECUTIONTYPE||]]></execution_type>\n" . "\t<importance><![CDATA[||IMPORTANCE||]]></importance>\n" . "\t<estimated_exec_duration>||ESTIMATED_EXEC_DURATION||</estimated_exec_duration>\n" . "\t<status>||STATUS||</status>\n" . "||STEPS||\n" . "||KEYWORDS||||CUSTOMFIELDS||||REQUIREMENTS||</testcase>\n"; // ||yyy||-> tags, {{xxx}} -> attribute // tags and attributes receive different treatment on exportDataToXML() // // each UPPER CASE word in this map KEY, MUST HAVE AN OCCURENCE on $elemTpl // value is a key inside $tc_data[0] // $info = array("{{TESTCASE_ID}}" => "testcase_id", "{{NAME}}" => "name", "||NODE_ORDER||" => "node_order", "||EXTERNALID||" => "tc_external_id", "||VERSION||" => "version", "||SUMMARY||" => "summary", "||PRECONDITIONS||" => "preconditions", "||EXECUTIONTYPE||" => "execution_type", "||IMPORTANCE||" => "importance", "||ESTIMATED_EXEC_DURATION||" => "estimated_exec_duration", "||STATUS||" => "status", "||STEPS||" => "xmlsteps", "||KEYWORDS||" => "xmlkeywords", "||CUSTOMFIELDS||" => "xmlcustomfields", "||REQUIREMENTS||" => "xmlrequirements"); $xmlTC = exportDataToXML($tc_data, $rootElem, $elemTpl, $info, $bNoXMLHeader); return $xmlTC; }