[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/request/__tests__/ -> DiffusionURITestCase.php (source)

   1  <?php
   2  
   3  final class DiffusionURITestCase extends ArcanistPhutilTestCase {
   4  
   5    public function testBlobDecode() {
   6      $map = array(
   7        // This is a basic blob.
   8        'branch/path.ext;abc$3' => array(
   9          'branch'  => 'branch',
  10          'path'    => 'path.ext',
  11          'commit'  => 'abc',
  12          'line'    => '3',
  13        ),
  14        'branch/path.ext$3' => array(
  15          'branch'  => 'branch',
  16          'path'    => 'path.ext',
  17          'line'    => '3',
  18        ),
  19        'branch/money;;/$$100'  => array(
  20          'branch'  => 'branch',
  21          'path'    => 'money;/$100',
  22        ),
  23        'a%252Fb/' => array(
  24          'branch'  => 'a/b',
  25        ),
  26        'branch/path/;Version-1_0_0' => array(
  27          'branch' => 'branch',
  28          'path'   => 'path/',
  29          'commit' => 'Version-1_0_0',
  30        ),
  31        'branch/path/;$$moneytag$$' => array(
  32          'branch' => 'branch',
  33          'path'   => 'path/',
  34          'commit' => '$moneytag$',
  35        ),
  36        'branch/path/semicolon;;;;;$$;;semicolon;;$$$$$100' => array(
  37          'branch' => 'branch',
  38          'path'   => 'path/semicolon;;',
  39          'commit' => '$;;semicolon;;$$',
  40          'line'   => '100',
  41        ),
  42        'branch/path.ext;abc$3-5,7-12,14' => array(
  43          'branch'  => 'branch',
  44          'path'    => 'path.ext',
  45          'commit'  => 'abc',
  46          'line'    => '3-5,7-12,14',
  47        ),
  48      );
  49  
  50      foreach ($map as $input => $expect) {
  51  
  52        // Simulate decode effect of the webserver.
  53        $input = rawurldecode($input);
  54  
  55        $expect = $expect + array(
  56          'branch' => null,
  57          'path'   => null,
  58          'commit' => null,
  59          'line'   => null,
  60        );
  61        $expect = array_select_keys(
  62          $expect,
  63          array('branch', 'path', 'commit', 'line'));
  64  
  65        $actual = $this->parseBlob($input);
  66  
  67        $this->assertEqual(
  68          $expect,
  69          $actual,
  70          "Parsing '{$input}'");
  71      }
  72    }
  73  
  74    public function testBlobDecodeFail() {
  75      $this->tryTestCaseMap(
  76        array(
  77          'branch/path/../../../secrets/secrets.key' => false,
  78        ),
  79        array($this, 'parseBlob'));
  80    }
  81  
  82    public function parseBlob($blob) {
  83      return DiffusionRequest::parseRequestBlob(
  84        $blob,
  85        $supports_branches = true);
  86    }
  87  
  88    public function testURIGeneration() {
  89      $map = array(
  90        '/diffusion/A/browse/branch/path.ext;abc$1' => array(
  91          'action'    => 'browse',
  92          'callsign'  => 'A',
  93          'branch'    => 'branch',
  94          'path'      => 'path.ext',
  95          'commit'    => 'abc',
  96          'line'      => '1',
  97        ),
  98        '/diffusion/A/browse/a%252Fb/path.ext' => array(
  99          'action'    => 'browse',
 100          'callsign'  => 'A',
 101          'branch'    => 'a/b',
 102          'path'      => 'path.ext',
 103        ),
 104        '/diffusion/A/browse/%2B/%20%21' => array(
 105          'action'    => 'browse',
 106          'callsign'  => 'A',
 107          'path'      => '+/ !',
 108        ),
 109        '/diffusion/A/browse/money/%24%24100$2' => array(
 110          'action'    => 'browse',
 111          'callsign'  => 'A',
 112          'path'      => 'money/$100',
 113          'line'      => '2',
 114        ),
 115        '/diffusion/A/browse/path/to/file.ext?view=things' => array(
 116          'action'    => 'browse',
 117          'callsign'  => 'A',
 118          'path'      => 'path/to/file.ext',
 119          'params'    => array(
 120            'view' => 'things',
 121          ),
 122        ),
 123        '/diffusion/A/repository/master/' => array(
 124          'action'    => 'branch',
 125          'callsign'  => 'A',
 126          'branch'    => 'master',
 127        ),
 128        'path/to/file.ext;abc' => array(
 129          'action'    => 'rendering-ref',
 130          'path'      => 'path/to/file.ext',
 131          'commit'    => 'abc',
 132        ),
 133        '/diffusion/A/browse/branch/path.ext$3-5%2C7-12%2C14' => array(
 134          'action'    => 'browse',
 135          'callsign'  => 'A',
 136          'branch'    => 'branch',
 137          'path'      => 'path.ext',
 138          'line'      => '3-5,7-12,14',
 139        ),
 140      );
 141  
 142      foreach ($map as $expect => $input) {
 143        $actual = DiffusionRequest::generateDiffusionURI($input);
 144        $this->assertEqual(
 145          $expect,
 146          (string)$actual);
 147      }
 148    }
 149  
 150  }


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