Path: blob/master/src/aphront/__tests__/AphrontRoutingMapTestCase.php
12249 views
<?php12final class AphrontRoutingMapTestCase3extends PhabricatorTestCase {45public function testRoutingMaps() {6$count = 0;78$sites = AphrontSite::getAllSites();9foreach ($sites as $site) {10$maps = $site->getRoutingMaps();11foreach ($maps as $map) {12foreach ($map->getRoutes() as $rule => $value) {13$this->assertRoutable($site, $map, array(), $rule, $value);14$count++;15}16}17}1819if (!$count) {20$this->assertSkipped(21pht('No sites define any routing rules.'));22}23}2425private function assertRoutable(26AphrontSite $site,27AphrontRoutingMap $map,28array $path,29$rule,30$value) {3132$path[] = $rule;3334$site_description = $site->getDescription();35$rule_path = implode(' > ', $path);3637$pattern = implode('', $path);38$pattern = '('.$pattern.')';39$ok = @preg_match($pattern, '');4041$this->assertTrue(42($ok !== false),43pht(44'Routing rule ("%s", for site "%s") does not compile into a '.45'valid regular expression.',46$rule_path,47$site_description));4849if (is_array($value)) {50$this->assertTrue(51(count($value) > 0),52pht(53'Routing rule ("%s", for site "%s") does not have any targets.',54$rule_path,55$site_description));5657foreach ($value as $sub_rule => $sub_value) {58$this->assertRoutable($site, $map, $path, $sub_rule, $sub_value);59}60return;61}6263if (is_string($value)) {64$this->assertTrue(65class_exists($value),66pht(67'Routing rule ("%s", for site "%s") points at controller ("%s") '.68'which does not exist.',69$rule_path,70$site_description,71$value));72return;73}7475$this->assertFailure(76pht(77'Routing rule ("%s", for site "%s") points at unknown value '.78'(of type "%s"), expected a controller class name string.',79$rule_path,80$site_description,81phutil_describe_type($value)));82}8384}858687