function RouterTest::testAttributeDiscovery

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest::testAttributeDiscovery()

Tests routes defined using PHP attributes.

File

core/modules/system/tests/src/Functional/Routing/RouterTest.php, line 408

Class

RouterTest
Functional class for the full integrated routing system.

Namespace

Drupal\Tests\system\Functional\Routing

Code

public function testAttributeDiscovery() : void {
  $this->drupalGet('/test_class_attribute');
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertSession()
    ->pageTextContains('Testing __invoke() with a Route attribute on the class');
  $this->drupalGet('/test_method_attribute');
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertSession()
    ->pageTextContains('Testing method with a Route attribute');
  $this->drupalGet('/test-form-route');
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertSession()
    ->addressEquals('test-form-route');
  $this->assertSession()
    ->buttonExists('Click here');
  // Route attribute used on a FormInterface class method is not discoverable.
  $this->drupalGet('/invalid-form-method-route');
  $this->assertSession()
    ->statusCodeEquals(404);
  // Route attribute used on non-FormInterface class in Form namespace is not
  // discoverable.
  $this->drupalGet('/non-form-object-route');
  $this->assertSession()
    ->statusCodeEquals(404);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.