/** * get Test Specification data within a Node * * using nodeId (that normally is a test suite id) as starting point * will return subtree that start at nodeId. * If filters are given, the subtree returned is filtered. * * Important Notice regaring keyword filtering * Keyword filter logic inside this function seems to work ONLY on OR mode. * Then how the AND mode is implemented ? * Filter for test case id is used, and the test case set has been generated * applying AND or OR logic (following user's choice). * Then seems that logic regarding keywords here, may be can be removed * * @param integer $masterContainerId can be a Test Project Id, or a Test Plan id. * is used only if keyword id filter has been specified * to get all keyword defined on masterContainer. * * @param integer $nodeId node that will be root of the view we want to build. * * @param string $specViewType: type of view requested * * @param array $filters * filters['keyword_id']: array of keywords * filters['tcase_id']: * filters['execution_type']: * filters['importance']: * filters['cfields']: * filters['tcase_name']: * * * @return array map with view (test cases subtree) * * @internal revisions * */ function getTestSpecFromNode(&$dbHandler, &$tcaseMgr, &$linkedItems, $masterContainerId, $nodeId, $specViewType, $filters) { $applyFilters = false; $testCaseSet = null; $tck_map = null; $tobj_mgr = new testproject($dbHandler); $opt = null; if ($specViewType == 'testplan') { $opt['order_cfg'] = array("type" => 'exec_order', 'tplan_id' => $masterContainerId); } $test_spec = $tobj_mgr->get_subtree($nodeId, null, $opt); $key2loop = null; $useAllowed = false; $nullCheckFilter = array('tcase_id' => false, 'importance' => false, 'tcase_name' => false, 'cfields' => false, 'status' => false); $zeroNullCheckFilter = array('execution_type' => false); $useFilter = array('keyword_id' => false) + $nullCheckFilter + $zeroNullCheckFilter; $applyFilters = false; foreach ($nullCheckFilter as $key => $value) { $useFilter[$key] = !is_null($filters[$key]); $applyFilters = $applyFilters || $useFilter[$key]; } // more specif analisys if ($useFilter['status'] = $filters['status'][0] > 0) { $applyFilters = true; $filtersByValue['status'] = array_flip((array) $filters['status']); } if ($useFilter['importance'] = $filters['importance'][0] > 0) { $applyFilters = true; $filtersByValue['importance'] = array_flip((array) $filters['importance']); } foreach ($zeroNullCheckFilter as $key => $value) { // need to check for > 0, because for some items 0 has same meaning that null -> no filter $useFilter[$key] = !is_null($filters[$key]) && $filters[$key] > 0; $applyFilters = $applyFilters || $useFilter[$key]; } if ($useFilter['tcase_id']) { $testCaseSet = is_array($filters['tcase_id']) ? $filters['tcase_id'] : array($filters['tcase_id']); } if (!is_array($filters['keyword_id'])) { $filters['keyword_id'] = array($filters['keyword_id']); } if ($useFilter['keyword_id'] = $filters['keyword_id'][0] > 0) { $applyFilters = true; switch ($specViewType) { case 'testplan': $tobj_mgr = new testplan($dbHandler); break; } $tck_map = $tobj_mgr->get_keywords_tcases($masterContainerId, $filters['keyword_id']); } if ($applyFilters) { $key2loop = array_keys($test_spec); // first step: generate list of TEST CASE NODES $itemSet = null; foreach ($key2loop as $key) { if ($test_spec[$key]['node_type_id'] == $filters['tcase_node_type_id']) { $itemSet[$test_spec[$key]['id']] = $key; } } $itemKeys = $itemSet; foreach ($itemKeys as $key => $tspecKey) { // case insensitive search if ($useFilter['keyword_id'] && !isset($tck_map[$test_spec[$tspecKey]['id']]) || $useFilter['tcase_id'] && !in_array($test_spec[$tspecKey]['id'], $testCaseSet) || $useFilter['tcase_name'] && stripos($test_spec[$tspecKey]['name'], $filters['tcase_name']) === false) { $test_spec[$tspecKey] = null; unset($itemSet[$key]); } } if (count($itemSet) > 0 && ($useFilter['execution_type'] || $useFilter['importance'] || $useFilter['cfields'] || $useFilter['status'])) { // This logic can have some Potential Performance ISSUE - 20120619 - fman $targetSet = array_keys($itemSet); $options = $specViewType == 'testPlanLinking' ? array('access_key' => 'testcase_id') : null; $getFilters = $useFilter['cfields'] ? array('cfields' => $filters['cfields']) : null; $s2h = config_get('tplanDesign')->hideTestCaseWithStatusIn; if (!is_null($s2h)) { $getFilters['status'] = array('not_in' => array_keys($s2h)); } $tcversionSet = $tcaseMgr->get_last_active_version($targetSet, $getFilters, $options); switch ($specViewType) { case 'testPlanLinking': // We need to analise linked items and spec foreach ($targetSet as $idx => $key) { $targetTestCase = isset($tcversionSet[$key]) ? $tcversionSet[$key]['testcase_id'] : null; if (is_null($targetTestCase)) { $test_spec[$itemSet[$key]] = null; $item = null; } else { if (isset($linkedItems[$targetTestCase])) { $item = current($linkedItems[$targetTestCase]); } else { // hmmm, does not understand this logic. $item = null; if (isset($test_spec[$itemSet[$targetTestCase]])) { $item = $tcversionSet[$targetTestCase]; } } } if (!is_null($item)) { if ($useFilter['execution_type'] && $item['execution_type'] != $filters['execution_type'] || $useFilter['importance'] && !isset($filtersByValue['importance'][$item['importance']]) || $useFilter['status'] && !isset($filtersByValue['status'][$item['status']])) { $tspecKey = $itemSet[$targetTestCase]; $test_spec[$tspecKey] = null; } } } break; default: $tcvidSet = array_keys($tcversionSet); foreach ($tcvidSet as $zx) { $tcidSet[$tcversionSet[$zx]['testcase_id']] = $zx; } $options = null; $doFilter = true; $allowedSet = null; // a first clean will not be bad, ok may be we are going to do more // loops that needed, but think logic will be more clear // (at least @20130426 is a little bit confusing ;) ) foreach ($targetSet as $idx => $key) { if (!isset($tcidSet[$key])) { $test_spec[$itemSet[$key]] = null; } } if ($useFilter['execution_type']) { // Potential Performance ISSUE $allowedSet = $tcaseMgr->filter_tcversions_by_exec_type($tcvidSet, $filters['execution_type'], $options); $doFilter = !is_null($allowedSet) && count($allowedSet) > 0; } if ($doFilter) { // Add another filter on cascade mode // @20130426 - seems we are applying TWICE the Custom Fields Filter // because we have applied it before on: // $tcversionSet = $tcaseMgr->get_last_active_version() if ($useFilter['cfields']) { $filteredSet = !is_null($allowedSet) && count($allowedSet) > 0 ? array_keys($allowedSet) : $tcvidSet; $dummySet = $tcaseMgr->filter_tcversions_by_cfields($filteredSet, $filters['cfields'], $options); // transform to make compatible with filter_tcversions_by_exec_type() return type if (!is_null($dummySet) && count($dummySet) > 0) { $allowedSet = null; $work2do = array_keys($dummySet); foreach ($work2do as $wkey) { $allowedSet[$wkey] = $dummySet[$wkey][0]; } unset($dummySet); } } } if (!is_null($allowedSet) && count($allowedSet) > 0) { $useAllowed = true; foreach ($allowedSet as $key => $value) { $tspecKey = $itemSet[$value['testcase_id']]; $test_spec[$tspecKey]['version'] = $value['version']; } reset($allowedSet); } $setToRemove = array_diff_key($tcversionSet, $allowedSet); if (!is_null($setToRemove) && count($setToRemove) > 0) { foreach ($setToRemove as $key => $value) { $tspecKey = $itemSet[$value['testcase_id']]; $test_spec[$tspecKey] = null; } } break; } // end switch } } // if apply filters unset($tobj_mgr); return $test_spec; }
/** * get Test Specification data within a Node * * using nodeId (that normally is a test suite id) as starting point * will return subtree that start at nodeId. * If filters are given, the subtree returned is filtered. * * Important Notice regaring keyword filtering * Keyword filter logic inside this function seems to work ONLY on OR mode. * Then how the AND mode is implemented ? * Filter for test case id is used, and the test case set has been generated * applying AND or OR logic (following user's choice). * Then seems that logic regarding keywords here, may be can be removed * * @param integer $masterContainerId can be a Test Project Id, or a Test Plan id. * is used only if keyword id filter has been specified * to get all keyword defined on masterContainer. * * @param integer $nodeId node that will be root of the view we want to build. * * @param string $specViewType: type of view requested * * @param array $filters * filters['keyword_id']: array of keywords * * * @return array map with view (test cases subtree) * * @internal revisions * 20100417 - franciscom - BUGID 2498 - added logic to filter by importance (defined on test case spec) * 20100411 - franciscom - added logic to filter by execution type */ function getTestSpecFromNode(&$dbHandler, &$tcaseMgr, &$linkedItems, $masterContainerId, $nodeId, $specViewType, $filters) { $applyFilters = false; $testCaseSet = null; $tck_map = null; $tobj_mgr = new testproject($dbHandler); $test_spec = $tobj_mgr->get_subtree($nodeId); $key2loop = null; $useAllowed = false; // 20100411 - BUGID 2797 - filter by test case execution type $useFilter = array('keyword_id' => false, 'tcase_id' => false, 'exec_type' => false); // BUGID 3768 if (!is_array($filters['keyword_id'])) { $filters['keyword_id'] = array($filters['keyword_id']); } if ($useFilter['keyword_id'] = $filters['keyword_id'][0] > 0) { $applyFilters = true; switch ($specViewType) { case 'testplan': $tobj_mgr = new testplan($dbHandler); break; } $tck_map = $tobj_mgr->get_keywords_tcases($masterContainerId, $filters['keyword_id']); } if ($useFilter['tcase_id'] = !is_null($filters['tcase_id'])) { $applyFilters = true; $testCaseSet = is_array($filters['tcase_id']) ? $filters['tcase_id'] : array($filters['tcase_id']); } if ($useFilter['execution_type'] = !is_null($filters['execution_type'])) { $applyFilters = true; } // BUGID if ($useFilter['importance'] = !is_null($filters['importance'])) { $applyFilters = true; } if ($applyFilters) { $key2loop = array_keys($test_spec); // first step: generate list of TEST CASE NODES $itemSet = null; foreach ($key2loop as $key) { if ($test_spec[$key]['node_type_id'] == $filters['tcase_node_type_id']) { $itemSet[$test_spec[$key]['id']] = $key; } } $itemKeys = $itemSet; foreach ($itemKeys as $key => $tspecKey) { if ($useFilter['keyword_id'] && !isset($tck_map[$test_spec[$tspecKey]['id']]) || $useFilter['tcase_id'] && !in_array($test_spec[$tspecKey]['id'], $testCaseSet)) { $test_spec[$tspecKey] = null; unset($itemSet[$key]); } } if (count($itemSet) > 0 && ($useFilter['execution_type'] || $useFilter['importance'])) { $targetSet = array_keys($itemSet); $options = $specViewType == 'testPlanLinking' ? array('access_key' => 'testcase_id') : null; $tcversionSet = $tcaseMgr->get_last_active_version($targetSet, $options); switch ($specViewType) { case 'testPlanLinking': // We need to analise linked items and spec foreach ($targetSet as $idx => $key) { $targetTestCase = $tcversionSet[$key]['testcase_id']; if (isset($linkedItems[$targetTestCase])) { $item = current($linkedItems[$targetTestCase]); } else { $item = null; if (isset($test_spec[$itemSet[$targetTestCase]])) { $item = $tcversionSet[$targetTestCase]; } } if (!is_null($item)) { if ($useFilter['exec_type'] && $item['execution_type'] != $filters['exec_type'] || $useFilter['importance'] && $item['importance'] != $filters['importance']) { $tspecKey = $itemSet[$targetTestCase]; $test_spec[$tspecKey] = null; } } } break; default: $tcvidSet = array_keys($tcversionSet); // $options = array('access_key' => 'testcase_id'); $options = null; // $allowedSet = $tcaseMgr->filter_tcversions_by_exec_type($tcvidSet,$filters['exec_type'],$options); $allowedSet = $tcaseMgr->filter_tcversions_by_exec_type($tcvidSet, $filters, $options); if (!is_null($allowedSet) && count($allowedSet) > 0) { $useAllowed = true; foreach ($allowedSet as $key => $value) { $tspecKey = $itemSet[$value['testcase_id']]; $test_spec[$tspecKey]['version'] = $value['version']; } reset($allowedSet); } $setToRemove = array_diff_key($tcversionSet, $allowedSet); if (!is_null($setToRemove) && count($setToRemove) > 0) { foreach ($setToRemove as $key => $value) { $tspecKey = $itemSet[$value['testcase_id']]; $test_spec[$tspecKey] = null; } } break; } // end switch } } // if apply filters unset($tobj_mgr); return $test_spec; }
/** * get Test Specification data within a Node * * using nodeId (that normally is a test suite id) as starting point * will return subtree that start at nodeId. * If filters are given, the subtree returned is filtered. * * Important Notice regaring keyword filtering * Keyword filter logic inside this function seems to work ONLY on OR mode. * Then how the AND mode is implemented ? * Filter for test case id is used, and the test case set has been generated * applying AND or OR logic (following user's choice). * Then seems that logic regarding keywords here, may be can be removed * * @param integer $masterContainerId can be a Test Project Id, or a Test Plan id. * is used only if keyword id filter has been specified * to get all keyword defined on masterContainer. * * @param integer $nodeId node that will be root of the view we want to build. * * @param string $specViewType: type of view requested * * @param array $filters * filters['keyword_id']: array of keywords * filters['tcase_id']: * filters['execution_type']: * filters['importance']: * filters['cfields']: * filters['tcase_name']: * * * @return array map with view (test cases subtree) * * @internal revisions * 20101024 - franciscom - BUGID 3932: Add test case to test plan - Execution type filter does not affect right pane * BUGID 3936: Assign Test Case Execution - Right pane does not reflect custom field filter. * * 20100417 - franciscom - BUGID 2498 - added logic to filter by importance (defined on test case spec) * 20100411 - franciscom - added logic to filter by execution type */ function getTestSpecFromNode(&$dbHandler, &$tcaseMgr, &$linkedItems, $masterContainerId, $nodeId, $specViewType, $filters) { $applyFilters = false; $testCaseSet = null; $tck_map = null; $tobj_mgr = new testproject($dbHandler); $test_spec = $tobj_mgr->get_subtree($nodeId); $key2loop = null; $useAllowed = false; // 20100411 - BUGID 2797 - filter by test case execution type $nullCheckFilter = array('tcase_id' => false, 'importance' => false, 'tcase_name' => false, 'cfields' => false); $zeroNullCheckFilter = array('execution_type' => false); $useFilter = array('keyword_id' => false) + $nullCheckFilter + $zeroNullCheckFilter; foreach ($nullCheckFilter as $key => $value) { $useFilter[$key] = !is_null($filters[$key]); $applyFilters = $applyFilters || $useFilter[$key]; } foreach ($zeroNullCheckFilter as $key => $value) { // need to check for > 0, because for some items 0 has same meaning that null -> no filter $useFilter[$key] = !is_null($filters[$key]) && $filters[$key] > 0; $applyFilters = $applyFilters || $useFilter[$key]; } if ($useFilter['tcase_id']) { $testCaseSet = is_array($filters['tcase_id']) ? $filters['tcase_id'] : array($filters['tcase_id']); } // BUGID 3768 if (!is_array($filters['keyword_id'])) { $filters['keyword_id'] = array($filters['keyword_id']); } if ($useFilter['keyword_id'] = $filters['keyword_id'][0] > 0) { $applyFilters = true; switch ($specViewType) { case 'testplan': $tobj_mgr = new testplan($dbHandler); break; } $tck_map = $tobj_mgr->get_keywords_tcases($masterContainerId, $filters['keyword_id']); } if ($applyFilters) { $key2loop = array_keys($test_spec); // first step: generate list of TEST CASE NODES $itemSet = null; foreach ($key2loop as $key) { if ($test_spec[$key]['node_type_id'] == $filters['tcase_node_type_id']) { $itemSet[$test_spec[$key]['id']] = $key; } } $itemKeys = $itemSet; foreach ($itemKeys as $key => $tspecKey) { // 20101209 - asimon - exchanged strpos by stripos to make search case insensitive if ($useFilter['keyword_id'] && !isset($tck_map[$test_spec[$tspecKey]['id']]) || $useFilter['tcase_id'] && !in_array($test_spec[$tspecKey]['id'], $testCaseSet) || $useFilter['tcase_name'] && stripos($test_spec[$tspecKey]['name'], $filters['tcase_name']) === false) { $test_spec[$tspecKey] = null; unset($itemSet[$key]); } } if (count($itemSet) > 0 && ($useFilter['execution_type'] || $useFilter['importance'] || $useFilter['cfields'])) { $targetSet = array_keys($itemSet); $options = $specViewType == 'testPlanLinking' ? array('access_key' => 'testcase_id') : null; // BUGID 3889: Add Test Cases to Test plan - Right pane does not honor custom field filter $getFilters = $useFilter['cfields'] ? array('cfields' => $filters['cfields']) : null; // BUGID 4025 - add test case (specification) status filter $tcstatus = config_get('tplanDesign')->hideTestCaseWithStatusIn; if (!is_null($tcstatus)) { $getFilters['status'] = array('not_in' => array_keys($tcstatus)); } $tcversionSet = $tcaseMgr->get_last_active_version($targetSet, $getFilters, $options); switch ($specViewType) { case 'testPlanLinking': // We need to analise linked items and spec foreach ($targetSet as $idx => $key) { $targetTestCase = isset($tcversionSet[$key]) ? $tcversionSet[$key]['testcase_id'] : null; // BUGID 3936 - Design Time Custom Field Filter if (is_null($targetTestCase)) { $test_spec[$itemSet[$key]] = null; //BUGID 4024 $item = null; } else { if (isset($linkedItems[$targetTestCase])) { $item = current($linkedItems[$targetTestCase]); } else { // hmmm, does not understand this logic. $item = null; if (isset($test_spec[$itemSet[$targetTestCase]])) { $item = $tcversionSet[$targetTestCase]; } } } if (!is_null($item)) { if ($useFilter['execution_type'] && $item['execution_type'] != $filters['execution_type'] || $useFilter['importance'] && $item['importance'] != $filters['importance']) { $tspecKey = $itemSet[$targetTestCase]; $test_spec[$tspecKey] = null; } } } break; default: $tcvidSet = array_keys($tcversionSet); $options = null; // BUGID 3934 $doFilter = true; $allowedSet = null; if ($useFilter['execution_type']) { $allowedSet = $tcaseMgr->filter_tcversions_by_exec_type($tcvidSet, $filters['execution_type'], $options); $doFilter = !is_null($allowedSet) && count($allowedSet) > 0; } if ($doFilter) { // Add another filter on cascade mode // BUGID 3936: Assign Test Case Execution - Right pane does not reflect custom field filter. if ($useFilter['cfields']) { $filteredSet = !is_null($allowedSet) && count($allowedSet) > 0 ? array_keys($allowedSet) : $tcvidSet; $dummySet = $tcaseMgr->filter_tcversions_by_cfields($filteredSet, $filters['cfields'], $options); // transform to make compatible with filter_tcversions_by_exec_type() return type if (!is_null($dummySet) && count($dummySet) > 0) { $allowedSet = null; $work2do = array_keys($dummySet); foreach ($work2do as $wkey) { $allowedSet[$wkey] = $dummySet[$wkey][0]; } unset($dummySet); } } } if (!is_null($allowedSet) && count($allowedSet) > 0) { $useAllowed = true; foreach ($allowedSet as $key => $value) { $tspecKey = $itemSet[$value['testcase_id']]; $test_spec[$tspecKey]['version'] = $value['version']; } reset($allowedSet); } $setToRemove = array_diff_key($tcversionSet, $allowedSet); if (!is_null($setToRemove) && count($setToRemove) > 0) { foreach ($setToRemove as $key => $value) { $tspecKey = $itemSet[$value['testcase_id']]; $test_spec[$tspecKey] = null; } } break; } // end switch } } // if apply filters unset($tobj_mgr); return $test_spec; }