class AdminRouteSubscriberTest

Same name in other branches
  1. 9 core/modules/system/tests/src/Unit/Routing/AdminRouteSubscriberTest.php \Drupal\Tests\system\Unit\Routing\AdminRouteSubscriberTest
  2. 8.9.x core/modules/system/tests/src/Unit/Routing/AdminRouteSubscriberTest.php \Drupal\Tests\system\Unit\Routing\AdminRouteSubscriberTest
  3. 11.x core/modules/system/tests/src/Unit/Routing/AdminRouteSubscriberTest.php \Drupal\Tests\system\Unit\Routing\AdminRouteSubscriberTest

@coversDefaultClass \Drupal\system\EventSubscriber\AdminRouteSubscriber @group system

Hierarchy

Expanded class hierarchy of AdminRouteSubscriberTest

File

core/modules/system/tests/src/Unit/Routing/AdminRouteSubscriberTest.php, line 17

Namespace

Drupal\Tests\system\Unit\Routing
View source
class AdminRouteSubscriberTest extends UnitTestCase {
    
    /**
     * @covers ::alterRoutes
     * @covers ::isHtmlRoute
     *
     * @dataProvider providerTestAlterRoutes
     */
    public function testAlterRoutes(Route $route, $is_admin) : void {
        $collection = new RouteCollection();
        $collection->add('the_route', $route);
        (new AdminRouteSubscriber())->onAlterRoutes(new RouteBuildEvent($collection));
        $this->assertSame($is_admin, $route->getOption('_admin_route'));
    }
    public static function providerTestAlterRoutes() {
        $data = [];
        $data['non-admin'] = [
            new Route('/foo'),
            NULL,
        ];
        $data['admin prefix'] = [
            new Route('/admin/foo'),
            TRUE,
        ];
        $data['admin only'] = [
            new Route('/admin'),
            TRUE,
        ];
        $data['admin in part of a word'] = [
            new Route('/administration/foo'),
            NULL,
        ];
        $data['admin in part of a word with admin_route option'] = [
            (new Route('/administration/foo'))->setOption('_admin_route', TRUE),
            TRUE,
        ];
        $data['admin not at the start of the path'] = [
            new Route('/foo/admin/bar'),
            NULL,
        ];
        $data['admin in part of a word not at the start of the path'] = [
            new Route('/foo/administration/bar'),
            NULL,
        ];
        $data['admin option'] = [
            (new Route('/foo'))->setOption('_admin_route', TRUE),
            TRUE,
        ];
        $data['admin prefix, non-HTML format'] = [
            (new Route('/admin/foo'))->setRequirement('_format', 'json'),
            NULL,
        ];
        $data['admin option, non-HTML format'] = [
            (new Route('/foo'))->setRequirement('_format', 'json')
                ->setOption('_admin_route', TRUE),
            TRUE,
        ];
        $data['admin prefix, HTML format'] = [
            (new Route('/admin/foo'))->setRequirement('_format', 'html'),
            TRUE,
        ];
        $data['admin prefix, multi-format including HTML'] = [
            (new Route('/admin/foo'))->setRequirement('_format', 'json|html'),
            TRUE,
        ];
        return $data;
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overrides
AdminRouteSubscriberTest::providerTestAlterRoutes public static function
AdminRouteSubscriberTest::testAlterRoutes public function @covers ::alterRoutes
@covers ::isHtmlRoute
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUp protected function 358
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

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