Fix searching legalpad documents by contributors
[phabricator.git] / src / aphront / __tests__ / AphrontRoutingMapTestCase.php
blob42d79d1089b09fed4194376bbba285a029bde396
1 <?php
3 final class AphrontRoutingMapTestCase
4 extends PhabricatorTestCase {
6 public function testRoutingMaps() {
7 $count = 0;
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++;
20 if (!$count) {
21 $this->assertSkipped(
22 pht('No sites define any routing rules.'));
26 private function assertRoutable(
27 AphrontSite $site,
28 AphrontRoutingMap $map,
29 array $path,
30 $rule,
31 $value) {
33 $path[] = $rule;
35 $site_description = $site->getDescription();
36 $rule_path = implode(' > ', $path);
38 $pattern = implode('', $path);
39 $pattern = '('.$pattern.')';
40 $ok = @preg_match($pattern, '');
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));
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));
58 foreach ($value as $sub_rule => $sub_value) {
59 $this->assertRoutable($site, $map, $path, $sub_rule, $sub_value);
61 return;
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;
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)));