예제 #1
0
 protected function _postIssueValidation(TBGRequest $request, &$errors, &$permission_errors)
 {
     $i18n = TBGContext::getI18n();
     if (!$this->selected_project instanceof TBGProject) {
         $errors['project'] = $i18n->__('You have to select a valid project');
     }
     if (!$this->selected_issuetype instanceof TBGIssuetype) {
         $errors['issuetype'] = $i18n->__('You have to select a valid issue type');
     }
     if (empty($errors)) {
         $fields_array = $this->selected_project->getReportableFieldsArray($this->issuetype_id);
         $this->title = $request->getRawParameter('title');
         $this->selected_description = $request->getRawParameter('description', null, false);
         $this->selected_description_syntax = $request->getParameter('description_syntax', null, false);
         $this->selected_reproduction_steps = $request->getRawParameter('reproduction_steps', null, false);
         $this->selected_reproduction_steps_syntax = $request->getRawParameter('reproduction_steps_syntax', null, false);
         if ($edition_id = (int) $request['edition_id']) {
             $this->selected_edition = TBGContext::factory()->TBGEdition($edition_id);
         }
         if ($build_id = (int) $request['build_id']) {
             $this->selected_build = TBGContext::factory()->TBGBuild($build_id);
         }
         if ($component_id = (int) $request['component_id']) {
             $this->selected_component = TBGContext::factory()->TBGComponent($component_id);
         }
         if (trim($this->title) == '' || $this->title == $this->default_title) {
             $errors['title'] = true;
         }
         if (isset($fields_array['description']) && $fields_array['description']['required'] && trim($this->selected_description) == '') {
             $errors['description'] = true;
         }
         if (isset($fields_array['reproduction_steps']) && !$request->isAjaxCall() && $fields_array['reproduction_steps']['required'] && trim($this->selected_reproduction_steps) == '') {
             $errors['reproduction_steps'] = true;
         }
         if (isset($fields_array['edition']) && $edition_id && !in_array($edition_id, array_keys($fields_array['edition']['values']))) {
             $errors['edition'] = true;
         }
         if (isset($fields_array['build']) && $build_id && !in_array($build_id, array_keys($fields_array['build']['values']))) {
             $errors['build'] = true;
         }
         if (isset($fields_array['component']) && $component_id && !in_array($component_id, array_keys($fields_array['component']['values']))) {
             $errors['component'] = true;
         }
         if ($category_id = (int) $request['category_id']) {
             $this->selected_category = TBGContext::factory()->TBGCategory($category_id);
         }
         if ($status_id = (int) $request['status_id']) {
             $this->selected_status = TBGContext::factory()->TBGStatus($status_id);
         }
         if ($reproducability_id = (int) $request['reproducability_id']) {
             $this->selected_reproducability = TBGContext::factory()->TBGReproducability($reproducability_id);
         }
         if ($milestone_id = (int) $request['milestone_id']) {
             $this->selected_milestone = TBGContext::factory()->TBGMilestone($milestone_id);
         }
         if ($parent_issue_id = (int) $request['parent_issue_id']) {
             $this->parent_issue = TBGContext::factory()->TBGIssue($parent_issue_id);
         }
         if ($resolution_id = (int) $request['resolution_id']) {
             $this->selected_resolution = TBGContext::factory()->TBGResolution($resolution_id);
         }
         if ($severity_id = (int) $request['severity_id']) {
             $this->selected_severity = TBGContext::factory()->TBGSeverity($severity_id);
         }
         if ($priority_id = (int) $request['priority_id']) {
             $this->selected_priority = TBGContext::factory()->TBGPriority($priority_id);
         }
         if ($request['estimated_time']) {
             $this->selected_estimated_time = $request['estimated_time'];
         }
         if ($request['spent_time']) {
             $this->selected_spent_time = $request['spent_time'];
         }
         if (is_numeric($request['percent_complete'])) {
             $this->selected_percent_complete = (int) $request['percent_complete'];
         }
         if ($pain_bug_type_id = (int) $request['pain_bug_type_id']) {
             $this->selected_pain_bug_type = $pain_bug_type_id;
         }
         if ($pain_likelihood_id = (int) $request['pain_likelihood_id']) {
             $this->selected_pain_likelihood = $pain_likelihood_id;
         }
         if ($pain_effect_id = (int) $request['pain_effect_id']) {
             $this->selected_pain_effect = $pain_effect_id;
         }
         $selected_customdatatype = array();
         foreach (TBGCustomDatatype::getAll() as $customdatatype) {
             $customdatatype_id = $customdatatype->getKey() . '_id';
             $customdatatype_value = $customdatatype->getKey() . '_value';
             if ($customdatatype->hasCustomOptions()) {
                 $selected_customdatatype[$customdatatype->getKey()] = null;
                 if ($request->hasParameter($customdatatype_id)) {
                     ${$customdatatype_id} = (int) $request->getParameter($customdatatype_id);
                     $selected_customdatatype[$customdatatype->getKey()] = new TBGCustomDatatypeOption(${$customdatatype_id});
                 }
             } else {
                 $selected_customdatatype[$customdatatype->getKey()] = null;
                 switch ($customdatatype->getType()) {
                     case TBGCustomDatatype::INPUT_TEXTAREA_MAIN:
                     case TBGCustomDatatype::INPUT_TEXTAREA_SMALL:
                         if ($request->hasParameter($customdatatype_value)) {
                             $selected_customdatatype[$customdatatype->getKey()] = $request->getParameter($customdatatype_value, null, false);
                         }
                         break;
                     default:
                         if ($request->hasParameter($customdatatype_value)) {
                             $selected_customdatatype[$customdatatype->getKey()] = $request->getParameter($customdatatype_value);
                         } elseif ($request->hasParameter($customdatatype_id)) {
                             $selected_customdatatype[$customdatatype->getKey()] = $request->getParameter($customdatatype_id);
                         }
                         break;
                 }
             }
         }
         $this->selected_customdatatype = $selected_customdatatype;
         foreach ($fields_array as $field => $info) {
             if ($field == 'user_pain') {
                 if ($info['required']) {
                     if (!($this->selected_pain_bug_type != 0 && $this->selected_pain_likelihood != 0 && $this->selected_pain_effect != 0)) {
                         $errors['user_pain'] = true;
                     }
                 }
             } elseif ($info['required']) {
                 $var_name = "selected_{$field}";
                 if (in_array($field, TBGDatatype::getAvailableFields(true)) && ($this->{$var_name} === null || $this->{$var_name} === 0) || !in_array($field, TBGDatatype::getAvailableFields(true)) && !in_array($field, array('pain_bug_type', 'pain_likelihood', 'pain_effect')) && (array_key_exists($field, $selected_customdatatype) && $selected_customdatatype[$field] === null)) {
                     $errors[$field] = true;
                 }
             } else {
                 if (in_array($field, TBGDatatype::getAvailableFields(true))) {
                     if (!$this->selected_project->fieldPermissionCheck($field, true)) {
                         $permission_errors[$field] = true;
                     }
                 } elseif (!$this->selected_project->fieldPermissionCheck($field, true, true)) {
                     $permission_errors[$field] = true;
                 }
             }
         }
         $event = new TBGEvent('core', 'mainActions::_postIssueValidation', null, array(), $errors);
         $event->trigger();
         $errors = $event->getReturnList();
     }
     return !(bool) (count($errors) + count($permission_errors));
 }
예제 #2
0
 /**
  * @covers TBGEvent::listen
  * @covers TBGEvent::trigger
  * @covers TBGEvent::triggerUntilProcessed
  * @depends testListening
  */
 public function testTriggeringAndProcessing(TBGEvent $event)
 {
     $this->wastriggered = false;
     TBGEvent::clearListeners('modulename', 'identifier');
     TBGEvent::listen('modulename', 'identifier', array($this, 'listenerCallback'));
     $event->trigger();
     $this->assertAttributeEquals(true, 'wastriggered', $this);
     TBGEvent::clearListeners('modulename', 'identifier');
     TBGEvent::listen('modulename', 'identifier', array($this, 'listenerCallbackNonProcessingFirst'));
     TBGEvent::listen('modulename', 'identifier', array($this, 'listenerCallbackNonProcessingSecond'));
     TBGEvent::listen('modulename', 'identifier', array($this, 'listenerCallbackProcessing'));
     $this->wasprocessed = array();
     $event->triggerUntilProcessed();
     $this->assertAttributeNotEmpty('wasprocessed', $this);
     $this->assertAttributeContains(1, 'wasprocessed', $this);
     $this->assertAttributeContains(2, 'wasprocessed', $this);
     $this->assertAttributeNotContains(3, 'wasprocessed', $this);
 }