Skip to content

Commit 64cc4fe

Browse files
author
epriestley
committedFeb 15, 2020
Add a test to verify that all routing maps are plausibly valid, and remove some dead routes
Summary: Previously, see D20999. See also <https://discourse.phabricator-community.org/t/the-phutil-library-phutil-has-not-been-loaded/3543/>. There are a couple of dead "Config" routes after recent changes. Add test coverage to make sure routes all point somewhere valid, then remove all the dead routes that turned up. Test Plan: Ran tests, saw failures. Removed dead routes, got clean tests. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Differential Revision: https://secure.phabricator.com/D21000
1 parent 4790a3d commit 64cc4fe

File tree

11 files changed

+88
-33
lines changed

11 files changed

+88
-33
lines changed
 

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275
'AphrontResponse' => 'aphront/response/AphrontResponse.php',
276276
'AphrontResponseProducerInterface' => 'aphront/interface/AphrontResponseProducerInterface.php',
277277
'AphrontRoutingMap' => 'aphront/site/AphrontRoutingMap.php',
278+
'AphrontRoutingMapTestCase' => 'aphront/__tests__/AphrontRoutingMapTestCase.php',
278279
'AphrontRoutingResult' => 'aphront/site/AphrontRoutingResult.php',
279280
'AphrontSchemaQueryException' => 'infrastructure/storage/exception/AphrontSchemaQueryException.php',
280281
'AphrontScopedUnguardedWriteCapability' => 'aphront/writeguard/AphrontScopedUnguardedWriteCapability.php',
@@ -6283,6 +6284,7 @@
62836284
'AphrontRequestTestCase' => 'PhabricatorTestCase',
62846285
'AphrontResponse' => 'Phobject',
62856286
'AphrontRoutingMap' => 'Phobject',
6287+
'AphrontRoutingMapTestCase' => 'PhabricatorTestCase',
62866288
'AphrontRoutingResult' => 'Phobject',
62876289
'AphrontSchemaQueryException' => 'AphrontQueryException',
62886290
'AphrontScopedUnguardedWriteCapability' => 'Phobject',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
final 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+
}

‎src/applications/config/application/PhabricatorConfigApplication.php

-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ public function getRoutes() {
3838
return array(
3939
'/config/' => array(
4040
'' => 'PhabricatorConfigConsoleController',
41-
'application/' => 'PhabricatorConfigApplicationController',
42-
'all/' => 'PhabricatorConfigAllController',
43-
'history/' => 'PhabricatorConfigHistoryController',
4441
'edit/(?P<key>[\w\.\-]+)/' => 'PhabricatorConfigEditController',
45-
'group/(?P<key>[^/]+)/' => 'PhabricatorConfigGroupController',
4642
'database/'.
4743
'(?:(?P<ref>[^/]+)/'.
4844
'(?:(?P<database>[^/]+)/'.

‎src/applications/countdown/application/PhabricatorCountdownApplication.php

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public function getRoutes() {
4242
'/countdown/' => array(
4343
'(?:query/(?P<queryKey>[^/]+)/)?'
4444
=> 'PhabricatorCountdownListController',
45-
'comment/(?P<id>[1-9]\d*)/'
46-
=> 'PhabricatorCountdownCommentController',
4745
$this->getEditRoutePattern('edit/')
4846
=> 'PhabricatorCountdownEditController',
4947
),

‎src/applications/differential/application/PhabricatorDifferentialApplication.php

-4
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ public function getRoutes() {
7676
=> 'DifferentialRevisionInlinesController',
7777
),
7878
'comment/' => array(
79-
'preview/(?P<id>[1-9]\d*)/' => 'DifferentialCommentPreviewController',
80-
'save/(?P<id>[1-9]\d*)/' => 'DifferentialCommentSaveController',
8179
'inline/' => array(
82-
'preview/(?P<id>[1-9]\d*)/'
83-
=> 'DifferentialInlineCommentPreviewController',
8480
'edit/(?P<id>[1-9]\d*)/'
8581
=> 'DifferentialInlineCommentEditController',
8682
),

‎src/applications/files/application/PhabricatorFilesApplication.php

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public function getRoutes() {
8181
'upload/' => 'PhabricatorFileUploadController',
8282
'dropupload/' => 'PhabricatorFileDropUploadController',
8383
'compose/' => 'PhabricatorFileComposeController',
84-
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorFileCommentController',
8584
'thread/(?P<phid>[^/]+)/' => 'PhabricatorFileLightboxController',
8685
'delete/(?P<id>[1-9]\d*)/' => 'PhabricatorFileDeleteController',
8786
$this->getEditRoutePattern('edit/')

‎src/applications/harbormaster/application/PhabricatorHarbormasterApplication.php

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public function getRoutes() {
8181
$this->getQueryRoutePattern() => 'HarbormasterPlanListController',
8282
$this->getEditRoutePattern('edit/')
8383
=> 'HarbormasterPlanEditController',
84-
'order/(?:(?P<id>\d+)/)?' => 'HarbormasterPlanOrderController',
8584
'disable/(?P<id>\d+)/' => 'HarbormasterPlanDisableController',
8685
'behavior/(?P<id>\d+)/(?P<behaviorKey>[^/]+)/' =>
8786
'HarbormasterPlanBehaviorController',

‎src/applications/people/application/PhabricatorPeopleApplication.php

-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ public function getRoutes() {
8181
),
8282
'/p/(?P<username>[\w._-]+)/' => array(
8383
'' => 'PhabricatorPeopleProfileViewController',
84-
'item/' => $this->getProfileMenuRouting(
85-
'PhabricatorPeopleProfileMenuController'),
8684
),
8785
);
8886
}

‎src/applications/phame/application/PhabricatorPhameApplication.php

+1-15
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public function getRoutes() {
4949
'view/(?P<id>\d+)/(?:(?P<slug>[^/]+)/)?' => 'PhamePostViewController',
5050
'(?P<action>publish|unpublish)/(?P<id>\d+)/'
5151
=> 'PhamePostPublishController',
52-
'preview/(?P<id>\d+)/' => 'PhamePostPreviewController',
5352
'preview/' => 'PhabricatorMarkupPreviewController',
5453
'move/(?P<id>\d+)/' => 'PhamePostMoveController',
5554
'archive/(?P<id>\d+)/' => 'PhamePostArchiveController',
@@ -66,20 +65,7 @@ public function getRoutes() {
6665
'picture/(?P<id>[1-9]\d*)/' => 'PhameBlogProfilePictureController',
6766
'header/(?P<id>[1-9]\d*)/' => 'PhameBlogHeaderPictureController',
6867
),
69-
) + $this->getResourceSubroutes(),
70-
);
71-
}
72-
73-
public function getResourceRoutes() {
74-
return array(
75-
'/phame/' => $this->getResourceSubroutes(),
76-
);
77-
}
78-
79-
private function getResourceSubroutes() {
80-
return array(
81-
'r/(?P<id>\d+)/(?P<hash>[^/]+)/(?P<name>.*)' =>
82-
'PhameResourceController',
68+
),
8369
);
8470
}
8571

‎src/applications/phortune/application/PhabricatorPhortuneApplication.php

-3
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,8 @@ public function getRoutes() {
101101
'product/' => array(
102102
'' => 'PhortuneProductListController',
103103
'view/(?P<id>\d+)/' => 'PhortuneProductViewController',
104-
'edit/(?:(?P<id>\d+)/)?' => 'PhortuneProductEditController',
105104
),
106105
'provider/' => array(
107-
'edit/(?:(?P<id>\d+)/)?' => 'PhortuneProviderEditController',
108-
'disable/(?P<id>\d+)/' => 'PhortuneProviderDisableController',
109106
'(?P<id>\d+)/(?P<action>[^/]+)/'
110107
=> 'PhortuneProviderActionController',
111108
),

‎src/applications/search/application/PhabricatorSearchApplication.php

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function getRoutes() {
3030
return array(
3131
'/search/' => array(
3232
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorSearchController',
33-
'index/(?P<phid>[^/]+)/' => 'PhabricatorSearchIndexController',
3433
'hovercard/'
3534
=> 'PhabricatorSearchHovercardController',
3635
'handle/(?P<phid>[^/]+)/'

0 commit comments

Comments
 (0)
Failed to load comments.