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'));
 }
    function testNotify()
    {
        $defs = array(array('has_changed' => 1, 'isNotificationsSupported' => 1, 'hasNotifications' => 0, 'recipients' => array()), array('has_changed' => 0, 'isNotificationsSupported' => 1, 'hasNotifications' => 1, 'recipients' => array('a_user')), array('has_changed' => 0, 'isNotificationsSupported' => 1, 'hasNotifications' => 0, 'recipients' => array('should_not_appear')), array('has_changed' => 0, 'isNotificationsSupported' => 0, 'hasNotifications' => 1, 'recipients' => array('should_not_appear_(not_supported)')), array('has_changed' => 0, 'isNotificationsSupported' => 1, 'hasNotifications' => 1, 'recipients' => array('multiple_users', '*****@*****.**')));
        $fact = new MockTracker_FormElementFactory();
        $dar = new MockDataAccessResult();
        $dao = new MockTracker_Artifact_Changeset_ValueDao();
        $artifact = new MockTracker_Artifact();
        $tracker = new MockTracker();
        $um = new MockUserManager();
        $comment = new MockTracker_Artifact_Changeset_Comment();
        $i = 0;
        // try DRY in unit tests also... build mocks automatically
        foreach ($defs as $d) {
            $id = $i + 1;
            $changeset_value_id = 1000 + $id;
            $dar->setReturnValueAt($i++, 'current', array('changeset_id' => 66, 'field_id' => $id, 'id' => $changeset_value_id, 'has_changed' => $d['has_changed']));
            $f = new MockTracker_FormElement_Field_Selectbox();
            $fact->setReturnReference('getFieldById', $f, array($id));
            $f->setReturnValue('getId', $id);
            $f->setReturnValue('getLabel', 'field_' . $id);
            $f->setReturnValue('isNotificationsSupported', $d['isNotificationsSupported']);
            $f->setReturnValue('hasNotifications', $d['hasNotifications']);
            $f->setReturnValue('getRecipients', $d['recipients']);
            $p = new MockTracker_Artifact_ChangesetValue_List();
            $c = new MockTracker_Artifact_ChangesetValue_List();
            $c->setReturnValue('hasChanged', $d['has_changed']);
            $c->setReturnValue('diff', 'has changed', array($p));
            $f->setReturnReference('getChangesetValue', $c, array('*', $changeset_value_id, $d['has_changed']));
            unset($f);
        }
        $dar->setReturnValue('valid', true);
        $dar->setReturnValueAt($i, 'valid', false);
        $dao->setReturnReference('searchById', $dar);
        $artifact->setReturnReference('getTracker', $tracker);
        $artifact->setReturnValue('getCommentators', array('comment1', 'comment2'));
        $artifact->setReturnValue('getId', 666);
        $tracker->setReturnValue('getItemName', 'story');
        $tracker->setReturnValue('isNotificationStopped', false);
        $tracker->setReturnValue('getRecipients', array(array('recipients' => array('global1', 'global2'), 'on_updates' => false, 'check_permissions' => true), array('recipients' => array('dont_check_perms', 'global3', '*****@*****.**'), 'on_updates' => true, 'check_permissions' => false)));
        $config = mock('TrackerPluginConfig');
        $current_changeset = new Tracker_Artifact_ChangesetTestVersion();
        $current_changeset->setReturnValue('getId', 66);
        $current_changeset->setReturnReference('getValueDao', $dao);
        $current_changeset->setReturnReference('getFormElementFactory', $fact);
        $current_changeset->setReturnReference('getArtifact', $artifact);
        $current_changeset->setReturnReference('getUserManager', $um);
        $current_changeset->setReturnReference('getTracker', $tracker);
        $current_changeset->setReturnReference('getComment', $comment);
        $current_changeset->setReturnReference('getTrackerPluginConfig', $config);
        $expected_body = <<<BODY
story #666
<http://{$GLOBALS['sys_default_domain']}/tracker/?aid=666>

BODY;
        $current_changeset->expect('sendNotification', array(array('a_user', 'multiple_users', '*****@*****.**', 'dont_check_perms', 'global3', 'comment1', 'comment2'), array(), '[story #666]', $expected_body));
        $current_changeset->notify();
    }
Ejemplo n.º 3
0
 function testBeforeShouldTriggerTransitionActions()
 {
     $current_user = new MockUser();
     $f = new MockTracker_FormElement_Field_List();
     $f->setReturnValue('getId', 103);
     $v1 = new MockTracker_FormElement_Field_List_Value();
     $v2 = new MockTracker_FormElement_Field_List_Value();
     $v1->setReturnValue('getId', 801);
     $v2->setReturnValue('getId', 802);
     $t1 = new MockTransition();
     $t2 = new MockTransition();
     $t1->setReturnValue('getFieldValueFrom', null);
     $t1->setReturnReference('getFieldValueTo', $v1);
     $t2->setReturnReference('getFieldValueFrom', $v1);
     $t2->setReturnReference('getFieldValueTo', $v2);
     $cvl = new MockTracker_Artifact_ChangesetValue_List();
     $cvl->setReturnValue('getValue', array(801));
     $changeset = new MockTracker_Artifact_Changeset();
     $changeset->setReturnValue('getValue', $cvl, array($f));
     $a = new MockTracker_Artifact();
     $a->setReturnValue('getLastChangeset', $changeset);
     $workflow_id = 1;
     $tracker_id = 2;
     $field_id = 103;
     $is_used = 1;
     $transitions = array($t1, $t2);
     $workflow = new Workflow($workflow_id, $tracker_id, $field_id, $is_used, $transitions);
     $workflow->setField($f);
     $workflow->setArtifact($a);
     $fields_data = array('103' => '802');
     $t1->expectNever('before');
     $t2->expectOnce('before', array($fields_data, $current_user));
     $workflow->before($fields_data, $current_user);
 }