예제 #1
0
/**
 * @param object dbHandler reference to db handler
 *
 */
function doImport(&$dbHandler, $testproject_id)
{
    $import_msg = array('ok' => array(), 'ko' => array());
    $file_check = array('show_results' => 0, 'status_ok' => 0, 'msg' => '', 'filename' => '', 'import_msg' => $import_msg);
    $key = 'targetFilename';
    $dest = TL_TEMP_PATH . session_id() . "-import_platforms.tmp";
    $fInfo = $_FILES[$key];
    $source = isset($fInfo['tmp_name']) ? $fInfo['tmp_name'] : null;
    if ($source != 'none' && $source != '') {
        $file_check['filename'] = $fInfo['name'];
        $xml = false;
        if (move_uploaded_file($source, $dest)) {
            $xml = @simplexml_load_file($dest);
        }
        if ($xml !== FALSE) {
            $file_check['status_ok'] = 1;
            $file_check['show_results'] = 1;
            $platform_mgr = new tlPlatform($dbHandler, $testproject_id);
            $platformsOnSystem = $platform_mgr->getAllAsMap('name', 'rows');
            foreach ($xml as $platform) {
                // Check if platform with this name already exists on test Project
                // if answer is yes => update fields
                $name = trim($platform->name);
                if (isset($platformsOnSystem[$name])) {
                    $import_msg['ok'][] = sprintf(lang_get('platform_updated'), $platform->name);
                    $platform_mgr->update($platformsOnSystem[$name]['id'], $name, $platform->notes);
                } else {
                    $import_msg['ok'][] = sprintf(lang_get('platform_imported'), $platform->name);
                    $platform_mgr->create($name, $platform->notes);
                }
            }
        } else {
            $file_check['msg'] = lang_get('problems_loading_xml_content');
        }
    } else {
        $msg = getFileUploadErrorMessage($fInfo);
        $file_check = array('show_results' => 0, 'status_ok' => 0, 'msg' => $msg);
    }
    $file_check['import_msg'] = $import_msg;
    return $file_check;
}
예제 #2
0
 /**
  *
  */
 private function initShowGui($guiObj, $grantsObj, $id, $idCard)
 {
     $goo = is_null($guiObj) ? new stdClass() : $guiObj;
     $goo->execution_types = $this->execution_types;
     $goo->tcase_cfg = $this->cfg->testcase;
     $goo->import_limit = TL_REPOSITORY_MAXFILESIZE;
     $goo->msg = '';
     $goo->fileUploadMsg = '';
     $goo->fileUploadURL = $_SESSION['basehref'] . $this->getFileUploadRelativeURL($idCard);
     $goo->delAttachmentURL = $_SESSION['basehref'] . $this->getDeleteAttachmentRelativeURL($idCard);
     $goo->requirement_mgmt = property_exists($grantsObj, 'mgt_modify_req') ? $grantsObj->mgt_modify_req : null;
     if (is_null($goo->requirement_mgmt)) {
         $goo->requirement_mgmt = property_exists($grantsObj, 'requirement_mgmt') ? $grantsObj->requirement_mgmt : 0;
     }
     // some config options have been migrated to rights
     // In order to refactor less code, we will remap to OLD config options present on config file.
     $goo->tcase_cfg->can_edit_executed = $grantsObj->testproject_edit_executed_testcases == 'yes' ? 1 : 0;
     $goo->tcase_cfg->can_delete_executed = $grantsObj->testproject_delete_executed_testcases == 'yes' ? 1 : 0;
     $goo->view_req_rights = property_exists($grantsObj, 'mgt_view_req') ? $grantsObj->mgt_view_req : 0;
     $goo->parentTestSuiteName = '';
     $goo->tprojectName = '';
     $goo->submitCode = "";
     $goo->dialogName = '';
     $goo->bodyOnLoad = "";
     $goo->bodyOnUnload = "storeWindowSize('TCEditPopup')";
     $goo->tableColspan = 5;
     // sorry magic related to table to display steps
     $goo->tc_current_version = array();
     $goo->status_quo = array();
     $goo->keywords_map = array();
     $goo->arrReqs = array();
     $goo->cf_current_version = null;
     $goo->cf_other_versions = null;
     $goo->linked_versions = null;
     $goo->platforms = null;
     $viewer_defaults = array('title' => lang_get('title_test_case'), 'show_title' => 'no', 'action' => '', 'msg_result' => '', 'user_feedback' => '', 'refreshTree' => 1, 'disable_edit' => 0, 'display_testproject' => 0, 'display_parent_testsuite' => 0, 'hilite_testcase_name' => 0, 'show_match_count' => 0);
     $viewer_defaults = array_merge($viewer_defaults, (array) $guiObj->viewerArgs);
     $goo->display_testproject = $viewer_defaults['display_testproject'];
     $goo->display_parent_testsuite = $viewer_defaults['display_parent_testsuite'];
     $goo->show_title = $viewer_defaults['show_title'];
     $goo->hilite_testcase_name = $viewer_defaults['hilite_testcase_name'];
     $goo->action = $viewer_defaults['action'];
     $goo->user_feedback = $viewer_defaults['user_feedback'];
     $goo->pageTitle = $viewer_defaults['title'];
     $goo->display_testcase_path = !is_null($goo->path_info);
     $goo->show_match_count = $viewer_defaults['show_match_count'];
     if ($goo->show_match_count && $goo->display_testcase_path) {
         $goo->pageTitle .= '-' . lang_get('match_count') . ':' . ($goo->match_count = count($goo->path_info));
     }
     $goo->refreshTree = isset($goo->refreshTree) ? $goo->refreshTree : $viewer_defaults['refreshTree'];
     $goo->sqlResult = $viewer_defaults['msg_result'];
     // fine grain control of operations
     if ($viewer_defaults['disable_edit'] == 1 || $grantsObj->mgt_modify_tc == false) {
         $goo->show_mode = 'editDisabled';
     } else {
         if (!is_null($goo->show_mode) && $goo->show_mode == 'editOnExec') {
             // refers to two javascript functions present in testlink_library.js
             // and logic used to refresh both frames when user call this
             // method to edit a test case while executing it.
             $goo->dialogName = 'tcview_dialog';
             $goo->bodyOnLoad = "dialog_onLoad({$gui->dialogName})";
             $goo->bodyOnUnload = "dialog_onUnload({$gui->dialogName})";
             $goo->submitCode = "return dialog_onSubmit({$gui->dialogName})";
         }
     }
     $dummy = getConfigAndLabels('testCaseStatus', 'code');
     $goo->domainTCStatus = $dummy['lbl'];
     $goo->can_do = $this->getShowViewerActions($goo->show_mode);
     $path2root = $this->tree_manager->get_path($id);
     $goo->tproject_id = $path2root[0]['parent_id'];
     $info = $this->tproject_mgr->get_by_id($goo->tproject_id);
     $goo->requirementsEnabled = $info['opt']->requirementsEnabled;
     if ($goo->display_testproject) {
         $goo->tprojectName = $info['name'];
     }
     if ($goo->display_parent_testsuite) {
         $parent = count($path2root) - 2;
         $goo->parentTestSuiteName = $path2root[$parent]['name'];
     }
     $testplans = $this->tproject_mgr->get_all_testplans($goo->tproject_id, array('plan_status' => 1));
     $goo->has_testplans = !is_null($testplans) && count($testplans) > 0 ? 1 : 0;
     $platformMgr = new tlPlatform($this->db, $goo->tproject_id);
     $goo->platforms = $platformMgr->getAllAsMap();
     $goo->tcasePrefix = $this->tproject_mgr->getTestCasePrefix($goo->tproject_id) . $this->cfg->testcase->glue_character;
     return $goo;
 }
예제 #3
0
/**
 *
 *
 */
function processTestCase(&$dbHandler, $tplEngine, $args, &$gui, $grants, $cfg)
{
    $get_path_info = false;
    $item_mgr = new testcase($dbHandler);
    // has sense only when we work on test case
    $dummy = testcase::getLayout();
    $gui->tableColspan = $dummy->tableToDisplayTestCaseSteps->colspan;
    $gui->viewerArgs['refresh_tree'] = 'no';
    $gui->path_info = null;
    $gui->platforms = null;
    $gui->loadOnCancelURL = '';
    $gui->attachments = null;
    $gui->direct_link = null;
    $gui->steps_results_layout = $cfg['spec']->steps_results_layout;
    $gui->bodyOnUnload = "storeWindowSize('TCEditPopup')";
    if ($args->caller == 'navBar' && !is_null($args->targetTestCase) && strcmp($args->targetTestCase, $args->tcasePrefix) != 0) {
        $args->id = $item_mgr->getInternalID($args->targetTestCase);
        $args->tcversion_id = testcase::ALL_VERSIONS;
        // I've added $args->caller, in order to make clear the logic, because some actions need to be done ONLY
        // when we have arrived to this script because user has requested a search from navBar.
        // Before we have trusted the existence of certain variables (do not think this old kind of approach is good).
        //
        // why strcmp($args->targetTestCase,$args->tcasePrefix) ?
        // because in navBar targetTestCase is initialized with testcase prefix to provide some help to user
        // then if user request search without adding nothing, we will not be able to search.
        // From navBar we want to allow ONLY to search for ONE and ONLY ONE test case ID.
        $gui->viewerArgs['show_title'] = 'no';
        $gui->viewerArgs['display_testproject'] = 1;
        $gui->viewerArgs['display_parent_testsuite'] = 1;
        if (!($get_path_info = $args->id > 0)) {
            $gui->warning_msg = $args->id == 0 ? lang_get('testcase_does_not_exists') : lang_get('prefix_does_not_exists');
        }
    }
    // because we can arrive here from a User Search Request, if args->id == 0 => nothing found
    if ($args->id > 0) {
        if ($get_path_info || $args->show_path) {
            $gui->path_info = $item_mgr->tree_manager->get_full_path_verbose($args->id);
        }
        $platform_mgr = new tlPlatform($dbHandler, $args->tproject_id);
        $gui->platforms = $platform_mgr->getAllAsMap();
        $gui->attachments[$args->id] = getAttachmentInfosFrom($item_mgr, $args->id);
        $gui->direct_link = $item_mgr->buildDirectWebLink($_SESSION['basehref'], $args->id);
        $gui->id = $args->id;
        $identity = new stdClass();
        $identity->id = $args->id;
        $identity->tproject_id = $args->tproject_id;
        $identity->version_id = $args->tcversion_id;
        try {
            $item_mgr->show($tplEngine, $gui, $identity, $grants);
        } catch (Exception $e) {
            echo $e->getMessage();
        }
        exit;
    } else {
        $templateCfg = templateConfiguration();
        // need to initialize search fields
        $xbm = $item_mgr->getTcSearchSkeleton();
        $xbm->warning_msg = lang_get('no_records_found');
        $xbm->pageTitle = lang_get('caption_search_form');
        $xbm->tableSet = null;
        $xbm->doSearch = false;
        $xbm->tproject_id = $args->tproject_id;
        $tplEngine->assign('gui', $xbm);
        $tplEngine->display($templateCfg->template_dir . 'tcSearchResults.tpl');
    }
}
예제 #4
0
        // has been called from a test case search
        if (!is_null($args->targetTestCase) && strcmp($args->targetTestCase, $args->tcasePrefix) != 0) {
            $viewerArgs['show_title'] = 'no';
            $viewerArgs['display_testproject'] = 1;
            $viewerArgs['display_parent_testsuite'] = 1;
            $args->id = $item_mgr->getInternalID($args->targetTestCase);
            if (!($get_path_info = $args->id > 0)) {
                $gui->warning_msg = $args->id == 0 ? lang_get('testcase_does_not_exists') : lang_get('prefix_does_not_exists');
            }
        }
        if ($args->id > 0) {
            if ($get_path_info || $args->show_path) {
                $path_info = $item_mgr->tree_manager->get_full_path_verbose($args->id);
            }
            $platform_mgr = new tlPlatform($db, $args->tproject_id);
            $gui->platforms = $platform_mgr->getAllAsMap();
            $gui->attachments[$args->id] = getAttachmentInfosFrom($item_mgr, $args->id);
            $gui->direct_link = $item_mgr->buildDirectWebLink($_SESSION['basehref'], $args->id);
        }
        $gui->id = $args->id;
        $item_mgr->show($smarty, $gui, $templateCfg->template_dir, $args->id, $args->tcversion_id, $viewerArgs, $path_info, $args->show_mode);
        break;
    default:
        tLog('Argument "edit" has invalid value: ' . $args->feature, 'ERROR');
        trigger_error($_SESSION['currentUser']->login . '> Argument "edit" has invalid value.', E_USER_ERROR);
}
/**
 * 
 *
 */
function init_args(&$viewerCfg)
예제 #5
0
 /**
 	 * Show Test Case logic
 	 * 
 	 * @param object $smarty reference to smarty object (controls viewer).
 	 * @param integer $id Test case unique identifier
 	 * @param integer $version_id (optional) you can work on ONE test case version, 
 	 * 				or on ALL; default: ALL
 	 * 
 	 * @internal
         [viewer_args]: map with keys
 	                       action
 	                       msg_result
 	                       refresh_tree: controls if tree view is refreshed after every operation.
 	                                     default: yes
 	                       user_feedback
 	                       disable_edit: used to overwrite user rights
 	                                        default: 0 -> no
   returns:
   rev :
 	       20090215 - franciscom - added info about links to test plans
 	       
 	       20081114 - franciscom -
 	       added arguments and options that are useful when this method is
 	       used to display test case search results.
 	       path_info: map: key: testcase id
 	                       value: array with path to test case, where:
 	                              element 0 -> test project name
 	                              other elements test suites name
 	       
 	       new options on viewer_args: hilite_testcase_name,show_match_count
 	       
 	       20070930 - franciscom - REQ - BUGID 1078
 	       added disable_edit argument
 */
 function show(&$smarty, $guiObj, $template_dir, $id, $version_id = self::ALL_VERSIONS, $viewer_args = null, $path_info = null, $mode = null)
 {
     // echo 'DEBUG' . __FUNCTION__ . '<br>';
     $status_ok = 1;
     $gui = is_null($guiObj) ? new stdClass() : $guiObj;
     $gui->parentTestSuiteName = '';
     $gui->path_info = $path_info;
     $gui->tprojectName = '';
     $gui->linked_versions = null;
     $gui->tc_current_version = array();
     $gui->bodyOnLoad = "";
     // 20101008 - asimon - BUGID 3311
     $gui->bodyOnUnload = "storeWindowSize('TCEditPopup')";
     $gui->submitCode = "";
     $gui->dialogName = '';
     $gui->platforms = null;
     $gui->tableColspan = 5;
     // sorry magic related to table to display steps
     $gui->opt_requirements = false;
     $gui_cfg = config_get('gui');
     $the_tpl = config_get('tpl');
     $my_template = isset($the_tpl['tcView']) ? $the_tpl['tcView'] : 'tcView.tpl';
     $tcase_cfg = config_get('testcase_cfg');
     $req_mgr = new requirement_mgr($this->db);
     $tc_other_versions = array();
     $status_quo_map = array();
     $keywords_map = array();
     $arrReqs = array();
     $userid_array = array();
     // 20090718 - franciscom
     $cf_smarty = null;
     $formatOptions = null;
     $cfPlaces = $this->buildCFLocationMap();
     if (!is_null($mode) && $mode == 'editOnExec') {
         // refers to two javascript functions present in testlink_library.js
         // and logic used to refresh both frames when user call this
         // method to edit a test case while executing it.
         $gui->dialogName = 'tcview_dialog';
         $gui->bodyOnLoad = "dialog_onLoad({$gui->dialogName})";
         $gui->bodyOnUnload = "dialog_onUnload({$gui->dialogName})";
         $gui->submitCode = "return dialog_onSubmit({$gui->dialogName})";
     }
     $viewer_defaults = array('title' => lang_get('title_test_case'), 'show_title' => 'no', 'action' => '', 'msg_result' => '', 'user_feedback' => '', 'refreshTree' => 1, 'disable_edit' => 0, 'display_testproject' => 0, 'display_parent_testsuite' => 0, 'hilite_testcase_name' => 0, 'show_match_count' => 0);
     if (!is_null($viewer_args) && is_array($viewer_args)) {
         foreach ($viewer_defaults as $key => $value) {
             if (isset($viewer_args[$key])) {
                 $viewer_defaults[$key] = $viewer_args[$key];
             }
         }
     }
     $gui->show_title = $viewer_defaults['show_title'];
     $gui->display_testcase_path = !is_null($path_info);
     $gui->hilite_testcase_name = $viewer_defaults['hilite_testcase_name'];
     $gui->pageTitle = $viewer_defaults['title'];
     $gui->show_match_count = $viewer_defaults['show_match_count'];
     if ($gui->show_match_count && $gui->display_testcase_path) {
         $gui->match_count = count($path_info);
     }
     // fine grain control of operations
     // if( $viewer_defaults['disable_edit'] == 1 || has_rights($this->db,"mgt_modify_tc") == 'no' )
     // BUGID 3387
     if ($viewer_defaults['disable_edit'] == 1 || has_rights($this->db, "mgt_modify_tc") == false) {
         $mode = 'editDisabled';
     }
     $gui->show_mode = $mode;
     $gui->can_do = $this->getShowViewerActions($mode);
     if (is_array($id)) {
         $a_id = $id;
     } else {
         $status_ok = $id > 0 ? 1 : 0;
         $a_id = array($id);
     }
     if ($status_ok) {
         $path2root = $this->tree_manager->get_path($a_id[0]);
         $tproject_id = $path2root[0]['parent_id'];
         $info = $this->tproject_mgr->get_by_id($tproject_id);
         $gui->opt_requirements = $info['opt']->requirementsEnabled;
         $platformMgr = new tlPlatform($this->db, $tproject_id);
         $gui->platforms = $platformMgr->getAllAsMap();
         // BUGID 2378
         $testplans = $this->tproject_mgr->get_all_testplans($tproject_id, array('plan_status' => 1));
         $gui->has_testplans = !is_null($testplans) && count($testplans) > 0 ? 1 : 0;
         if ($viewer_defaults['display_testproject']) {
             $gui->tprojectName = $info['name'];
         }
         if ($viewer_defaults['display_parent_testsuite']) {
             $parent_idx = count($path2root) - 2;
             $gui->parentTestSuiteName = $path2root[$parent_idx]['name'];
         }
         $tcasePrefix = $this->tproject_mgr->getTestCasePrefix($tproject_id);
         if (trim($tcasePrefix) != "") {
             // Add To Testplan button will be disabled if the testcase doesn't belong to the current selected testproject
             // $gui->can_do->add2tplan = 'no';
             if ($_SESSION['testprojectPrefix'] == $tcasePrefix) {
                 $gui->can_do->add2tplan = $gui->can_do->add2tplan == 'yes' ? has_rights($this->db, "testplan_planning") : 'no';
             } else {
                 $gui->can_do->add2tplan = 'no';
             }
             $tcasePrefix .= $tcase_cfg->glue_character;
         }
     }
     if ($status_ok && sizeof($a_id)) {
         $cfx = 0;
         $allTCKeywords = $this->getKeywords($a_id, null, 'testcase_id', ' ORDER BY keyword ASC ');
         $allReqs = $req_mgr->get_all_for_tcase($a_id);
         foreach ($a_id as $key => $tc_id) {
             $tc_array = $this->get_by_id($tc_id, $version_id);
             if (!$tc_array) {
                 continue;
             }
             $tc_array[0]['tc_external_id'] = $tcasePrefix . $tc_array[0]['tc_external_id'];
             // get the status quo of execution and links of tc versions
             $status_quo_map[] = $this->get_versions_status_quo($tc_id);
             $gui->linked_versions[] = $this->get_linked_versions($tc_id);
             $keywords_map[] = isset($allTCKeywords[$tc_id]) ? $allTCKeywords[$tc_id] : null;
             $tc_current = $tc_array[0];
             $tcversion_id_current = $tc_array[0]['id'];
             $gui->tc_current_version[] = array($tc_current);
             //Get UserID and Updater ID for current Version
             $userid_array[$tc_current['author_id']] = null;
             $userid_array[$tc_current['updater_id']] = null;
             // BUGID 3431
             foreach ($cfPlaces as $locationKey => $locationFilter) {
                 // BUGID 3431
                 $cf_current_version[$cfx][$locationKey] = $this->html_table_of_custom_field_values($tc_id, 'design', $locationFilter, null, null, $tproject_id, null, $tcversion_id_current);
             }
             // Other versions (if exists)
             if (count($tc_array) > 1) {
                 $tc_other_versions[] = array_slice($tc_array, 1);
                 $target_idx = count($tc_other_versions) - 1;
                 // BUGID 3431
                 $loop2do = count($tc_other_versions[$target_idx]);
                 // echo 'count($tc_other_versions):' . count($tc_other_versions) . '<br>';
                 // echo '$loop2do:' . $loop2do . '<br>';
                 for ($qdx = 0; $qdx < $loop2do; $qdx++) {
                     $target_tcversion = $tc_other_versions[$target_idx][$qdx]['id'];
                     foreach ($cfPlaces as $locationKey => $locationFilter) {
                         // BUGID 3431
                         $cf_other_versions[$cfx][$qdx][$locationKey] = $this->html_table_of_custom_field_values($tc_id, 'design', $locationFilter, null, null, $tproject_id, null, $target_tcversion);
                     }
                 }
             } else {
                 $tc_other_versions[] = null;
                 $cf_other_versions[$cfx] = null;
             }
             $cfx++;
             // Get author and updater id for each version
             if ($tc_other_versions[0]) {
                 foreach ($tc_other_versions[0] as $key => $version) {
                     $userid_array[$version['author_id']] = null;
                     $userid_array[$version['updater_id']] = null;
                 }
             }
             $tcReqs = isset($allReqs[$tc_id]) ? $allReqs[$tc_id] : null;
             $arrReqs[] = $tcReqs;
         }
         // foreach($a_id as $key => $tc_id)
     }
     // if (sizeof($a_id))
     // Removing duplicate and NULL id's
     unset($userid_array['']);
     $passeduserarray = array_keys($userid_array);
     $gui->cf = null;
     // $cf_current_version; // $cf_smarty;
     $gui->cf_current_version = $cf_current_version;
     // $cf_smarty;
     $gui->cf_other_versions = $cf_other_versions;
     // $cf_smarty;
     $gui->refreshTree = $viewer_defaults['refreshTree'];
     $gui->sqlResult = $viewer_defaults['msg_result'];
     $gui->action = $viewer_defaults['action'];
     $gui->user_feedback = $viewer_defaults['user_feedback'];
     $gui->execution_types = $this->execution_types;
     $gui->tcase_cfg = $tcase_cfg;
     $gui->users = tlUser::getByIDs($this->db, $passeduserarray, 'id');
     $gui->status_quo = $status_quo_map;
     $gui->testcase_other_versions = $tc_other_versions;
     $gui->arrReqs = $arrReqs;
     $gui->view_req_rights = has_rights($this->db, "mgt_view_req");
     $gui->keywords_map = $keywords_map;
     $smarty->assign('gui', $gui);
     $smarty->display($template_dir . $my_template);
 }
예제 #6
0
/**
 * @internal revisions
 */
function importTestPlanLinksFromXML(&$dbHandler, &$tplanMgr, $targetFile, $contextObj)
{
    //   <testplan>
    //     <name></name>
    //     <platforms>
    //       <platform>
    //         <name> </name>
    //         <internal_id></internal_id>
    //       </platform>
    //       <platform>
    //       ...
    //       </platform>
    //     </platforms>
    //     <executables>
    //       <link>
    //         <platform>
    //           <name> </name>
    //         </platform>
    //         <testcase>
    //           <name> </name>
    //           <externalid> </externalid>
    //           <version> </version>
    //           <execution_order> </execution_order>
    //         </testcase>
    //       </link>
    //       <link>
    //       ...
    //       </link>
    //     </executables>
    //   </testplan>
    // </xml>
    $msg = array();
    $labels = init_labels(array('link_without_required_platform' => null, 'ok' => null, 'link_without_platform_element' => null, 'no_platforms_on_tproject' => null, 'tcase_link_updated' => null, 'link_with_platform_not_needed' => null, 'tproject_has_zero_testcases' => null, 'platform_not_on_tproject' => null, 'platform_linked' => null, 'platform_not_linked' => null, 'tcase_doesnot_exist' => null, 'tcversion_doesnot_exist' => null, 'not_imported' => null, 'link_to_tplan_feedback' => null, 'link_to_platform' => null));
    // Double Check
    // Check if Test Plan Parent (Test Project) has testcases, if not abort
    $tprojectMgr = new testproject($dbHandler);
    $tprojectInfo = $tprojectMgr->get_by_id($contextObj->tproject_id);
    $tcasePrefix = $tprojectInfo['prefix'] . config_get('testcase_cfg')->glue_character;
    $tprojectHasTC = $tprojectMgr->count_testcases($contextObj->tproject_id) > 0;
    if (!$tprojectHasTC) {
        $msg[] = array(sprintf($labels['tproject_has_zero_testcases'], $tprojectInfo['name']), $labels['not_imported']);
        return $msg;
        // >>>-----> Bye
    }
    $xml = @simplexml_load_file_wrapper($targetFile);
    if ($xml !== FALSE) {
        $tcaseMgr = new testcase($dbHandler);
        $tcaseSet = array();
        $tprojectMgr->get_all_testcases_id($contextObj->tproject_id, $tcaseSet, array('output' => 'external_id'));
        $tcaseSet = array_flip($tcaseSet);
        // Test Plan name will not be used
        // <testplan>  <name></name>
        //
        // Platform definition info will not be used
        //
        // I will try to link the platforms if are defined
        $status_ok = true;
        if (property_exists($xml, 'platforms')) {
            $platformMgr = new tlPlatform($dbHandler, $contextObj->tproject_id);
            $platformUniverse = $platformMgr->getAllAsMap();
            if (is_null($platformUniverse)) {
                $status_ok = false;
                $msg[] = array($labels['no_platforms_on_tproject'], $labels['not_imported']);
            } else {
                $platformUniverse = array_flip($platformUniverse);
                $op = processPlatforms($platformMgr, $tplanMgr, $platformUniverse, $xml->platforms, $labels, $contextObj->tplan_id);
                $status_ok = $op['status_ok'];
                $msg = $op['msg'];
            }
        }
        if ($status_ok && $xml->xpath('//executables')) {
            $tables = tlObjectWithDB::getDBTables(array('testplan_tcversions'));
            $platformSet = $tplanMgr->getPlatforms($contextObj->tplan_id, array('outputFormat' => 'mapAccessByName'));
            $targetHasPlatforms = count($platformSet) > 0;
            $xmlLinks = $xml->executables->children();
            $loops2do = count($xmlLinks);
            // new dBug($platformSet);
            for ($idx = 0; $idx < $loops2do; $idx++) {
                // if Target Test Plan has platforms and importing file NO => Fatal Error
                $targetName = null;
                $platformID = -1;
                $linkWithPlatform = false;
                $status_ok = false;
                $dummy_msg = null;
                $import_status = $labels['ok'];
                if ($platformElementExists = property_exists($xmlLinks[$idx], 'platform')) {
                    $targetName = trim((string) $xmlLinks[$idx]->platform->name);
                    $linkWithPlatform = $targetName != '';
                }
                // echo "\$targetHasPlatforms:$targetHasPlatforms<br>";
                // echo "\$linkWithPlatform:$linkWithPlatform<br>";
                if ($targetHasPlatforms) {
                    // each link need to have platform or will not be imported
                    if ($linkWithPlatform && isset($platformSet[$targetName])) {
                        $platformID = $platformSet[$targetName]['id'];
                        $status_ok = true;
                        $dummy_msg = null;
                    } else {
                        $import_status = $labels['not_imported'];
                        if (!$platformElementExists) {
                            $dummy_msg = sprintf($labels['link_without_platform_element'], $idx + 1);
                        } else {
                            if (!$linkWithPlatform) {
                                $dummy_msg = sprintf($labels['link_without_required_platform'], $idx + 1);
                            } else {
                                $dummy_msg = sprintf($labels['platform_not_linked'], $idx + 1, $targetName, $contextObj->tplan_name);
                            }
                        }
                    }
                } else {
                    if ($linkWithPlatform) {
                        $import_status = $labels['not_imported'];
                        $dummy_msg = sprintf($labels['link_with_platform_not_needed'], $idx + 1);
                    } else {
                        $platformID = 0;
                        $status_ok = true;
                    }
                }
                if (!is_null($dummy_msg)) {
                    $msg[] = array($dummy_msg, $import_status);
                }
                // echo '$status_ok' . $status_ok . ' ' . __LINE__ . '<br>' ;
                if ($status_ok) {
                    $createLink = false;
                    $updateLink = false;
                    // Link passed ok check on platform
                    // Now we need to understand if requested Test case is present on Test Project
                    $externalID = (int) $xmlLinks[$idx]->testcase->externalid;
                    $tcaseName = (string) $xmlLinks[$idx]->testcase->name;
                    $execOrder = (int) $xmlLinks[$idx]->testcase->execution_order;
                    $version = (int) $xmlLinks[$idx]->testcase->version;
                    if (isset($tcaseSet[$externalID])) {
                        // now need to check if requested version exists
                        $dummy = $tcaseMgr->get_basic_info($tcaseSet[$externalID], array('number' => $version));
                        if (count($dummy) > 0) {
                            // Check :
                            // for same test plan there is a different version already linked ?
                            // if YES => error.
                            //
                            $lvFilters = array('tplan_id' => $contextObj->tplan_id);
                            $linkedVersions = $tcaseMgr->get_linked_versions($dummy[0]['id'], $lvFilters);
                            $updateLink = false;
                            $doUpdateFeedBack = true;
                            // TICKET 5189: Import a test plan does not import test cases execution order
                            // new dBug($linkedVersions);
                            if (!($createLink = is_null($linkedVersions))) {
                                // Now need to understand if is already linked with this signature.
                                if (!isset($linkedVersions[$dummy[0]['tcversion_id']])) {
                                    //echo 'CREATE';
                                    $createLink = true;
                                } else {
                                    // linked platforms
                                    $createLink = false;
                                    $updateLink = false;
                                    $plat_keys = array_keys($linkedVersions[$dummy[0]['tcversion_id']][$contextObj->tplan_id]);
                                    $plat_keys = array_flip($plat_keys);
                                    if (isset($plat_keys[$platformID])) {
                                        $updateLink = true;
                                    } else {
                                        if ($platformID == 0) {
                                            // User request to add without platform, but platforms exist => SKIP
                                            $msg[] = array('platform 0 missing messages', $labels['not_imported']);
                                        } else {
                                            $createLink = true;
                                        }
                                    }
                                }
                            }
                            if ($createLink) {
                                // Create link
                                // function link_tcversions($id,&$items_to_link,$userId)
                                $item2link['items'] = array($dummy[0]['id'] => array($platformID => $dummy[0]['tcversion_id']));
                                $item2link['tcversion'] = array($dummy[0]['id'] => $dummy[0]['tcversion_id']);
                                $tplanMgr->link_tcversions($contextObj->tplan_id, $item2link, $contextObj->userID);
                                $dummy_msg = sprintf($labels['link_to_tplan_feedback'], $externalID, $version);
                                if ($platformID > 0) {
                                    $dummy_msg .= sprintf($labels['link_to_platform'], $targetName);
                                }
                                $msg[] = array($dummy_msg, $labels['ok']);
                                // TICKET 5189: Import a test plan does not import test cases execution order
                                $updateLink = true;
                                $doUpdateFeedBack = false;
                            }
                            if ($updateLink) {
                                $newOrder = array($dummy[0]['tcversion_id'] => $execOrder);
                                $tplanMgr->setExecutionOrder($contextObj->tplan_id, $newOrder);
                                if ($doUpdateFeedBack) {
                                    $dummy_msg = sprintf($labels['tcase_link_updated'], $tcasePrefix . $externalID . ' ' . $tcaseName, $version);
                                    $msg[] = array($dummy_msg, $labels['ok']);
                                }
                            }
                        } else {
                            $msg[] = array(sprintf($labels['tcversion_doesnot_exist'], $externalID, $version, $tprojectInfo['name']));
                        }
                    } else {
                        $msg[] = array(sprintf($labels['tcase_doesnot_exist'], $externalID, $tprojectInfo['name']));
                    }
                    //$tcaseMgr->get_by_external
                    // echo '<pre><xmp>';
                    // var_dump($xmlLinks[$idx]->testcase);
                    // echo 'TCBAME' . (string)$xmlLinks[$idx]->testcase->name;
                    // echo '</xmp></pre>';
                }
            }
        }
    }
    return $msg;
}
예제 #7
0
 /**
  * Show Test Case logic
  * 
  * @param object $smarty reference to smarty object (controls viewer).
  * @param integer $id Test case unique identifier
  * @param integer $version_id (optional) you can work on ONE test case version, 
  * 				or on ALL; default: ALL
  * 
  * @internal
 
         [viewer_args]: map with keys
                        action
                        msg_result
                        refresh_tree: controls if tree view is refreshed after every operation.
                                      default: yes
                        user_feedback
                        disable_edit: used to overwrite user rights
                                         default: 0 -> no
 
   returns:
 
   rev :
 */
 function show(&$smarty, $guiObj, $identity, $grants)
 {
     $env_tproject_id = $identity->tproject_id;
     $id = $identity->id;
     $version_id = isset($identity->version_id) ? $identity->version_id : self::ALL_VERSIONS;
     $idSet = is_array($id) ? $id : (array) $id;
     $status_ok = $idSet[0] > 0 ? 1 : 0;
     $gui = $this->initShowGui($guiObj, $grants);
     $gui->grants = $grants;
     $gui->testcase_other_versions = array();
     if ($status_ok) {
         $req_mgr = new requirement_mgr($this->db);
         $path2root = $this->tree_manager->get_path($idSet[0]);
         $gui->tproject_id = $path2root[0]['parent_id'];
         $info = $this->tproject_mgr->get_by_id($gui->tproject_id);
         $gui->opt_requirements = $info['opt']->requirementsEnabled;
         $gui->requirementsEnabled = $info['opt']->requirementsEnabled;
         $platformMgr = new tlPlatform($this->db, $gui->tproject_id);
         $gui->platforms = $platformMgr->getAllAsMap();
         $testplans = $this->tproject_mgr->get_all_testplans($gui->tproject_id, array('plan_status' => 1));
         $gui->has_testplans = !is_null($testplans) && count($testplans) > 0 ? 1 : 0;
         if ($gui->display_testproject) {
             $gui->tprojectName = $info['name'];
         }
         if ($gui->display_parent_testsuite) {
             $parent_idx = count($path2root) - 2;
             $gui->parentTestSuiteName = $path2root[$parent_idx]['name'];
         }
         $tcasePrefix = $this->tproject_mgr->getTestCasePrefix($gui->tproject_id);
         if (trim($tcasePrefix) != "") {
             // 'Add To Testplan' button will be disabled if the testcase doesn't belong
             // to the current selected testproject
             // $gui->can_do->add2tplan = 'no';
             if ($env_tproject_id != $gui->tproject_id) {
                 $gui->can_do->add2tplan = $gui->can_do->add2tplan == 'yes' ? $grants->testplan_planning : 'no';
             } else {
                 $gui->can_do->add2tplan = 'yes';
             }
             $tcasePrefix .= $gui->tcase_cfg->glue_character;
         }
     }
     $userid_array = array();
     if ($status_ok && sizeof($idSet)) {
         $cfx = 0;
         $allTCKeywords = $this->getKeywords($idSet, null, 'testcase_id', ' ORDER BY keyword ASC ');
         $allReqs = $req_mgr->get_all_for_tcase($idSet);
         $tcStatus2exclude = config_get('tplanDesign')->hideTestCaseWithStatusIn;
         foreach ($idSet as $key => $tc_id) {
             $tc_array = $this->get_by_id($tc_id, $version_id);
             if (!$tc_array) {
                 continue;
             }
             $gui->attach[$tc_id] = new stdClass();
             $gui->attach[$tc_id]->itemID = $tc_id;
             $gui->attach[$tc_id]->dbTable = $this->attachmentTableName;
             $gui->attach[$tc_id]->infoSet = null;
             $gui->attach[$tc_id]->gui = null;
             list($gui->attach[$tc_id]->infoSet, $gui->attach[$tc_id]->gui) = $this->buildAttachSetup($tc_id);
             $gui->attach[$tc_id]->gui->display = TRUE;
             $gui->attach[$tc_id]->enabled = $gui->attach[$tc_id]->gui->enabled;
             $tc_array[0]['tc_external_id'] = $tcasePrefix . $tc_array[0]['tc_external_id'];
             // get the status quo of execution and links of tc versions
             // $gui->status_quo_map[] = $this->get_versions_status_quo($tc_id);
             $gui->status_quo[] = $this->get_versions_status_quo($tc_id);
             $gui->linked_versions[] = $this->get_linked_versions($tc_id);
             $gui->keywords_map[] = isset($allTCKeywords[$tc_id]) ? $allTCKeywords[$tc_id] : null;
             $tc_current = $tc_array[0];
             // add new attribute
             // enabledOnTestPlanDesign
             $tc_current['enabledOnTestPlanDesign'] = !isset($tcStatus2exclude[$tc_current['status']]);
             $tcversion_id_current = $tc_current['id'];
             $gui->tc_current_version[] = array($tc_current);
             //Get UserID and Updater ID for current Version
             $userid_array[$tc_current['author_id']] = null;
             $userid_array[$tc_current['updater_id']] = null;
             $cfPlaces = $this->buildCFLocationMap();
             foreach ($cfPlaces as $locationKey => $locationFilter) {
                 $gui->cf_current_version[$cfx][$locationKey] = $this->html_table_of_custom_field_values($tc_id, 'design', $locationFilter, null, null, $gui->tproject_id, null, $tcversion_id_current);
             }
             // Other versions (if exists)
             if (count($tc_array) > 1) {
                 $gui->testcase_other_versions[] = array_slice($tc_array, 1);
                 $target_idx = count($gui->testcase_other_versions) - 1;
                 $loop2do = count($gui->testcase_other_versions[$target_idx]);
                 for ($qdx = 0; $qdx < $loop2do; $qdx++) {
                     $tcRef =& $gui->testcase_other_versions[$target_idx][$qdx];
                     $tcRef['enabledOnTestPlanDesign'] = !isset($tcStatus2exclude[$tcRef['status']]);
                     $target_tcversion = $tcRef['id'];
                     foreach ($cfPlaces as $locationKey => $locationFilter) {
                         $gui->cf_other_versions[$cfx][$qdx][$locationKey] = $this->html_table_of_custom_field_values($tc_id, 'design', $locationFilter, null, null, $gui->tproject_id, null, $target_tcversion);
                     }
                 }
             } else {
                 $gui->testcase_other_versions[] = null;
                 $gui->cf_other_versions[$cfx] = null;
             }
             $cfx++;
             // Get author and updater id for each version
             // @TODO - franciscom - explain magic ZERO
             if ($gui->testcase_other_versions[0]) {
                 foreach ($gui->testcase_other_versions[0] as $key => $version) {
                     $userid_array[$version['author_id']] = null;
                     $userid_array[$version['updater_id']] = null;
                 }
             }
             $tcReqs = isset($allReqs[$tc_id]) ? $allReqs[$tc_id] : null;
             $gui->arrReqs[] = $tcReqs;
         }
         // foreach($a_id as $key => $tc_id)
     }
     // if (sizeof($a_id))
     // Removing duplicate and NULL id's
     unset($userid_array['']);
     $this->initShowGuiActions(&$gui);
     $gui->users = tlUser::getByIDs($this->db, array_keys($userid_array), 'id');
     $smarty->assign('gui', $gui);
     $dummy = templateConfiguration('tcView');
     $smarty->display($dummy->template_dir . $dummy->default_template);
 }