/** * Update an artifact (means create a new changeset) * * @param array $fields_data Artifact fields values * @param string $comment The comment (follow-up) associated with the artifact update * @param PFUser $submitter The user who is doing the update * @param boolean $send_notification true if a notification must be sent, false otherwise * @param string $comment_format The comment (follow-up) type ("text" | "html") * * @throws Tracker_Exception In the validation * @throws Tracker_NoChangeException In the validation * @return Tracker_Artifact_Changeset|Boolean The new changeset if update is done without error, false otherwise */ public function createNewChangeset($fields_data, $comment, PFUser $submitter, $send_notification = true, $comment_format = Tracker_Artifact_Changeset_Comment::TEXT_COMMENT) { $submitted_on = $_SERVER['REQUEST_TIME']; $creator = new Tracker_Artifact_Changeset_NewChangesetCreator(new Tracker_Artifact_Changeset_NewChangesetFieldsValidator($this->getFormElementFactory()), $this->getFormElementFactory(), $this->getChangesetDao(), $this->getChangesetCommentDao(), $this->getArtifactFactory(), $this->getEventManager(), $this->getReferenceManager()); return $creator->create($this, $fields_data, $comment, $submitter, $submitted_on, $send_notification, $comment_format); }
function testCreateNewChangesetWithWorkflowAndNoPermsOnPostActionField() { $email = null; //not anonymous user $comment = ''; $comment_dao = new MockTracker_Artifact_Changeset_CommentDao(); stub($comment_dao)->createNewVersion()->returns(true); $comment_dao->expectCallCount('createNewVersion', 1); $dao = new MockTracker_Artifact_ChangesetDao(); $dao->setReturnValueAt(0, 'create', 1001, array(66, 1234, null, $_SERVER['REQUEST_TIME'])); $dao->setReturnValueAt(1, 'create', 1002, array(66, 1234, null, $_SERVER['REQUEST_TIME'])); $dao->expectCallCount('create', 1); $user = mock('PFUser'); $user->setReturnValue('getId', 1234); $user->setReturnValue('isAnonymous', false); $tracker = new MockTracker(); $tracker->setReturnValue('getGroupId', 666); $tracker->setReturnValue('getItemName', 'foobar'); $tracker->setReturnValue('getFormElements', array()); $factory = new MockTracker_FormElementFactory(); $artifact = partial_mock('Tracker_Artifact', array('getChangesetDao', 'getChangesetCommentDao', 'getFormElementFactory', 'getTracker', 'getId', 'getLastChangeset', 'getReferenceManager', 'getChangesets', 'getChangeset', 'getUserManager', 'getArtifactFactory', 'getWorkflow')); $workflow = new MockWorkflow(); $workflow->expectCallCount('before', 2); $workflow->setReturnValue('validate', true); $artifact->setReturnValue('getWorkflow', $workflow); $field1 = new MockTracker_FormElement_Field(); $field1->setReturnValue('getId', 101); $field1->setReturnValue('isValid', true); $field1->setReturnValue('userCanUpdate', true); $field1->setReturnValue('saveNewChangeset', true); $workflow->setReturnValue('bypassPermissions', false, array($field1)); $field1->expectOnce('saveNewChangeset'); $field2 = new MockTracker_FormElement_Field(); $field2->setReturnValue('getId', 102); $field2->setReturnValue('isValid', true); $field2->setReturnValue('userCanUpdate', false); $field2->setReturnValue('saveNewChangeset', true); $workflow->setReturnValue('bypassPermissions', true, array($field2)); $field2->expectOnce('saveNewChangeset', array('*', '*', '*', '*', $user, false, true)); $factory->setReturnValue('getUsedFields', array($field1, $field2)); $factory->setReturnValue('getAllFormElementsForTracker', array()); $new_changeset = new MockTracker_Artifact_Changeset(); $new_changeset->expect('notify', array()); $changeset = new MockTracker_Artifact_Changeset(); $changeset->setReturnValue('getValues', array()); $changeset->setReturnValue('hasChanges', true); $changeset_value1 = new MockTracker_Artifact_ChangesetValue(); $changeset->setReturnReference('getValue', $changeset_value1, array($field1)); $reference_manager = new MockReferenceManager(); $reference_manager->expect('extractCrossRef', array($comment, 66, 'plugin_tracker_artifact', 666, $user->getId(), 'foobar')); $art_factory = new MockTracker_ArtifactFactory(); stub($art_factory)->save()->returns(true); $artifact->setReturnReference('getTracker', $tracker); $artifact->setReturnValue('getId', 66); $artifact->setReturnReference('getLastChangeset', $changeset); $art_factory->expectOnce('save'); // Valid $fields_data = array(101 => '123', 102 => '456'); $submitted_on = $_SERVER['REQUEST_TIME']; $send_notification = false; $comment_format = Tracker_Artifact_Changeset_Comment::TEXT_COMMENT; $fields_validator = mock('Tracker_Artifact_Changeset_NewChangesetFieldsValidator'); stub($fields_validator)->validate()->returns(true); $creator = new Tracker_Artifact_Changeset_NewChangesetCreator($fields_validator, $factory, $dao, $comment_dao, $art_factory, mock('EventManager'), $reference_manager); $creator->create($artifact, $fields_data, $comment, $user, $submitted_on, $send_notification, $comment_format); }