Example #1
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;
}
Example #2
0
/**
 *
 *
 */
function systemWideTestCaseSearch(&$dbHandler, &$argsObj, $glue)
{
    // Attention:
    // this algorithm has potential flaw (IMHO) because we can find the glue character
    // in situation where it's role is not this.
    // Anyway i will work on this in the future (if I've time)
    //
    if (strpos($argsObj->targetTestCase, $glue) === false) {
        // We suppose user was lazy enough to do not provide prefix,
        // then we will try to help him/her
        $argsObj->targetTestCase = $argsObj->tcasePrefix . $argsObj->targetTestCase;
    }
    if (!is_null($argsObj->targetTestCase)) {
        // parse to get JUST prefix, find the last glue char.
        // This useful because from navBar, user can request search of test cases that belongs
        // to test project DIFFERENT to test project setted in environment
        if (($gluePos = strrpos($argsObj->targetTestCase, $glue)) !== false) {
            $tcasePrefix = substr($argsObj->targetTestCase, 0, $gluePos);
        }
        $tprojectMgr = new testproject($dbHandler);
        $argsObj->tcaseTestProject = $tprojectMgr->get_by_prefix($tcasePrefix);
        $tcaseMgr = new testcase($dbHandler);
        $argsObj->tcase_id = $tcaseMgr->getInternalID($argsObj->targetTestCase);
        $dummy = $tcaseMgr->get_basic_info($argsObj->tcase_id, array('number' => $argsObj->tcaseVersionNumber));
        if (!is_null($dummy)) {
            $argsObj->tcversion_id = $dummy[0]['tcversion_id'];
        }
    }
}
Example #3
0
/**
 * 
 *
 */
function init_args(&$dbHandler)
{
    $_REQUEST = strings_stripSlashes($_REQUEST);
    $iParams = array("edit" => array(tlInputParameter::STRING_N, 0, 50), "id" => array(tlInputParameter::INT_N), "show_path" => array(tlInputParameter::INT_N), "show_mode" => array(tlInputParameter::STRING_N, 0, 50), "tcase_id" => array(tlInputParameter::INT_N), "tcversion_id" => array(tlInputParameter::INT_N), "tproject_id" => array(tlInputParameter::INT_N), "targetTestCase" => array(tlInputParameter::STRING_N, 0, 24), "tcasePrefix" => array(tlInputParameter::STRING_N, 0, 16), "tcaseExternalID" => array(tlInputParameter::STRING_N, 0, 16), "tcaseVersionNumber" => array(tlInputParameter::INT_N));
    $args = new stdClass();
    R_PARAMS($iParams, $args);
    // For more information about the data accessed in session here, see the comment
    // in the file header of lib/functions/tlTestCaseFilterControl.class.php.
    $form_token = isset($_REQUEST['form_token']) ? $_REQUEST['form_token'] : 0;
    $mode = 'edit_mode';
    $cfg = config_get('testcase_cfg');
    $session_data = isset($_SESSION[$mode]) && isset($_SESSION[$mode][$form_token]) ? $_SESSION[$mode][$form_token] : null;
    $args->refreshTree = isset($session_data['setting_refresh_tree_on_action']) ? $session_data['setting_refresh_tree_on_action'] : 0;
    $args->user_id = isset($_SESSION['userID']) ? $_SESSION['userID'] : 0;
    $args->feature = $args->edit;
    $args->opt_requirements = null;
    $args->automationEnabled = 0;
    $args->requirementsEnabled = 0;
    $args->testPriorityEnabled = 0;
    $args->tcasePrefix = trim($args->tcasePrefix);
    $tprojectMgr = new testproject($dbHandler);
    if ($args->tproject_id <= 0 && strlen($args->tcaseExternalID) > 0) {
        // parse to get JUST prefix
        $gluePos = strrpos($args->tcaseExternalID, $cfg->glue_character);
        // Find the last glue char
        $status_ok = $gluePos !== false;
        if ($status_ok) {
            $tcasePrefix = substr($args->tcaseExternalID, 0, $gluePos);
        }
        $dummy = $tprojectMgr->get_by_prefix($tcasePrefix);
        $tcaseMgr = new testcase($dbHandler);
        $args->tcase_id = $tcaseMgr->getInternalID($args->tcaseExternalID);
        $tcinfo = $tcaseMgr->get_basic_info($args->tcase_id, array('number' => $args->tcaseVersionNumber));
        if (!is_null($tcinfo)) {
            $args->tcversion_id = $tcinfo[0]['tcversion_id'];
        }
        unset($tcaseMgr);
    } else {
        $dummy = $tprojectMgr->get_by_id($args->tproject_id);
    }
    if (!is_null($dummy)) {
        $args->tproject_id = $dummy['id'];
    }
    $args->opt_requirements = $dummy['opt']->requirementsEnabled;
    $args->requirementsEnabled = $dummy['opt']->requirementsEnabled;
    $args->automationEnabled = $dummy['opt']->automationEnabled;
    $args->testPriorityEnabled = $dummy['opt']->testPriorityEnabled;
    if (!$args->tcversion_id) {
        $args->tcversion_id = testcase::ALL_VERSIONS;
    }
    // used to manage goback
    if (intval($args->tcase_id) > 0) {
        $args->feature = 'testcase';
        $args->id = intval($args->tcase_id);
    }
    $args->id = is_null($args->id) ? 0 : $args->id;
    switch ($args->feature) {
        case 'testsuite':
            $_SESSION['setting_refresh_tree_on_action'] = $args->refreshTree ? 1 : 0;
            break;
        case 'testproject':
            $args->id = $args->tproject_id;
            break;
    }
    if (strpos($args->targetTestCase, $cfg->glue_character) === false) {
        $args->targetTestCase = $args->tcasePrefix . $args->targetTestCase;
    }
    return $args;
}