@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final 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 'a - b' => 'a_-_b/',
38 'a[b]' => 'a_b/',
39 'ab!' => 'ab!/',
40 );
41
42 foreach ($slugs as $slug => $normal) {
43 $this->assertEqual(
44 $normal,
45 PhabricatorSlug::normalize($slug),
46 pht("Normalization of '%s'", $slug));
47 }
48 }
49
50 public function testProjectSlugs() {
51 $slugs = array(
52 'a:b' => 'a_b',
53 'a!b' => 'a_b',
54 'a - b' => 'a_-_b',
55 '' => '',
56 'Demonology: HSA (Hexes, Signs, Alchemy)' =>
57 'demonology_hsa_hexes_signs_alchemy',
58 );
59
60 foreach ($slugs as $slug => $normal) {
61 $this->assertEqual(
62 $normal,
63 PhabricatorSlug::normalizeProjectSlug($slug),
64 pht('Hashtag normalization of "%s"', $slug));
65 }
66 }
67
68 public function testSlugAncestry() {
69 $slugs = array(
70 '/' => array(),
71 'pokemon/' => array('/'),
72 'pokemon/squirtle/' => array('/', 'pokemon/'),
73 );
74
75 foreach ($slugs as $slug => $ancestry) {
76 $this->assertEqual(
77 $ancestry,
78 PhabricatorSlug::getAncestry($slug),
79 pht("Ancestry of '%s'", $slug));
80 }
81 }
82
83 public function testSlugDepth() {
84 $slugs = array(
85 '/' => 0,
86 'a/' => 1,
87 'a/b/' => 2,
88 'a////b/' => 2,
89 );
90
91 foreach ($slugs as $slug => $depth) {
92 $this->assertEqual(
93 $depth,
94 PhabricatorSlug::getDepth($slug),
95 pht("Depth of '%s'", $slug));
96 }
97 }
98}