[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/maniphest/constants/__tests__/ -> ManiphestTaskStatusTestCase.php (source)

   1  <?php
   2  
   3  final class ManiphestTaskStatusTestCase extends PhabricatorTestCase {
   4  
   5    public function testManiphestStatusConstants() {
   6      $map = array(
   7        'y' => true,
   8        'closed' => true,
   9        'longlonglong' => true,
  10        'duplicate2' => true,
  11  
  12        '' => false,
  13        'longlonglonglong' => false,
  14        '.' => false,
  15        'ABCD' => false,
  16        'a b c ' => false,
  17      );
  18  
  19      foreach ($map as $input => $expect) {
  20        $this->assertEqual(
  21          $expect,
  22          ManiphestTaskStatus::isValidStatusConstant($input),
  23          pht('Validate "%s"', $input));
  24      }
  25    }
  26  
  27    public function testManiphestStatusConfigValidation() {
  28      $this->assertConfigValid(
  29        false,
  30        pht('Empty'),
  31        array());
  32  
  33      // This is a minimal, valid configuration.
  34  
  35      $valid = array(
  36        'open' => array(
  37          'name' => 'Open',
  38          'special' => 'default',
  39        ),
  40        'closed' => array(
  41          'name' => 'Closed',
  42          'special' => 'closed',
  43          'closed' => true,
  44        ),
  45        'duplicate' => array(
  46          'name' => 'Duplicate',
  47          'special' => 'duplicate',
  48          'closed' => true,
  49        ),
  50      );
  51      $this->assertConfigValid(true, pht('Minimal Valid Config'), $valid);
  52  
  53      // We should raise on a bad key.
  54      $bad_key = $valid;
  55      $bad_key['!'] = array('name' => 'Exclaim');
  56      $this->assertConfigValid(false, pht('Bad Key'), $bad_key);
  57  
  58      // We should raise on a value type.
  59      $bad_type = $valid;
  60      $bad_type['other'] = 'other';
  61      $this->assertConfigValid(false, pht('Bad Value Type'), $bad_type);
  62  
  63      // We should raise on an unknown configuration key.
  64      $invalid_key = $valid;
  65      $invalid_key['open']['imaginary'] = 'unicorn';
  66      $this->assertConfigValid(false, pht('Invalid Key'), $invalid_key);
  67  
  68      // We should raise on two statuses with the same special.
  69      $double_close = $valid;
  70      $double_close['finished'] = array(
  71        'name' => 'Finished',
  72        'special' => 'closed',
  73        'closed' => true,
  74      );
  75      $this->assertConfigValid(false, pht('Duplicate Special'), $double_close);
  76  
  77      // We should raise if any of the special statuses are missing.
  78      foreach ($valid as $key => $config) {
  79        $missing = $valid;
  80        unset($missing[$key]);
  81        $this->assertConfigValid(false, pht('Missing Special'), $missing);
  82      }
  83  
  84      // The "default" special should be an open status.
  85      $closed_default = $valid;
  86      $closed_default['open']['closed'] = true;
  87      $this->assertConfigValid(false, pht('Closed Default'), $closed_default);
  88  
  89      // The "closed" special should be a closed status.
  90      $open_closed = $valid;
  91      $open_closed['closed']['closed'] = false;
  92      $this->assertConfigValid(false, pht('Open Closed'), $open_closed);
  93  
  94      // The "duplicate" special should be a closed status.
  95      $open_duplicate = $valid;
  96      $open_duplicate['duplicate']['closed'] = false;
  97      $this->assertConfigValid(false, pht('Open Duplicate'), $open_duplicate);
  98    }
  99  
 100    private function assertConfigValid($expect, $name, array $config) {
 101      $caught = null;
 102      try {
 103        ManiphestTaskStatus::validateConfiguration($config);
 104      } catch (Exception $ex) {
 105        $caught = $ex;
 106      }
 107  
 108      $this->assertEqual(
 109        $expect,
 110        !($caught instanceof Exception),
 111        pht('Validation of "%s"', $name));
 112    }
 113  
 114  }


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