@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 AphrontRoutingMapTestCase
4 extends PhabricatorTestCase {
5
6 public function testRoutingMaps() {
7 $count = 0;
8
9 $sites = AphrontSite::getAllSites();
10 foreach ($sites as $site) {
11 $maps = $site->getRoutingMaps();
12 foreach ($maps as $map) {
13 foreach ($map->getRoutes() as $rule => $value) {
14 $this->assertRoutable($site, $map, array(), $rule, $value);
15 $count++;
16 }
17 }
18 }
19
20 if (!$count) {
21 $this->assertSkipped(
22 pht('No sites define any routing rules.'));
23 }
24 }
25
26 private function assertRoutable(
27 AphrontSite $site,
28 AphrontRoutingMap $map,
29 array $path,
30 $rule,
31 $value) {
32
33 $path[] = $rule;
34
35 $site_description = $site->getDescription();
36 $rule_path = implode(' > ', $path);
37
38 $pattern = implode('', $path);
39 $pattern = '('.$pattern.')';
40 $ok = @preg_match($pattern, '');
41
42 $this->assertTrue(
43 ($ok !== false),
44 pht(
45 'Routing rule ("%s", for site "%s") does not compile into a '.
46 'valid regular expression.',
47 $rule_path,
48 $site_description));
49
50 if (is_array($value)) {
51 $this->assertTrue(
52 (count($value) > 0),
53 pht(
54 'Routing rule ("%s", for site "%s") does not have any targets.',
55 $rule_path,
56 $site_description));
57
58 foreach ($value as $sub_rule => $sub_value) {
59 $this->assertRoutable($site, $map, $path, $sub_rule, $sub_value);
60 }
61 return;
62 }
63
64 if (is_string($value)) {
65 $this->assertTrue(
66 class_exists($value),
67 pht(
68 'Routing rule ("%s", for site "%s") points at controller ("%s") '.
69 'which does not exist.',
70 $rule_path,
71 $site_description,
72 $value));
73 return;
74 }
75
76 $this->assertFailure(
77 pht(
78 'Routing rule ("%s", for site "%s") points at unknown value '.
79 '(of type "%s"), expected a controller class name string.',
80 $rule_path,
81 $site_description,
82 phutil_describe_type($value)));
83 }
84
85}