Example #1
0
 function testGetCommentators()
 {
     $c1 = new MockTracker_Artifact_Changeset();
     $c2 = new MockTracker_Artifact_Changeset();
     $c3 = new MockTracker_Artifact_Changeset();
     $c4 = new MockTracker_Artifact_Changeset();
     $u1 = mock('PFUser');
     $u1->setReturnValue('getUserName', 'sandrae');
     $u2 = mock('PFUser');
     $u2->setReturnValue('getUserName', 'marc');
     $um = new MockUserManager();
     $um->setReturnReference('getUserById', $u1, array(101));
     $um->setReturnReference('getUserById', $u2, array(102));
     $artifact = new Tracker_ArtifactTestVersion();
     $artifact->setReturnValue('getChangesets', array($c1, $c2, $c3, $c4));
     $artifact->setReturnValue('getUserManager', $um);
     $c1->setReturnValue('getSubmittedBy', 101);
     $c2->setReturnValue('getSubmittedBy', 102);
     $c2->setReturnValue('getEmail', '*****@*****.**');
     $c3->setReturnValue('getSubmittedBy', null);
     $c3->setReturnValue('getEmail', '*****@*****.**');
     $c4->setReturnValue('getSubmittedBy', null);
     $c4->setReturnValue('getEmail', '');
     $this->assertEqual($artifact->getCommentators(), array('sandrae', 'marc', '*****@*****.**'));
 }
 public function itCleansUserFromRecipientsWhenUserCantReadAtLeastOneChangedField()
 {
     $field1 = new MockTracker_FormElement_Field_Date();
     $value1_previous = new MockTracker_Artifact_ChangesetValue_Date();
     $value1_current = new MockTracker_Artifact_ChangesetValue_Date();
     $dao = new MockTracker_Artifact_Changeset_ValueDao();
     $dar = new MockDataAccessResult();
     $fact = new MockTracker_FormElementFactory();
     $artifact = new MockTracker_Artifact();
     $previous_changeset = new MockTracker_Artifact_Changeset();
     $um = new MockUserManager();
     $comment = new MockTracker_Artifact_Changeset_Comment();
     $current_changeset = new Tracker_Artifact_ChangesetTestVersion();
     $previous_changeset->setReturnValue('getId', 65);
     $previous_changeset->setReturnReference('getValue', $value1_previous, array($field1));
     $previous_changeset->setReturnReference('getUserManager', $um);
     $artifact->setReturnReference('getPreviousChangeset', $previous_changeset, array(66));
     $dar->setReturnValueAt(0, 'current', array('changeset_id' => 66, 'field_id' => 1, 'id' => 11, 'has_changed' => 1));
     $dar->setReturnValue('valid', true);
     $dar->setReturnValueAt(2, 'valid', false);
     $dao->setReturnReference('searchById', $dar);
     $fact->setReturnReference('getFieldById', $field1, array(1));
     $field1->setReturnValue('getId', 1);
     $field1->setReturnValue('getLabel', 'field1');
     $field1->setReturnValue('userCanRead', false);
     $field1->setReturnReference('getChangesetValue', $value1_current, array('*', 11, 1));
     $value1_previous->expectNever('hasChanged');
     $value1_current->setReturnValue('hasChanged', true);
     $value1_current->setReturnValue('diff', 'has changed', array($value1_previous, '*'));
     $comment->setReturnValue('hasEmptyBody', true);
     $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('getComment', $comment);
     $recipients = array("recipient1" => true, "recipient2" => true, "recipient3" => true);
     $user1 = stub('PFUser')->getUserName()->returns('recipient1');
     $user2 = stub('PFUser')->getUserName()->returns('recipient2');
     $user3 = stub('PFUser')->getUserName()->returns('recipient3');
     $um->setReturnReference('getUserByUserName', $user1);
     $um->setReturnReference('getUserByUserName', $user2);
     $um->setReturnReference('getUserByUserName', $user3);
     $current_changeset->removeRecipientsThatMayReceiveAnEmptyNotification($recipients);
     $this->assertEqual($recipients, array());
 }
 function testDiffToPrevious()
 {
     $field1 = new MockTracker_FormElement_Field_Date();
     $value1_previous = new MockTracker_Artifact_ChangesetValue_Date();
     $value1_current = new MockTracker_Artifact_ChangesetValue_Date();
     $field2 = new MockTracker_FormElement_Field_Date();
     $value2_previous = new MockTracker_Artifact_ChangesetValue_Date();
     $value2_current = new MockTracker_Artifact_ChangesetValue_Date();
     $dao = new MockTracker_Artifact_Changeset_ValueDao();
     $dar = new MockDataAccessResult();
     $fact = new MockTracker_FormElementFactory();
     $value = new MockTracker_Artifact_ChangesetValue_Date();
     $artifact = new MockTracker_Artifact();
     $previous_changeset = new MockTracker_Artifact_Changeset();
     $um = new MockUserManager();
     $current_changeset = new Tracker_Artifact_ChangesetTestVersion();
     $previous_changeset->setReturnValue('getId', 65);
     $previous_changeset->setReturnReference('getValue', $value1_previous, array($field1));
     $previous_changeset->setReturnReference('getValue', $value2_previous, array($field2));
     $previous_changeset->setReturnReference('getUserManager', $um);
     $artifact->setReturnReference('getPreviousChangeset', $previous_changeset, array(66));
     $dar->setReturnValueAt(0, 'current', array('changeset_id' => 66, 'field_id' => 1, 'id' => 11, 'has_changed' => 1));
     $dar->setReturnValueAt(1, 'current', array('changeset_id' => 66, 'field_id' => 2, 'id' => 21, 'has_changed' => 0));
     $dar->setReturnValue('valid', true);
     $dar->setReturnValueAt(2, 'valid', false);
     $dao->setReturnReference('searchById', $dar);
     $fact->setReturnReference('getFieldById', $field1, array(1));
     $fact->setReturnReference('getFieldById', $field2, array(2));
     $field1->setReturnValue('getId', 1);
     $field1->setReturnValue('getLabel', 'field1');
     $field1->setReturnValue('userCanRead', true);
     $field1->setReturnReference('getChangesetValue', $value1_current, array('*', 11, 1));
     $value1_previous->expectNever('hasChanged');
     $value1_current->setReturnValue('hasChanged', true);
     $value1_current->setReturnValue('diff', 'has changed', array($value1_previous, '*'));
     $field2->setReturnValue('getId', 2);
     $field2->setReturnValue('getLabel', 'field2');
     $field2->setReturnValue('userCanRead', true);
     $field2->setReturnReference('getChangesetValue', $value2_current, array('*', 21, 0));
     $value2_previous->expectNever('hasChanged');
     $value2_current->setReturnValue('hasChanged', false);
     $value2_current->expectNever('diff');
     $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);
     $this->assertPattern('/field1/', $current_changeset->diffToprevious());
     $this->assertNoPattern('/field2/', $current_changeset->diffToprevious());
 }
 private function GivenAChangesetValueWithArtifactIds($field, $ids)
 {
     $changeset_value = new MockTracker_Artifact_ChangesetValue_ArtifactLink();
     $changeset_value->setReturnValue('getArtifactIds', $ids);
     $changeset = new MockTracker_Artifact_Changeset();
     $changeset->setReturnValue('getValue', $changeset_value, array($field));
     return $changeset;
 }
Example #5
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);
 }