public function itBuildsAMappingBasedOnTheNames()
 {
     $this->template_ugroup_dev = stub('ProjectUGroup')->getName()->returns('dev');
     $this->template_ugroup_support = stub('ProjectUGroup')->getName()->returns('support');
     $this->template_ugroup_staff = stub('ProjectUGroup')->getName()->returns('staff');
     $this->target_ugroup_dev = stub('ProjectUGroup')->getName()->returns('DEV');
     $this->target_ugroup_support = stub('ProjectUGroup')->getName()->returns('support');
     $this->target_ugroup_client = stub('ProjectUGroup')->getName()->returns('client');
     stub($this->template_ugroup_support)->getId()->returns(1001);
     stub($this->target_ugroup_support)->getId()->returns(1002);
     $template_project = stub('Project')->getId()->returns(103);
     $this->template_tracker = aTracker()->withProject($template_project)->build();
     $this->target_project = stub('Project')->getId()->returns(104);
     $this->ugroup_manager = mock('UGroupManager');
     $this->permissions_retriever = mock('Tracker_UgroupPermissionsGoldenRetriever');
     stub($this->permissions_retriever)->getListOfInvolvedStaticUgroups($this->template_tracker)->returns(array($this->template_ugroup_dev, $this->template_ugroup_support, $this->template_ugroup_staff));
     stub($this->ugroup_manager)->getStaticUGroups($this->target_project)->returns(array($this->target_ugroup_dev, $this->target_ugroup_support, $this->target_ugroup_client));
     $builder = new Tracker_UgroupMappingBuilder($this->permissions_retriever, $this->ugroup_manager);
     $mapping = $builder->getMapping($this->template_tracker, $this->target_project);
     $this->assertEqual($mapping, array(1001 => 1002));
 }
Exemplo n.º 2
0
 /**
  * create - use this to create a new Tracker in the database.
  *
  * @param Project $project_id          the group id of the new tracker
  * @param int     $project_id_template the template group id (used for the copy)
  * @param int     $id_template         the template tracker id
  * @param string  $name                the name of the new tracker
  * @param string  $description         the description of the new tracker
  * @param string  $itemname            the itemname of the new tracker
  * @param Array   $ugroup_mapping the ugroup mapping
  *
  * @return mixed array(Tracker object, field_mapping array) or false on failure.
  */
 function create($project_id, $project_id_template, $id_template, $name, $description, $itemname, $ugroup_mapping = false)
 {
     if ($this->validMandatoryInfoOnCreate($name, $description, $itemname, $project_id)) {
         // Get the template tracker
         $template_tracker = $this->getTrackerById($id_template);
         if (!$template_tracker) {
             $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_common_type', 'invalid_tracker_tmpl'));
             return false;
         }
         $template_group = $template_tracker->getProject();
         if (!$template_group || !is_object($template_group) || $template_group->isError()) {
             $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_common_type', 'invalid_templ'));
             return false;
         }
         $project_id_template = $template_group->getId();
         //Ask to dao to duplicate the tracker
         if ($id = $this->getDao()->duplicate($id_template, $project_id, $name, $description, $itemname)) {
             // Duplicate Form Elements
             $field_mapping = Tracker_FormElementFactory::instance()->duplicate($id_template, $id, $ugroup_mapping);
             if ($ugroup_mapping) {
                 $duplicate_type = PermissionsDao::DUPLICATE_NEW_PROJECT;
             } else {
                 if ($project_id == $project_id_template) {
                     $duplicate_type = PermissionsDao::DUPLICATE_SAME_PROJECT;
                 } else {
                     $ugroup_manager = new UGroupManager();
                     $builder = new Tracker_UgroupMappingBuilder(new Tracker_UgroupPermissionsGoldenRetriever(new Tracker_PermissionsDao(), $ugroup_manager), $ugroup_manager);
                     $ugroup_mapping = $builder->getMapping($template_tracker, ProjectManager::instance()->getProject($project_id));
                     $duplicate_type = PermissionsDao::DUPLICATE_OTHER_PROJECT;
                 }
             }
             // Duplicate workflow
             foreach ($field_mapping as $mapping) {
                 if ($mapping['workflow']) {
                     WorkflowFactory::instance()->duplicate($id_template, $id, $mapping['from'], $mapping['to'], $mapping['values'], $field_mapping, $ugroup_mapping, $duplicate_type);
                 }
             }
             // Duplicate Reports
             Tracker_ReportFactory::instance()->duplicate($id_template, $id, $field_mapping);
             // Duplicate Semantics
             Tracker_SemanticFactory::instance()->duplicate($id_template, $id, $field_mapping);
             // Duplicate Canned Responses
             Tracker_CannedResponseFactory::instance()->duplicate($id_template, $id);
             //Duplicate field dependencies
             $this->getRuleFactory()->duplicate($id_template, $id, $field_mapping);
             $tracker = $this->getTrackerById($id);
             // Process event that tracker is created
             $em =& EventManager::instance();
             $pref_params = array('atid_source' => $id_template, 'atid_dest' => $id);
             $em->processEvent('Tracker_created', $pref_params);
             //Duplicate Permissions
             $this->duplicatePermissions($id_template, $id, $ugroup_mapping, $field_mapping, $duplicate_type);
             $this->postCreateActions($tracker);
             return array('tracker' => $tracker, 'field_mapping' => $field_mapping);
         }
     }
     return false;
 }