Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / FunctionalTests / Routing / PathEncodedTest.php
1 <?php
2
3 namespace Drupal\FunctionalTests\Routing;
4
5 use Drupal\Core\Url;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Tests url generation and routing for route paths with encoded characters.
10  *
11  * @group routing
12  */
13 class PathEncodedTest extends BrowserTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['system', 'path_encoded_test'];
19
20   public function testGetEncoded() {
21     $route_paths = [
22       'path_encoded_test.colon' => '/hi/llamma:party',
23       'path_encoded_test.atsign' => '/bloggy/@Dries',
24       'path_encoded_test.parens' => '/cat(box)',
25     ];
26     foreach ($route_paths as $route_name => $path) {
27       $this->drupalGet(Url::fromRoute($route_name));
28       $this->assertSession()->pageTextContains('PathEncodedTestController works');
29     }
30   }
31
32   public function testAliasToEncoded() {
33     $route_paths = [
34       'path_encoded_test.colon' => '/hi/llamma:party',
35       'path_encoded_test.atsign' => '/bloggy/@Dries',
36       'path_encoded_test.parens' => '/cat(box)',
37     ];
38     /** @var \Drupal\Core\Path\AliasStorageInterface $alias_storage */
39     $alias_storage = $this->container->get('path.alias_storage');
40     $aliases = [];
41     foreach ($route_paths as $route_name => $path) {
42       $aliases[$route_name] = $this->randomMachineName();
43       $alias_storage->save($path, '/' . $aliases[$route_name]);
44     }
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');
51     }
52   }
53
54 }