class AdminRouteSubscriberTest in Drupal 8
Same name and namespace in other branches
- 9 core/modules/system/tests/src/Unit/Routing/AdminRouteSubscriberTest.php \Drupal\Tests\system\Unit\Routing\AdminRouteSubscriberTest
@coversDefaultClass \Drupal\system\EventSubscriber\AdminRouteSubscriber @group system
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\system\Unit\Routing\AdminRouteSubscriberTest
Expanded class hierarchy of AdminRouteSubscriberTest
File
- core/
modules/ system/ tests/ src/ Unit/ Routing/ AdminRouteSubscriberTest.php, line 15
Namespace
Drupal\Tests\system\Unit\RoutingView source
class AdminRouteSubscriberTest extends UnitTestCase {
/**
* @covers ::alterRoutes
* @covers ::isHtmlRoute
*
* @dataProvider providerTestAlterRoutes
*/
public function testAlterRoutes(Route $route, $is_admin) {
$collection = new RouteCollection();
$collection
->add('the_route', $route);
(new AdminRouteSubscriber())
->onAlterRoutes(new RouteBuildEvent($collection));
$this
->assertSame($is_admin, $route
->getOption('_admin_route'));
}
public 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AdminRouteSubscriberTest:: |
public | function | ||
AdminRouteSubscriberTest:: |
public | function | @covers ::alterRoutes @covers ::isHtmlRoute | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |