CaseInsensitivePathTest.php 3.7 KB

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