function LanguageSwitchingTest::testLanguageBlock

Functional tests for the language switcher block.

File

core/modules/language/tests/src/Functional/LanguageSwitchingTest.php, line 64

Class

LanguageSwitchingTest
Functional tests for the language switching feature.

Namespace

Drupal\Tests\language\Functional

Code

public function testLanguageBlock() : void {
  // Add language.
  $edit = [
    'predefined_langcode' => 'fr',
  ];
  $this->drupalGet('admin/config/regional/language/add');
  $this->submitForm($edit, 'Add language');
  // Set the native language name.
  $this->saveNativeLanguageName('fr', 'français');
  // Enable URL language detection and selection.
  $edit = [
    'language_interface[enabled][language-url]' => '1',
  ];
  $this->drupalGet('admin/config/regional/language/detection');
  $this->submitForm($edit, 'Save settings');
  // Enable the language switching block.
  $block = $this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, [
    'id' => 'test_language_block',
    // Ensure a 2-byte UTF-8 sequence is in the tested output.
'label' => $this->randomMachineName(8) . '×',
  ]);
  $this->doTestLanguageBlockAuthenticated($block->label());
  $this->doTestHomePageLinks($block->label());
  $this->doTestLanguageBlockAnonymous($block->label());
  $this->doTestLanguageBlock404($block->label(), 'system/404');
  // Confirm that enabling big_pipe doesn't change the behavior of the block.
  // Note that this is the case because the language switcher block deny lists
  // the big_pipe placeholder strategy, otherwise it would be subject to the
  // bug described in https://www.drupal.org/project/drupal/issues/3349201
  \Drupal::service('module_installer')->install([
    'big_pipe',
  ]);
  $this->rebuildAll();
  $this->doTestLanguageBlock404($block->label(), 'system/404');
  $this->drupalLogin($this->drupalCreateUser());
  $this->doTestLanguageBlock404($block->label(), 'system/404');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.