[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/infrastructure/util/__tests__/ -> PhabricatorSlugTestCase.php (source)

   1  <?php
   2  
   3  final class PhabricatorSlugTestCase extends PhabricatorTestCase {
   4  
   5    public function testSlugNormalization() {
   6      $slugs = array(
   7        ''                  => '/',
   8        '/'                 => '/',
   9        '//'                => '/',
  10        '&&&'               => '_/',
  11        '/derp/'            => 'derp/',
  12        'derp'              => 'derp/',
  13        'derp//derp'        => 'derp/derp/',
  14        'DERP//DERP'        => 'derp/derp/',
  15        'a B c'             => 'a_b_c/',
  16        '-1~2.3abcd'        => '-1~2.3abcd/',
  17        "T\x00O\x00D\x00O"  => 't_o_d_o/',
  18        'x#%&+=\\?<> y'     => 'x_y/',
  19        "\xE2\x98\x83"      => "\xE2\x98\x83/",
  20        '..'                => 'dotdot/',
  21        '../'               => 'dotdot/',
  22        '/../'              => 'dotdot/',
  23        'a/b'               => 'a/b/',
  24        'a//b'              => 'a/b/',
  25        'a/../b/'           => 'a/dotdot/b/',
  26        '/../a'             => 'dotdot/a/',
  27        '../a'              => 'dotdot/a/',
  28        'a/..'              => 'a/dotdot/',
  29        'a/../'             => 'a/dotdot/',
  30        'a?'                => 'a/',
  31        '??'                => '_/',
  32        'a/?'               => 'a/_/',
  33        '??/a/??'           => '_/a/_/',
  34        'a/??/c'            => 'a/_/c/',
  35        'a/?b/c'            => 'a/b/c/',
  36        'a/b?/c'            => 'a/b/c/',
  37      );
  38  
  39      foreach ($slugs as $slug => $normal) {
  40        $this->assertEqual(
  41          $normal,
  42          PhabricatorSlug::normalize($slug),
  43          "Normalization of '{$slug}'");
  44      }
  45    }
  46  
  47    public function testSlugAncestry() {
  48      $slugs = array(
  49        '/'                   => array(),
  50        'pokemon/'            => array('/'),
  51        'pokemon/squirtle/'   => array('/', 'pokemon/'),
  52      );
  53  
  54      foreach ($slugs as $slug => $ancestry) {
  55        $this->assertEqual(
  56          $ancestry,
  57          PhabricatorSlug::getAncestry($slug),
  58          "Ancestry of '{$slug}'");
  59      }
  60    }
  61  
  62    public function testSlugDepth() {
  63      $slugs = array(
  64        '/'       => 0,
  65        'a/'      => 1,
  66        'a/b/'    => 2,
  67        'a////b/' => 2,
  68      );
  69  
  70      foreach ($slugs as $slug => $depth) {
  71        $this->assertEqual(
  72          $depth,
  73          PhabricatorSlug::getDepth($slug),
  74          "Depth of '{$slug}'");
  75      }
  76    }
  77  }


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