@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 PhutilURIHelperTestCase extends PhabricatorTestCase {
4
5 public function testPhutilURIHelper() {
6
7 // Every row is a test. Every column is:
8 // - 0: name of the test
9 // - 1: test input value
10 // - 2: is the URI pointing to Phorge itself?
11 // - 3: is the URI an anchor? (no domain, no protocol)
12 // - 4: is the URI starting with a slash? (no domain, no protocol)
13 $tests = array(
14 array('internal anchor', '#asd', true, true, false),
15 array('internal relative dir', '/foo/', true, false, true),
16 array('internal relative dir also', 'foo/', true, false, false),
17 array('internal root dir', '/', true, false, true),
18 array('internal root dir', './', true, false, false),
19 array('internal root dir', '../', true, false, false),
20 array('internal root dir', '/#asd', true, false, true),
21 array('external', 'https://gnu.org/', false, false, false),
22 array('external anchor', 'https://gnu.org/#asd', false, false, false),
23 );
24
25 // Add additional self-tests if base URI is available.
26 $base = PhabricatorEnv::getEnvConfigIfExists('phabricator.base-uri');
27 if ($base) {
28 $domain = id(new PhutilURI($base))->getDomain();
29 $tests[] = array('base uri', $base, true, false, false);
30 $tests[] = array('base uri anchor', "{$base}#asd", true, false, false);
31 }
32
33 foreach ($tests as $test) {
34 $name = $test[0];
35 $uri = $test[1];
36 $is_self = $test[2];
37 $is_anchor = $test[3];
38 $is_slash = $test[4];
39
40 // Test input variants for the constructor of PhutilURIHelper.
41 $uri_variants = array(
42 $uri,
43 new PhutilURI($uri),
44 );
45 foreach ($uri_variants as $variant_uri) {
46
47 $test_name = pht("test %s value '%s' (from '%s' type %s)",
48 $name, $variant_uri, $uri, phutil_describe_type($variant_uri));
49
50 $uri = new PhutilURIHelper($variant_uri);
51
52 $this->assertEqual($is_self, $uri->isSelf(),
53 pht('%s - points to myself', $test_name));
54
55 $this->assertEqual($is_anchor, $uri->isAnchor(),
56 pht('%s - is just an anchor', $test_name));
57
58 $this->assertEqual($is_slash, $uri->isStartingWithSlash(),
59 pht('%s - is starting with slash', $test_name));
60 }
61 }
62 }
63}