function exportTestSuiteDataToXML($container_id, $tproject_id, $optExport = array()) { static $keywordMgr; static $getLastVersionOpt = array('output' => 'minimun'); static $tcase_mgr; if (is_null($keywordMgr)) { $keywordMgr = new tlKeyword(); } $xmlTC = null; $relCache = array(); $doRecursion = isset($optExport['RECURSIVE']) ? $optExport['RECURSIVE'] : 0; if ($doRecursion) { $cfXML = null; $kwXML = null; $tsuiteData = $this->get_by_id($container_id); if (isset($optExport['KEYWORDS']) && $optExport['KEYWORDS']) { $kwMap = $this->getKeywords($container_id); if ($kwMap) { $kwXML = "<keywords>" . $keywordMgr->toXMLString($kwMap, true) . "</keywords>"; } } if (isset($optExport['CFIELDS']) && $optExport['CFIELDS']) { $cfMap = (array) $this->get_linked_cfields_at_design($container_id, null, null, $tproject_id); if (count($cfMap) > 0) { $cfXML = $this->cfield_mgr->exportValueAsXML($cfMap); } } $xmlTC = '<testsuite id="' . $tsuiteData['id'] . '" ' . 'name="' . htmlspecialchars($tsuiteData['name']) . '" >' . "\n<node_order><![CDATA[{$tsuiteData['node_order']}]]></node_order>\n" . "<details><![CDATA[{$tsuiteData['details']}]]></details> \n{$kwXML}{$cfXML}"; } else { $xmlTC = "<testcases>"; } $test_spec = $this->get_subtree($container_id, self::USE_RECURSIVE_MODE); $childNodes = isset($test_spec['childNodes']) ? $test_spec['childNodes'] : null; $tcase_mgr = null; $relXmlData = ''; if (!is_null($childNodes)) { $loop_qty = sizeof($childNodes); for ($idx = 0; $idx < $loop_qty; $idx++) { $cNode = $childNodes[$idx]; $nTable = $cNode['node_table']; if ($doRecursion && $nTable == 'testsuites') { $xmlTC .= $this->exportTestSuiteDataToXML($cNode['id'], $tproject_id, $optExport); } else { if ($nTable == 'testcases') { if (is_null($tcase_mgr)) { $tcase_mgr = new testcase($this->db); } $xmlTC .= $tcase_mgr->exportTestCaseDataToXML($cNode['id'], testcase::LATEST_VERSION, $tproject_id, true, $optExport); // 20140816 // Collect and do cache of all test case relations that exists inside this test suite. $relSet = $tcase_mgr->getRelations($cNode['id']); if ($relSet['num_relations'] > 0) { foreach ($relSet['relations'] as $key => $rel) { // If we have already found this relation, skip it. if (!in_array($rel['id'], $relCache)) { $relXmlData .= $tcase_mgr->exportRelationToXML($rel, $relSet['item']); $relCache[] = $rel['id']; } } } } } } } // after we scanned all relations and exported all relations to xml, let's output it to the XML buffer $xmlTC .= $relXmlData; $xmlTC .= $doRecursion ? "</testsuite>" : "</testcases>"; return $xmlTC; }