3 namespace Drupal\FunctionalTests\Routing;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests incoming path case insensitivity.
12 class CaseInsensitivePathTest extends BrowserTestBase {
17 public static $modules = ['system', 'views', 'node', 'system_test'];
22 protected function setUp() {
24 \Drupal::state()->set('system_test.module_hidden', FALSE);
25 $this->createContentType(['type' => 'page']);
29 * Tests mixed case paths.
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/');
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);
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/');
51 // Tests paths with query arguments.
53 // Make sure our node title doesn't exist.
54 $this->drupalGet('admin/content');
55 $this->assertSession()->linkNotExists('FooBarBaz');
56 $this->assertSession()->linkNotExists('foobarbaz');
58 // Create a node, and make sure it shows up on admin/content.
59 $node = $this->createNode([
60 'title' => 'FooBarBaz',
64 $this->drupalGet('admin/content', [
66 'title' => 'FooBarBaz',
70 $this->assertSession()->linkExists('FooBarBaz');
71 $this->assertSession()->linkByHrefExists($node->toUrl()->toString());
73 // Make sure the path is case-insensitive, and query case is preserved.
75 $this->drupalGet('Admin/Content', [
77 'title' => 'FooBarBaz',
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/');
91 * Tests paths with slugs.
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/');
99 $this->drupalGet('system-test/echo/FooBarBaz');
100 $this->assertSession()->statusCodeEquals(200);
101 $this->assertSession()->pageTextMatches('/FooBarBaz/');
102 $this->assertSession()->pageTextNotMatches('/foobarbaz/');
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/');