You are here

public function BlockLanguageTest::testLanguageBlockVisibility in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/block/tests/src/Functional/BlockLanguageTest.php \Drupal\Tests\block\Functional\BlockLanguageTest::testLanguageBlockVisibility()
  2. 9 core/modules/block/tests/src/Functional/BlockLanguageTest.php \Drupal\Tests\block\Functional\BlockLanguageTest::testLanguageBlockVisibility()

Tests the visibility settings for the blocks based on language.

File

core/modules/block/tests/src/Functional/BlockLanguageTest.php, line 68

Class

BlockLanguageTest
Tests if a block can be configured to be only visible on a particular language.

Namespace

Drupal\Tests\block\Functional

Code

public function testLanguageBlockVisibility() {

  // Check if the visibility setting is available.
  $default_theme = $this
    ->config('system.theme')
    ->get('default');
  $this
    ->drupalGet('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme);

  // Ensure that the language visibility field is visible without a type
  // setting.
  $this
    ->assertSession()
    ->fieldExists('visibility[language][langcodes][en]');
  $this
    ->assertSession()
    ->fieldNotExists('visibility[language][context_mapping][language]');

  // Enable a standard block and set the visibility setting for one language.
  $edit = [
    'visibility[language][langcodes][en]' => TRUE,
    'id' => strtolower($this
      ->randomMachineName(8)),
    'region' => 'sidebar_first',
  ];
  $this
    ->drupalGet('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme);
  $this
    ->submitForm($edit, 'Save block');

  // Change the default language.
  $edit = [
    'site_default_language' => 'fr',
  ];
  $this
    ->drupalGet('admin/config/regional/language');
  $this
    ->submitForm($edit, 'Save configuration');

  // Check that a page has a block.
  $this
    ->drupalGet('en');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('Powered by Drupal');

  // Check that a page doesn't has a block for the current language anymore.
  $this
    ->drupalGet('fr');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextNotContains('Powered by Drupal');
}