Loading core/modules/system/tests/modules/router_test_directory/src/Controller/TestClassAttributeClassOnly.php 0 → 100644 +27 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\router_test\Controller; use Drupal\Core\Controller\ControllerBase; use Symfony\Component\Routing\Attribute\Route; /** * Test controller: class-only #[Route] with bare __invoke(). */ #[Route( path: '/test_class_attribute_class_only', name: 'router_test.class_only', requirements: ['_access' => 'TRUE'], )] class TestClassAttributeClassOnly extends ControllerBase { /** * Provides test content. */ public function __invoke(): array { return ['#markup' => 'Testing class-only #[Route] with bare __invoke()']; } } core/tests/Drupal/Tests/Core/Routing/AttributeRouteDiscoveryTest.php +14 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ use Drupal\Core\Routing\RouteCompiler; use Drupal\router_test\Controller\TestAttributes; use Drupal\router_test\Controller\TestClassAttribute; use Drupal\router_test\Controller\TestClassAttributeClassOnly; use Drupal\router_test\Form\TestRouteAttributeForm; use Drupal\Tests\UnitTestCase; use org\bovigo\vfs\vfsStream; Loading Loading @@ -196,6 +197,19 @@ public function testAllRouteProperties(): void { $this->assertSame($route, $this->routeCollection->get(TestAttributes::class . '::allProperties')); } /** * Tests that class-only #[Route] registers a route for invokable controllers. */ public function testClassOnlyRouteWithInvoke(): void { $route = $this->routeCollection->get('router_test.class_only'); $this->assertNotNull($route); $this->assertSame('/test_class_attribute_class_only', $route->getPath()); $this->assertSame(TestClassAttributeClassOnly::class, $route->getDefault('_controller')); $this->assertSame('TRUE', $route->getRequirement('_access')); // Aliases for invokable controllers must also be registered. $this->assertSame($route, $this->routeCollection->get(TestClassAttributeClassOnly::class . '::__invoke')); } /** * Tests that invalid controller classes do not break route discovery. */ Loading Loading
core/modules/system/tests/modules/router_test_directory/src/Controller/TestClassAttributeClassOnly.php 0 → 100644 +27 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\router_test\Controller; use Drupal\Core\Controller\ControllerBase; use Symfony\Component\Routing\Attribute\Route; /** * Test controller: class-only #[Route] with bare __invoke(). */ #[Route( path: '/test_class_attribute_class_only', name: 'router_test.class_only', requirements: ['_access' => 'TRUE'], )] class TestClassAttributeClassOnly extends ControllerBase { /** * Provides test content. */ public function __invoke(): array { return ['#markup' => 'Testing class-only #[Route] with bare __invoke()']; } }
core/tests/Drupal/Tests/Core/Routing/AttributeRouteDiscoveryTest.php +14 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ use Drupal\Core\Routing\RouteCompiler; use Drupal\router_test\Controller\TestAttributes; use Drupal\router_test\Controller\TestClassAttribute; use Drupal\router_test\Controller\TestClassAttributeClassOnly; use Drupal\router_test\Form\TestRouteAttributeForm; use Drupal\Tests\UnitTestCase; use org\bovigo\vfs\vfsStream; Loading Loading @@ -196,6 +197,19 @@ public function testAllRouteProperties(): void { $this->assertSame($route, $this->routeCollection->get(TestAttributes::class . '::allProperties')); } /** * Tests that class-only #[Route] registers a route for invokable controllers. */ public function testClassOnlyRouteWithInvoke(): void { $route = $this->routeCollection->get('router_test.class_only'); $this->assertNotNull($route); $this->assertSame('/test_class_attribute_class_only', $route->getPath()); $this->assertSame(TestClassAttributeClassOnly::class, $route->getDefault('_controller')); $this->assertSame('TRUE', $route->getRequirement('_access')); // Aliases for invokable controllers must also be registered. $this->assertSame($route, $this->routeCollection->get(TestClassAttributeClassOnly::class . '::__invoke')); } /** * Tests that invalid controller classes do not break route discovery. */ Loading