PathEncodedTest.php in Drupal 9
File
core/tests/Drupal/FunctionalTests/Routing/PathEncodedTest.php
View source
<?php
namespace Drupal\FunctionalTests\Routing;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\Traits\Core\PathAliasTestTrait;
class PathEncodedTest extends BrowserTestBase {
use PathAliasTestTrait;
protected static $modules = [
'system',
'path_encoded_test',
];
protected $defaultTheme = 'stark';
public function testGetEncoded() {
$route_paths = [
'path_encoded_test.colon' => '/hi/llamma:party',
'path_encoded_test.atsign' => '/bloggy/@Dries',
'path_encoded_test.parens' => '/cat(box)',
];
foreach ($route_paths as $route_name => $path) {
$this
->drupalGet(Url::fromRoute($route_name));
$this
->assertSession()
->pageTextContains('PathEncodedTestController works');
}
}
public function testAliasToEncoded() {
$route_paths = [
'path_encoded_test.colon' => '/hi/llamma:party',
'path_encoded_test.atsign' => '/bloggy/@Dries',
'path_encoded_test.parens' => '/cat(box)',
];
$aliases = [];
foreach ($route_paths as $route_name => $path) {
$aliases[$route_name] = $this
->randomMachineName();
$this
->createPathAlias($path, '/' . $aliases[$route_name]);
}
foreach ($route_paths as $route_name => $path) {
$this
->assertMatchesRegularExpression('@/' . rawurlencode($aliases[$route_name]) . '$@', Url::fromRoute($route_name)
->toString());
$this
->drupalGet(Url::fromRoute($route_name));
$this
->assertSession()
->pageTextContains('PathEncodedTestController works');
}
}
}
Classes
Name |
Description |
PathEncodedTest |
Tests url generation and routing for route paths with encoded characters. |