CaseInsensitivePathTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 function setUp() {
  18. parent::setUp();
  19. \Drupal::state()->set('system_test.module_hidden', FALSE);
  20. $this->createContentType(['type' => 'page']);
  21. }
  22. /**
  23. * Tests mixed case paths.
  24. */
  25. public function testMixedCasePaths() {
  26. // Tests paths defined by routes from standard modules as anonymous.
  27. $this->drupalGet('user/login');
  28. $this->assertSession()->statusCodeEquals(200);
  29. $this->assertSession()->pageTextMatches('/Log in/');
  30. $this->drupalGet('User/Login');
  31. $this->assertSession()->statusCodeEquals(200);
  32. $this->assertSession()->pageTextMatches('/Log in/');
  33. // Tests paths defined by routes from the Views module.
  34. $admin = $this->drupalCreateUser(['access administration pages', 'administer nodes', 'access content overview']);
  35. $this->drupalLogin($admin);
  36. $this->drupalGet('admin/content');
  37. $this->assertSession()->statusCodeEquals(200);
  38. $this->assertSession()->pageTextMatches('/Content/');
  39. $this->drupalGet('Admin/Content');
  40. $this->assertSession()->statusCodeEquals(200);
  41. $this->assertSession()->pageTextMatches('/Content/');
  42. // Tests paths with query arguments.
  43. // Make sure our node title doesn't exist.
  44. $this->drupalGet('admin/content');
  45. $this->assertSession()->linkNotExists('FooBarBaz');
  46. $this->assertSession()->linkNotExists('foobarbaz');
  47. // Create a node, and make sure it shows up on admin/content.
  48. $node = $this->createNode([
  49. 'title' => 'FooBarBaz',
  50. 'type' => 'page',
  51. ]);
  52. $this->drupalGet('admin/content', [
  53. 'query' => [
  54. 'title' => 'FooBarBaz'
  55. ]
  56. ]);
  57. $this->assertSession()->linkExists('FooBarBaz');
  58. $this->assertSession()->linkByHrefExists($node->toUrl()->toString());
  59. // Make sure the path is case-insensitive, and query case is preserved.
  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. $this->assertSession()->fieldValueEquals('edit-title', 'FooBarBaz');
  68. // Check that we can access the node with a mixed case path.
  69. $this->drupalGet('NOdE/' . $node->id());
  70. $this->assertSession()->statusCodeEquals(200);
  71. $this->assertSession()->pageTextMatches('/FooBarBaz/');
  72. }
  73. /**
  74. * Tests paths with slugs.
  75. */
  76. public function testPathsWithArguments() {
  77. $this->drupalGet('system-test/echo/foobarbaz');
  78. $this->assertSession()->statusCodeEquals(200);
  79. $this->assertSession()->pageTextMatches('/foobarbaz/');
  80. $this->assertSession()->pageTextNotMatches('/FooBarBaz/');
  81. $this->drupalGet('system-test/echo/FooBarBaz');
  82. $this->assertSession()->statusCodeEquals(200);
  83. $this->assertSession()->pageTextMatches('/FooBarBaz/');
  84. $this->assertSession()->pageTextNotMatches('/foobarbaz/');
  85. // Test utf-8 characters in the route path.
  86. $this->drupalGet('/system-test/Ȅchȏ/meΦω/ABc123');
  87. $this->assertSession()->statusCodeEquals(200);
  88. $this->assertSession()->pageTextMatches('/ABc123/');
  89. $this->drupalGet('/system-test/ȅchȎ/MEΦΩ/ABc123');
  90. $this->assertSession()->statusCodeEquals(200);
  91. $this->assertSession()->pageTextMatches('/ABc123/');
  92. }
  93. }