function testCreateNewChangesetWithoutNotification() { $email = null; //not anonymous user $comment = ''; $this->response->expectCallCount('addFeedback', 0); $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(); $field1 = new MockTracker_FormElement_Field(); $field1->setReturnValue('getId', 101); $field1->setReturnValue('isValid', true); $field1->setReturnValue('isValidRegardingRequiredProperty', true); $field1->setReturnValue('userCanUpdate', true); $field1->setReturnValue('saveNewChangeset', true); $field1->expectOnce('saveNewChangeset'); $field2 = new MockTracker_FormElement_Field(); $field2->setReturnValue('getId', 102); $field2->setReturnValue('isValid', true, array('*', '123')); $field2->setReturnValue('isValid', false, array('*', '456')); $field2->setReturnValue('isValidRegardingRequiredProperty', true); $field2->setReturnValue('userCanUpdate', true); $field2->setReturnValue('saveNewChangeset', true); $field2->expectOnce('saveNewChangeset'); $field3 = new MockTracker_FormElement_Field(); $field3->setReturnValue('getId', 103); $field3->setReturnValue('isValid', true); $field3->setReturnValue('isValidRegardingRequiredProperty', true); $field3->setReturnValue('saveNewChangeset', true); $field3->expectOnce('saveNewChangeset'); $field3->setReturnValue('userCanUpdate', true); $factory->setReturnValue('getUsedFields', array($field1, $field2, $field3)); $factory->setReturnValue('getAllFormElementsForTracker', array()); $new_changeset = new MockTracker_Artifact_Changeset(); $new_changeset->expectNever('notify', array()); $changeset = new MockTracker_Artifact_Changeset(); $changeset->setReturnValue('hasChanges', true); $changeset_value1 = new MockTracker_Artifact_ChangesetValue(); $changeset_value2 = new MockTracker_Artifact_ChangesetValue(); $changeset_value3 = new MockTracker_Artifact_ChangesetValue(); $changeset->setReturnReference('getValue', $changeset_value1, array($field1)); $changeset->setReturnReference('getValue', $changeset_value2, array($field2)); $changeset->setReturnReference('getValue', $changeset_value3, array($field3)); $changeset->setReturnValue('getValues', array()); $reference_manager = new MockReferenceManager(); $reference_manager->expect('extractCrossRef', array($comment, 66, 'plugin_tracker_artifact', 666, $user->getId(), 'foobar')); $art_factory = new MockTracker_ArtifactFactory(); $artifact = new Tracker_ArtifactTestVersion(); $artifact->setReturnReference('getChangesetDao', $dao); $artifact->setReturnReference('getChangesetCommentDao', $comment_dao); $artifact->setReturnReference('getFormElementFactory', $factory); $artifact->setReturnReference('getTracker', $tracker); $artifact->setReturnValue('getId', 66); $artifact->setReturnReference('getLastChangeset', $changeset); $artifact->setReturnReference('getChangeset', $new_changeset); $artifact->setReturnReference('getReferenceManager', $reference_manager); $artifact->setReturnReference('getArtifactFactory', $art_factory); stub($art_factory)->save()->returns(true); $art_factory->expectOnce('save'); $workflow = new MockWorkflow(); $workflow->expectCallCount('before', 2); $workflow->setReturnValue('validate', true); $artifact->setReturnValue('getWorkflow', $workflow); // Valid $fields_data = array(102 => '123'); $artifact->createNewChangeset($fields_data, $comment, $user, false); // Not valid $fields_data = array(102 => '456'); $this->expectException('Tracker_Exception'); $artifact->createNewChangeset($fields_data, $comment, $user); }
function testDontCreateNewChangesetIfNoCommentOrNoChanges() { $this->language->setReturnValue('getText', 'no changes', array('plugin_tracker_artifact', 'no_changes', '*')); $this->response->expectOnce('addFeedback', array('info', 'no changes', CODENDI_PURIFIER_LIGHT)); $comment_dao = new MockTracker_Artifact_Changeset_CommentDao(); $comment_dao->expectNever('createNewVersion'); $dao = new MockTracker_Artifact_ChangesetDao(); $dao->expectNever('create'); $user = new MockUser(); $user->setReturnValue('getId', 1234); $user->setReturnValue('isAnonymous', false); $tracker = new MockTracker(); $factory = new MockTracker_FormElementFactory(); $rules_manager = new MockTracker_RulesManager(); $rules_manager->setReturnValue('validate', true); $tracker->setReturnReference('getRulesManager', $rules_manager); $field1 = new MockTracker_FormElement_Field(); $field1->setReturnValue('getId', 101); $field1->setReturnValue('isValid', true); $field1->setReturnValue('userCanUpdate', true); $field1->expectNever('saveNewChangeset'); $field2 = new MockTracker_FormElement_Field(); $field2->setReturnValue('getId', 102); $field2->setReturnValue('isValid', true); $field2->setReturnValue('userCanUpdate', true); $field2->expectNever('saveNewChangeset'); $field3 = new MockTracker_FormElement_Field(); $field3->setReturnValue('getId', 103); $field3->setReturnValue('isValid', true); $field3->setReturnValue('userCanUpdate', true); $field3->expectNever('saveNewChangeset'); $factory->setReturnValue('getUsedFields', array($field1, $field2, $field3)); $changeset = new MockTracker_Artifact_Changeset(); $changeset->setReturnValue('hasChanges', false); $changeset_value1 = new MockTracker_Artifact_ChangesetValue(); $changeset_value2 = new MockTracker_Artifact_ChangesetValue(); $changeset_value3 = new MockTracker_Artifact_ChangesetValue(); $changeset->setReturnReference('getValue', $changeset_value1, array($field1)); $changeset->setReturnReference('getValue', $changeset_value2, array($field2)); $changeset->setReturnReference('getValue', $changeset_value3, array($field3)); $artifact = new Tracker_ArtifactTestVersion(); $artifact->setReturnReference('getChangesetDao', $dao); $artifact->setReturnReference('getChangesetCommentDao', $comment_dao); $artifact->setReturnReference('getFormElementFactory', $factory); $artifact->setReturnReference('getTracker', $tracker); $artifact->setReturnValue('getId', 66); $artifact->setReturnReference('getLastChangeset', $changeset); $workflow = new MockWorkflow(); $workflow->expectNever('before'); $artifact->setReturnValue('getWorkflow', $workflow); $email = null; //not annonymous user $comment = ''; //empty comment // Valid $fields_data = array(); $artifact->createNewChangeset($fields_data, $comment, $user, $email); }