Chris@14: adminUser = $this->drupalCreateUser(['administer blocks', 'administer languages', 'access administration pages']); Chris@14: $this->drupalLogin($this->adminUser); Chris@14: Chris@14: // Add language. Chris@14: ConfigurableLanguage::createFromLangcode('fr')->save(); Chris@14: Chris@14: // Enable session language detection and selection. Chris@14: $edit = [ Chris@14: 'language_interface[enabled][language-url]' => FALSE, Chris@14: 'language_interface[enabled][language-session]' => TRUE, Chris@14: ]; Chris@14: $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); Chris@14: Chris@14: // A more common scenario is domain-based negotiation but that can not be Chris@14: // tested. Session negotiation by default is not considered by the URL Chris@14: // language type that is used to resolve the alias. Explicitly enable Chris@14: // that to be able to test this scenario. Chris@14: // @todo Improve in https://www.drupal.org/project/drupal/issues/1125428. Chris@14: $this->config('language.types') Chris@14: ->set('negotiation.language_url.enabled', ['language-session' => 0]) Chris@14: ->save(); Chris@14: Chris@14: // Enable the language switching block. Chris@14: $this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, [ Chris@14: 'id' => 'test_language_block', Chris@14: ]); Chris@14: Chris@14: } Chris@14: Chris@14: /** Chris@14: * Tests aliases when the negotiated language is not in the path. Chris@14: */ Chris@14: public function testAliases() { Chris@14: // Switch to French and try to access the now inaccessible block. Chris@14: $this->drupalGet(''); Chris@14: Chris@14: // Create an alias for user/UID just for en, make sure that this is a 404 Chris@14: // on the french page exist in english, no matter which language is Chris@14: // checked first. Create the alias after visiting frontpage to make sure Chris@14: // there is no existing cache entry for this that affects the tests. Chris@14: \Drupal::service('path.alias_storage')->save('/user/' . $this->adminUser->id(), '/user-page', 'en'); Chris@14: Chris@14: $this->clickLink('French'); Chris@14: $this->drupalGet('user-page'); Chris@14: $this->assertSession()->statusCodeEquals(404); Chris@14: Chris@14: // Switch to english, make sure it works now. Chris@14: $this->clickLink('English'); Chris@14: $this->drupalGet('user-page'); Chris@14: $this->assertSession()->statusCodeEquals(200); Chris@14: Chris@14: // Clear cache and repeat the check, this time with english first. Chris@14: $this->resetAll(); Chris@14: $this->drupalGet('user-page'); Chris@14: $this->assertSession()->statusCodeEquals(200); Chris@14: Chris@14: $this->clickLink('French'); Chris@14: $this->drupalGet('user-page'); Chris@14: $this->assertSession()->statusCodeEquals(404); Chris@14: } Chris@14: Chris@14: }