class RoutePathTest
Verifies route paths are valid.
Route paths are considered valid when they start with a slash.
@group examples
Hierarchy
- class \Drupal\Tests\examples\Unit\RoutePathTest uses \Drupal\Tests\examples\Unit\FilesTestTrait, \Drupal\Tests\examples\Unit\RetrieveRoutingFilesTrait extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of RoutePathTest
File
-
tests/
src/ Unit/ RoutePathTest.php, line 15
Namespace
Drupal\Tests\examples\UnitView source
class RoutePathTest extends UnitTestCase {
use FilesTestTrait;
use RetrieveRoutingFilesTrait;
/**
* Provides test data for testPathStartsWithSlash().
*
* @return array
* The test data.
*/
public static function providerRoutingFiles() : array {
$data = [];
$directory = self::projectPathname('modules');
return self::retrieveFiles($directory, 'yml', self::routingFilesCallback(...));
}
/**
* Tests that route paths start with a slash.
*
* @dataProvider providerRoutingFiles
*/
public function testPathStartsWithSlash(string $filename, string $path, string $pathname) : void {
$routes = Yaml::parse(file_get_contents($pathname));
foreach ($routes as $name => $route) {
if (isset($route['path'])) {
$this->assertEquals('/', $route['path'][0], "{$filename} in {$path} contains a route ({$name}) that does not start with a slash.");
}
}
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| FilesTestTrait::projectPathname | protected static | function | Gets the absolute pathname for a project directory. |
| FilesTestTrait::retrieveFiles | protected static | function | Retrieves files in a project directory. |
| RetrieveRoutingFilesTrait::routingFilesCallback | protected static | function | Callback to filter Drupal routing files. |
| RoutePathTest::providerRoutingFiles | public static | function | Provides test data for testPathStartsWithSlash(). |
| RoutePathTest::testPathStartsWithSlash | public | function | Tests that route paths start with a slash. |