* **/ require_once "../../config.inc.php"; require_once "common.php"; require_once "csv.inc.php"; require_once "xml.inc.php"; testlinkInitPage($db); $templateCfg = templateConfiguration(); $args = init_args($db); checkRights($db, $_SESSION['currentUser'], $args); switch ($args->doAction) { case "do_export": $op = do_export($db, $smarty, $args); break; } $keyword = new tlKeyword(); $gui = new stdClass(); $gui->tproject_id = $args->tproject_id; $gui->exportTypes = $keyword->getSupportedSerializationInterfaces(); $gui->action_descr = lang_get('export_keywords'); $gui->main_descr = lang_get('testproject') . TITLE_SEP . $args->tproject_name; $gui->export_filename = is_null($args->export_filename) ? $args->tproject_name . '-keywords.xml' : $args->export_filename; $smarty = new TLSmarty(); $smarty->assign('gui', $gui); $smarty->display($templateCfg->template_dir . $templateCfg->default_template); function init_args(&$dbHandler) { $_REQUEST = strings_stripSlashes($_REQUEST); $args = new stdClass(); $iParams = array("doAction" => array(tlInputParameter::STRING_N, 0, 50), "export_filename" => array(tlInputParameter::STRING_N, 0, 255), "exportType" => array(tlInputParameter::STRING_N, 0, 255), "tproject_id" => array(tlInputParameter::INT_N)); R_PARAMS($iParams, $args);
function exportTestCaseDataToXML($tcase_id, $tcversion_id, $tproject_id = null, $bNoXMLHeader = false, $optExport = array()) { static $reqMgr; static $keywordMgr; static $cfieldMgr; if (is_null($reqMgr)) { $reqMgr = new requirement_mgr($this->db); $keywordMgr = new tlKeyword(); $cfieldMgr = new cfield_mgr($this->db); } // Useful when you need to get info but do not have tcase id $tcase_id = intval((int) $tcase_id); $tcversion_id = intval((int) $tcversion_id); if ($tcase_id <= 0 && $tcversion_id > 0) { $info = $this->tree_manager->get_node_hierarchy_info($tcversion_id); $tcase_id = $info['parent_id']; } $tc_data = $this->get_by_id($tcase_id, $tcversion_id); $testCaseVersionID = $tc_data[0]['id']; if (!$tproject_id) { $tproject_id = $this->getTestProjectFromTestCase($tcase_id); } if (isset($optExport['CFIELDS']) && $optExport['CFIELDS']) { $cfMap = $this->get_linked_cfields_at_design($tcase_id, $testCaseVersionID, null, null, $tproject_id); // ||yyy||-> tags, {{xxx}} -> attribute // tags and attributes receive different treatment on exportDataToXML() // // each UPPER CASE word in this map KEY, MUST HAVE AN OCCURENCE on $elemTpl // value is a key inside $tc_data[0] // if (!is_null($cfMap) && count($cfMap) > 0) { // $cfRootElem = "<custom_fields>{{XMLCODE}}</custom_fields>"; // $cfElemTemplate = "\t" . "<custom_field>\n" . // "\t<name><![CDATA[||NAME||]]></name>\n" . // "\t<value><![CDATA[||VALUE||]]></value>\n</custom_field>\n"; // $cfDecode = array ("||NAME||" => "name","||VALUE||" => "value"); // $tc_data[0]['xmlcustomfields'] = $cfieldMgr->exportDataToXML($cfMap,$cfRootElem,$cfElemTemplate,$cfDecode,true); $tc_data[0]['xmlcustomfields'] = $cfieldMgr->exportValueAsXML($cfMap); } } if (isset($optExport['KEYWORDS']) && $optExport['KEYWORDS']) { $keywords = $this->getKeywords($tcase_id); if (!is_null($keywords)) { $xmlKW = "<keywords>" . $keywordMgr->toXMLString($keywords, true) . "</keywords>"; $tc_data[0]['xmlkeywords'] = $xmlKW; } } if (isset($optExport['REQS']) && $optExport['REQS']) { $requirements = $reqMgr->get_all_for_tcase($tcase_id); if (!is_null($requirements) && count($requirements) > 0) { $reqRootElem = "\t<requirements>\n{{XMLCODE}}\t</requirements>\n"; $reqElemTemplate = "\t\t<requirement>\n" . "\t\t\t<req_spec_title><![CDATA[||REQ_SPEC_TITLE||]]></req_spec_title>\n" . "\t\t\t<doc_id><![CDATA[||REQ_DOC_ID||]]></doc_id>\n" . "\t\t\t<title><![CDATA[||REQ_TITLE||]]></title>\n" . "\t\t</requirement>\n"; $reqDecode = array("||REQ_SPEC_TITLE||" => "req_spec_title", "||REQ_DOC_ID||" => "req_doc_id", "||REQ_TITLE||" => "title"); $tc_data[0]['xmlrequirements'] = exportDataToXML($requirements, $reqRootElem, $reqElemTemplate, $reqDecode, true); } } // ------------------------------------------------------------------------------------ $stepRootElem = "<steps>{{XMLCODE}}</steps>"; $stepTemplate = "\n" . '<step>' . "\n" . "\t<step_number><![CDATA[||STEP_NUMBER||]]></step_number>\n" . "\t<actions><![CDATA[||ACTIONS||]]></actions>\n" . "\t<expectedresults><![CDATA[||EXPECTEDRESULTS||]]></expectedresults>\n" . "\t<execution_type><![CDATA[||EXECUTIONTYPE||]]></execution_type>\n" . "</step>\n"; $stepInfo = array("||STEP_NUMBER||" => "step_number", "||ACTIONS||" => "actions", "||EXPECTEDRESULTS||" => "expected_results", "||EXECUTIONTYPE||" => "execution_type"); $stepSet = $tc_data[0]['steps']; $xmlsteps = exportDataToXML($stepSet, $stepRootElem, $stepTemplate, $stepInfo, true); $tc_data[0]['xmlsteps'] = $xmlsteps; // ------------------------------------------------------------------------------------ $rootElem = "{{XMLCODE}}"; if (isset($optExport['ROOTELEM'])) { $rootElem = $optExport['ROOTELEM']; } $elemTpl = "\n" . '<testcase internalid="{{TESTCASE_ID}}" name="{{NAME}}">' . "\n" . "\t<node_order><![CDATA[||NODE_ORDER||]]></node_order>\n"; if (!isset($optExport['EXTERNALID']) || $optExport['EXTERNALID']) { $elemTpl .= "\t<externalid><![CDATA[||EXTERNALID||]]></externalid>\n"; } $elemTpl .= "\t<version><![CDATA[||VERSION||]]></version>\n" . "\t<summary><![CDATA[||SUMMARY||]]></summary>\n" . "\t<preconditions><![CDATA[||PRECONDITIONS||]]></preconditions>\n" . "\t<execution_type><![CDATA[||EXECUTIONTYPE||]]></execution_type>\n" . "\t<importance><![CDATA[||IMPORTANCE||]]></importance>\n" . "\t<estimated_exec_duration>||ESTIMATED_EXEC_DURATION||</estimated_exec_duration>\n" . "\t<status>||STATUS||</status>\n" . "||STEPS||\n" . "||KEYWORDS||||CUSTOMFIELDS||||REQUIREMENTS||</testcase>\n"; // ||yyy||-> tags, {{xxx}} -> attribute // tags and attributes receive different treatment on exportDataToXML() // // each UPPER CASE word in this map KEY, MUST HAVE AN OCCURENCE on $elemTpl // value is a key inside $tc_data[0] // $info = array("{{TESTCASE_ID}}" => "testcase_id", "{{NAME}}" => "name", "||NODE_ORDER||" => "node_order", "||EXTERNALID||" => "tc_external_id", "||VERSION||" => "version", "||SUMMARY||" => "summary", "||PRECONDITIONS||" => "preconditions", "||EXECUTIONTYPE||" => "execution_type", "||IMPORTANCE||" => "importance", "||ESTIMATED_EXEC_DURATION||" => "estimated_exec_duration", "||STATUS||" => "status", "||STEPS||" => "xmlsteps", "||KEYWORDS||" => "xmlkeywords", "||CUSTOMFIELDS||" => "xmlcustomfields", "||REQUIREMENTS||" => "xmlrequirements"); $xmlTC = exportDataToXML($tc_data, $rootElem, $elemTpl, $info, $bNoXMLHeader); return $xmlTC; }
function exportTestSuiteDataToXML($container_id, $tproject_id, $optExport = array()) { static $keywordMgr; if (is_null($keywordMgr)) { $keywordMgr = new tlKeyword(); } // echo __FUNCTION__ . '<br>'; $xmlTC = null; $doRecursion = isset($optExport['RECURSIVE']) ? $optExport['RECURSIVE'] : 0; if ($doRecursion) { $cfXML = null; $kwXML = null; $tsuiteData = $this->get_by_id($container_id); if (@$optExport['KEYWORDS']) { $kwMap = $this->getKeywords($container_id); if ($kwMap) { $kwXML = "<keywords>" . $keywordMgr->toXMLString($kwMap, true) . "</keywords>"; } } if ($optExport['CFIELDS']) { // 20090106 - franciscom - custom fields $cfMap = $this->get_linked_cfields_at_design($container_id, null, null, $tproject_id); if (!is_null($cfMap) && count($cfMap) > 0) { $cfRootElem = "<custom_fields>{{XMLCODE}}</custom_fields>"; $cfElemTemplate = "\t" . '<custom_field><name><![CDATA[' . "\n||NAME||\n]]>" . "</name>" . '<value><![CDATA[' . "\n||VALUE||\n]]>" . '</value></custom_field>' . "\n"; $cfDecode = array("||NAME||" => "name", "||VALUE||" => "value"); $cfXML = exportDataToXML($cfMap, $cfRootElem, $cfElemTemplate, $cfDecode, true); } } $xmlTC = "<testsuite name=\"" . htmlspecialchars($tsuiteData['name']) . '" >' . "\n<node_order><![CDATA[{$tsuiteData['node_order']}]]></node_order>\n" . "<details><![CDATA[{$tsuiteData['details']}]]> \n{$kwXML}{$cfXML}</details>"; } 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; 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); } } } } $xmlTC .= $doRecursion ? "</testsuite>" : "</testcases>"; return $xmlTC; }
$tproject = new testproject($db); $result = $tproject->{$pfn}($args->testproject_id, $dest); if ($result != tl::OK) { $msg = lang_get('wrong_keywords_file'); } else { header("Location: keywordsView.php"); exit; } } @unlink($dest); } } else { $msg = lang_get('please_choose_keywords_file'); } } $tlKeyword = new tlKeyword(); $importTypes = $tlKeyword->getSupportedSerializationInterfaces(); $formatStrings = $tlKeyword->getSupportedSerializationFormatDescriptions(); $file_size_limit = config_get('import_file_max_size_bytes'); $smarty = new TLSmarty(); $smarty->assign('import_type_selected', $args->importType); $smarty->assign('msg', $msg); $smarty->assign('keywordFormatStrings', $formatStrings); $smarty->assign('importTypes', $importTypes); $smarty->assign('tproject_name', $args->testproject_name); $smarty->assign('tproject_id', $args->testproject_id); $smarty->assign('fileSizeLimitMsg', sprintf(lang_get('max_file_size_is'), $file_size_limit / 1024 . ' KB ')); $smarty->assign('importLimit', $file_size_limit); $smarty->display($templateCfg->template_dir . $templateCfg->default_template); /** * @return object returns the arguments for the page
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; $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 name=\"" . htmlspecialchars($tsuiteData['name']) . '" >' . "\n<node_order><![CDATA[{$tsuiteData['node_order']}]]></node_order>\n" . "<details><![CDATA[{$tsuiteData['details']}]]> \n{$kwXML}{$cfXML}</details>"; } 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; 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); } } } } $xmlTC .= $doRecursion ? "</testsuite>" : "</testcases>"; return $xmlTC; }
/** * * */ 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; }
/** * Check if keyword name is not duplicated * * @param resource &$db [ref] database connection * * @return integer returns tl::OK on success, error code else */ protected function checkKeyword(&$db) { $this->name = trim($this->name); $this->notes = trim($this->notes); $result = tlKeyword::doesKeywordExist($db, $this->name, $this->testprojectID, $this->dbID); if ($result >= tl::OK) { $result = tlKeyword::checkKeywordName($this->name); } return $result; }
/** * @param $testproject_id * @param $simpleXMLObj */ function importKeywordsFromSimpleXML($testproject_id, $simpleXMLObj) { $status = tl::OK; if (!$simpleXMLObj || $simpleXMLObj->getName() != 'keywords') { $status = tlKeyword::E_WRONGFORMAT; } if ($status == tl::OK && $simpleXMLObj->keyword) { foreach ($simpleXMLObj->keyword as $keyword) { $kw = new tlKeyword(); $kw->initialize(null, $testproject_id, NULL, NULL); $status = tlKeyword::E_WRONGFORMAT; if ($kw->readFromSimpleXML($keyword) >= tl::OK) { $status = tl::OK; if ($kw->writeToDB($this->db) >= tl::OK) { logAuditEvent(TLS("audit_keyword_created", $kw->name), "CREATE", $kw->dbID, "keywords"); } } } } return $status; }
function renderTestSuiteForManagement(&$tplEngine, &$argsObj, &$guiObj, &$tsuiteMgr, $keywordSet, $userInput = null) { $guiObj->optionTransfer = tlKeyword::optionTransferGuiControl(); $guiObj->optionTransfer->setNewRightInputName('assigned_keyword_list'); $guiObj->optionTransfer->initFromPanel(null, lang_get('available_kword')); $guiObj->optionTransfer->initToPanel(null, lang_get('assigned_kword')); $guiObj->optionTransfer->setFromPanelContent($keywordSet['testproject']); $guiObj->optionTransfer->setToPanelContent($keywordSet['testsuite']); $guiObj->optionTransfer->updatePanelsContent($argsObj->assigned_keyword_list); $guiObj->optionTransferJSObject = json_encode($guiObj->optionTransfer->getHtmlInputNames()); $context = array('tproject_id' => $argsObj->tproject_id, 'parent_id' => $argsObj->containerID, 'id' => $argsObj->testsuiteID); $editorsObj = initWebEditors(); $tsuiteMgr->viewer_edit_new($tplEngine, $guiObj, $argsObj->action, $context, $editorsObj, null, $userInput); }
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; }
private function initKeywordGuiControl($argsObj, $userInput) { $widget = new stdClass(); $widget->optionTransfer = tlKeyword::optionTransferGuiControl(); $widget->optionTransfer->from->lbl = lang_get('available_kword'); $widget->optionTransfer->to->lbl = lang_get('assigned_kword'); $widget->optionTransfer->setNewRightInputName('assigned_keyword_list'); $widget->optionTransfer->initFromPanel(null, lang_get('available_kword')); $widget->optionTransfer->initToPanel(null, lang_get('assigned_kword')); $widget->optionTransfer->setFromPanelContent($this->keywordSet['testproject']); $widget->optionTransfer->setToPanelContent($this->keywordSet['testcase']); $inputNames = $widget->optionTransfer->getHtmlInputNames(); $toKeywordSet = isset($userInput[$inputNames->newRight]) ? $userInput[$inputNames->newRight] : ""; $widget->optionTransfer->updatePanelsContent($toKeywordSet); $widget->optionTransferJSObject = json_encode($inputNames); return array($widget->optionTransfer, $widget->optionTransferJSObject); }