Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / metamta / storage / __tests__ / PhabricatorMetaMTAReceivedMailTestCase.php
blob2630a50feb47f5461fb28e0f0a4da7ba37c5ad8a
1 <?php
3 final class PhabricatorMetaMTAReceivedMailTestCase extends PhabricatorTestCase {
5 protected function getPhabricatorTestCaseConfiguration() {
6 return array(
7 self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
8 );
11 public function testDropSelfMail() {
12 $mail = new PhabricatorMetaMTAReceivedMail();
13 $mail->setHeaders(
14 array(
15 'X-Phabricator-Sent-This-Message' => 'yes',
16 ));
17 $mail->save();
19 $mail->processReceivedMail();
21 $this->assertEqual(
22 MetaMTAReceivedMailStatus::STATUS_FROM_PHABRICATOR,
23 $mail->getStatus());
27 public function testDropDuplicateMail() {
28 $mail_a = new PhabricatorMetaMTAReceivedMail();
29 $mail_a->setHeaders(
30 array(
31 'Message-ID' => 'test@example.com',
32 ));
33 $mail_a->save();
35 $mail_b = new PhabricatorMetaMTAReceivedMail();
36 $mail_b->setHeaders(
37 array(
38 'Message-ID' => 'test@example.com',
39 ));
40 $mail_b->save();
42 $mail_a->processReceivedMail();
43 $mail_b->processReceivedMail();
45 $this->assertEqual(
46 MetaMTAReceivedMailStatus::STATUS_DUPLICATE,
47 $mail_b->getStatus());
50 public function testDropUnreceivableMail() {
51 $user = $this->generateNewTestUser()
52 ->save();
54 $mail = new PhabricatorMetaMTAReceivedMail();
55 $mail->setHeaders(
56 array(
57 'Message-ID' => 'test@example.com',
58 'To' => 'does+not+exist@example.com',
59 'From' => $user->loadPrimaryEmail()->getAddress(),
60 ));
61 $mail->setBodies(
62 array(
63 'text' => 'test',
64 ));
65 $mail->save();
67 $mail->processReceivedMail();
69 $this->assertEqual(
70 MetaMTAReceivedMailStatus::STATUS_NO_RECEIVERS,
71 $mail->getStatus());
74 public function testDropUnknownSenderMail() {
75 $this->setManiphestCreateEmail();
77 $mail = new PhabricatorMetaMTAReceivedMail();
78 $mail->setHeaders(
79 array(
80 'Message-ID' => 'test@example.com',
81 'To' => 'bugs@example.com',
82 'From' => 'does+not+exist@example.com',
83 ));
84 $mail->setBodies(
85 array(
86 'text' => 'test',
87 ));
88 $mail->save();
90 $mail->processReceivedMail();
92 $this->assertEqual(
93 MetaMTAReceivedMailStatus::STATUS_UNKNOWN_SENDER,
94 $mail->getStatus());
98 public function testDropDisabledSenderMail() {
99 $this->setManiphestCreateEmail();
101 $user = $this->generateNewTestUser()
102 ->setIsDisabled(true)
103 ->save();
105 $mail = new PhabricatorMetaMTAReceivedMail();
106 $mail->setHeaders(
107 array(
108 'Message-ID' => 'test@example.com',
109 'From' => $user->loadPrimaryEmail()->getAddress(),
110 'To' => 'bugs@example.com',
112 $mail->setBodies(
113 array(
114 'text' => 'test',
116 $mail->save();
118 $mail->processReceivedMail();
120 $this->assertEqual(
121 MetaMTAReceivedMailStatus::STATUS_DISABLED_SENDER,
122 $mail->getStatus());
125 private function setManiphestCreateEmail() {
126 $maniphest_app = new PhabricatorManiphestApplication();
127 try {
128 id(new PhabricatorMetaMTAApplicationEmail())
129 ->setApplicationPHID($maniphest_app->getPHID())
130 ->setAddress('bugs@example.com')
131 ->setConfigData(array())
132 ->save();
133 } catch (AphrontDuplicateKeyQueryException $ex) {}