1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 10:12:41 +01:00

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
This commit is contained in:
epriestley 2020-02-14 13:56:08 -08:00
parent 4790a3d94b
commit 64cc4fe915
11 changed files with 88 additions and 33 deletions

View file

@ -275,6 +275,7 @@ phutil_register_library_map(array(
'AphrontResponse' => 'aphront/response/AphrontResponse.php', 'AphrontResponse' => 'aphront/response/AphrontResponse.php',
'AphrontResponseProducerInterface' => 'aphront/interface/AphrontResponseProducerInterface.php', 'AphrontResponseProducerInterface' => 'aphront/interface/AphrontResponseProducerInterface.php',
'AphrontRoutingMap' => 'aphront/site/AphrontRoutingMap.php', 'AphrontRoutingMap' => 'aphront/site/AphrontRoutingMap.php',
'AphrontRoutingMapTestCase' => 'aphront/__tests__/AphrontRoutingMapTestCase.php',
'AphrontRoutingResult' => 'aphront/site/AphrontRoutingResult.php', 'AphrontRoutingResult' => 'aphront/site/AphrontRoutingResult.php',
'AphrontSchemaQueryException' => 'infrastructure/storage/exception/AphrontSchemaQueryException.php', 'AphrontSchemaQueryException' => 'infrastructure/storage/exception/AphrontSchemaQueryException.php',
'AphrontScopedUnguardedWriteCapability' => 'aphront/writeguard/AphrontScopedUnguardedWriteCapability.php', 'AphrontScopedUnguardedWriteCapability' => 'aphront/writeguard/AphrontScopedUnguardedWriteCapability.php',
@ -6283,6 +6284,7 @@ phutil_register_library_map(array(
'AphrontRequestTestCase' => 'PhabricatorTestCase', 'AphrontRequestTestCase' => 'PhabricatorTestCase',
'AphrontResponse' => 'Phobject', 'AphrontResponse' => 'Phobject',
'AphrontRoutingMap' => 'Phobject', 'AphrontRoutingMap' => 'Phobject',
'AphrontRoutingMapTestCase' => 'PhabricatorTestCase',
'AphrontRoutingResult' => 'Phobject', 'AphrontRoutingResult' => 'Phobject',
'AphrontSchemaQueryException' => 'AphrontQueryException', 'AphrontSchemaQueryException' => 'AphrontQueryException',
'AphrontScopedUnguardedWriteCapability' => 'Phobject', 'AphrontScopedUnguardedWriteCapability' => 'Phobject',

View file

@ -0,0 +1,85 @@
<?php
final class AphrontRoutingMapTestCase
extends PhabricatorTestCase {
public function testRoutingMaps() {
$count = 0;
$sites = AphrontSite::getAllSites();
foreach ($sites as $site) {
$maps = $site->getRoutingMaps();
foreach ($maps as $map) {
foreach ($map->getRoutes() as $rule => $value) {
$this->assertRoutable($site, $map, array(), $rule, $value);
$count++;
}
}
}
if (!$count) {
$this->assertSkipped(
pht('No sites define any routing rules.'));
}
}
private function assertRoutable(
AphrontSite $site,
AphrontRoutingMap $map,
array $path,
$rule,
$value) {
$path[] = $rule;
$site_description = $site->getDescription();
$rule_path = implode(' > ', $path);
$pattern = implode('', $path);
$pattern = '('.$pattern.')';
$ok = @preg_match($pattern, '');
$this->assertTrue(
($ok !== false),
pht(
'Routing rule ("%s", for site "%s") does not compile into a '.
'valid regular expression.',
$rule_path,
$site_description));
if (is_array($value)) {
$this->assertTrue(
(count($value) > 0),
pht(
'Routing rule ("%s", for site "%s") does not have any targets.',
$rule_path,
$site_description));
foreach ($value as $sub_rule => $sub_value) {
$this->assertRoutable($site, $map, $path, $sub_rule, $sub_value);
}
return;
}
if (is_string($value)) {
$this->assertTrue(
class_exists($value),
pht(
'Routing rule ("%s", for site "%s") points at controller ("%s") '.
'which does not exist.',
$rule_path,
$site_description,
$value));
return;
}
$this->assertFailure(
pht(
'Routing rule ("%s", for site "%s") points at unknown value '.
'(of type "%s"), expected a controller class name string.',
$rule_path,
$site_description,
phutil_describe_type($value)));
}
}

View file

@ -38,11 +38,7 @@ final class PhabricatorConfigApplication extends PhabricatorApplication {
return array( return array(
'/config/' => array( '/config/' => array(
'' => 'PhabricatorConfigConsoleController', '' => 'PhabricatorConfigConsoleController',
'application/' => 'PhabricatorConfigApplicationController',
'all/' => 'PhabricatorConfigAllController',
'history/' => 'PhabricatorConfigHistoryController',
'edit/(?P<key>[\w\.\-]+)/' => 'PhabricatorConfigEditController', 'edit/(?P<key>[\w\.\-]+)/' => 'PhabricatorConfigEditController',
'group/(?P<key>[^/]+)/' => 'PhabricatorConfigGroupController',
'database/'. 'database/'.
'(?:(?P<ref>[^/]+)/'. '(?:(?P<ref>[^/]+)/'.
'(?:(?P<database>[^/]+)/'. '(?:(?P<database>[^/]+)/'.

View file

@ -42,8 +42,6 @@ final class PhabricatorCountdownApplication extends PhabricatorApplication {
'/countdown/' => array( '/countdown/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' '(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorCountdownListController', => 'PhabricatorCountdownListController',
'comment/(?P<id>[1-9]\d*)/'
=> 'PhabricatorCountdownCommentController',
$this->getEditRoutePattern('edit/') $this->getEditRoutePattern('edit/')
=> 'PhabricatorCountdownEditController', => 'PhabricatorCountdownEditController',
), ),

View file

@ -76,11 +76,7 @@ final class PhabricatorDifferentialApplication
=> 'DifferentialRevisionInlinesController', => 'DifferentialRevisionInlinesController',
), ),
'comment/' => array( 'comment/' => array(
'preview/(?P<id>[1-9]\d*)/' => 'DifferentialCommentPreviewController',
'save/(?P<id>[1-9]\d*)/' => 'DifferentialCommentSaveController',
'inline/' => array( 'inline/' => array(
'preview/(?P<id>[1-9]\d*)/'
=> 'DifferentialInlineCommentPreviewController',
'edit/(?P<id>[1-9]\d*)/' 'edit/(?P<id>[1-9]\d*)/'
=> 'DifferentialInlineCommentEditController', => 'DifferentialInlineCommentEditController',
), ),

View file

@ -81,7 +81,6 @@ final class PhabricatorFilesApplication extends PhabricatorApplication {
'upload/' => 'PhabricatorFileUploadController', 'upload/' => 'PhabricatorFileUploadController',
'dropupload/' => 'PhabricatorFileDropUploadController', 'dropupload/' => 'PhabricatorFileDropUploadController',
'compose/' => 'PhabricatorFileComposeController', 'compose/' => 'PhabricatorFileComposeController',
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorFileCommentController',
'thread/(?P<phid>[^/]+)/' => 'PhabricatorFileLightboxController', 'thread/(?P<phid>[^/]+)/' => 'PhabricatorFileLightboxController',
'delete/(?P<id>[1-9]\d*)/' => 'PhabricatorFileDeleteController', 'delete/(?P<id>[1-9]\d*)/' => 'PhabricatorFileDeleteController',
$this->getEditRoutePattern('edit/') $this->getEditRoutePattern('edit/')

View file

@ -81,7 +81,6 @@ final class PhabricatorHarbormasterApplication extends PhabricatorApplication {
$this->getQueryRoutePattern() => 'HarbormasterPlanListController', $this->getQueryRoutePattern() => 'HarbormasterPlanListController',
$this->getEditRoutePattern('edit/') $this->getEditRoutePattern('edit/')
=> 'HarbormasterPlanEditController', => 'HarbormasterPlanEditController',
'order/(?:(?P<id>\d+)/)?' => 'HarbormasterPlanOrderController',
'disable/(?P<id>\d+)/' => 'HarbormasterPlanDisableController', 'disable/(?P<id>\d+)/' => 'HarbormasterPlanDisableController',
'behavior/(?P<id>\d+)/(?P<behaviorKey>[^/]+)/' => 'behavior/(?P<id>\d+)/(?P<behaviorKey>[^/]+)/' =>
'HarbormasterPlanBehaviorController', 'HarbormasterPlanBehaviorController',

View file

@ -81,8 +81,6 @@ final class PhabricatorPeopleApplication extends PhabricatorApplication {
), ),
'/p/(?P<username>[\w._-]+)/' => array( '/p/(?P<username>[\w._-]+)/' => array(
'' => 'PhabricatorPeopleProfileViewController', '' => 'PhabricatorPeopleProfileViewController',
'item/' => $this->getProfileMenuRouting(
'PhabricatorPeopleProfileMenuController'),
), ),
); );
} }

View file

@ -49,7 +49,6 @@ final class PhabricatorPhameApplication extends PhabricatorApplication {
'view/(?P<id>\d+)/(?:(?P<slug>[^/]+)/)?' => 'PhamePostViewController', 'view/(?P<id>\d+)/(?:(?P<slug>[^/]+)/)?' => 'PhamePostViewController',
'(?P<action>publish|unpublish)/(?P<id>\d+)/' '(?P<action>publish|unpublish)/(?P<id>\d+)/'
=> 'PhamePostPublishController', => 'PhamePostPublishController',
'preview/(?P<id>\d+)/' => 'PhamePostPreviewController',
'preview/' => 'PhabricatorMarkupPreviewController', 'preview/' => 'PhabricatorMarkupPreviewController',
'move/(?P<id>\d+)/' => 'PhamePostMoveController', 'move/(?P<id>\d+)/' => 'PhamePostMoveController',
'archive/(?P<id>\d+)/' => 'PhamePostArchiveController', 'archive/(?P<id>\d+)/' => 'PhamePostArchiveController',
@ -66,20 +65,7 @@ final class PhabricatorPhameApplication extends PhabricatorApplication {
'picture/(?P<id>[1-9]\d*)/' => 'PhameBlogProfilePictureController', 'picture/(?P<id>[1-9]\d*)/' => 'PhameBlogProfilePictureController',
'header/(?P<id>[1-9]\d*)/' => 'PhameBlogHeaderPictureController', 'header/(?P<id>[1-9]\d*)/' => 'PhameBlogHeaderPictureController',
), ),
) + $this->getResourceSubroutes(), ),
);
}
public function getResourceRoutes() {
return array(
'/phame/' => $this->getResourceSubroutes(),
);
}
private function getResourceSubroutes() {
return array(
'r/(?P<id>\d+)/(?P<hash>[^/]+)/(?P<name>.*)' =>
'PhameResourceController',
); );
} }

View file

@ -101,11 +101,8 @@ final class PhabricatorPhortuneApplication extends PhabricatorApplication {
'product/' => array( 'product/' => array(
'' => 'PhortuneProductListController', '' => 'PhortuneProductListController',
'view/(?P<id>\d+)/' => 'PhortuneProductViewController', 'view/(?P<id>\d+)/' => 'PhortuneProductViewController',
'edit/(?:(?P<id>\d+)/)?' => 'PhortuneProductEditController',
), ),
'provider/' => array( 'provider/' => array(
'edit/(?:(?P<id>\d+)/)?' => 'PhortuneProviderEditController',
'disable/(?P<id>\d+)/' => 'PhortuneProviderDisableController',
'(?P<id>\d+)/(?P<action>[^/]+)/' '(?P<id>\d+)/(?P<action>[^/]+)/'
=> 'PhortuneProviderActionController', => 'PhortuneProviderActionController',
), ),

View file

@ -30,7 +30,6 @@ final class PhabricatorSearchApplication extends PhabricatorApplication {
return array( return array(
'/search/' => array( '/search/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorSearchController', '(?:query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorSearchController',
'index/(?P<phid>[^/]+)/' => 'PhabricatorSearchIndexController',
'hovercard/' 'hovercard/'
=> 'PhabricatorSearchHovercardController', => 'PhabricatorSearchHovercardController',
'handle/(?P<phid>[^/]+)/' 'handle/(?P<phid>[^/]+)/'