* rev : * */ require_once '../../../config.inc.php'; require_once 'common.php'; testlinkInitPage($db); echo "<pre> testsuite - constructor - testsuite(&\$db)"; echo "</pre>"; $tsuite_mgr = new testsuite($db); new dBug($tsuite_mgr); $tsuite_name = 'Build Management'; echo "<pre> testsuite - get_by_name(\$name)"; echo "</pre>"; echo "<pre> get_by_name({$tsuite_name})"; echo "</pre>"; $tsuite_info = $tsuite_mgr->get_by_name($tsuite_name); new dBug($tsuite_info); die; $tsuite_id = 689; echo "<pre> testsuite - get_children(\$id)"; echo "</pre>"; echo "<pre> get_children({$tsuite_id})"; echo "</pre>"; $tsuite_info = $tsuite_mgr->get_children($tsuite_id); new dBug($tsuite_info); $tsuite_id = 676; echo "<pre> testsuite - get_by_id(\$id)"; echo "</pre>"; echo "<pre> get_by_id({$tsuite_id})"; echo "</pre>"; $tsuite_info = $tsuite_mgr->get_by_id($tsuite_id);
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; }
function importTestSuitesFromSimpleXML(&$dbHandler, &$xml, $parentID, $tproject_id, $userID, $kwMap, $importIntoProject = 0, $duplicateLogic) { static $tsuiteXML; static $tsuiteMgr; static $myself; static $callCounter = 0; $resultMap = array(); // $callCounter++; if (is_null($tsuiteXML)) { $tsuiteXML = array(); $tsuiteXML['elements'] = array('string' => array("details"), 'integer' => array("node_order")); $tsuiteXML['attributes'] = array('string' => array("name")); $tsuiteMgr = new testsuite($dbHandler); $myself = __FUNCTION__; } 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']); $tsuiteID = $ret['id']; } else { $tsuiteID = $info[0]['id']; $ret = $tsuiteMgr->update($tsuiteID, $tsuite['name'], $tsuite['details'], null, $tsuite['node_order']); } unset($tsuite); unset($dummy); if (!$tsuiteID) { return null; } } else { if ($importIntoProject) { $tsuiteID = $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)); // 20100904 - francisco.mancardi@gruppotesi.com // echo 'Going to work on Test Case INSIDE Test Suite:' . $tsuite['name'] . '<br>'; $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; // do not understand why we need to do this particular logic. // Need to understand // do not understand why we need to do this particular logic. // Need to understand case 'details': if (!$importIntoProject) { $keywords = getKeywordsFromSimpleXMLObj($target->xpath("//keyword")); if ($keywords) { $kwIDs = buildKeywordList($kwMap, $keywords); $tsuiteMgr->addKeywords($tsuiteID, $kwIDs); } } break; } } } return $resultMap; }