/** * * * @internal revisions * 20100317 - added internalid - BUGID 3236 */ function getTestCaseSetFromIssueSimpleXMLObj($xmlObj) { $itemSet = null; if (!$xmlObj) { return $itemSet; } $l18n = init_labels(array('issue_issue' => null, 'issue_steps_to_reproduce' => null, 'issue_summary' => null, 'issue_target_version' => null, 'issue_description' => null, 'issue_additional_information' => null)); $jdx = 0; $xmlIssue = $xmlObj->issue; $loops2do = sizeof($xmlIssue); $XMLDef['elements'] = array('string' => array('summary' => null, 'description' => null, 'additional_information' => null, 'steps_to_reproduce' => null, 'target_version' => null, 'id' => null)); $itemSet = array(); $nl = "<p>"; for ($idx = 0; $idx < $loops2do; $idx++) { $dummy = getItemsFromSimpleXMLObj(array($xmlIssue[$idx]), $XMLDef); $dummy = $dummy[0]; $isum = $l18n['issue_description'] . $nl . $dummy['description']; if (!is_null($dummy['steps_to_reproduce'])) { $isum .= $nl . $l18n['issue_steps_to_reproduce'] . $nl . $dummy['steps_to_reproduce']; } if (!is_null($dummy['additional_information'])) { $isum .= $nl . $l18n['issue_additional_information'] . $nl . $dummy['additional_information']; } $itemSet[$jdx++] = array('name' => $l18n['issue_issue'] . ':' . $dummy['id'] . ' - ' . $dummy['summary'], 'summary' => $isum, 'steps' => null, 'internalid' => null, 'externalid' => null, 'author_login' => null, 'preconditions' => null); } return $itemSet; }
/** * */ function getFromMantisIssueSimpleXMLObj($xmlObj) { $itemSet = null; if (!$xmlObj) { return $itemSet; } $l18n = init_labels(array('issue_issue' => null, 'issue_steps_to_reproduce' => null, 'issue_summary' => null, 'issue_target_version' => null, 'issue_description' => null, 'issue_additional_information' => null)); $jdx = 0; $xmlIssue = $xmlObj->issue; $loops2do = sizeof($xmlIssue); $XMLDef['elements'] = array('string' => array('summary' => null, 'description' => null, 'additional_information' => null, 'steps_to_reproduce' => null, 'target_version' => null, 'id' => null)); $itemSet = array(); $nl = "<p>"; for ($idx = 0; $idx < $loops2do; $idx++) { $dummy = getItemsFromSimpleXMLObj(array($xmlIssue[$idx]), $XMLDef); $dummy = $dummy[0]; $isum = $l18n['issue_description'] . $nl . $dummy['description']; if (!is_null($dummy['steps_to_reproduce'])) { $isum .= $nl . $l18n['issue_steps_to_reproduce'] . $nl . $dummy['steps_to_reproduce']; } if (!is_null($dummy['additional_information'])) { $isum .= $nl . $l18n['issue_additional_information'] . $nl . $dummy['additional_information']; } $itemSet[$jdx++] = array('docid' => 'Mantis Task ID:' . $dummy['id'], 'title' => $l18n['issue_issue'] . ':' . $dummy['id'] . ' - ' . $dummy['summary'], 'description' => $isum, 'node_order' => $idx, 'status' => '', 'type' => '', 'expected_coverage' => 1); } return $itemSet; }
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; }
function importTestSuitesFromSimpleXML(&$dbHandler, &$xml, $parentID, $tproject_id, $userID, $kwMap, $importIntoProject = 0) { 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; if ($tsuite['name'] != "") { $ret = $tsuiteMgr->create($parentID, $tsuite['name'], $tsuite['details'], $tsuite['node_order']); $tsuiteID = $ret['id']; 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)); // TEST $resultMap = array_merge($resultMap, saveImportedTCData($dbHandler, $tcData, $tproject_id, $tsuiteID, $userID, $kwMap)); unset($tcData); break; case 'testsuite': $resultMap = array_merge($resultMap, $myself($dbHandler, $target, $tsuiteID, $tproject_id, $userID, $kwMap)); 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; }
function importExecutionFromXML(&$xmlTCExec) { if (!$xmlTCExec) { return null; } $execInfo = array(); $execInfo['tcase_id'] = isset($xmlTCExec["id"]) ? (int) $xmlTCExec["id"] : 0; $execInfo['tcase_external_id'] = (string) $xmlTCExec["external_id"]; // Developer Note - 20100328 - franciscom: // seems that no PHP error is generated when trying to access an undefined // property. Do not know if will not be better anyway to use property_exists() // $execInfo['tcase_name'] = (string) $xmlTCExec->name; $execInfo['result'] = (string) trim($xmlTCExec->result); $execInfo['notes'] = (string) trim($xmlTCExec->notes); $execInfo['timestamp'] = (string) trim($xmlTCExec->timestamp); $execInfo['tester'] = (string) trim($xmlTCExec->tester); $execInfo['execution_type'] = intval((int) trim($xmlTCExec->execution_type)); $execInfo['execution_duration'] = trim($xmlTCExec->execution_duration); $bugQty = count($xmlTCExec->bug_id); if (($bugQty = count($xmlTCExec->bug_id)) > 0) { foreach ($xmlTCExec->bug_id as $bug) { $execInfo['bug_id'][] = (string) $bug; // BUGID 3331 } } $execInfo['steps'] = null; if (property_exists($xmlTCExec, 'steps') && property_exists($xmlTCExec->steps, 'step')) { $itemStructure['elements'] = array('integer' => array("step_number" => 'intval'), 'string' => array("result" => 'trim', "notes" => 'trim')); $execInfo['steps'] = getItemsFromSimpleXMLObj($xmlTCExec->steps->step, $itemStructure); } $execInfo['custom_fields'] = null; if (property_exists($xmlTCExec, 'custom_fields') && property_exists($xmlTCExec->custom_fields, 'custom_field')) { $itemStructure['elements'] = array('string' => array("name" => 'trim', "value" => 'trim')); $execInfo['custom_fields'] = getItemsFromSimpleXMLObj($xmlTCExec->custom_fields->custom_field, $itemStructure); } return $execInfo; }