[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/parser/__tests__/ -> DifferentialCommitMessageParserTestCase.php (source)

   1  <?php
   2  
   3  final class DifferentialCommitMessageParserTestCase
   4    extends PhabricatorTestCase {
   5  
   6    public function testDifferentialCommitMessageParser() {
   7      $dir = dirname(__FILE__).'/messages/';
   8      $list = Filesystem::listDirectory($dir, $include_hidden = false);
   9      foreach ($list as $file) {
  10        if (!preg_match('/.txt$/', $file)) {
  11          continue;
  12        }
  13  
  14        $data = Filesystem::readFile($dir.$file);
  15        $divider = "~~~~~~~~~~\n";
  16        $parts = explode($divider, $data);
  17        if (count($parts) !== 4) {
  18          throw new Exception(
  19            pht(
  20              'Expected test file "%s" to contain four parts (message, fields, '.
  21              'output, errors) divided by "~~~~~~~~~~".',
  22              $file));
  23        }
  24  
  25        list($message, $fields, $output, $errors) = $parts;
  26        $fields = phutil_json_decode($fields);
  27        $output = phutil_json_decode($output);
  28        $errors = phutil_json_decode($errors);
  29  
  30        $parser = id(new DifferentialCommitMessageParser())
  31          ->setLabelMap($fields)
  32          ->setTitleKey('title')
  33          ->setSummaryKey('summary');
  34  
  35        $result_output = $parser->parseCorpus($message);
  36        $result_errors = $parser->getErrors();
  37  
  38        $this->assertEqual($output, $result_output);
  39        $this->assertEqual($errors, $result_errors);
  40      }
  41    }
  42  
  43    public function testDifferentialCommitMessageParserNormalization() {
  44      $map = array(
  45        'Test Plan' => 'test plan',
  46        'REVIEWERS' => 'reviewers',
  47        'sUmmArY'   => 'summary',
  48      );
  49  
  50      foreach ($map as $input => $expect) {
  51        $this->assertEqual(
  52          $expect,
  53          DifferentialCommitMessageParser::normalizeFieldLabel($input),
  54          pht('Field normalization of label "%s".', $input));
  55      }
  56    }
  57  
  58  }


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