/** * Create a bind for the field * * @param Field $field the field * @param string $type the type of bind. If empty, STATIK * @param array $bind_data the data used to create the bind * * @return Bind null if error */ public function createBind($field, $type, $bind_data) { $bind = null; switch ($type) { case '': //default is static //default is static case self::STATIK: $dao = new Tracker_FormElement_Field_List_Bind_StaticDao(); if ($dao->save($field->getId(), 0)) { $bind = new Tracker_FormElement_Field_List_Bind_Static($field, 0, array(), array(), array()); $bind->process($bind_data, 'no redirect'); } break; case self::USERS: $dao = new Tracker_FormElement_Field_List_Bind_UsersDao(); if ($dao->save($field->getId(), array())) { $bind = new Tracker_FormElement_Field_List_Bind_Users($field, '', array(), array()); $bind->process($bind_data, 'no redirect'); } break; case self::UGROUPS: $bind = new Tracker_FormElement_Field_List_Bind_Ugroups($field, array(), array(), array(), $this->ugroup_manager, $this->getUgroupsValueDao()); $bind->process($bind_data, 'no redirect'); break; default: break; } return $bind; }
public function testGetRecipients() { //$recipients = array(); //foreach ($changeset_value->getBindValues() as $user_value) { // $recipients[] = $user_value->getUser()->getUserName(); //} //return $recipients; //$user1 = mock('PFUser'); $user1->setReturnValue('getUserName', 'u1'); //$user2 = mock('PFUser'); $user2->setReturnValue('getUserName', 'u2'); $changeset_value = new MockTracker_Artifact_ChangesetValue_List(); $changeset_value->setReturnValue('getListValues', array($u1 = new MockTracker_FormElement_Field_List_Bind_UsersValue(), $u2 = new MockTracker_FormElement_Field_List_Bind_UsersValue())); //$u1->setReturnReference('getUser', $user1); //$u2->setReturnReference('getUser', $user2); $u1->setReturnValue('getUsername', 'u1'); $u2->setReturnValue('getUsername', 'u2'); $field = new MockTracker_FormElement_Field_List(); $field->setReturnValue('getId', 123); $value_function = 'project_members'; $default_values = $decorators = ''; $users = new Tracker_FormElement_Field_List_Bind_Users($field, $value_function, $default_values, $decorators); $this->assertEqual($users->getRecipients($changeset_value), array('u1', 'u2')); }