function importTestSuitesFromSimpleXML(&$dbHandler, &$xml, $parentID, $tproject_id, $userID, $kwMap, $importIntoProject = 0, $duplicateLogic) { static $tsuiteXML; static $tsuiteMgr; static $myself; static $callCounter = 0; static $cfSpec; static $doCF; $resultMap = array(); if (is_null($tsuiteXML)) { $myself = __FUNCTION__; $tsuiteXML = array(); $tsuiteXML['elements'] = array('string' => array("details" => null), 'integer' => array("node_order" => null)); $tsuiteXML['attributes'] = array('string' => array("name" => 'trim')); $tsuiteMgr = new testsuite($dbHandler); $doCF = !is_null($cfSpec = $tsuiteMgr->get_linked_cfields_at_design(null, null, null, $tproject_id, 'name')); } if ($xml->getName() == 'testsuite') { // getItemsFromSimpleXMLObj() first argument must be an array $dummy = getItemsFromSimpleXMLObj(array($xml), $tsuiteXML); $tsuite = current($dummy); $tsuiteID = $parentID; // hmmm, not clear if ($tsuite['name'] != "") { // Check if Test Suite with this name exists on this container // if yes -> update instead of create $info = $tsuiteMgr->get_by_name($tsuite['name'], $parentID); if (is_null($info)) { $ret = $tsuiteMgr->create($parentID, $tsuite['name'], $tsuite['details'], $tsuite['node_order']); $tsuite['id'] = $ret['id']; } else { $ret = $tsuiteMgr->update($tsuite['id'] = $info[0]['id'], $tsuite['name'], $tsuite['details'], null, $tsuite['node_order']); } unset($dummy); $tsuiteID = $tsuite['id']; // $tsuiteID is needed on more code pieces => DO NOT REMOVE if (!$tsuite['id']) { return null; } if ($doCF) { $cf = getCustomFieldsFromSimpleXMLObj($xml->custom_fields->custom_field); if (!is_null($cf)) { processTestSuiteCF($tsuiteMgr, $xml, $cfSpec, $cf, $tsuite, $tproject_id); } } if ($keywords = getKeywordsFromSimpleXMLObj($xml->keywords->keyword)) { $kwIDs = buildKeywordList($kwMap, $keywords); $tsuiteMgr->addKeywords($tsuite['id'], $kwIDs); } unset($tsuite); } else { if ($importIntoProject) { $tsuiteID = intval($tproject_id); } } $childrenNodes = $xml->children(); $loop2do = sizeof($childrenNodes); for ($idx = 0; $idx < $loop2do; $idx++) { $target = $childrenNodes[$idx]; switch ($target->getName()) { case 'testcase': // getTestCaseSetFromSimpleXMLObj() first argument must be an array $tcData = getTestCaseSetFromSimpleXMLObj(array($target)); $resultMap = array_merge($resultMap, saveImportedTCData($dbHandler, $tcData, $tproject_id, $tsuiteID, $userID, $kwMap, $duplicateLogic)); unset($tcData); break; case 'testsuite': $resultMap = array_merge($resultMap, $myself($dbHandler, $target, $tsuiteID, $tproject_id, $userID, $kwMap, $importIntoProject, $duplicateLogic)); break; // Important Development Notice // Due to XML file structure, while looping // we will find also this children: // node_order,keywords,custom_fields,details // // It's processing to get and save values is done // on other pieces of this code. // // Form a logical point of view seems the better // to consider and process here testcase and testsuite as children. // } } } return $resultMap; }
/** * * */ private function exportTestSuiteDataToXML($container, $tproject_id, $tplan_id, $platform_id) { static $keywordMgr; static $getLastVersionOpt = array('output' => 'minimun'); static $tcaseMgr; static $tsuiteMgr; static $tcaseExportOptions; static $linkedItems; if (is_null($keywordMgr)) { $tcaseExportOptions = array('CFIELDS' => true, 'KEYWORDS' => true, 'EXEC_ORDER' => 0); $keywordMgr = new tlKeyword(); $tsuiteMgr = new testsuite($this->db); $linkedItems = $this->getLinkedItems($tplan_id); } $xmlTC = null; $cfXML = null; $kwXML = null; if (isset($container['id'])) { $kwMap = $tsuiteMgr->getKeywords($container['id']); if ($kwMap) { $kwXML = "<keywords>" . $keywordMgr->toXMLString($kwMap, true) . "</keywords>"; } $cfMap = (array) $tsuiteMgr->get_linked_cfields_at_design($container['id'], null, null, $tproject_id); if (count($cfMap) > 0) { $cfXML = $this->cfield_mgr->exportValueAsXML($cfMap); } $tsuiteData = $tsuiteMgr->get_by_id($container['id']); $xmlTC = "\n\t<testsuite name=\"" . htmlspecialchars($tsuiteData['name']) . '" >' . "\n\t\t<node_order><![CDATA[{$tsuiteData['node_order']}]]></node_order>" . "\n\t\t<details><![CDATA[{$tsuiteData['details']}]]>" . "\n\t\t{$kwXML}{$cfXML}</details>"; } $childNodes = isset($container['childNodes']) ? $container['childNodes'] : null; if (!is_null($childNodes)) { $loop_qty = sizeof($childNodes); for ($idx = 0; $idx < $loop_qty; $idx++) { $cNode = $childNodes[$idx]; switch ($cNode['node_table']) { case 'testsuites': $xmlTC .= $this->exportTestSuiteDataToXML($cNode, $tproject_id, $tplan_id, $platform_id); break; case 'testcases': if (is_null($tcaseMgr)) { $tcaseMgr = new testcase($this->db); } // testcase::LATEST_VERSION, $tcaseExportOptions['EXEC_ORDER'] = $linkedItems[$cNode['id']][$platform_id]['node_order']; $xmlTC .= $tcaseMgr->exportTestCaseDataToXML($cNode['id'], $cNode['tcversion_id'], $tproject_id, testcase::NOXMLHEADER, $tcaseExportOptions); break; } } } if (isset($container['id'])) { $xmlTC .= "</testsuite>"; } return $xmlTC; }
$tcversion_id=5; $tplan_id=8; echo "<pre> testsuite - get_version_exec_assignment(\$tcversion_id,\$tplan_id)";echo "</pre>"; echo "<pre> get_version_exec_assignment($tcversion_id,$tplan_id)";echo "</pre>"; $version_exec_assignment=$tsuite_mgr->get_version_exec_assignment($tcversion_id,$tplan_id); new dBug($version_exec_assignment); */ echo "<pre> testsuite - get_linked_cfields_at_design(\$id,\$parent_id=null,\$show_on_execution=null)"; echo "</pre>"; echo "<pre> get_linked_cfields_at_design({$tsuite_id})"; echo "</pre>"; $linked_cfields_at_design = $tsuite_mgr->get_linked_cfields_at_design($tsuite_id); new dBug($linked_cfields_at_design); echo "<pre> testsuite - get_linked_cfields_at_execution(\$id,\$parent_id=null,<br>\r\n \$show_on_execution=null,<br>\r\n \$execution_id=null,\$testplan_id=null)"; echo "</pre>"; echo "<pre> get_linked_cfields_at_execution({$tsuite_id})"; echo "</pre>"; $linked_cfields_at_execution = $tsuite_mgr->get_linked_cfields_at_execution($tsuite_id); new dBug($linked_cfields_at_execution); echo "<pre> testsuite - html_table_of_custom_field_inputs(\$id,\$parent_id=null,\$scope='design',\$name_suffix='')"; echo "</pre>"; echo "<pre> html_table_of_custom_field_inputs({$tsuite_id})"; echo "</pre>"; $table_of_custom_field_inputs = $tsuite_mgr->html_table_of_custom_field_inputs($tsuite_id); echo "<pre>"; echo $table_of_custom_field_inputs; echo "</pre>";