Esempio n. 1
0
         if (!$tp_tcs) {
             $tree['childNodes'] = null;
         }
         //@TODO:REFACTOR
         // prepareNode($db,$tree,$decoding_hash,$dummy,$dummy,$tp_tcs,
         //              SHOW_TESTCASES,null,null,0,1,0);
         $dummy = null;
         $pnFilters = null;
         $pnOptions = array('hideTestCases' => 0, 'showTestCaseID' => 1, 'getExternalTestCaseID' => 0, 'ignoreInactiveTestCases' => 0);
         prepareNode($db, $tree, $decoding_hash, $dummy, $dummy, $tp_tcs, $pnFilters, $pnOptions);
         $treeForPlatform[$platform_id] = $tree;
     }
     break;
 case 'testsuite':
     foreach ($platforms as $platform_id => $platform_name) {
         $tsuite = new testsuite($db);
         $tInfo = $tsuite->get_by_id($args->itemID);
         $children_tsuites = $tree_manager->get_subtree_list($args->itemID, $hash_descr_id['testsuite']);
         if (!is_null($children_tsuites) and trim($children_tsuites) != "") {
             $branch_tsuites = explode(',', $children_tsuites);
         }
         $branch_tsuites[] = $args->itemID;
         $filters = array('tsuites_id' => $branch_tsuites, 'platform_id' => $platform_id);
         $tp_tcs = $tplan_mgr->get_linked_tcversions($args->tplan_id, $filters);
         $tcase_filter = !is_null($tp_tcs) ? array_keys((array) $tp_tcs) : null;
         $tInfo['node_type_id'] = $hash_descr_id['testsuite'];
         $tInfo['childNodes'] = isset($subtree['childNodes']) ? $subtree['childNodes'] : null;
         //@TODO: schlundus, can we speed up with NO_EXTERNAL?
         $dummy = null;
         $pnFilters = null;
         $pnOptions = array('hideTestCases' => 0);
Esempio n. 2
0
 *
 * @internal revisions
 * @since 2.0
 *
 **/
require_once "../../config.inc.php";
require_once "common.php";
require_once "opt_transfer.php";
require_once "web_editor.php";
$cfg = getCfg();
testlinkInitPage($db);
$optionTransferName = 'ot';
$tcase_mgr = new testcase($db);
$tproject_mgr = new testproject($db);
$tree_mgr = new tree($db);
$tsuite_mgr = new testsuite($db);
$args = init_args($db, $cfg, $tproject_mgr);
require_once require_web_editor($cfg->webEditorCfg['type']);
$commandMgr = new testcaseCommands($db, $_SESSION['currentUser'], $args->tproject_id);
$commandMgr->setTemplateCfg(templateConfiguration());
$testCaseEditorKeys = array('summary' => 'summary', 'preconditions' => 'preconditions');
$oWebEditor = createWebEditors($args->basehref, $cfg->webEditorCfg, $testCaseEditorKeys);
$sqlResult = "";
$init_inputs = true;
$show_newTC_form = 0;
$opt_cfg = initializeOptionTransferCfg($optionTransferName, $args, $tproject_mgr);
$gui = initializeGui($db, $args, $cfg, $tcase_mgr, $_SESSION['currentUser']);
$smarty = new TLSmarty();
$smarty->templateCfg = templateConfiguration('tcEdit');
$name_ok = 1;
$doRender = false;
Esempio n. 3
0
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;
}
Esempio n. 4
0
/**
 *
 */
function buildContentForTestPlanBranch(&$dbHandler, $itemsTree, $branchRoot, $tplanID, $platformIDSet, &$docInfo, $decode, &$tplanMgr, $options = null)
{
    $linkedBy = array();
    $branch_tsuites = null;
    $contentByPlatform = array();
    $pnOptions = array('hideTestCases' => 0);
    $pnOptions = array_merge($pnOptions, (array) $options);
    $tsuite = new testsuite($dbHandler);
    $tInfo = $tsuite->get_by_id($branchRoot);
    $tInfo['node_type_id'] = $decode['node_descr_id']['testsuite'];
    $docInfo->title = htmlspecialchars(isset($tInfo['name']) ? $tInfo['name'] : $docInfo->testplan_name);
    $children_tsuites = $tsuite->tree_manager->get_subtree_list($branchRoot, $decode['node_descr_id']['testsuite']);
    if (!is_null($children_tsuites) and trim($children_tsuites) != "") {
        $branch_tsuites = explode(',', $children_tsuites);
    }
    $branch_tsuites[] = $branchRoot;
    $metrics = (object) array('estimatedExecTime' => null, 'realExecTime' => null);
    $filters = array('tsuites_id' => $branch_tsuites);
    foreach ($platformIDSet as $platform_id) {
        // IMPORTANTE NOTICE:
        // This need to be initialized on each iteration because prepareNode() make changes on it.
        $tInfo['childNodes'] = isset($itemsTree['childNodes']) ? $itemsTree['childNodes'] : null;
        $filters['platform_id'] = $platform_id;
        $metrics->estimatedExecTime[$platform_id] = null;
        $metrics->realExecTime[$platform_id] = null;
        $avalon = $tplanMgr->getLTCVNewGeneration($tplanID, $filters, array('addExecInfo' => true));
        $k2l = array_keys($avalon);
        foreach ($k2l as $key) {
            $linkedBy[$platform_id][$key] = $avalon[$key][$platform_id];
        }
        // After architecture changes on how CF design values for Test Cases are
        // managed, we need the test case version ID and not test case ID
        // In addition if we loop over Platforms we need to save this set each time!!!
        $items2loop = !is_null($linkedBy[$platform_id]) ? array_keys($linkedBy[$platform_id]) : null;
        if (!is_null($items2loop)) {
            foreach ($items2loop as $rdx) {
                $metrics->estimatedExecTime[$platform_id][] = $linkedBy[$platform_id][$rdx]['tcversion_id'];
            }
        }
        // Prepare Node -> pn
        $pnFilters = null;
        $dummy4reference = null;
        $contentByPlatform[$platform_id]['childNodes'] = array();
        if (!is_null($linkedBy[$platform_id])) {
            prepareNode($dbHandler, $tInfo, $decode, $dummy4reference, $dummy4reference, $linkedBy[$platform_id], $pnFilters, $pnOptions);
            $contentByPlatform[$platform_id]['childNodes'] = array($tInfo);
        }
    }
    $metrics->realExecTime = $linkedBy;
    return array($contentByPlatform, $metrics);
}
 function create_tc_from_requirement($mixIdReq, $srs_id, $user_id, $tproject_id = null, $tc_count = null)
 {
     $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
     $tcase_mgr = new testcase($this->db);
     $tsuite_mgr = new testsuite($this->db);
     $req_cfg = config_get('req_cfg');
     $field_size = config_get('field_size');
     $auto_testsuite_name = $req_cfg->default_testsuite_name;
     $node_descr_type = $this->tree_mgr->get_available_node_types();
     $empty_steps = null;
     $empty_preconditions = '';
     // fix for BUGID 2995
     $labels['tc_created'] = lang_get('tc_created');
     $output = null;
     $reqSet = is_array($mixIdReq) ? $mixIdReq : array($mixIdReq);
     /* contribution BUGID 2996, testcase creation */
     if (is_null($tproject_id) || $tproject_id == 0) {
         $tproject_id = $this->tree_mgr->getTreeRoot($srs_id);
     }
     if ($req_cfg->use_req_spec_as_testsuite_name) {
         $full_path = $this->tree_mgr->get_path($srs_id);
         $addition = " (" . lang_get("testsuite_title_addition") . ")";
         $truncate_limit = $field_size->testsuite_name - strlen($addition);
         // REQ_SPEC_A
         //           |-- REQ_SPEC_A1
         //                          |-- REQ_SPEC_A2
         //                                         |- REQ100
         //                                         |- REQ101
         //
         // We will try to check if a test suite has already been created for
         // top REQ_SPEC_A  (we do search using automatic generated name as search criteria).
         // If not => we need to create all path till leaves (REQ100 and REQ200)
         //
         //
         // First search: we use test project
         $parent_id = $tproject_id;
         $deep_create = false;
         foreach ($full_path as $key => $node) {
             // follow hierarchy of test suites to create
             $tsuiteInfo = null;
             $testsuite_name = substr($node['name'], 0, $truncate_limit) . $addition;
             if (!$deep_create) {
                 // child test suite with this name, already exists on current parent ?
                 // At first a failure we will not check anymore an proceed with deep create
                 $sql = "/* {$debugMsg} */ SELECT id,name FROM {$this->tables['nodes_hierarchy']} NH " . " WHERE name='" . $this->db->prepare_string($testsuite_name) . "' " . " AND node_type_id=" . $node_descr_type['testsuite'] . " AND parent_id = {$parent_id} ";
                 // If returns more that one record use ALWAYS first
                 $tsuiteInfo = $this->db->fetchRowsIntoMap($sql, 'id');
             }
             if (is_null($tsuiteInfo)) {
                 $tsuiteInfo = $tsuite_mgr->create($parent_id, $testsuite_name, $req_cfg->testsuite_details);
                 $output[] = sprintf(lang_get('testsuite_name_created'), $testsuite_name);
                 $deep_create = true;
             } else {
                 $tsuiteInfo = current($tsuiteInfo);
                 $tsuite_id = $tsuiteInfo['id'];
             }
             $tsuite_id = $tsuiteInfo['id'];
             // last value here will be used as parent for test cases
             $parent_id = $tsuite_id;
         }
         $output[] = sprintf(lang_get('created_on_testsuite'), $testsuite_name);
     } else {
         // don't use req_spec as testsuite name
         // Warning:
         // We are not maintaining hierarchy !!!
         $sql = " SELECT id FROM {$this->tables['nodes_hierarchy']} NH " . " WHERE name='" . $this->db->prepare_string($auto_testsuite_name) . "' " . " AND parent_id=" . $testproject_id . " " . " AND node_type_id=" . $node_descr_type['testsuite'];
         $result = $this->db->exec_query($sql);
         if ($this->db->num_rows($result) == 1) {
             $row = $this->db->fetch_array($result);
             $tsuite_id = $row['id'];
             $label = lang_get('created_on_testsuite');
         } else {
             // not found -> create
             tLog('test suite:' . $auto_testsuite_name . ' was not found.');
             $new_tsuite = $tsuite_mgr->create($testproject_id, $auto_testsuite_name, $req_cfg->testsuite_details);
             $tsuite_id = $new_tsuite['id'];
             $label = lang_get('testsuite_name_created');
         }
         $output[] = sprintf($label, $auto_testsuite_name);
     }
     /* end contribution */
     // create TC
     $createOptions = array();
     $createOptions['check_names_for_duplicates'] = config_get('check_names_for_duplicates');
     $createOptions['action_on_duplicate_name'] = config_get('action_on_duplicate_name');
     $testcase_importance_default = config_get('testcase_importance_default');
     // compute test case order
     $testcase_order = config_get('treemenu_default_testcase_order');
     $nt2exclude = array('testplan' => 'exclude_me', 'requirement_spec' => 'exclude_me', 'requirement' => 'exclude_me');
     $siblings = $this->tree_mgr->get_children($tsuite_id, $nt2exclude);
     if (!is_null($siblings)) {
         $dummy = end($siblings);
         $testcase_order = $dummy['node_order'];
     }
     foreach ($reqSet as $reqID) {
         $reqData = $this->get_by_id($reqID, requirement_mgr::LATEST_VERSION);
         $count = !is_null($tc_count) ? $tc_count[$reqID] : 1;
         $reqData = $reqData[0];
         // Generate name with progessive
         $instance = 1;
         $getOptions = array('check_criteria' => 'like', 'access_key' => 'name');
         $itemSet = $tcase_mgr->getDuplicatesByName($reqData['title'], $tsuite_id, $getOptions);
         $nameSet = null;
         if (!is_null($itemSet)) {
             $nameSet = array_flip(array_keys($itemSet));
         }
         for ($idx = 0; $idx < $count; $idx++) {
             $testcase_order++;
             // We have a little problem to work on:
             // suppose you have created:
             // TC [1]
             // TC [2]
             // TC [3]
             // If we delete TC [2]
             // When I got siblings  il will got 2, if I create new progressive using next,
             // it will be 3 => I will get duplicated name.
             //
             // Seems better option can be:
             // Get all siblings names, put on array, create name an check if exists, if true
             // generate a new name.
             // This may be at performance level is better than create name then check on db,
             // because this approach will need more queries to DB
             //
             $tcase_name = $reqData['title'] . " [{$instance}]";
             if (!is_null($nameSet)) {
                 while (isset($nameSet[$tcase_name])) {
                     $instance++;
                     $tcase_name = $reqData['title'] . " [{$instance}]";
                 }
             }
             $nameSet[$tcase_name] = $tcase_name;
             // 20100106 - franciscom - multiple test case steps feature - removed expected_results
             // Julian - BUGID 2995
             $tcase = $tcase_mgr->create($tsuite_id, $tcase_name, $req_cfg->testcase_summary_prefix . $reqData['scope'], $empty_preconditions, $empty_steps, $user_id, null, $testcase_order, testcase::AUTOMATIC_ID, TESTCASE_EXECUTION_TYPE_MANUAL, $testcase_importance_default, $createOptions);
             $tcase_name = $tcase['new_name'] == '' ? $tcase_name : $tcase['new_name'];
             $output[] = sprintf($labels['tc_created'], $tcase_name);
             // create coverage dependency
             if (!$this->assign_to_tcase($reqData['id'], $tcase['id'])) {
                 $output[] = 'Test case: ' . $tcase_name . " was not created";
             }
         }
     }
     return $output;
 }
Esempio n. 6
0
/**
 *
 */
function getTargetTestCases(&$dbHandler, &$argsObj)
{
    if (is_null($items = $argsObj->tcaseSet)) {
        $mgr = new testsuite($dbHandler);
        $items = $mgr->get_testcases_deep($argsObj->id, 'only_id');
    }
    return $items;
}
Esempio n. 7
0
function renderTestSuiteNodeForPrinting(&$db, &$node, &$options, $tocPrefix, $level, $tplan_id, $tproject_id)
{
    static $tsuite_mgr;
    $labels = array('test_suite' => lang_get('test_suite'), 'details' => lang_get('details'));
    $code = null;
    $name = isset($node['name']) ? htmlspecialchars($node['name']) : '';
    $title_separator = config_get('gui_title_separator_1');
    $cfields = array('design' => '');
    $cfieldFormatting = array('table_css_style' => 'class="cf"');
    $docHeadingNumbering = '';
    if ($options['headerNumbering']) {
        $docHeadingNumbering = "{$tocPrefix}. ";
    }
    if ($options['toc']) {
        $spacing = $level == 2 && $tocPrefix != 1 ? "<br>" : "";
        $options['tocCode'] .= $spacing . '<b><p style="padding-left: ' . 10 * $level . 'px;">' . '<a href="#' . prefixToHTMLID($tocPrefix) . '">' . $docHeadingNumbering . $name . "</a></p></b>\n";
        $code .= "<a name='" . prefixToHTMLID($tocPrefix) . "'></a>\n";
    }
    $docHeadingLevel = $level - 1;
    //we would like to have html top heading H1 - H6
    $docHeadingLevel = $docHeadingLevel > 6 ? 6 : $docHeadingLevel;
    $code .= "<h{$docHeadingLevel} class='doclevel'>" . $docHeadingNumbering . $labels['test_suite'] . $title_separator . $name . "</h{$docHeadingLevel}>\n";
    // ----- get Test Suite text -----------------
    if ($options['header']) {
        if (!$tsuite_mgr) {
            $tsuite_mgr = new testsuite($db);
        }
        $tInfo = $tsuite_mgr->get_by_id($node['id']);
        if ($tInfo['details'] != '') {
            $code .= '<div>' . $tInfo['details'] . '</div>';
        }
        // get Custom fields
        // Attention: for test suites custom fields can not be edited during execution,
        //            then we need to get just custom fields with scope  'design'
        foreach ($cfields as $key => $value) {
            $cfields[$key] = $tsuite_mgr->html_table_of_custom_field_values($node['id'], $key, null, $tproject_id, $cfieldFormatting);
            if ($cfields[$key] != "") {
                $add_br = true;
                $code .= '<p>' . $cfields[$key] . '</p>';
            }
        }
    }
    return $code;
}
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;
}
/**
 * get linked versions filtered by Keyword ID
 * Filter is done ONLY on attributes THAT ARE COMMON to ALL test case versions,
 * because (till now) while adding/removing test cases user works on Test Spec Tree
 * and filter applied to this tree acts on:
 *
 * 1. attributes COMMON to all versions
 * 2. attributes present ON LAST ACTIVE version.
 *  
 * But do no make considerations regarding versions linked to test plan
 * DEV NOTE: may be this has to be changed in future ?  
 *
 * @param ref $dbHandler:
 * @param ref $argsObj: stdClass object with information about filters
 * @param ref $tplanMgr: test plan manager object
 * @param ref $tcaseMgr: test case manager object
 * @param map $options:  default null   (at today 20110820 seems not be used).
 *  
 * 
 *
 * @internal revisions
 * @since 1.9.14
 * 
 */
function getFilteredLinkedVersions(&$dbHandler, &$argsObj, &$tplanMgr, &$tcaseMgr, $options = null)
{
    static $tsuite_mgr;
    $doFilterByKeyword = !is_null($argsObj->keyword_id) && $argsObj->keyword_id > 0 ? true : false;
    // Multiple step algoritm to apply keyword filter on type=AND
    // get_*_tcversions filters by keyword ALWAYS in OR mode.
    //
    $filters = array('keyword_id' => $argsObj->keyword_id, 'platform_id' => null);
    if (property_exists($argsObj, 'control_panel') && intval($argsObj->control_panel['setting_platform']) > 0) {
        $filters['platform_id'] = intval($argsObj->control_panel['setting_platform']);
    }
    if (isset($options['assigned_on_build']) && $options['assigned_on_build'] > 0) {
        $filters['assigned_on_build'] = $options['assigned_on_build'];
    }
    // get test suites in branch to limit search
    $itemID = property_exists($argsObj, 'object_id') ? $argsObj->object_id : $argsObj->id;
    if (!is_null($itemID)) {
        // will get all test suites in this branch, in order to limit amount of data returned by
        // get_*_tcversions
        if (!$tsuite_mgr) {
            $tsuite_mgr = new testsuite($dbHandler);
        }
        $xx = $tsuite_mgr->get_branch($itemID);
        $xx .= $xx == '' ? $itemID : ',' . $itemID;
        $filters['tsuites_id'] = explode(',', $xx);
    }
    // $opx = array('addExecInfo' => true, 'specViewFields' => true) + (array)$options;
    $opx = array_merge(array('addExecInfo' => true, 'specViewFields' => true, 'tlFeature' => 'none'), (array) $options);
    switch ($opx['tlFeature']) {
        case 'testCaseExecTaskAssignment':
            $method2call = 'getLinkedTCVXmen';
            break;
        case 'testCaseTestPlanAssignment':
        default:
            $method2call = 'getLTCVNewGeneration';
            break;
    }
    if (isset($argsObj->testcases_to_show) && !is_null($argsObj->testcases_to_show)) {
        $filters['tcase_id'] = $argsObj->testcases_to_show;
    }
    if (isset($argsObj->platform_id) && $argsObj->platform_id > 0) {
        $filters['platform_id'] = $argsObj->platform_id;
    }
    $tplan_tcases = $tplanMgr->{$method2call}($argsObj->tplan_id, $filters, $opx);
    if (!is_null($tplan_tcases) && $doFilterByKeyword && $argsObj->keywordsFilterType == 'AND') {
        $filteredSet = $tcaseMgr->filterByKeyword(array_keys($tplan_tcases), $argsObj->keyword_id, $argsObj->keywordsFilterType);
        $filters = array('tcase_id' => array_keys($filteredSet));
        // HERE WE CAN HAVE AN ISSUE
        $tplan_tcases = $tplanMgr->getLTCVNewGeneration($argsObj->tplan_id, $filters, $opx);
    }
    return $tplan_tcases;
}
Esempio n. 10
0
/**
 * 
 *
 */
function doBulkAssignment(&$dbHandler, &$argsObj, $targetTestCaseSet = null)
{
    $req_mgr = new requirement_mgr($dbHandler);
    $assignmentCounter = 0;
    $requirements = array_keys($argsObj->reqIdSet);
    if (!is_null($requirements) && count($requirements) > 0) {
        $tcase_set = $targetTestCaseSet;
        if (is_null($tcase_set)) {
            $tsuite_mgr = new testsuite($dbHandler);
            echo 'DEBUG BEFORE';
            $tcase_set = $tsuite_mgr->get_testcases_deep($argsObj->id, 'only_id');
        }
        if (!is_null($tcase_set) && count($tcase_set)) {
            $assignmentCounter = $req_mgr->bulk_assignment($requirements, $tcase_set);
        }
    }
    return $assignmentCounter;
}
Esempio n. 11
0
 * @version $Revision: 1.9 $
 * @modified $Date: 2010/06/24 17:25:56 $ by $Author: asimon83 $
 * @author Francisco Mancardi
 *
 * With this page you can launch a set of available methods, to understand
 * and have inside view about return type .
 *
 * 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);
Esempio n. 12
0
/**
 * get linked versions filtered by Keyword ID
 * Filter is done ONLY on attributes THAT ARE COMMON to ALL test case versions,
 * because (till now) while adding/removing test cases user works on Test Spec Tree
 * and filter applied to this tree acts on:
 *
 * 1. attributes COMMON to all versions
 * 2. attributes present ON LAST ACTIVE version.
 *  
 * But do no make considerations regarding versions linked to test plan
 * DEV NOTE: may be this has to be changed in future ?  
 *
 * @param ref $dbHandler:
 * @param ref $argsObj: stdClass object with information about filters
 * @param ref $tplanMgr: test plan manager object
 * @param ref $tcaseMgr: test case manager object
 * @param map $options:  default null   (at today 20110820 seems not be used).
 *  
 * 
 *
 * @internal revisions
 * @since 1.9.8
 * 
 */
function getFilteredLinkedVersions(&$dbHandler, &$argsObj, &$tplanMgr, &$tcaseMgr, $options = null)
{
    static $tsuite_mgr;
    $doFilterByKeyword = !is_null($argsObj->keyword_id) && $argsObj->keyword_id > 0 ? true : false;
    // Multiple step algoritm to apply keyword filter on type=AND
    // get_*_tcversions filters by keyword ALWAYS in OR mode.
    //
    $filters = array('keyword_id' => $argsObj->keyword_id, 'platform_id' => null);
    if (property_exists($argsObj, 'control_panel') && intval($argsObj->control_panel['setting_platform']) > 0) {
        $filters['platform_id'] = intval($argsObj->control_panel['setting_platform']);
    }
    if (isset($options['assigned_on_build']) && $options['assigned_on_build'] > 0) {
        $filters['assigned_on_build'] = $options['assigned_on_build'];
    }
    // get test suites in branch to limit search
    $itemID = property_exists($argsObj, 'object_id') ? $argsObj->object_id : $argsObj->id;
    if (!is_null($itemID)) {
        // will get all test suites in this branch, in order to limit amount of data returned by
        // get_*_tcversions
        if (!$tsuite_mgr) {
            $tsuite_mgr = new testsuite($dbHandler);
        }
        $xx = $tsuite_mgr->get_branch($itemID);
        $xx .= $xx == '' ? $itemID : ',' . $itemID;
        $filters['tsuites_id'] = explode(',', $xx);
    }
    // $opx = array('addExecInfo' => true, 'specViewFields' => true,'addPriority' => true) +   (array)$options;
    // $opx = array('addExecInfo' => true, 'specViewFields' => true, 'orderBy' => ' execution_order ') +   (array)$options;
    $opx = array('addExecInfo' => true, 'specViewFields' => true) + (array) $options;
    $tplan_tcases = $tplanMgr->getLTCVNewGeneration($argsObj->tplan_id, $filters, $opx);
    if (!is_null($tplan_tcases) && $doFilterByKeyword && $argsObj->keywordsFilterType == 'AND') {
        $filteredSet = $tcaseMgr->filterByKeyword(array_keys($tplan_tcases), $argsObj->keyword_id, $argsObj->keywordsFilterType);
        $filters = array('tcase_id' => array_keys($filteredSet));
        $tplan_tcases = $tplanMgr->getLTCVNewGeneration($argsObj->tplan_id, $filters, $opx);
    }
    return $tplan_tcases;
}
Esempio n. 13
0
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 getTargetTestCases(&$dbHandler, &$argsObj)
{
    $mgr = new testsuite($dbHandler);
    $items = $mgr->get_testcases_deep($argsObj->id, 'only_id');
    if (!is_null($argsObj->tcaseSet)) {
        $rr = array_intersect($items, $argsObj->tcaseSet);
        $items = $rr;
    }
    return $items;
}
Esempio n. 15
0
 * link/unlink test cases to a test plan
 *
 * @filesource	planAddTC.php
 * @package 	  TestLink
 * @copyright 	2007-2012, TestLink community 
 * @link 		    http://www.teamst.org/index.php
 * 
 * @internal revisions
 *
 **/
require_once '../../config.inc.php';
require_once "common.php";
require_once 'email_api.php';
require_once "specview.php";
testlinkInitPage($db);
$tsuite_mgr = new testsuite($db);
$tplan_mgr = new testplan($db);
$tproject_mgr = new testproject($db);
$tcase_mgr = new testcase($db);
$templateCfg = templateConfiguration();
$args = init_args($tproject_mgr);
checkRights($db, $_SESSION['currentUser'], $args);
$gui = initializeGui($db, $args, $tplan_mgr, $tcase_mgr);
//new dBug($gui);die();
$keywordsFilter = null;
if (is_array($args->keyword_id)) {
    $keywordsFilter = new stdClass();
    $keywordsFilter->items = $args->keyword_id;
    $keywordsFilter->type = $gui->keywordsFilterType->selected;
}
$do_display = 0;
Esempio n. 16
0
function renderTestSuiteNodeForPrinting(&$db, &$node, $env, &$options, $context)
{
    static $tsuite_mgr;
    static $labels;
    static $title_separator;
    static $cfieldFormatting;
    if (!is_null($labels)) {
        $labels = array('test_suite' => lang_get('test_suite'), 'details' => lang_get('details'));
        $title_separator = config_get('gui_title_separator_1');
        $cfieldFormatting = array('table_css_style' => 'class="cf"');
    }
    $code = null;
    $name = isset($node['name']) ? htmlspecialchars($node['name']) : '';
    $cfields = array('design' => '');
    $docHeadingNumbering = $options['headerNumbering'] ? $env->tocPrefix . "." : '';
    if ($options['toc']) {
        $spacing = $context['level'] == 2 && $env->tocPrefix != 1 ? "<br>" : "";
        $options['tocCode'] .= $spacing . '<b><p style="padding-left: ' . 10 * $context['level'] . 'px;">' . '<a href="#' . prefixToHTMLID($env->tocPrefix) . '">' . $docHeadingNumbering . $name . "</a></p></b>\n";
        $code .= "<a name='" . prefixToHTMLID($context['prefix']) . "'></a>\n";
    }
    $docHeadingLevel = $context['level'] - 1;
    //we would like to have html top heading H1 - H6
    $docHeadingLevel = $docHeadingLevel > 6 ? 6 : $docHeadingLevel;
    $code .= "<h{$docHeadingLevel} class='doclevel'>" . $docHeadingNumbering . $labels['test_suite'] . $title_separator . $name . "</h{$docHeadingLevel}>\n";
    // ----- get Test Suite text -----------------
    if ($options['header']) {
        if (!$tsuite_mgr) {
            $tsuite_mgr = new testsuite($db);
        }
        $tInfo = $tsuite_mgr->get_by_id($node['id']);
        if ($tInfo['details'] != '') {
            $code .= '<div>' . $tInfo['details'] . '</div>';
        }
        $attachSet = (array) $tsuite_mgr->getAttachmentInfos($node['id']);
        if (count($attachSet) > 0) {
            $code .= "<table>";
            $code .= "<tr><td><span class=\"label\">" . $labels['attached_files'] . "</span></td><td><ul>";
            foreach ($attachSet as $item) {
                $fname = "";
                if ($item['title']) {
                    $fname .= htmlspecialchars($item['title']) . " : ";
                }
                $fname .= htmlspecialchars($item['file_name']);
                $code .= "<li>{$fname}</li>";
                if ($item['is_image']) {
                    $code .= '<li>' . '<img src="' . $env->base_href . 'lib/attachments/attachmentdownload.php?skipCheck=1&id=' . $item['id'] . '"> </li>';
                }
            }
            $code .= "</ul></td></tr>";
            $code .= "</table>";
        }
        // get Custom fields
        // Attention: for test suites custom fields can not be edited during execution,
        //            then we need to get just custom fields with scope  'design'
        foreach ($cfields as $key => $value) {
            $cfields[$key] = $tsuite_mgr->html_table_of_custom_field_values($node['id'], $key, null, $context['tproject_id'], $cfieldFormatting);
            if ($cfields[$key] != "") {
                $add_br = true;
                $code .= '<p>' . $cfields[$key] . '</p>';
            }
        }
    }
    return $code;
}
Esempio n. 17
0
 *
 * @internal revisions
 * @since 1.9.13
 *
 **/
require_once "../../config.inc.php";
require_once "common.php";
require_once "opt_transfer.php";
require_once "web_editor.php";
$cfg = getCfg();
$optionTransferName = 'ot';
testlinkInitPage($db);
$tcase_mgr = new testcase($db);
$tproject_mgr = new testproject($db);
$tree_mgr = new tree($db);
$tsuite_mgr = new testsuite($db);
$args = init_args($cfg, $optionTransferName, $tcase_mgr);
require_once require_web_editor($cfg->webEditorCfg['type']);
$templateCfg = templateConfiguration('tcEdit');
$commandMgr = new testcaseCommands($db, $args->user, $args->tproject_id);
$commandMgr->setTemplateCfg(templateConfiguration());
$testCaseEditorKeys = array('summary' => 'summary', 'preconditions' => 'preconditions');
$init_inputs = true;
$opt_cfg = initializeOptionTransferCfg($optionTransferName, $args, $tproject_mgr);
$gui = initializeGui($db, $args, $cfg, $tcase_mgr);
$smarty = new TLSmarty();
$active_status = 0;
$name_ok = 1;
$action_result = "deactivate_this_version";
if ($args->do_activate_this) {
    $active_status = 1;
function renderTestSuiteNodeForPrinting(&$db, &$node, $env, &$options, $context, $tocPrefix, $indentLevel)
{
    static $tsuite_mgr;
    static $l10n;
    static $title_separator;
    static $cfieldFormatting;
    static $getOpt;
    if (is_null($l10n)) {
        $tsuite_mgr = new testsuite($db);
        $l10n = array('test_suite' => 'test_suite', 'details' => 'details', 'attached_files' => 'attached_files');
        $l10n = init_labels($l10n);
        $title_separator = config_get('gui_title_separator_1');
        $cfieldFormatting = array('table_css_style' => 'class="cf"');
        $getOpt['getByID'] = array('fields' => ' TS.id,TS.details ', 'renderImageInline' => true);
    }
    $code = null;
    $name = isset($node['name']) ? htmlspecialchars($node['name']) : '';
    $cfields = array('design' => '');
    $docHeadingNumbering = $options['headerNumbering'] ? $tocPrefix . "." : '';
    if ($options['toc']) {
        $spacing = $indentLevel == 2 && $tocPrefix != 1 ? "<br>" : "";
        $options['tocCode'] .= $spacing . '<b><p style="padding-left: ' . 10 * $indentLevel . 'px;">' . '<a href="#' . prefixToHTMLID($tocPrefix) . '">' . $docHeadingNumbering . $name . "</a></p></b>\n";
        $code .= "<a name='" . prefixToHTMLID($context['prefix']) . "'></a>\n";
    }
    // we would like to have html top heading H1 - H6
    $docHeadingLevel = $indentLevel - 1;
    // Remember that only H1 to H6 exists
    $docHeadingLevel = $docHeadingLevel > 6 ? 6 : $docHeadingLevel;
    $docHeadingLevel = $docHeadingLevel < 1 ? 1 : $docHeadingLevel;
    $code .= "<h{$docHeadingLevel} class='doclevel'>" . $docHeadingNumbering . $l10n['test_suite'] . $title_separator . $name . "</h{$docHeadingLevel}>\n";
    // ----- get Test Suite text -----------------
    if ($options['header']) {
        $tInfo = $tsuite_mgr->get_by_id($node['id'], $getOpt['getByID']);
        if ($tInfo['details'] != '') {
            $code .= '<div>' . $tInfo['details'] . '</div>';
        }
        $tInfo = null;
        $attachSet = (array) $tsuite_mgr->getAttachmentInfos($node['id']);
        if (count($attachSet) > 0) {
            $code .= '<table><caption style="text-align:left;">' . $l10n['attached_files'] . '</caption>';
            $code .= '<tr><td>&nbsp</td>';
            $code .= '<td><ul>';
            foreach ($attachSet as $item) {
                $fname = "";
                if ($item['title']) {
                    $fname .= htmlspecialchars($item['title']) . " : ";
                }
                $fname .= htmlspecialchars($item['file_name']);
                $code .= "<li>{$fname}</li>";
                if ($item['is_image']) {
                    $code .= '<li>' . '<img src="' . $env->base_href . 'lib/attachments/attachmentdownload.php?skipCheck=1&id=' . $item['id'] . '"> </li>';
                } else {
                    $code .= '<li>' . '<a href="' . $env->base_href . 'lib/attachments/attachmentdownload.php?skipCheck=1&id=' . $item['id'] . '" ' . ' target="#blank" > ' . htmlspecialchars($item['file_name']) . '</a></li>';
                }
            }
            $code .= "</ul></td></tr>";
            $code .= "</table>";
        }
        $attachSet = null;
        // get Custom fields
        // Attention: for test suites custom fields can not be edited during execution,
        //            then we need to get just custom fields with scope  'design'
        foreach ($cfields as $key => $value) {
            $cfields[$key] = $tsuite_mgr->html_table_of_custom_field_values($node['id'], $key, null, $context['tproject_id'], $cfieldFormatting);
            if ($cfields[$key] != "") {
                $add_br = true;
                $code .= '<p>' . $cfields[$key] . '</p>';
            }
        }
        $cfields = null;
    }
    return $code;
}
Esempio n. 19
0
function processTestSuite(&$dbHandler, &$guiObj, &$argsObj, $linked_tcversions, &$treeMgr, &$tcaseMgr, &$docRepository)
{
    $locationFilters = $tcaseMgr->buildCFLocationMap();
    $testSet = new stdClass();
    $cf_filters = array('show_on_execution' => 1);
    // BUGID 1650 (REQ)
    $tsuite_mgr = new testsuite($dbHandler);
    $tsuite_data = $tsuite_mgr->get_by_id($argsObj->id);
    $opt = array('write_button_only_if_linked' => 1, 'prune_unlinked_tcversions' => 1);
    // @TODO - 20090815 - franciscom
    // why here we do not have filtered by tester ?
    // same for platform_id
    $filters = array('keywords' => $argsObj->keyword_id);
    $out = gen_spec_view($dbHandler, 'testplan', $argsObj->tplan_id, $argsObj->id, $tsuite_data['name'], $linked_tcversions, null, $filters, $opt);
    $testSet->tcase_id = array();
    $testSet->tcversion_id = array();
    foreach ($out['spec_view'] as $key => $value) {
        if (count($value['testcases']) > 0) {
            foreach ($value['testcases'] as $xkey => $xvalue) {
                $testSet->tcase_id[] = $xkey;
                $testSet->tcversion_id[] = $xvalue['linked_version_id'];
            }
        }
    }
    // ---------------------------------------------------------------------------------
    // Get the path for every test case, grouping test cases that have same parent.
    $testCaseQty = count($testSet->tcase_id);
    if ($testCaseQty > 0) {
        $dummy = $tcaseMgr->cfield_mgr->getLocations();
        $verboseLocationCode = array_flip($dummy['testcase']);
        $filters = null;
        foreach ($verboseLocationCode as $key => $value) {
            $filters[$key]['location'] = $value;
        }
        $dummy_id = current($testSet->tcase_id);
        $index = $testCaseQty == 1 ? $dummy_id : 0;
        // 0 => BULK
        $suffix = '_' . $index;
        $execution_time_cfields = $tcaseMgr->html_table_of_custom_field_inputs($dummy_id, $argsObj->tproject_id, 'execution', $suffix, null, null, $argsObj->tproject_id);
        $guiObj->execution_time_cfields[$index] = $execution_time_cfields;
        $gdx = 0;
        foreach ($testSet->tcase_id as $testcase_id) {
            $path_f = $treeMgr->get_path($testcase_id, null, 'full');
            foreach ($path_f as $key => $path_elem) {
                if ($path_elem['parent_id'] == $argsObj->id) {
                    // Can be added because is present in the branch the user wants to view
                    // ID of branch starting node is in $argsObj->id
                    $guiObj->tcAttachments[$testcase_id] = getAttachmentInfos($docRepository, $testcase_id, 'nodes_hierarchy', true, 1);
                    foreach ($locationFilters as $locationKey => $filterValue) {
                        $finalFilters = $cf_filters + $filterValue;
                        //
                        // BUGID 3431 - Custom Field values at Test Case VERSION Level
                        // $guiObj->design_time_cfields[$testcase_id][$locationKey] =
                        // 	$tcaseMgr->html_table_of_custom_field_values($testcase_id,'design',$finalFilters);
                        $guiObj->design_time_cfields[$testcase_id][$locationKey] = $tcaseMgr->html_table_of_custom_field_values($testcase_id, 'design', $finalFilters, null, null, $argsObj->tproject_id, null, $testSet->tcversion_id[$gdx]);
                        $guiObj->testplan_design_time_cfields[$testcase_id] = $tcaseMgr->html_table_of_custom_field_values($testcase_id, 'testplan_design', $cf_filters, null, null, $argsObj->tproject_id);
                    }
                    // BUGID 856: Guest user can execute test case
                    if ($guiObj->grants->execute) {
                        $guiObj->execution_time_cfields[$testcase_id] = $tcaseMgr->html_table_of_custom_field_inputs($testcase_id, null, 'execution', "_" . $testcase_id, null, null, $argsObj->tproject_id);
                    }
                }
                // if( $path_elem['parent_id'] == $argsObj->id )
                // We do this because do not know if some test case not yet analised will be direct
                // child of this test suite, then we get this info in advance.
                // In situations where only last test suite on branch have test cases, we are colleting
                // info we will never use.
                if ($path_elem['node_table'] == 'testsuites' && !isset($guiObj->tSuiteAttachments[$path_elem['id']])) {
                    $guiObj->tSuiteAttachments[$path_elem['id']] = getAttachmentInfos($docRepository, $path_elem['id'], 'nodes_hierarchy', true, 1);
                }
            }
            //foreach($path_f as $key => $path_elem)
            $gdx++;
        }
    }
    return array($testSet->tcase_id, $testSet->tcversion_id);
}
Esempio n. 20
0
 * @package 	  TestLink
 * @author 		  Martin Havlat
 * @copyright 	2005-2012, TestLink community 
 * @link 		    http://www.teamst.org/index.php
 *
 * @internal revisions
 */
require_once "../../config.inc.php";
require_once "common.php";
require_once "web_editor.php";
$editorCfg = getWebEditorCfg('design');
require_once require_web_editor($editorCfg['type']);
testlinkInitPage($db);
$tree_mgr = new tree($db);
$tproject_mgr = new testproject($db);
$tsuite_mgr = new testsuite($db);
$tcase_mgr = new testcase($db);
$assign_gui = true;
$refreshTree = false;
list($args, $gui) = initializeEnv($db, $tree_mgr);
$keywordSet = array('testproject' => $tproject_mgr->get_keywords_map($args->tproject_id), 'testsuite' => null);
if ($args->action == 'edit_testsuite') {
    $keywordSet['testsuite'] = $tsuite_mgr->get_keywords_map($args->testsuiteID, " ORDER BY keyword ASC ");
}
$gui_cfg = config_get('gui');
$tpl = null;
$smarty = new TLSmarty();
$smarty->tlTemplateCfg = templateConfiguration();
$smarty->assign('editorType', $editorCfg['type']);
switch ($args->action) {
    case 'edit_testsuite':
Esempio n. 21
0
 /**
  * get list of TestSuites which are DIRECT children of a given TestSuite
  *
  * @param struct $args
  * @param string $args["devKey"]
  * @param int $args["testsuiteid"]
  * @return mixed $resultInfo
  *
  * @access public
  */
 public function getTestSuitesForTestSuite($args)
 {
     $operation = __FUNCTION__;
     $msg_prefix = "({$operation}) - ";
     $items = null;
     $this->_setArgs($args);
     $status_ok = $this->_runChecks(array('authenticate', 'checkTestSuiteID'), $msg_prefix) && $this->userHasRight("mgt_view_tc", self::CHECK_PUBLIC_PRIVATE_ATTR);
     if ($status_ok) {
         $testSuiteID = $this->args[self::$testSuiteIDParamName];
         $tsuiteMgr = new testsuite($this->dbObj);
         $items = $tsuiteMgr->get_children($testSuiteID);
     }
     return $status_ok ? $items : $this->errors;
 }
Esempio n. 22
0
$tproject_mgr = new testproject($db);
$tcase_mgr = new testcase($db);
$result = null;
$keyword_assignment_subtitle = null;
$can_do = 0;
$itemID = null;
$opt_cfg->global_lbl = '';
$opt_cfg->additional_global_lbl = null;
$opt_cfg->from->lbl = lang_get('available_kword');
$opt_cfg->to->lbl = lang_get('assigned_kword');
$opt_cfg->from->map = $tproject_mgr->get_keywords_map($args->testproject_id);
$opt_cfg->to->map = $tcase_mgr->get_keywords_map($args->id, " ORDER BY keyword ASC ");
if ($args->edit == 'testsuite') {
    // We are going to walk all test suites contained
    // in the selected container, and assign/remove keywords on each test case.
    $tsuite_mgr = new testsuite($db);
    $testsuite = $tsuite_mgr->get_by_id($args->id);
    $keyword_assignment_subtitle = lang_get('test_suite') . TITLE_SEP . $testsuite['name'];
    $tcs = $tsuite_mgr->get_testcases_deep($args->id, 'only_id');
    if (sizeof($tcs)) {
        $can_do = 1;
        if ($args->bAssignTestSuite) {
            $result = 'ok';
            for ($i = 0; $i < sizeof($tcs); $i++) {
                $tcID = $tcs[$i];
                $tcase_mgr->setKeywords($tcID, $args->keywordArray);
            }
        }
        $itemID = $tcs;
    }
} else {
 /**
  * 
  *
  */
 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;
 }
Esempio n. 24
0
function processTestSuite(&$dbHandler, &$guiObj, &$argsObj, $testSet, &$treeMgr, &$tcaseMgr, &$docRepository)
{
    $locationFilters = $tcaseMgr->buildCFLocationMap();
    $cf_filters = array('show_on_execution' => 1);
    $tsuite_mgr = new testsuite($dbHandler);
    $tsuite_data = $tsuite_mgr->get_by_id($argsObj->id);
    // Get the path for every test case, grouping test cases that have same parent.
    $testCaseQty = count($testSet->tcase_id);
    if ($testCaseQty > 0) {
        $dummy = $tcaseMgr->cfield_mgr->getLocations();
        $verboseLocationCode = array_flip($dummy['testcase']);
        $filters = null;
        foreach ($verboseLocationCode as $key => $value) {
            $filters[$key]['location'] = $value;
        }
        $dummy_id = current($testSet->tcase_id);
        $index = $testCaseQty == 1 ? $dummy_id : 0;
        // 0 => BULK
        $suffix = '_' . $index;
        $execution_time_cfields = $tcaseMgr->html_table_of_custom_field_inputs($dummy_id, $argsObj->tproject_id, 'execution', $suffix, null, null, $argsObj->tproject_id);
        $guiObj->execution_time_cfields[$index] = $execution_time_cfields;
        $gdx = 0;
        foreach ($testSet->tcase_id as $testcase_id) {
            $path_f = $treeMgr->get_path($testcase_id, null, 'full');
            foreach ($path_f as $key => $path_elem) {
                if ($path_elem['parent_id'] == $argsObj->id) {
                    // Can be added because is present in the branch the user wants to view
                    // ID of branch starting node is in $argsObj->id
                    $guiObj->tcAttachments[$testcase_id] = getAttachmentInfos($docRepository, $testcase_id, 'nodes_hierarchy', true, 1);
                    foreach ($locationFilters as $locationKey => $filterValue) {
                        $finalFilters = $cf_filters + $filterValue;
                        $guiObj->design_time_cfields[$testcase_id][$locationKey] = $tcaseMgr->html_table_of_custom_field_values($testcase_id, 'design', $finalFilters, null, null, $argsObj->tproject_id, null, $testSet->tcversion_id[$gdx]);
                        $guiObj->testplan_design_time_cfields[$testcase_id] = $tcaseMgr->html_table_of_custom_field_values($testcase_id, 'testplan_design', $cf_filters, null, null, $argsObj->tproject_id);
                    }
                    if ($guiObj->grants->execute) {
                        $guiObj->execution_time_cfields[$testcase_id] = $tcaseMgr->html_table_of_custom_field_inputs($testcase_id, null, 'execution', "_" . $testcase_id, null, null, $argsObj->tproject_id);
                    }
                }
                // if( $path_elem['parent_id'] == $argsObj->id )
                // We do this because do not know if some test case not yet analised will be direct
                // child of this test suite, then we get this info in advance.
                // In situations where only last test suite on branch have test cases, we are colleting
                // info we will never use.
                if ($path_elem['node_table'] == 'testsuites' && !isset($guiObj->tSuiteAttachments[$path_elem['id']])) {
                    $guiObj->tSuiteAttachments[$path_elem['id']] = getAttachmentInfos($docRepository, $path_elem['id'], 'nodes_hierarchy', true, 1);
                }
            }
            //foreach($path_f as $key => $path_elem)
            $gdx++;
        }
    }
    // return array($testSet->tcase_id,$testSet->tcversion_id);
}
 /**
  * 
  *
  */
 function create(&$argsObj, &$otCfg)
 {
     $parentKeywords = array();
     $guiObj = $this->initGuiBean($argsObj);
     $guiObj->initWebEditorFromTemplate = true;
     $guiObj->containerID = $argsObj->container_id;
     if ($argsObj->container_id > 0) {
         $pnode_info = $this->tcaseMgr->tree_manager->get_node_hierarchy_info($argsObj->container_id);
         $node_descr = array_flip($this->tcaseMgr->tree_manager->get_available_node_types());
         $guiObj->parent_info['name'] = $pnode_info['name'];
         $guiObj->parent_info['description'] = lang_get($node_descr[$pnode_info['node_type_id']]);
         // get keywords
         $tsuiteMgr = new testsuite($this->db);
         $parentKeywords = $tsuiteMgr->getKeywords($argsObj->container_id);
     }
     $sep_1 = config_get('gui_title_separator_1');
     $sep_2 = config_get('gui_title_separator_2');
     $guiObj->main_descr = $guiObj->parent_info['description'] . $sep_1 . $guiObj->parent_info['name'] . $sep_2 . lang_get('title_new_tc');
     $otCfg->to->map = array();
     keywords_opt_transf_cfg($otCfg, implode(',', array_keys((array) $parentKeywords)));
     $guiObj->tc = array('id' => 0, 'name' => '', 'importance' => config_get('testcase_importance_default'), 'status' => null, 'estimated_exec_duration' => null, 'execution_type' => TESTCASE_EXECUTION_TYPE_MANUAL);
     $guiObj->opt_cfg = $otCfg;
     $templateCfg = templateConfiguration('tcNew');
     $guiObj->template = $templateCfg->default_template;
     $cfPlaces = $this->tcaseMgr->buildCFLocationMap();
     foreach ($cfPlaces as $locationKey => $locationFilter) {
         $guiObj->cf[$locationKey] = $this->tcaseMgr->html_table_of_custom_field_inputs(null, null, 'design', '', null, null, $argsObj->testproject_id, $locationFilter, $_REQUEST);
     }
     return $guiObj;
 }
Esempio n. 26
0
/**
 * 
 * @internal revisions:
 * 20100721 - asimon - BUGID 3406 - added $options for new user assignments per build
 * 20100218 - asimon - BUGID 3026 - added parameter $testcaseFilter to include functionality
 * 						previously used on tc_exec_assignment.php
 * 						to show only testcases present in filter argument
 *
 */
function keywordFilteredSpecView(&$dbHandler, &$argsObj, $keywordsFilter, &$tplanMgr, &$tcaseMgr, $testcaseFilter = null, $options = null)
{
    $tsuiteMgr = new testsuite($dbHandler);
    $tprojectMgr = new testproject($dbHandler);
    $tsuite_data = $tsuiteMgr->get_by_id($argsObj->id);
    $filterAssignedTo = property_exists($argsObj, 'filter_assigned_to') ? $argsObj->filter_assigned_to : null;
    // 3406
    //	$ua_build = !is_null($options) && isset($options['user_assignments_per_build']) ?
    //	$options['user_assignments_per_build'] : null;
    // @TODO - 20081019
    // Really understand differences between:
    // $argsObj->keyword_id and $keywordsFilter
    // BUGID 1041
    $filters = array('keyword_id' => $argsObj->keyword_id, 'assigned_to' => $filterAssignedTo);
    // 20100715 - asimon - why the double writing to $tplan_linked_tcversions?
    // will be overwritten again two lines below
    // $tplan_linked_tcversions = $tplanMgr->get_linked_tcversions($argsObj->tplan_id, $filters, $options);
    // This does filter on keywords ALWAYS in OR mode.
    // 3406: added $options
    $tplan_linked_tcversions = getFilteredLinkedVersions($argsObj, $tplanMgr, $tcaseMgr, $options);
    // With this pieces we implement the AND type of keyword filter.
    $testCaseSet = null;
    if (!is_null($keywordsFilter) && !is_null($keywordsFilter->items)) {
        $keywordsTestCases = $tprojectMgr->get_keywords_tcases($argsObj->tproject_id, $keywordsFilter->items, $keywordsFilter->type);
        $testCaseSet = array_keys($keywordsTestCases);
    }
    // BUGID 3026 - added $testcaseFilter
    if (!is_null($testCaseSet) && !is_null($testcaseFilter)) {
        $testCaseSet = array_intersect($testCaseSet, array($testcaseFilter));
    } else {
        if (is_null($testCaseSet) && !is_null($testcaseFilter)) {
            $testCaseSet = $testcaseFilter;
        }
    }
    // now get values as keys
    // 20100722 - asimon - additional check here because of warning from array_combine when $testCaseSet is null
    //$testCaseSet = array_combine($testCaseSet, $testCaseSet);
    $testCaseSet = !is_null($testCaseSet) ? array_combine($testCaseSet, $testCaseSet) : null;
    // function gen_spec_view(&$db,$spec_view_type='testproject',$tobj_id,$id,$name,&$linked_items,
    //                    $map_node_tccount,$filters=null, $options = null,$tproject_id = null)
    //
    // 3406
    $options = array('write_button_only_if_linked' => 1, 'prune_unlinked_tcversions' => 1) + (array) $options;
    $filters = array('keywords' => $argsObj->keyword_id, 'testcases' => $testCaseSet);
    $out = gen_spec_view($dbHandler, 'testplan', $argsObj->tplan_id, $argsObj->id, $tsuite_data['name'], $tplan_linked_tcversions, null, $filters, $options);
    return $out;
}
function migrate_cc_specs(&$source_db, &$target_db, &$items, &$old_new)
{
    $mgtcom_keys = array('intro' => 'introduction', 'scope' => 'scope', 'ref' => 'references', 'method' => 'methodology', 'lim' => 'limitations');
    $mgtcat_keys = array('objective' => 'objective', 'config' => 'configuration', 'data' => 'data', 'tools' => 'tools');
    $tproject_mgr = new testproject($target_db);
    $ts_mgr = new testsuite($target_db);
    $tree_mgr = new tree($target_db);
    foreach ($items as $prod_id => $pd) {
        $old_new['product'][$prod_id] = @$tproject_mgr->create($pd['name'], $pd['color'], $pd['option_reqs'], EMPTY_NOTES, $pd['active']);
        echo "<pre><font color='blue'>Product {$pd['name']} has became a test project!</font></pre>";
        flush();
        $tproject_id = $old_new['product'][$prod_id];
        $sql = "SELECT * FROM mgtcomponent WHERE prodid={$prod_id}";
        $comp = $source_db->fetchRowsIntoMap($sql, 'id');
        // for change_order_bulk($hash_node_id, $hash_node_order)
        // $hash_node_id=array(10=>10, 23=>23, 30=>30);
        // $hash_node_order=array(10=>3, 23=>1, 30=>2);
        // $hash_node_id=array();
        // $hash_node_order=array();
        // 20071021 - francisco.mancardi@gruppotesi.com
        //
        // $hash_order_node_order=array(3=>10, 1=>23, 2=>30);
        // means:  node_id: 10 order:3
        //         node_id: 23 order:1
        //         node_id: 30 order:2
        $hash_order_node_id = array();
        if (count($comp) > 0) {
            foreach ($comp as $coid => $cod) {
                $details = '';
                foreach ($mgtcom_keys as $key => $val) {
                    $details .= $val . ": <br>" . $cod[$key] . "<p>";
                }
                $ret = $ts_mgr->create($tproject_id, $cod['name'], $details);
                if ($ret['status_ok']) {
                    echo "<pre>Component " . htmlentities($cod['name']) . " Migrated<br></pre>";
                    flush();
                    $mgtcomp_id = $ret['id'];
                    $old_new['mgtcomp'][$coid] = $mgtcomp_id;
                }
                // ----------------------------------------------------------------------------------
                $sql = "SELECT * FROM mgtcategory WHERE compid={$coid}";
                $cat = $source_db->fetchRowsIntoMap($sql, 'id');
                if (count($cat) > 0) {
                    foreach ($cat as $caid => $cad) {
                        // ----------------------------------------------------------------------------------
                        $details = '';
                        foreach ($mgtcat_keys as $key => $val) {
                            $details .= $val . ": <br>" . $cad[$key] . "<p>";
                        }
                        // ----------------------------------------------------------------------------------
                        $ret = $ts_mgr->create($mgtcomp_id, $cad['name'], $details);
                        if ($ret['status_ok']) {
                            echo "<pre>    Category " . htmlentities($cad['name']) . " Migrated<br></pre>";
                            flush();
                            $mgtcat_id = $ret['id'];
                            $old_new['mgtcat'][$caid] = $mgtcat_id;
                            if ($cad['CATorder'] != 0) {
                                // 20071021 - franciscom
                                // $hash_node_id[$mgtcat_id]=$mgtcat_id;
                                // $hash_node_order[$mgtcat_id]=$cad['CATorder'];
                                $node_id = $mgtcat_id;
                                $node_order = $cad['CATorder'];
                                $hash_order_node_id[$node_order] = $node_id;
                            }
                        }
                        // ----------------------------------------------------------------------------------
                    }
                }
            }
            // 20060725 - franciscom
            // $tree_mgr->change_order_bulk($hash_node_id, $hash_node_order) ;
            $tree_mgr->change_order_bulk($hash_order_node_id);
        }
    }
}
Esempio n. 28
0
 /**
  * create a test suite
  * 
  * @param struct $args
  * @param string $args["devKey"]
  * @param int $args["testprojectid"]
  * @param string $args["testsuitename"]
  * @param string $args["details"]
  * @param int $args["parentid"] optional, if do not provided means test suite must be top level.
  * @param int $args["order"] optional. Order inside parent container
  * @param int $args["checkduplicatedname"] optional, default true.
  *                                          will check if there are siblings with same name.
  *
  * @param int $args["actiononduplicatedname"] optional
  *                                            applicable only if $args["checkduplicatedname"]=true
  *                                            what to do if already a sibling exists with same name.
  *	 
  * @return mixed $resultInfo
  */
 public function createTestSuite($args)
 {
     $result = array();
     $this->_setArgs($args);
     $operation = __FUNCTION__;
     $msg_prefix = "({$operation}) - ";
     $checkFunctions = array('authenticate', 'checkTestSuiteName', 'checkTestProjectID');
     $status_ok = $this->_runChecks($checkFunctions, $msg_prefix) && $this->userHasRight("mgt_modify_tc");
     if ($status_ok) {
         // Optional parameters
         $opt = array(self::$orderParamName => testsuite::DEFAULT_ORDER, self::$checkDuplicatedNameParamName => testsuite::CHECK_DUPLICATE_NAME, self::$actionOnDuplicatedNameParamName => 'block');
         foreach ($opt as $key => $value) {
             if ($this->_isParamPresent($key)) {
                 $opt[$key] = $this->args[$key];
             }
         }
     }
     if ($status_ok) {
         $parent_id = $args[self::$testProjectIDParamName];
         $tprojectInfo = $this->tprojectMgr->get_by_id($args[self::$testProjectIDParamName]);
         $tsuiteMgr = new testsuite($this->dbObj);
         if ($this->_isParamPresent(self::$parentIDParamName)) {
             $parent_id = $args[self::$parentIDParamName];
             // if parentid exists it must:
             // be a test suite id
             $node_info = $tsuiteMgr->get_by_id($args[self::$parentIDParamName]);
             if (!($status_ok = !is_null($node_info))) {
                 $msg = sprintf(INVALID_PARENT_TESTSUITEID_STR, $args[self::$parentIDParamName], $args[self::$testSuiteNameParamName]);
                 $this->errors[] = new IXR_Error(INVALID_PARENT_TESTSUITEID, $msg_prefix . $msg);
             }
             if ($status_ok) {
                 // Must belong to target test project
                 $root_node_id = $tsuiteMgr->getTestProjectFromTestSuite($args[self::$parentIDParamName], null);
                 if (!($status_ok = $root_node_id == $args[self::$testProjectIDParamName])) {
                     $msg = sprintf(TESTSUITE_DONOTBELONGTO_TESTPROJECT_STR, $args[self::$parentIDParamName], $tprojectInfo['name'], $args[self::$testProjectIDParamName]);
                     $this->errors[] = new IXR_Error(TESTSUITE_DONOTBELONGTO_TESTPROJECT, $msg_prefix . $msg);
                 }
             }
         }
     }
     if ($status_ok) {
         $op = $tsuiteMgr->create($parent_id, $args[self::$testSuiteNameParamName], $args[self::$detailsParamName], $opt[self::$orderParamName], $opt[self::$checkDuplicatedNameParamName], $opt[self::$actionOnDuplicatedNameParamName]);
         if ($status_ok = $op['status_ok']) {
             $op['status'] = $op['status_ok'] ? true : false;
             $op['operation'] = $operation;
             $op['additionalInfo'] = '';
             $op['message'] = $op['msg'];
             unset($op['msg']);
             unset($op['status_ok']);
             $result[] = $op;
         } else {
             $op['msg'] = sprintf($op['msg'], $args[self::$testSuiteNameParamName]);
             $this->errors = $op;
         }
     }
     return $status_ok ? $result : $this->errors;
 }