Differential D16038 Diff 38604 src/applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php
| Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | $this->assertEqual( | ||||
| PhabricatorMailOutboundStatus::STATUS_FAIL, | PhabricatorMailOutboundStatus::STATUS_FAIL, | ||||
| $mail->getStatus()); | $mail->getStatus()); | ||||
| } | } | ||||
| public function testRecipients() { | public function testRecipients() { | ||||
| $user = $this->generateNewTestUser(); | $user = $this->generateNewTestUser(); | ||||
| $phid = $user->getPHID(); | $phid = $user->getPHID(); | ||||
| $prefs = $user->loadPreferences(); | |||||
| $mailer = new PhabricatorMailImplementationTestAdapter(); | $mailer = new PhabricatorMailImplementationTestAdapter(); | ||||
| $mail = new PhabricatorMetaMTAMail(); | $mail = new PhabricatorMetaMTAMail(); | ||||
| $mail->addTos(array($phid)); | $mail->addTos(array($phid)); | ||||
| $this->assertTrue( | $this->assertTrue( | ||||
| in_array($phid, $mail->buildRecipientList()), | in_array($phid, $mail->buildRecipientList()), | ||||
| pht('"To" is a recipient.')); | pht('"To" is a recipient.')); | ||||
| // Test that the "No Self Mail" and "No Mail" preferences work correctly. | // Test that the "No Self Mail" and "No Mail" preferences work correctly. | ||||
| $mail->setFrom($phid); | $mail->setFrom($phid); | ||||
| $this->assertTrue( | $this->assertTrue( | ||||
| in_array($phid, $mail->buildRecipientList()), | in_array($phid, $mail->buildRecipientList()), | ||||
| pht('"From" does not exclude recipients by default.')); | pht('"From" does not exclude recipients by default.')); | ||||
| $prefs->setPreference( | $user = $this->writeSetting( | ||||
| PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL, | $user, | ||||
| PhabricatorEmailSelfActionsSetting::SETTINGKEY, | |||||
| true); | true); | ||||
| $prefs->save(); | |||||
| $this->assertFalse( | $this->assertFalse( | ||||
| in_array($phid, $mail->buildRecipientList()), | in_array($phid, $mail->buildRecipientList()), | ||||
| pht('"From" excludes recipients with no-self-mail set.')); | pht('"From" excludes recipients with no-self-mail set.')); | ||||
| $prefs->unsetPreference( | $user = $this->writeSetting( | ||||
| PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL); | $user, | ||||
| $prefs->save(); | PhabricatorEmailSelfActionsSetting::SETTINGKEY, | ||||
| null); | |||||
| $this->assertTrue( | $this->assertTrue( | ||||
| in_array($phid, $mail->buildRecipientList()), | in_array($phid, $mail->buildRecipientList()), | ||||
| pht('"From" does not exclude recipients by default.')); | pht('"From" does not exclude recipients by default.')); | ||||
| $prefs->setPreference( | $user = $this->writeSetting( | ||||
| PhabricatorUserPreferences::PREFERENCE_NO_MAIL, | $user, | ||||
| PhabricatorEmailNotificationsSetting::SETTINGKEY, | |||||
| true); | true); | ||||
| $prefs->save(); | |||||
| $this->assertFalse( | $this->assertFalse( | ||||
| in_array($phid, $mail->buildRecipientList()), | in_array($phid, $mail->buildRecipientList()), | ||||
| pht('"From" excludes recipients with no-mail set.')); | pht('"From" excludes recipients with no-mail set.')); | ||||
| $mail->setForceDelivery(true); | $mail->setForceDelivery(true); | ||||
| $this->assertTrue( | $this->assertTrue( | ||||
| in_array($phid, $mail->buildRecipientList()), | in_array($phid, $mail->buildRecipientList()), | ||||
| pht('"From" includes no-mail recipients when forced.')); | pht('"From" includes no-mail recipients when forced.')); | ||||
| $mail->setForceDelivery(false); | $mail->setForceDelivery(false); | ||||
| $prefs->unsetPreference( | $user = $this->writeSetting( | ||||
| PhabricatorUserPreferences::PREFERENCE_NO_MAIL); | $user, | ||||
| $prefs->save(); | PhabricatorEmailNotificationsSetting::SETTINGKEY, | ||||
| null); | |||||
| $this->assertTrue( | $this->assertTrue( | ||||
| in_array($phid, $mail->buildRecipientList()), | in_array($phid, $mail->buildRecipientList()), | ||||
| pht('"From" does not exclude recipients by default.')); | pht('"From" does not exclude recipients by default.')); | ||||
| // Test that explicit exclusion works correctly. | // Test that explicit exclusion works correctly. | ||||
| $mail->setExcludeMailRecipientPHIDs(array($phid)); | $mail->setExcludeMailRecipientPHIDs(array($phid)); | ||||
| $this->assertFalse( | $this->assertFalse( | ||||
| in_array($phid, $mail->buildRecipientList()), | in_array($phid, $mail->buildRecipientList()), | ||||
| pht('Explicit exclude excludes recipients.')); | pht('Explicit exclude excludes recipients.')); | ||||
| $mail->setExcludeMailRecipientPHIDs(array()); | $mail->setExcludeMailRecipientPHIDs(array()); | ||||
| // Test that mail tag preferences exclude recipients. | // Test that mail tag preferences exclude recipients. | ||||
| $prefs->setPreference( | $user = $this->writeSetting( | ||||
| PhabricatorUserPreferences::PREFERENCE_MAILTAGS, | $user, | ||||
| PhabricatorEmailTagsSetting::SETTINGKEY, | |||||
| array( | array( | ||||
| 'test-tag' => false, | 'test-tag' => false, | ||||
| )); | )); | ||||
| $prefs->save(); | |||||
| $mail->setMailTags(array('test-tag')); | $mail->setMailTags(array('test-tag')); | ||||
| $this->assertFalse( | $this->assertFalse( | ||||
| in_array($phid, $mail->buildRecipientList()), | in_array($phid, $mail->buildRecipientList()), | ||||
| pht('Tag preference excludes recipients.')); | pht('Tag preference excludes recipients.')); | ||||
| $prefs->unsetPreference(PhabricatorUserPreferences::PREFERENCE_MAILTAGS); | $user = $this->writeSetting( | ||||
| $prefs->save(); | $user, | ||||
| PhabricatorEmailTagsSetting::SETTINGKEY, | |||||
| null); | |||||
| $this->assertTrue( | $this->assertTrue( | ||||
| in_array($phid, $mail->buildRecipientList()), | in_array($phid, $mail->buildRecipientList()), | ||||
| 'Recipients restored after tag preference removed.'); | 'Recipients restored after tag preference removed.'); | ||||
| } | } | ||||
| public function testThreadIDHeaders() { | public function testThreadIDHeaders() { | ||||
| $this->runThreadIDHeadersWithConfiguration(true, true); | $this->runThreadIDHeadersWithConfiguration(true, true); | ||||
| ▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | private function runThreadIDHeadersWithConfiguration( | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| $expect_references, | $expect_references, | ||||
| isset($dict['References']), | isset($dict['References']), | ||||
| pht( | pht( | ||||
| 'Expectation about existence of References header for case %s.', | 'Expectation about existence of References header for case %s.', | ||||
| $case)); | $case)); | ||||
| } | } | ||||
| private function writeSetting(PhabricatorUser $user, $key, $value) { | |||||
| $preferences = PhabricatorUserPreferences::loadUserPreferences($user); | |||||
| $editor = id(new PhabricatorUserPreferencesEditor()) | |||||
| ->setActor($user) | |||||
| ->setContentSource($this->newContentSource()) | |||||
| ->setContinueOnNoEffect(true) | |||||
| ->setContinueOnMissingFields(true); | |||||
| $xactions = array(); | |||||
| $xactions[] = $preferences->newTransaction($key, $value); | |||||
| $editor->applyTransactions($preferences, $xactions); | |||||
| return id(new PhabricatorPeopleQuery()) | |||||
| ->setViewer($user) | |||||
| ->withIDs(array($user->getID())) | |||||
| ->executeOne(); | |||||
| } | |||||
| } | } | ||||