Something went wrong. Try again.
@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
Something went wrong. Try again.
PHP
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586<?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))); }
}