You are here

public function CaseInsensitivePathTest::testMixedCasePaths in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalTests/Routing/CaseInsensitivePathTest.php \Drupal\FunctionalTests\Routing\CaseInsensitivePathTest::testMixedCasePaths()
  2. 10 core/tests/Drupal/FunctionalTests/Routing/CaseInsensitivePathTest.php \Drupal\FunctionalTests\Routing\CaseInsensitivePathTest::testMixedCasePaths()

Tests mixed case paths.

File

core/tests/Drupal/FunctionalTests/Routing/CaseInsensitivePathTest.php, line 36

Class

CaseInsensitivePathTest
Tests incoming path case insensitivity.

Namespace

Drupal\FunctionalTests\Routing

Code

public function testMixedCasePaths() {

  // Tests paths defined by routes from standard modules as anonymous.
  $this
    ->drupalGet('user/login');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextMatches('/Log in/');
  $this
    ->drupalGet('User/Login');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextMatches('/Log in/');

  // Tests paths defined by routes from the Views module.
  $admin = $this
    ->drupalCreateUser([
    'access administration pages',
    'administer nodes',
    'access content overview',
  ]);
  $this
    ->drupalLogin($admin);
  $this
    ->drupalGet('admin/content');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextMatches('/Content/');
  $this
    ->drupalGet('Admin/Content');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextMatches('/Content/');

  // Tests paths with query arguments.
  // Make sure our node title doesn't exist.
  $this
    ->drupalGet('admin/content');
  $this
    ->assertSession()
    ->linkNotExists('FooBarBaz');
  $this
    ->assertSession()
    ->linkNotExists('foobarbaz');

  // Create a node, and make sure it shows up on admin/content.
  $node = $this
    ->createNode([
    'title' => 'FooBarBaz',
    'type' => 'page',
  ]);
  $this
    ->drupalGet('admin/content', [
    'query' => [
      'title' => 'FooBarBaz',
    ],
  ]);
  $this
    ->assertSession()
    ->linkExists('FooBarBaz');
  $this
    ->assertSession()
    ->linkByHrefExists($node
    ->toUrl()
    ->toString());

  // Make sure the path is case-insensitive, and query case is preserved.
  $this
    ->drupalGet('Admin/Content', [
    'query' => [
      'title' => 'FooBarBaz',
    ],
  ]);
  $this
    ->assertSession()
    ->linkExists('FooBarBaz');
  $this
    ->assertSession()
    ->linkByHrefExists($node
    ->toUrl()
    ->toString());
  $this
    ->assertSession()
    ->fieldValueEquals('edit-title', 'FooBarBaz');

  // Check that we can access the node with a mixed case path.
  $this
    ->drupalGet('NOdE/' . $node
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextMatches('/FooBarBaz/');
}