function AttributeRouteDiscoveryTest::testClassGlobalsMerging
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Routing/AttributeRouteDiscoveryTest.php \Drupal\Tests\Core\Routing\AttributeRouteDiscoveryTest::testClassGlobalsMerging()
Tests that method-level properties correctly merge with class globals.
File
-
core/
tests/ Drupal/ Tests/ Core/ Routing/ AttributeRouteDiscoveryTest.php, line 135
Class
Namespace
Drupal\Tests\Core\RoutingCode
public function testClassGlobalsMerging() : void {
// The route name is the class prefix + method name.
$route = $this->routeCollection
->get('router_test.class_overrides');
$this->assertNotNull($route);
// Path is prefixed with the class path.
$this->assertSame('/test_class_attribute/overrides/{id}', $route->getPath());
// Controller is automatically configured.
$this->assertSame(TestClassAttribute::class . '::overrides', $route->getDefault('_controller'));
// Defaults: method key overrides class key, class-only key is inherited.
$this->assertSame('from_method', $route->getDefault('default_a'));
$this->assertSame('from_method', $route->getDefault('default_b'));
$this->assertSame('Class title', $route->getDefault('_title'));
// Requirements: access is inherited, id key is added.
$this->assertSame('TRUE', $route->getRequirement('_access'));
$this->assertSame('\\d+', $route->getRequirement('id'));
// Options: method key overrides class key, method-only key is added.
$this->assertSame('from_method', $route->getOption('option_a'));
$this->assertSame('from_method', $route->getOption('option_b'));
// Host: method overrides class (class had no host set).
$this->assertSame('method.example.com', $route->getHost());
// Methods: union of class ['GET'] and method ['POST'].
$methods = $route->getMethods();
$this->assertContains('GET', $methods);
$this->assertContains('POST', $methods);
$this->assertCount(2, $methods);
// Schemes: union of class ['http'] and method ['https'].
$schemes = $route->getSchemes();
$this->assertContains('http', $schemes);
$this->assertContains('https', $schemes);
$this->assertCount(2, $schemes);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.