Ejemplo n.º 1
0
 /**
  * Display the form to add a new test session.
  *
  * @param sfWebRequest $request
  */
 public function executeAdd(sfWebRequest $request)
 {
     $url_prefix = $this->getContext()->getInstance()->getRequest()->getUriPrefix() . $this->getContext()->getInstance()->getRequest()->getRelativeUrlRoot();
     // Set referer
     if (!$request->isMethod("post")) {
         $route = $this->getContext()->getRouting()->findRoute(MiscUtils::getUri($url_prefix, $this->getUser()->getCurrentReferer()));
         if (strpos($route["pattern"], "upload") === false) {
             $this->getUser()->setReferer($request->getUri());
         }
     }
     // Get referer to set default selected values in form
     $referer = MiscUtils::getUri($url_prefix, $this->getUser()->getReferer());
     $route = $this->getContext()->getRouting()->findRoute($referer);
     $defaultProject = isset($route['parameters']['project']) ? $route['parameters']['project'] : "";
     $defaultProduct = isset($route['parameters']['product']) ? $route['parameters']['product'] : "";
     $defaultEnvironment = isset($route["parameters"]["environment"]) ? $route["parameters"]["environment"] : "";
     $defaultImage = isset($route["parameters"]["image"]) ? $route["parameters"]["image"] : "";
     $defaultBuild = isset($route["parameters"]["build"]) ? $route["parameters"]["build"] : "";
     $defaultTestset = isset($route["parameters"]["testset"]) ? $route["parameters"]["testset"] : "";
     // Get project group id from project group name defined in app.yml
     $this->projectGroupId = Doctrine_Core::getTable("sfGuardGroup")->getProjectGroupId(sfConfig::get('app_project_group'));
     if ($this->projectGroupId == null) {
         throw new ErrorException("Unable to retrieve project group configuration! Application might need additional configuration or data!", 500);
     }
     // Get security level of current user
     $userSecurityLevel = $this->getUser()->isAuthenticated() ? $userSecurityLevel = $this->getUser()->getGuardUser()->getProfile()->getSecurityLevel() : 0;
     // Get last build ids
     $this->lastBuildIds = Doctrine_Core::getTable("TestSession")->getLastBuildIds();
     // Get last testsets
     $this->lastTestsets = Doctrine_Core::getTable("TestSession")->getLastTestsets();
     // Get last environments and images used to add sessions (for user experience)
     $this->lastEnvironments = Doctrine_Core::getTable("TestEnvironment")->getLastEnvironments();
     $this->lastImages = Doctrine_Core::getTable("Image")->getLastImages();
     $this->mandatoryBuildId = sfConfig::get('app_mandatory_build_id', false);
     $this->mandatoryTestset = sfConfig::get('app_mandatory_testset', false);
     // Create a new session form to import test results
     $this->form = new ImportForm(array(), array("projectGroupId" => $this->projectGroupId, "securityLevel" => $userSecurityLevel, "projectSlug" => $defaultProject, "productSlug" => $defaultProduct, "environmentSlug" => $defaultEnvironment, "imageSlug" => $defaultImage, "buildSlug" => $defaultBuild, "testsetSlug" => $defaultTestset, "mandatoryBuildId" => $this->mandatoryBuildId, "mandatoryTestset" => $this->mandatoryTestset));
     // Update list of products when submitting form (to match ajax selection)
     if (isset($_POST["test_session"])) {
         $project = Doctrine_Core::getTable("Project")->getBasicProjectById($_POST["test_session"]["project"]);
         $this->form = new ImportForm(array(), array("projectGroupId" => $this->projectGroupId, "securityLevel" => $userSecurityLevel, "projectSlug" => $project["name_slug"], "productSlug" => $defaultProduct, "environmentSlug" => $defaultEnvironment, "imageSlug" => $defaultImage, "buildSlug" => $defaultBuild, "testsetSlug" => $defaultTestset, "mandatoryBuildId" => $this->mandatoryBuildId, "mandatoryTestset" => $this->mandatoryTestset));
     }
     // Process the form
     if ($request->isMethod("post")) {
         $this->processAdd($request, $this->form);
     }
 }