comparison core/tests/Drupal/FunctionalTests/Routing/PathEncodedTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
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 }