Beispiel #1
0
 public function setUp()
 {
     parent::setUp();
     $this->user = mock('PFUser');
     $this->user->setReturnValue('getId', 666);
     $this->artifact = new MockTracker_Artifact($this);
     $af = new MockTracker_ArtifactFactory($this);
     $af->setReturnReference('getArtifactById', $this->artifact, array('1'));
     $this->report = new MockTracker_Report($this);
     $rf = new MockTracker_ReportFactory($this);
     $rf->setReturnReference('getReportById', $this->report, array('2', $this->user->getId(), true));
     $this->tracker = new MockTracker($this);
     $this->tracker->setReturnValue('isActive', true);
     $this->tracker->setReturnValue('userCanView', true);
     $tf = new MockTrackerFactory($this);
     $tf->setReturnReference('getTrackerById', $this->tracker, array(3));
     $this->formElement = new MockTracker_FormElement_Interface($this);
     $ff = new MockTracker_FormElementFactory($this);
     $ff->setReturnReference('getFormElementById', $this->formElement, array('4'));
     $this->artifact->setReturnReference('getTracker', $this->tracker);
     $this->report->setReturnReference('getTracker', $this->tracker);
     $this->formElement->setReturnReference('getTracker', $this->tracker);
     $this->url = new Tracker_URLTestVersion($this);
     $this->url->setReturnReference('getTrackerFactory', $tf);
     $this->url->setReturnReference('getTracker_FormElementFactory', $ff);
     $this->url->setReturnReference('getArtifactFactory', $af);
     $this->url->setReturnReference('getArtifactReportFactory', $rf);
 }
 public function testImportFormElement()
 {
     $xml = new SimpleXMLElement('<?xml version="1.0" standalone="yes"?>
         <formElement type="mon_type" ID="F0" rank="20" required="1">
             <name>field_name</name>
             <label>field_label</label>
             <description>field_description</description>
             <formElements>
                 <formElement type="date" ID="F1" rank="1" required="1">
                     <name>date</name>
                     <label>date</label>
                     <description>date</description>
                 </formElement>
             </formElements>
         </formElement>');
     $mapping = array();
     $a_formelement = new MockTracker_FormElement_Field_Date();
     $factory = new MockTracker_FormElementFactory();
     $factory->setReturnReference('getInstanceFromXML', $a_formelement);
     $f = new Tracker_FormElement_Container_FieldsetTestVersion();
     $f->setTracker(aTracker()->withProject(mock('Project'))->build());
     $f->setReturnReference('getFormElementFactory', $factory);
     $f->continueGetInstanceFromXML($xml, $mapping);
     $container_should_load_child = array($a_formelement);
     $this->assertEqual($f->getFormElements(), $container_should_load_child);
 }
Beispiel #3
0
 public function setUp()
 {
     parent::setUp();
     $this->user = new MockUser($this);
     $this->user->setReturnValue('getId', 666);
     $this->url = new MockTracker_URL();
     $project = new MockProject();
     $this->artifact = new MockTracker_Artifact($this);
     $af = new MockTracker_ArtifactFactory($this);
     $af->setReturnReference('getArtifactById', $this->artifact, array('1'));
     $this->report = new MockTracker_Report($this);
     $rf = new MockTracker_ReportFactory($this);
     $rf->setReturnReference('getReportById', $this->report, array('2', $this->user->getId(), true));
     $this->tracker = new MockTracker($this);
     $this->tracker->setReturnValue('isActive', true);
     $this->tracker->setReturnValue('getTracker', $this->tracker);
     $tf = new MockTrackerFactory($this);
     $tf->setReturnReference('getTrackerById', $this->tracker, array(3));
     $this->formElement = new MockTracker_FormElement_Interface($this);
     $ff = new MockTracker_FormElementFactory($this);
     $ff->setReturnReference('getFormElementById', $this->formElement, array('4'));
     $this->artifact->setReturnReference('getTracker', $this->tracker);
     $this->report->setReturnReference('getTracker', $this->tracker);
     $this->formElement->setReturnReference('getTracker', $this->tracker);
     $this->tracker->setReturnValue('getGroupId', 5);
     $this->tracker->setReturnReference('getProject', $project);
     $this->tm = new TrackerManagerTestVersion($this);
     $this->tm->setReturnReference('getUrl', $this->url);
     $this->tm->setReturnReference('getTrackerFactory', $tf);
     $this->tm->setReturnReference('getTracker_FormElementFactory', $ff);
     $this->tm->setReturnReference('getArtifactFactory', $af);
     $this->tm->setReturnReference('getArtifactReportFactory', $rf);
     $this->tm->setReturnValue('checkServiceEnabled', true);
     $GLOBALS['HTML'] = new MockLayout();
 }
 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());
 }
 public function testBeforeShouldNOTDisplayFeedback()
 {
     $current_user = new MockUser();
     $field = new MockTracker_FormElement_Field_Date();
     $field->setReturnValue('getId', 102);
     $field->setReturnValue('getLabel', 'Close Date');
     $field->setReturnValue('userCanRead', false, array($current_user));
     $factory = new MockTracker_FormElementFactory();
     $factory->setReturnReference('getFormElementById', $field, array($field->getId()));
     $expected = $field->formatDate($_SERVER['REQUEST_TIME']);
     $transition = new MockTransition();
     $field_id = $field->getId();
     $id = 1;
     $fields_data = array('field_id' => 'value');
     $value_type = Transition_PostAction_Field_Date::CLEAR_DATE;
     $post_action = new Transition_PostAction_Field_DateTestVersion();
     $post_action->expectNever('addFeedback');
     $post_action->setReturnReference('getFormElementFactory', $factory);
     $post_action->__construct($transition, $id, $field, $value_type);
     $post_action->before($fields_data, $current_user);
     $this->assertEqual($expected, $fields_data[$field_id]);
 }
    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();
        $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)));
        $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);
        $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();
    }
 function setUp()
 {
     // Fields:
     // F1(A1, A2)
     // F2(B1, B2, B3)
     // F3(C1, C2)
     // F4(D1, D2)
     //
     // Rules:
     // F1(A1) => F2(B1, B3) The resource A1 can be used in rooms B1 and B3
     // F1(A2) => F2(B2, B3) The resource A2 can be used in rooms B2 and B3
     // F2(B1) => F3(C1) The person C1 can access to rooms B1 and B3
     // F2(B2) => F3(C2)     The person C2 can access to room B2 only
     // F2(B3) => F3(C1)     The person C1 can access to rooms B1 and B3
     //
     // Scenarios:
     // S1 => A2, B3, C1, D1 should be valid (C2 can use A2 in B3)
     // S2 => A2, B3, C2, D1 should *not* be valid (C2 cannot access to B3)
     // S3 => (A1, A2), B3, C1, D1 should be valid
     // S4 => (A1, A2), B2, C2, D1 should be valid (even if A1 cannot access to B2)
     // S5 => A1, (B1, B3), C1, D1 should be valid
     // S6 => A1, (B1, B2), C1, D1 should *not* be valid (A1 or C1 cannot access to B2)
     $r1 = new Tracker_Rule_List(1, 1, 'F1', 'A1', 'F2', 'B1');
     $r2 = new Tracker_Rule_List(2, 1, 'F1', 'A1', 'F2', 'B3');
     $r3 = new Tracker_Rule_List(3, 1, 'F1', 'A2', 'F2', 'B2');
     $r4 = new Tracker_Rule_List(4, 1, 'F1', 'A2', 'F2', 'B3');
     $r5 = new Tracker_Rule_List(5, 1, 'F2', 'B1', 'F3', 'C1');
     $r6 = new Tracker_Rule_List(6, 1, 'F2', 'B2', 'F3', 'C2');
     $r7 = new Tracker_Rule_List(7, 1, 'F2', 'B3', 'F3', 'C1');
     $arf = new MockTracker_RuleFactory($this);
     $arf->setReturnValue('getAllListRulesByTrackerWithOrder', array($r1, $r2, $r3, $r4, $r5, $r6, $r7));
     $f1 = new MockTracker_FormElement_Field_Selectbox($this);
     $f1->setReturnReference('getBind', $bind);
     $f1->setReturnValue('getID', 'F1');
     $f1->setReturnValue('getLabel', 'f_1');
     $f1->setReturnValue('getAllValues', null);
     $f2 = new MockTracker_FormElement_Field_Selectbox($this);
     $f2->setReturnReference('getBind', $bind);
     $f2->setReturnValue('getID', 'F2');
     $f2->setReturnValue('getLabel', 'f_2');
     $f2->setReturnValue('getAllValues', null);
     $f3 = new MockTracker_FormElement_Field_Selectbox($this);
     $f3->setReturnReference('getBind', $bind);
     $f3->setReturnValue('getID', 'F3');
     $f3->setReturnValue('getLabel', 'f_3');
     $f3->setReturnValue('getAllValues', null);
     $f4 = new MockTracker_FormElement_Field_Selectbox($this);
     $f4->setReturnReference('getBind', $bind);
     $f4->setReturnValue('getID', 'F4');
     $f4->setReturnValue('getLabel', 'f_4');
     $f4->setReturnValue('getAllValues', null);
     $aff = new MockTracker_FormElementFactory($this);
     $aff->setReturnReference('getFormElementById', $f1, array('F1'));
     $aff->setReturnReference('getFormElementById', $f2, array('F2'));
     $aff->setReturnReference('getFormElementById', $f3, array('F3'));
     $aff->setReturnReference('getFormElementById', $f4, array('F4'));
     $rule_date_factory = mock('Tracker_Rule_Date_Factory');
     stub($rule_date_factory)->searchByTrackerId()->returns(array());
     $this->arm = new Tracker_RulesManagerTestVersion($this);
     $this->arm->setTrackerFormElementFactory($aff);
     $this->arm->setRuleDateFactory($rule_date_factory);
     $this->arm->setReturnReference('getRuleFactory', $arf);
     $this->arm->setReturnValue('getSelectedValuesForField', array('a_1'), array($f1, 'A1'));
     $this->arm->setReturnValue('getSelectedValuesForField', array('a_2'), array($f1, 'A2'));
     $this->arm->setReturnValue('getSelectedValuesForField', array('b_1'), array($f2, 'B1'));
     $this->arm->setReturnValue('getSelectedValuesForField', array('b_2'), array($f2, 'B2'));
     $this->arm->setReturnValue('getSelectedValuesForField', array('b_3'), array($f2, 'B3'));
     $this->arm->setReturnValue('getSelectedValuesForField', array('c_1'), array($f3, 'C1'));
     $this->arm->setReturnValue('getSelectedValuesForField', array('c_2'), array($f3, 'C2'));
     $this->arm->setReturnValue('getSelectedValuesForField', array('a_1'), array($f1, array('A1')));
     $this->arm->setReturnValue('getSelectedValuesForField', array('a_2'), array($f1, array('A2')));
     $this->arm->setReturnValue('getSelectedValuesForField', array('b_1'), array($f2, array('B1')));
     $this->arm->setReturnValue('getSelectedValuesForField', array('b_2'), array($f2, array('B2')));
     $this->arm->setReturnValue('getSelectedValuesForField', array('b_3'), array($f2, array('B3')));
     $this->arm->setReturnValue('getSelectedValuesForField', array('c_1'), array($f3, array('C1')));
     $this->arm->setReturnValue('getSelectedValuesForField', array('c_2'), array($f3, array('C2')));
     $this->arm->setReturnValue('getSelectedValuesForField', array('a_1', 'a_2'), array($f1, array('A1', 'A2')));
     $this->arm->setReturnValue('getSelectedValuesForField', array('b_1', 'b_3'), array($f2, array('B1', 'B3')));
     $this->arm->setReturnValue('getSelectedValuesForField', array('b_1', 'b_2'), array($f2, array('B1', 'B2')));
     $this->arm->setReturnValue('getSelectedValuesForField', array('b_2', 'b_3'), array($f2, array('B2', 'B3')));
 }