You are here

public function RouteCachingNonPathLanguageNegotiationTest::testAliases in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalTests/Routing/RouteCachingNonPathLanguageNegotiationTest.php \Drupal\FunctionalTests\Routing\RouteCachingNonPathLanguageNegotiationTest::testAliases()

Tests aliases when the negotiated language is not in the path.

File

core/tests/Drupal/FunctionalTests/Routing/RouteCachingNonPathLanguageNegotiationTest.php, line 79

Class

RouteCachingNonPathLanguageNegotiationTest
Tests the route cache when the language is not in the path.

Namespace

Drupal\FunctionalTests\Routing

Code

public function testAliases() {

  // Switch to French and try to access the now inaccessible block.
  $this
    ->drupalGet('');

  // Create an alias for user/UID just for en, make sure that this is a 404
  // on the french page exist in english, no matter which language is
  // checked first. Create the alias after visiting frontpage to make sure
  // there is no existing cache entry for this that affects the tests.
  $this
    ->createPathAlias('/user/' . $this->adminUser
    ->id(), '/user-page', 'en');
  $this
    ->clickLink('French');
  $this
    ->drupalGet('user-page');
  $this
    ->assertSession()
    ->statusCodeEquals(404);

  // Switch to english, make sure it works now.
  $this
    ->clickLink('English');
  $this
    ->drupalGet('user-page');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Clear cache and repeat the check, this time with english first.
  $this
    ->resetAll();
  $this
    ->drupalGet('user-page');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->clickLink('French');
  $this
    ->drupalGet('user-page');
  $this
    ->assertSession()
    ->statusCodeEquals(404);
}