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; }
/** * * * @internal revisions * 20100317 - added internalid - BUGID 3236 */ function getTestCaseSetFromSimpleXMLObj($xmlTCs) { $tcSet = null; if (!$xmlTCs) { return $tcSet; } $jdx = 0; $loops2do = sizeof($xmlTCs); $tcaseSet = array(); $tcXML['elements'] = array('string' => array("summary", "preconditions"), 'integer' => array("node_order", "externalid", "execution_type", "importance")); $tcXML['attributes'] = array('string' => array("name"), 'integer' => array('internalid')); for ($idx = 0; $idx < $loops2do; $idx++) { $dummy = getItemsFromSimpleXMLObj(array($xmlTCs[$idx]), $tcXML); $tc = $dummy[0]; if ($tc) { // Test Case Steps $steps = getStepsFromSimpleXMLObj($xmlTCs[$idx]->steps->step); $tc['steps'] = $steps; $keywords = getKeywordsFromSimpleXMLObj($xmlTCs[$idx]->keywords->keyword); if ($keywords) { $tc['keywords'] = $keywords; } $cf = getCustomFieldsFromSimpleXMLObj($xmlTCs[$idx]->custom_fields->custom_field); if ($cf) { $tc['customfields'] = $cf; } $requirements = getRequirementsFromSimpleXMLObj($xmlTCs[$idx]->requirements->requirement); if ($requirements) { $tc['requirements'] = $requirements; } } $tcaseSet[$jdx++] = $tc; } return $tcaseSet; }