3 namespace Drupal\FunctionalTests\Routing;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests url generation and routing for route paths with encoded characters.
13 class PathEncodedTest extends BrowserTestBase {
18 public static $modules = ['system', 'path_encoded_test'];
20 public function testGetEncoded() {
22 'path_encoded_test.colon' => '/hi/llamma:party',
23 'path_encoded_test.atsign' => '/bloggy/@Dries',
24 'path_encoded_test.parens' => '/cat(box)',
26 foreach ($route_paths as $route_name => $path) {
27 $this->drupalGet(Url::fromRoute($route_name));
28 $this->assertSession()->pageTextContains('PathEncodedTestController works');
32 public function testAliasToEncoded() {
34 'path_encoded_test.colon' => '/hi/llamma:party',
35 'path_encoded_test.atsign' => '/bloggy/@Dries',
36 'path_encoded_test.parens' => '/cat(box)',
38 /** @var \Drupal\Core\Path\AliasStorageInterface $alias_storage */
39 $alias_storage = $this->container->get('path.alias_storage');
41 foreach ($route_paths as $route_name => $path) {
42 $aliases[$route_name] = $this->randomMachineName();
43 $alias_storage->save($path, '/' . $aliases[$route_name]);
45 foreach ($route_paths as $route_name => $path) {
46 // The alias may be only a suffix of the generated path when the test is
47 // run with Drupal installed in a subdirectory.
48 $this->assertRegExp('@/' . rawurlencode($aliases[$route_name]) . '$@', Url::fromRoute($route_name)->toString());
49 $this->drupalGet(Url::fromRoute($route_name));
50 $this->assertSession()->pageTextContains('PathEncodedTestController works');