class RoutePathTest
Same name and namespace in other branches
- 3.x tests/src/Unit/RoutePathTest.php \Drupal\Tests\examples\Unit\RoutePathTest
- 8.x-1.x tests/src/Unit/RoutePathTest.php \Drupal\Tests\examples\Unit\RoutePathTest
Verifies route paths are valid.
Route paths are considered valid when they start with a slash.
@group examples
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\examples\Unit\RoutePathTest uses \Drupal\Tests\examples\Unit\FilesTestTrait, \Drupal\Tests\examples\Unit\RetrieveRoutingFilesTrait implements \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 | Deprecated | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|---|
FilesTestTrait::projectPathname | protected static | function | Gets the absolute pathname for a project directory. | ||
FilesTestTrait::retrieveFiles | protected static | function | Retrieves files in a project directory. | ||
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. | |
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. | ||
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 |