[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/metamta/parser/__tests__/ -> PhabricatorMetaMTAEmailBodyParserTestCase.php (source)

   1  <?php
   2  
   3  final class PhabricatorMetaMTAEmailBodyParserTestCase
   4    extends PhabricatorTestCase {
   5  
   6    public function testQuotedTextStripping() {
   7      $bodies = $this->getEmailBodies();
   8      foreach ($bodies as $body) {
   9        $parser = new PhabricatorMetaMTAEmailBodyParser();
  10        $stripped = $parser->stripTextBody($body);
  11        $this->assertEqual('OKAY', $stripped);
  12      }
  13    }
  14  
  15    public function testEmailBodyCommandParsing() {
  16      $bodies = $this->getEmailBodiesWithFullCommands();
  17      foreach ($bodies as $body) {
  18        $parser = new PhabricatorMetaMTAEmailBodyParser();
  19        $body_data = $parser->parseBody($body);
  20        $this->assertEqual('OKAY', $body_data['body']);
  21        $this->assertEqual('whatevs', $body_data['command']);
  22        $this->assertEqual('dude', $body_data['command_value']);
  23      }
  24      $bodies = $this->getEmailBodiesWithPartialCommands();
  25      foreach ($bodies as $body) {
  26        $parser = new PhabricatorMetaMTAEmailBodyParser();
  27        $body_data = $parser->parseBody($body);
  28        $this->assertEqual('OKAY', $body_data['body']);
  29        $this->assertEqual('whatevs', $body_data['command']);
  30        $this->assertEqual(null, $body_data['command_value']);
  31      }
  32    }
  33  
  34    public function testFalsePositiveForOnWrote() {
  35      $body = <<<EOEMAIL
  36  On which horse shall you ride?
  37  
  38  On Sep 23, alincoln wrote:
  39  
  40  > Hey bro do you want to go ride horses tomorrow?
  41  EOEMAIL;
  42  
  43      $parser = new PhabricatorMetaMTAEmailBodyParser();
  44      $stripped = $parser->stripTextBody($body);
  45      $this->assertEqual('On which horse shall you ride?', $stripped);
  46    }
  47  
  48    private function getEmailBodiesWithFullCommands() {
  49      $bodies = $this->getEmailBodies();
  50      $with_commands = array();
  51      foreach ($bodies as $body) {
  52        $with_commands[] = "!whatevs dude\n".$body;
  53      }
  54      return $with_commands;
  55    }
  56  
  57    private function getEmailBodiesWithPartialCommands() {
  58      $bodies = $this->getEmailBodies();
  59      $with_commands = array();
  60      foreach ($bodies as $body) {
  61        $with_commands[] = "!whatevs\n".$body;
  62      }
  63      return $with_commands;
  64    }
  65  
  66  
  67    private function getEmailBodies() {
  68      $trailing_space = ' ';
  69      $emdash = "\xE2\x80\x94";
  70  
  71      return array(
  72  <<<EOEMAIL
  73  OKAY
  74  
  75  On May 30, 2011, at 8:36 PM, Someone wrote:
  76  
  77  > ...
  78  
  79  EOEMAIL
  80  ,
  81  <<<EOEMAIL
  82  OKAY
  83  
  84  On Fri, May 27, 2011 at 9:39 AM, Someone <
  85  [email protected]> wrote:
  86  
  87  > ...
  88  
  89  EOEMAIL
  90  ,
  91  <<<EOEMAIL
  92  OKAY
  93  
  94  On Fri, May 27, 2011 at 9:39 AM, Someone
  95  <[email protected]> wrote:
  96  
  97  > ...
  98  
  99  EOEMAIL
 100  ,
 101  <<<EOEMAIL
 102  OKAY
 103  
 104  -----Oprindelig Meddelelse-----
 105  
 106  > ...
 107  EOEMAIL
 108  ,
 109  <<<EOEMAIL
 110  OKAY
 111  
 112  -----Original Message-----
 113  
 114  > ...
 115  EOEMAIL
 116  ,
 117  <<<EOEMAIL
 118  OKAY
 119  
 120  -----oprindelig meddelelse-----
 121  
 122  > ...
 123  EOEMAIL
 124  ,
 125  <<<EOEMAIL
 126  OKAY
 127  
 128  -----original message-----
 129  
 130  > ...
 131  EOEMAIL
 132  ,
 133  <<<EOEMAIL
 134  OKAY
 135  
 136  Sent from my HTC smartphone on the Now Network from Sprint!
 137  
 138  -Reply message ----- From: "somebody (someone)" <
 139  [email protected]>
 140  To: <[email protected]>
 141  Subject: Some Text Date: Mon, Apr 2, 2012 1:42 pm
 142  > ...
 143  EOEMAIL
 144  ,
 145  <<<EOEMAIL
 146  OKAY
 147  
 148  --{$trailing_space}
 149  Abraham Lincoln
 150  Supreme Galactic Emperor
 151  EOEMAIL
 152  ,
 153  <<<EOEMAIL
 154  OKAY
 155  
 156  Sent from my iPhone
 157  EOEMAIL
 158  ,
 159  <<<EOMAIL
 160  OKAY
 161  
 162  ________________________________________
 163  From: Abraham Lincoln <[email protected]>
 164  Subject: Core World Tariffs
 165  EOMAIL
 166  ,
 167  <<<EOMAIL
 168  OKAY
 169  
 170  > On 17 Oct 2013, at 17:47, "Someone" <somebody@somewhere> wrote:
 171  > ...
 172  EOMAIL
 173  ,
 174  <<<EOMAIL
 175  OKAY
 176  
 177  > -----Original Message-----
 178  >
 179  > ...
 180  EOMAIL
 181  ,
 182  <<<EOMAIL
 183  OKAY {$emdash}{$trailing_space}
 184  Sent from Mailbox
 185  EOMAIL
 186      );
 187    }
 188  
 189  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1