public function getFunctionByScenarioTestSetAndPosition($position, EiScenario $ei_scenario = null, EiTestSet $ei_test_set = null) { if ($position == null || $ei_scenario == null || $ei_test_set == null) { return null; } $q = Doctrine_Core::getTable('EiFonction')->createQuery('f')->where('EiTestSetFunction.ei_fonction_id=f.id And EiTestSetFunction.ei_test_set_id=? And EiTestSetFunction.position=?', array($ei_test_set->getId(), $position))->andWhere('EiTestSet.id=EiTestSetFunction.ei_test_set_id And EiTestSet.ei_scenario_id=?', array($ei_scenario->getId()))->execute(); if (count($q) > 0) { return $q->getFirst(); } return null; }
/** * Méthode permettant de générer le jeu de test. * * @param sfWebRequest $request * @return sfView */ public function executeGenerateTestSet(sfWebRequest $request) { $this->getResponse()->setContentType('application/json'); $this->setLayout(false); $chronometre1 = new Chronometre(); $chronometre2 = new Chronometre(); $chronometre3 = new Chronometre(); $chronometre4 = new Chronometre(); $chronometre5 = new Chronometre(); $keyword = "PERFORMANCE JDT - "; // Début mesure. $chronometre1->lancerChrono($keyword . "LANCEMENT GENERATION DU JEU DE TEST"); /** @var EiCampaignExecutionGraphTable $tableExecutionGraph */ $tableExecutionGraph = Doctrine_Core::getTable("EiCampaignExecutionGraph"); /** @var EiTestSetTable $tableTestSet */ $tableTestSet = Doctrine_Core::getTable("EiTestSet"); // Récupération des éléments relatifs à la campagne (si existe). $executionId = $request->getParameter("execution_id"); $stepId = $request->getParameter("graph_id"); try { $this->getUrlParameters($request); // Choix du navigateur. $deviceChoice = $request->getParameter("device"); $testSet = new EiTestSet(); $testSet->setEiScenarioId($this->ei_scenario->getId()); $testSet->setEiVersionId($this->ei_version->getId()); $testSet->setProfileId($this->profile_id); $testSet->setProfileRef($this->profile_ref); $testSet->setModeByIde($request->getParameter("exec_mode")); $testSet->setAuthorId($this->user->getGuardId()); $testSet->setDevice($deviceChoice == null || !DevicesConst::isValid($deviceChoice) ? DevicesConst::SELENIUM_IDE : $deviceChoice); $testSet->setEiIteration($this->getRequestActiveIteration()); if ($this->ei_data_set instanceof EiDataSet) { $testSet->setEiDataSetId($this->ei_data_set->getEiDataSetTemplate()->getEiDataSetRefId()); // Début mesure. $chronometre2->lancerChrono($keyword . "COMPLETION JDD"); // Complétion du jeu de données. $testSet->getEiDataSet()->completeDataSet(); // Fin mesure $chronometre2->arreterEtAfficherChrono(); } $testSet->save(); $tableTestSet->searchRelatedEiExecutionStackAndTaggedIt($testSet, $this->ei_project); $this->getLogger()->info("----- Jeu de données à créer."); //*******************************************************************// //********** AFFECTATION TEST SET ID A LA CAMPAGNE **********// //*******************************************************************// if ($executionId != null && $stepId != null && $executionId != 0 && $stepId != 0) { /** @var EiCampaignExecutionGraph $executionGraph */ $executionGraph = $executionId != null ? $tableExecutionGraph->findOneByExecutionIdAndGraphId($executionId, $stepId) : null; // On vérifie que l'étape de l'exécution a bien été trouvée et que l'id du scénario correspond à l'ID // du scénario du JDT. if ($executionGraph != null && $executionGraph->getEiScenario()->getId() == $testSet->getEiScenarioId()) { $executionGraph->setEiTestSetId($testSet->getId()); $executionGraph->save(); } } // Génération du jeu de données pour le jeu de test. // Début mesure. $chronometre3->lancerChrono($keyword . "GENERATION JDD"); $testSet->generateTestSetDataSet(); // Fin mesure $chronometre3->arreterEtAfficherChrono(); $this->getLogger()->info("----- Jeu de données créé."); $this->getLogger()->info("----- Paramètres de blocks à créer."); // Début mesure. $chronometre5->lancerChrono($keyword . "GENERATION PARAMS BLOCK"); // Fin mesure $chronometre5->arreterEtAfficherChrono(); $this->getLogger()->info("----- Paramètres de blocks créés."); // Fin mesure. $chronometre1->arreterEtAfficherChrono(); $JSONResponse['ei_test_set_id'] = $testSet->getId(); $JSONResponse['ei_data_set_id'] = $testSet->getEiDataSetId() != "" ? $testSet->getEiDataSetId() : 0; } catch (Exception $e) { $JSONResponse['error'] = $e->getMessage(); } return $this->renderText(json_encode($JSONResponse)); }
/** * @param EiTestSet $testSet * @param EiTestSetBlockParam $parent * @param null $index * @param string $path * @return mixed */ public function generateTestSetParameters(EiTestSet $testSet = null, $parent = null, $index = null, $path = "", $deep = false, Doctrine_Connection $conn = null) { $conn = $conn == null ? Doctrine_Manager::connection() : $conn; $path .= "/" . $this->getName(); $chronometre = new Chronometre(); $recupStr = $chronometre->lancerChrono("Récupération structure param", true); // Vérification si l'élément existe. /** @var EiTestSetBlockParam $element */ $element = EiTestSetBlockParamTable::getInstance()->findOneByEiTestSetIdAndPath($testSet->getId(), $path); $chronometre->arreterEtAfficherChrono("Récupération structure param", $recupStr); $eltExists = $element == null ? false : true; if (!$eltExists) { $element = new EiTestSetBlockParam(); $element->setEiVersionStructureId($this->getId()); $element->setName($this->getName()); $element->setSlug($this->getSlug()); $element->setType($this->getType()); $element->setEiTestSetId($testSet->getId()); $element->setIndexRepetition($index); $element->setPath($path); if ($parent != null) { $element->setParentId($parent->getId()); } } $recupMap = $chronometre->lancerChrono("Récupération du mapping", true); /** @var EiBlockDataSetMapping $mapping */ $mapping = $this->getMapping(EiBlockDataSetMapping::$TYPE_IN); if ($mapping != null && $parent->getType() == EiVersionStructure::$TYPE_FOREACH) { /** @var EiMappingStructureSyncIn $iteratorMap */ $iteratorMap = $parent->getEiVersionStructure()->getIteratorMapping(); /** @var Doctrine_Node_NestedSet $node */ $node = $mapping != null ? $mapping->getEiDataSetStructureMapping()->getNode() : null; $indexToMap = !$node->isDescendantOf($iteratorMap->getEiDataSetStructureMapping()) ? 1 : $index; $value = $mapping->getValueFromTestSetJdd($testSet, $indexToMap, $parent); } elseif ($mapping != null) { $value = $mapping->getValueFromTestSetJdd($testSet, $index, $parent); } else { $value = ""; } $chronometre->arreterEtAfficherChrono("Récupération du mapping", $recupMap); // Sauvegarde de la valeur de l'élément. $element->setValue($value); $saveChro = $chronometre->lancerChrono("Sauvegarde paramètre de block", true); $element->save($conn); if (!$eltExists) { if (!$parent->getNode()->getChildren()) { $element->getNode()->insertAsFirstChildOf($parent); } else { $element->getNode()->insertAsNextSiblingOf($parent->getNode()->getLastChild()); } } $chronometre->arreterEtAfficherChrono("Sauvegarde paramètre de block", $saveChro); return $element; }
/** * Méthode permettant de localiser la partie du JDD à lier à l'élément du block. * * TODO: Unifier les deux méthodes en une seule. * TODO: A vérifier * * Liée à EiTestSetBlockStack->getDataFromDataSet * * @param EiTestSet $testSet * @param EiVersionStructure $block * @param EiTestSetBlockStack $previousStack * @param EiTestSetBlockStack $parentStack * @return mixed|null */ public function getDataFromDataSet(EiTestSet $testSet, EiVersionStructure $block, EiTestSetBlockStack $previousStack = null, EiTestSetBlockStack $parentStack = null) { /** @var EiTestSetDataSetTable $tableDSS */ $tableDSS = Doctrine_Core::getTable("EiTestSetDataSet"); $mapping = $block->getMappingDataSet(EiBlockDataSetMapping::$TYPE_IN); $dssStr = null; // Cas où il y a un mapping et que le parent est nul : On prend le premier élément que l'on trouve. if ($parentStack == null && $mapping != null) { $dssStr != null ? $tableDSS->getRelatedDataFromUniqueDataSetStructure($testSet->getId(), $mapping) : null; } elseif ($mapping != null) { // On vérifie que le block en question est une boucle. if ($block->isEiLoop()) { // On récupère le contexte du père. $contexte = $parentStack->getContext(); $index = 1; // var_dump("DataSet Père : " . $parentStack->getEiTestSetDatasetId()); // var_dump("Contexte DataSet Père : " . $contexte); // Si le block courant est de même nature que le block précédent if ($parentStack->getEiVersionStructureId() != $block->getId() && $block->getId() == $previousStack->getEiVersionStructureId()) { // var_dump("DataSet Structure CAS 1"); // On vérifie s'il s'agit de la même boucle mais concerne une partie différente. if ($previousStack->getPartIndex() < $previousStack->getPartsCount()) { $index = $previousStack->getRepetitionIndex(); $contexte .= "-" . $index; } else { $index = $previousStack->getRepetitionIndex() + 1; $contexte .= "-" . $index; } } elseif ($parentStack->getEiVersionStructureId() != $block->getId()) { // var_dump("DataSet Structure CAS 2"); $parentStr = $parentStack->getEiTestSetDataSet() != null ? $parentStack->getEiTestSetDataSet()->getEiDataSetStructure() : null; if ($parentStr != null && $mapping->getEiDataSetStructureMapping()->getNode()->isDescendantOf($parentStr)) { // var_dump("DataSet Structure CAS 2.1"); $parentMapping = $parentStr != null ? $parentStr->getId() : null; $myMappingParent = $mapping->getEiDataSetStructureMapping()->getEiDatasetStructureParentId(); if ($parentMapping == null || $myMappingParent == $parentMapping) { $contexte .= "-1"; } else { if (preg_match("/([0-9]+)\$/", $contexte, $matched)) { $length = strlen($matched[1]); } else { $length = 1; } $contexte = substr($contexte, 0, -$length) . 1; } } else { // var_dump("DataSet Structure CAS 2.2"); $contexteArray = array(); for ($cpt = 0; $cpt <= $mapping->getEiDataSetStructureMapping()->getLevel(); $cpt++) { $contexteArray[] = 1; } $contexte = implode("-", $contexteArray); // var_dump("New context : " . $contexte); } } else { // var_dump("DataSet Structure CAS 3"); if (preg_match("/([0-9]+)\$/", $contexte, $matched)) { $length = strlen($matched[1]); } else { $length = 1; } $contexte = substr($contexte, 0, -$length); // On vérifie s'il s'agit de la même boucle mais concerne une partie différente. if (!$parentStack->isComplete()) { $index = $parentStack->getRepetitionIndex(); } else { $index = $parentStack->getRepetitionIndex() + 1; } $contexte .= $index; // var_dump($parentStack->getEiVersionStructureId(), $block->getId()); // var_dump($contexte); } $dssStr = $tableDSS->getDataFromContext($testSet->getId(), $mapping->getEiDatasetStructureId(), $contexte, $index); } } return $dssStr; }
/** * @param EiTestSet $testSet * @param EiVersionStructure $block * @return mixed|null * * @createdAt 18/08/2015 * @updatedAt 18/08/2015 */ public function getParentBlock($testSet, $block) { // Récupération de la connexion BDD. $conn = Doctrine_Manager::connection(); try { // Définition requête SQL permettant de générer $searchSql = "\nSELECT id\nFROM " . $this->getTableName() . "\nWHERE ei_version_structure_id = " . $block->getId() . "\nAND ei_test_set_id = " . $testSet->getId() . "\nORDER BY lft DESC\nLIMIT 1;"; // Récupération du block parent. $blockId = $conn->execute($searchSql)->fetch(); if (!is_bool($blockId) && isset($blockId["id"])) { return $this->find($blockId["id"]); } } catch (Exception $exc) { return null; } }
/** * @param EiTestSet $testSet * @param EiProjet $project */ public function searchRelatedEiExecutionStackAndTaggedIt(EiTestSet $testSet, EiProjet $project) { /** @var EiExecutionStack $executionStack */ $executionStack = Doctrine_Core::getTable("EiExecutionStack")->search($testSet->getEiScenarioId(), $testSet->getEiDataSetId(), $testSet->getProfileRef(), $testSet->getProfileId(), $project->getRefId(), $project->getProjectId(), $testSet->getSfGuardUser()->getId()); if ($executionStack != null && $executionStack->getId() != "") { $executionStack->setEiTestSetId($testSet->getId()); $executionStack->save(); } }
/** * @param EiTestSet $testSet * @param null $parent * @param null $index * @param string $path * @param bool $deep * @param Doctrine_Connection $conn * * @return EiTestSetBlockParam|mixed|void */ public function generateTestSetParameters(EiTestSet $testSet = null, $parent = null, $index = null, $path = "", $deep = true, Doctrine_Connection $conn = null) { $conn = $conn == null ? Doctrine_Manager::connection() : $conn; $chronometre = new Chronometre(); $index = $index == null ? 1 : $index; $path .= "/" . $this->getName() . "[" . $index . "]"; // Vérification si l'élément existe. $element = EiTestSetBlockParamTable::getInstance()->findOneByEiTestSetIdAndPath($testSet->getId(), $path); if ($element == null) { // Création de l'élément. $element = new EiTestSetBlockParam(); $element->setEiVersionStructureId($this->getId()); $element->setName($this->getName()); $element->setSlug($this->getSlug()); $element->setType($this->getType()); $element->setEiTestSetId($testSet->getId()); $element->setIndexRepetition($index); $element->setPath($path); if ($parent != null) { $element->setParentId($parent->getId()); } $element->save($conn); if ($parent == null) { $element->setRootId($element->getId()); $element->setLft(1); $element->setRgt(2); $element->setLevel(0); $element->save($conn); } elseif ($parent != null) { /** @var EiTestSetBlockParam $parent */ $parent->refresh(true); if (!$parent->getNode()->getChildren()) { $element->getNode()->insertAsFirstChildOf($parent); } else { $element->getNode()->insertAsNextSiblingOf($parent->getNode()->getLastChild()); } } } $chronometre->lancerChrono("Récupération des paramètres"); /** @var EiBlockParam[] $parametres */ $parametres = $this->getParams(); $chronometre->arreterEtAfficherChrono(); $chronometre->lancerChrono("Génération des paramètres"); /** @var EiBlockParam $param */ foreach ($parametres as $param) { $param->generateTestSetParameters($testSet, $element, $index, $path); } $chronometre->arreterEtAfficherChrono(); /** @var EiVersionStructure[] $descendants */ $descendants = $this->getNode()->getDescendants(true); if ($deep === true && $descendants) { /** @var EiVersionStructure $descendant */ foreach ($descendants as $descendant) { /** @var EiBlock $descendant */ if ($descendant instanceof EiBlock || $descendant instanceof EiBlockForeach) { $descendant->generateTestSetParameters($testSet, $element, $index, $path, false, $conn); } } } else { return $element; } }
/** * @param EiTestSet $testSet * @param EiTestSetBlockParam $parent * @return int */ public function getCountMappingFromTestSetJdd($testSet, $parent = null) { $count = 0; $mapId = $this->getEiDatasetStructureId(); $testSetDS = $testSet->getFilteredEiTestSetDataSet($mapId); $nb = $testSetDS->count(); if ($nb > 0) { $contexteBlock = $parent != null ? $parent->getBlockContext() : ""; /** @var EiTestSetDataSet $line */ foreach ($testSetDS as $line) { // TODO: Améliorer $contexteJdd = $line->getContext(); if ($contexteJdd == $contexteBlock) { $count++; } } } return $count; }
/** * Génère, à partir de l'arbre ITreeExplorer l'arborescence du jeu de données pour le JDT. * * @param ITreeExplorerItem $element */ private function generate(ITreeExplorerItem $element, $isParentRoot = false) { $elt = null; try { // On parcourt toutes les occurences de l'élément de la structure. foreach ($element->getOccurrences() as $occurrence) { $pid = $occurrence->getParent() != null ? $occurrence->getParent()->getId() : null; $pIndex = $occurrence->getParent() != null ? $occurrence->getParent()->getRepeatIndex() : $occurrence->getRepeatIndex(); // On crée l'objet. $elt = new EiTestSetDataSet(); // Puis, on lui affecte les quelques éléments en notre possession. $elt->setEiTestSetId($this->testSet->getId()); $elt->setEiDataSetStructureId($element->getId()); $elt->setIndexRepetition($occurrence->getRepeatIndex()); $elt->setParentIndexRepetition($pIndex); $elt->setType($element->getType() == "root" || $element->getType() == "node" ? EiDataSetStructure::$TYPE_NODE : EiDataSetStructure::$TYPE_LEAF); $elt->setName($element->getName()); $elt->setSlug($element->getSlug()); $elt->setValue($occurrence->getValue() != null ? $occurrence->getValue() : ""); if ($occurrence->getParent() != null && isset($this->registered[$occurrence->getParent()->getId()])) { $elt->setParentId($this->registered[$occurrence->getParent()->getId()]->getId()); } elseif (!(is_bool($isParentRoot) && $isParentRoot == false)) { $elt->setParentId($isParentRoot->getId()); } if ($element->getType() == "root") { $elt->setLft(1); $elt->setRgt(2); $elt->setLevel(0); $elt->save(); $elt->setRootId($elt->getId()); $elt->save(); $this->root_id = $elt->getId(); $this->root = $elt; } elseif (($pid != null || $pid == 0) && isset($this->registered[$pid])) { if ($element->getType() == "leaf") { $occurrence->setLeft($occurrence->getLeft() + ($pIndex - 1) * $occurrence->getRightNode()); $occurrence->setRight($occurrence->getRight() + ($pIndex - 1) * $occurrence->getRightNode()); if ($occurrence->getRight() > $this->maxRight) { $this->maxRight = $occurrence->getRight(); } } $elt->setLft($occurrence->getLeft()); $elt->setRgt($occurrence->getRight()); $elt->setLevel($occurrence->getLevel()); $elt->setRootId($this->root_id); $elt->save(); if (!isset($this->registeredChildren[$pid])) { $this->registeredChildren[$pid] = array(); $this->registeredChildren[$pid][] = $elt; } else { $this->registeredChildren[$pid][] = $elt; } } $this->registered[$occurrence->getId()] = $elt; } /** @var ITreeExplorerItem $child */ foreach ($element->getChildren() as $child) { $this->generate($child, $elt != null && $element->getType() == "root" ? $elt : false); } } catch (Exception $exc) { print_r($exc); } }
public function getTestSetParam(EiTestSet $ei_test_set) { $conn = Doctrine_Manager::connection(); $q = "\n \n SELECT p.*, f.* , fp.name\n\n FROM ei_test_set_param p\n LEFT JOIN ei_test_set_function f\n ON f.id = p.ei_test_set_function_id\n AND f.ei_test_set_id =p.ei_test_set_id\n \n LEFT JOIN ei_function_has_param fp\n ON fp.param_id = p.param_id\n \n WHERE p.ei_test_set_id= " . $ei_test_set->getId() . "\n \n ORDER BY f.position \n "; return $conn->fetchAll($q); }