Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / FunctionalTests / Routing / CaseInsensitivePathTest.php
1 <?php
2
3 namespace Drupal\FunctionalTests\Routing;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests incoming path case insensitivity.
9  *
10  * @group routing
11  */
12 class CaseInsensitivePathTest extends BrowserTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = ['system', 'views', 'node', 'system_test'];
18
19   /**
20    * {@inheritdoc}
21    */
22   protected function setUp() {
23     parent::setUp();
24     \Drupal::state()->set('system_test.module_hidden', FALSE);
25     $this->createContentType(['type' => 'page']);
26   }
27
28   /**
29    * Tests mixed case paths.
30    */
31   public function testMixedCasePaths() {
32     // Tests paths defined by routes from standard modules as anonymous.
33     $this->drupalGet('user/login');
34     $this->assertSession()->statusCodeEquals(200);
35     $this->assertSession()->pageTextMatches('/Log in/');
36     $this->drupalGet('User/Login');
37     $this->assertSession()->statusCodeEquals(200);
38     $this->assertSession()->pageTextMatches('/Log in/');
39
40     // Tests paths defined by routes from the Views module.
41     $admin = $this->drupalCreateUser(['access administration pages', 'administer nodes', 'access content overview']);
42     $this->drupalLogin($admin);
43
44     $this->drupalGet('admin/content');
45     $this->assertSession()->statusCodeEquals(200);
46     $this->assertSession()->pageTextMatches('/Content/');
47     $this->drupalGet('Admin/Content');
48     $this->assertSession()->statusCodeEquals(200);
49     $this->assertSession()->pageTextMatches('/Content/');
50
51     // Tests paths with query arguments.
52
53     // Make sure our node title doesn't exist.
54     $this->drupalGet('admin/content');
55     $this->assertSession()->linkNotExists('FooBarBaz');
56     $this->assertSession()->linkNotExists('foobarbaz');
57
58     // Create a node, and make sure it shows up on admin/content.
59     $node = $this->createNode([
60       'title' => 'FooBarBaz',
61       'type' => 'page',
62     ]);
63
64     $this->drupalGet('admin/content', [
65       'query' => [
66         'title' => 'FooBarBaz',
67       ],
68     ]);
69
70     $this->assertSession()->linkExists('FooBarBaz');
71     $this->assertSession()->linkByHrefExists($node->toUrl()->toString());
72
73     // Make sure the path is case-insensitive, and query case is preserved.
74
75     $this->drupalGet('Admin/Content', [
76       'query' => [
77         'title' => 'FooBarBaz',
78       ],
79     ]);
80
81     $this->assertSession()->linkExists('FooBarBaz');
82     $this->assertSession()->linkByHrefExists($node->toUrl()->toString());
83     $this->assertSession()->fieldValueEquals('edit-title', 'FooBarBaz');
84     // Check that we can access the node with a mixed case path.
85     $this->drupalGet('NOdE/' . $node->id());
86     $this->assertSession()->statusCodeEquals(200);
87     $this->assertSession()->pageTextMatches('/FooBarBaz/');
88   }
89
90   /**
91    * Tests paths with slugs.
92    */
93   public function testPathsWithArguments() {
94     $this->drupalGet('system-test/echo/foobarbaz');
95     $this->assertSession()->statusCodeEquals(200);
96     $this->assertSession()->pageTextMatches('/foobarbaz/');
97     $this->assertSession()->pageTextNotMatches('/FooBarBaz/');
98
99     $this->drupalGet('system-test/echo/FooBarBaz');
100     $this->assertSession()->statusCodeEquals(200);
101     $this->assertSession()->pageTextMatches('/FooBarBaz/');
102     $this->assertSession()->pageTextNotMatches('/foobarbaz/');
103
104     // Test utf-8 characters in the route path.
105     $this->drupalGet('/system-test/Ȅchȏ/meΦω/ABc123');
106     $this->assertSession()->statusCodeEquals(200);
107     $this->assertSession()->pageTextMatches('/ABc123/');
108     $this->drupalGet('/system-test/ȅchȎ/MEΦΩ/ABc123');
109     $this->assertSession()->statusCodeEquals(200);
110     $this->assertSession()->pageTextMatches('/ABc123/');
111   }
112
113 }